Package com.adaptris.csv.jdbc
Class BatchInsertCSV
java.lang.Object
com.adaptris.core.ServiceImp
com.adaptris.core.jdbc.JdbcService
com.adaptris.core.services.jdbc.JdbcMapInsert
com.adaptris.csv.jdbc.BatchInsertCSV
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,ConfigComment,ConnectedService,MessageEventGenerator,Service,StateManagedComponent
@ComponentProfile(summary="Insert a CSV file into a database",
tag="service,csv,jdbc",
since="3.6.5")
public class BatchInsertCSV
extends JdbcMapInsert
Convenience service for inserting a CSV file into a database.
This creates insert statements based on the CSV file. The actual insert statement will only be generated once based on the first CSV line and executed the appropriate number of times.
firstname, lastname, dob
alice, bob, 2017-01-01
bob, smith, 2017-01-01
carol, smith,2017-01-01
will effectively execute the following statement INSERT INTO table (firstname,lastname,dob) VALUES (?,?,?) 3
times; batching as required using PreparedStatement.addBatch() / Statement.executeBatch().
Note that no parsing/assertion of the column names will be done, so if they are invalid SQL columns then it's going to be fail.
- Since:
- 3.6.5
In the adapter configuration file this class is aliased as csv-jdbc-batch-insert which is the preferred alternative to the fully qualified classname when building your configuration.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.adaptris.core.services.jdbc.JdbcMapInsert
JdbcMapInsert.BasicType, JdbcMapInsert.InsertWrapper, JdbcMapInsert.StatementParam, JdbcMapInsert.StatementWrapper -
Field Summary
FieldsFields inherited from class com.adaptris.core.ServiceImp
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static intaccumulate(int[] rc) voiddoService(AdaptrisMessage msg) voidSet the batch window for operations.voidsetPreferenceBuilder(PreferenceBuilder formatBuilder) Methods inherited from class com.adaptris.core.services.jdbc.JdbcMapInsert
addUpdatedMetadata, buildStatementParam, closeJdbcService, columnBookend, getColumnBookendCharacter, getFieldMappings, getRowsAffectedMetadataKey, getTable, handleInsert, initJdbcService, prepareService, setColumnBookendCharacter, setFieldMappings, setRowsAffectedMetadataKey, setTable, startService, stopService, table, withColumnBookend, withMappings, withRowsAffectedMetadataKey, withTableMethods inherited from class com.adaptris.core.jdbc.JdbcService
applyTimeout, closeService, createStatement, getConnection, getConnection, getStatementTimeout, initService, prepare, prepareStatement, prepareStatement, setConnection, setStatementTimeout, start, stopMethods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, enabled, getComments, getContinueOnFail, getEnabled, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setComments, setContinueOnFail, setEnabled, setIsTrackingEndpoint, setUniqueIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.adaptris.core.AdaptrisComponent
getUniqueIdMethods inherited from interface com.adaptris.core.ComponentLifecycle
close, initMethods inherited from interface com.adaptris.core.ConfigComment
getComments, setCommentsMethods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpointMethods inherited from interface com.adaptris.core.Service
continueOnFailure, enabled, isBranching, setUniqueIdMethods inherited from interface com.adaptris.core.StateManagedComponent
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
-
Field Details
-
DEFAULT_BATCH_WINDOW
public static final int DEFAULT_BATCH_WINDOW- See Also:
-
-
Constructor Details
-
BatchInsertCSV
public BatchInsertCSV()
-
-
Method Details
-
getPreferenceBuilder
- Returns:
- the formatBuilder
-
setPreferenceBuilder
- Parameters:
formatBuilder- the formatBuilder to set
-
doService
- Throws:
ServiceException
-
accumulate
- Throws:
SQLException
-
getBatchWindow
- Returns:
- the batchWindow
-
setBatchWindow
Set the batch window for operations.- Parameters:
i- the batchWindow to set; default is 1024 if not specified.
-