public abstract class BaseDatabaseListener extends BaseListener
| Modifier and Type | Field and Description | 
|---|---|
protected List<Object[]> | 
batch
List for holding a batch until pageSize is reached and the batch is committed. 
 | 
protected int | 
batchSize
Batch size before doing a commit. 
 | 
protected Connection | 
conn
The database connection. 
 | 
protected DatabaseConnectionInformation | 
databaseConnectionInformation
The database connection information. 
 | 
protected org.apache.log4j.Logger | 
LOG
Logging object of output. 
 | 
protected String | 
preparedStatementSQL
The insert statement sql. 
 | 
protected PreparedStatement | 
ps
The prepared statement for inserting a record. 
 | 
protected boolean | 
validateConnectionEachBatch
If true, the connection is validated before committing each batch. 
 | 
annotationTypeFilter, docInfo, exitOnError, inputType, lastException, logErrors, mOutputDir, numReceived, numSent, previousReferenceId, referenceID| Constructor and Description | 
|---|
BaseDatabaseListener(DatabaseConnectionInformation databaseConnectionInformation,
                    String preparedStatementSQL)
Base gov.va.vinci.leo.listener. 
 | 
BaseDatabaseListener(DatabaseConnectionInformation databaseConnectionInformation,
                    String databaseName,
                    String databaseTable,
                    List<DatabaseField> fieldList)
Constructor for using a fieldList. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
collectionProcessComplete(org.apache.uima.collection.EntityProcessStatus aStatus)  | 
protected String | 
createCreateStatement(String dbsName,
                     String tableName,
                     List<DatabaseField> fieldList)
Protected method to build a create table statement. 
 | 
protected String | 
createPreparedStatementSQL(String databaseName,
                          String tableName,
                          List<DatabaseField> fields)
Creates an insert sql statement for the list of fields. 
 | 
void | 
createTable(boolean dropFirst,
           String dbsName,
           String tableName,
           List<DatabaseField> fieldList)
Creates the table structure. 
 | 
void | 
createTable(boolean dropFirst,
           String dbsName,
           String tableName,
           Map<String,String> fieldList)
Creates the table structure. 
 | 
void | 
createTable(String createStatement,
           boolean dropFirst,
           String tableName)
Creates the table structure. 
 | 
void | 
entityProcessComplete(org.apache.uima.cas.CAS aCas,
                     org.apache.uima.collection.EntityProcessStatus aStatus)  | 
int | 
getBatchSize()
Get the batch size for the number of records to accumulate before executing the batch. 
 | 
protected abstract List<Object[]> | 
getRows(org.apache.uima.cas.CAS aCas)
Abstract method: You must implement this method. 
 | 
boolean | 
isValidateConnectionEachBatch()
Return true if the connection will be validated when executing each batch. 
 | 
protected void | 
processBatch()
This is called when a batch is ready to be send to the database. 
 | 
<T extends BaseDatabaseListener> | 
setBatchSize(int batchSize)
Set the batch size for the number of records to accumulate before executing the batch. 
 | 
<T extends BaseDatabaseListener> | 
setValidateConnectionEachBatch(boolean validateConnectionEachBatch)
Set the flag that if true will cause the connection to be validated when executing each batch. 
 | 
protected void | 
validateConnection()
Method to validate the connection is not null, and if specified, run the validation query against the database. 
 | 
checkForError, entityProcessError, getAnnotationTypeFilter, getInputType, getInputTypesList, getNumReceived, getNumSent, getOutputDir, getReferenceLocation, hasAnnotationsToProcess, hasFilteredAnnotation, initializationComplete, isExitOnError, isLogErrors, onBeforeMessageSend, setAnnotationTypeFilter, setExitOnError, setInputType, setLogErrors, setOutputDirprotected Connection conn
protected PreparedStatement ps
protected DatabaseConnectionInformation databaseConnectionInformation
protected boolean validateConnectionEachBatch
protected String preparedStatementSQL
protected int batchSize
protected List<Object[]> batch
protected org.apache.log4j.Logger LOG
public BaseDatabaseListener(DatabaseConnectionInformation databaseConnectionInformation, String databaseName, String databaseTable, List<DatabaseField> fieldList)
databaseConnectionInformation - information on the database to connect todatabaseName - The database name. This is prepended to the table in the insert statement.databaseTable - The database table fieldList belongs to.fieldList - The fields that will be inserted to from this listener.public BaseDatabaseListener(DatabaseConnectionInformation databaseConnectionInformation, String preparedStatementSQL)
databaseConnectionInformation - information on the database to connect topreparedStatementSQL - the prepared statement to use for inserts. For example: insert into myTable ( col1, col2, col2) values (?, ?, ?)public boolean isValidateConnectionEachBatch()
public <T extends BaseDatabaseListener> T setValidateConnectionEachBatch(boolean validateConnectionEachBatch)
validateConnectionEachBatch - validate connection batch flag valuepublic int getBatchSize()
public <T extends BaseDatabaseListener> T setBatchSize(int batchSize)
batchSize - batch sizeprotected abstract List<Object[]> getRows(org.apache.uima.cas.CAS aCas)
aCas - the currently processed CASpublic void entityProcessComplete(org.apache.uima.cas.CAS aCas,
                                  org.apache.uima.collection.EntityProcessStatus aStatus)
entityProcessComplete in interface org.apache.uima.aae.client.UimaASStatusCallbackListenerentityProcessComplete in class BaseListeneraCas - the CAS containing the processed entity and the analysis resultsaStatus - the status of the processing. This object contains a record of any Exception that occurred, as well as timing information.UimaAsBaseCallbackListener.entityProcessComplete(org.apache.uima.cas.CAS, org.apache.uima.collection.EntityProcessStatus)protected void processBatch()
                     throws SQLException,
                            InstantiationException,
                            IllegalAccessException,
                            ClassNotFoundException
ClassNotFoundException - thrown if the JDBC driver cannot be found.IllegalAccessException - thrown if any of the reflection calls throw an exception.SQLException - thrown if  there is an SQL Exception accessing the database.InstantiationException - thrown if the JDBC driver cannot be instantiated.public void collectionProcessComplete(org.apache.uima.collection.EntityProcessStatus aStatus)
collectionProcessComplete in interface org.apache.uima.aae.client.UimaASStatusCallbackListenercollectionProcessComplete in class BaseListeneraStatus - the status of the processing. This object contains a record of any Exception that occurred, as well as timing information.UimaAsBaseCallbackListener.collectionProcessComplete(org.apache.uima.collection.EntityProcessStatus)protected void validateConnection()
                           throws SQLException,
                                  InstantiationException,
                                  IllegalAccessException,
                                  ClassNotFoundException
ClassNotFoundException - thrown if the JDBC driver cannot be found.IllegalAccessException - thrown if any of the reflection calls throw an exception.SQLException - thrown if  there is an SQL Exception accessing the database.InstantiationException - thrown if the JDBC driver cannot be instantiated.public void createTable(String createStatement, boolean dropFirst, String tableName) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException
createStatement - The sql create statement.dropFirst - If drop, the table is dropped before creation.tableName - The resulting table name.ClassNotFoundException - if the driver class is not in the classpath.SQLException - if there is an error executing the SQL to drop or create the table.InstantiationException - if there is an error creating the connectionIllegalAccessException - if there is an error executing the query due to insufficient rights or the database cannot be reached.public void createTable(boolean dropFirst,
                        String dbsName,
                        String tableName,
                        Map<String,String> fieldList)
                 throws ClassNotFoundException,
                        SQLException,
                        InstantiationException,
                        IllegalAccessException
dropFirst - If drop, the table is dropped before creation.dbsName - The database name (needed by some databases for the create statement)tableName - The resulting table namefieldList - A map of column names (key) and types (value) for example "id", "varchar(20)"ClassNotFoundException - if the driver class is not in the classpath.SQLException - if there is an error executing the SQL to drop or create the table.InstantiationException - if there is an error creating the connectionIllegalAccessException - if there is an error executing the query due to insufficient rights or the database cannot be reached.public void createTable(boolean dropFirst,
                        String dbsName,
                        String tableName,
                        List<DatabaseField> fieldList)
                 throws ClassNotFoundException,
                        SQLException,
                        InstantiationException,
                        IllegalAccessException
dropFirst - If drop, the table is dropped before creation.dbsName - The database name (needed by some databases for the create statement)tableName - The resulting table namefieldList - A map of column names (key) and types (value) for example "id", "varchar(20)"ClassNotFoundException - if the driver class is not in the classpath.SQLException - if there is an error executing the SQL to drop or create the table.InstantiationException - if there is an error creating the connectionIllegalAccessException - if there is an error executing the query due to insufficient rights or the database cannot be reached.protected String createCreateStatement(String dbsName, String tableName, List<DatabaseField> fieldList)
dbsName - the database name if needed.tableName - the table name.fieldList - A map of column names (key) and types (value) for example "id", "varchar(20)"protected String createPreparedStatementSQL(String databaseName, String tableName, List<DatabaseField> fields)
fields - the field list to create the insert statement for.Copyright © 2018 Department of Veterans Affairs. All Rights Reserved.