Class JdbcMultiWriter
Writes records to a database table using 1 or more connections; each connection writing asynchronously using a separate thread.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionJdbcMultiWriter(JdbcConnectionFactory factory, int connections, int maxQueuedRecordsPerConnection, String tableName) Creates a writer usingPreparedStatementInsertthat obtains its connections from the factory when opened.JdbcMultiWriter(JdbcConnectionFactory factory, int connections, int maxQueuedRecordsPerConnection, String tableName, IInsert insert) Creates a writer that obtains its connections from the factory when opened.JdbcMultiWriter(DataSource dataSource, int connections, int maxQueuedRecordsPerConnection, String tableName) Creates a writer usingPreparedStatementInsertthat obtains its connections from the data source when opened.JdbcMultiWriter(DataSource dataSource, int connections, int maxQueuedRecordsPerConnection, String tableName, IInsert insert) Creates a writer that obtains its connections from the data source when opened. -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.protected JdbcWritercreateJdbcWriter(Connection connection, String tableName, IInsert insertStrategy) Creates the writer for a connection obtained inopen(); the default copies this writer's settings and makes the new writer close the connection.getAsyncWriter(int index) Returns the asynchronous writer feeding the connection at the 0-based index ornullbeforeopen().intReturns the number of records to chunk together in batch updates; 1 or less (the default is -1) disables batching.intReturns the number of connections, each written to by its own thread.Returns an exception thrown by one of the internal AsyncWriters if any.Returns all exceptions thrown by the internal AsyncWriters (the list will not be null, but may contain no elements).Returns the insert strategy; each connection's writer uses its own clone.getJdbcType(Class<?> type) TheTypesconstant (or a database specific value) assigned to the specified Java class type usingsetJdbcType(Class, int)or null if none was set.getJdbcWriter(int index) Returns the writer for the connection at the 0-based index ornullbeforeopen().booleanIndicates if this writer should call commit on each connection after every batch is sent, otherwise, commit is called after the final batch update (default is false).booleanisDebug()Indicates if the generated SQL should be logged (default false).voidopen()Makes this endpoint ready for reading or writing.voidRe-throws an exception thrown by one of the internal AsyncWriters or returns silently if no exceptions were thrown.setBatchSize(int batchSize) Sets the number of records to chunk together in batch updates.setCommitBatch(boolean commitBatch) Indicates if this writer should call commit on each connection after every batch is sent, otherwise, commit is called after the final batch update (default is false).setDebug(boolean debug) Indicates if the generated SQL should be logged (default false).setJdbcType(Class<?> type, int jdbcType) Forces field values of the specified Java class type to be sent to the database usingPreparedStatement.setObject(parameterIndex, fieldValue, jdbcType)(instead of the appropriatePreparedStatement.setXXX()method for its field's type).setJdbcType(String fieldName, int jdbcType) The given Java object will be converted to the given targetSqlType before being sent to the database.protected voidOverridden by subclasses to write the specified record to thisDataWriter.Methods inherited from class com.northconcepts.datapipeline.core.ProxyWriter
available, close, getNestedWriter, interceptRecord, map, map, setNestedDataWriter, setNestedDataWriterMethods inherited from class com.northconcepts.datapipeline.core.DataWriter
getNestedEndpoint, getRootEndpoint, getRootWriter, getWriter, writeMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Constructor Details
-
JdbcMultiWriter
public JdbcMultiWriter(DataSource dataSource, int connections, int maxQueuedRecordsPerConnection, String tableName, IInsert insert) Creates a writer that obtains its connections from the data source when opened. -
JdbcMultiWriter
public JdbcMultiWriter(DataSource dataSource, int connections, int maxQueuedRecordsPerConnection, String tableName) Creates a writer usingPreparedStatementInsertthat obtains its connections from the data source when opened. -
JdbcMultiWriter
public JdbcMultiWriter(JdbcConnectionFactory factory, int connections, int maxQueuedRecordsPerConnection, String tableName, IInsert insert) throws DataException Creates a writer that obtains its connections from the factory when opened.- Throws:
DataException
-
JdbcMultiWriter
public JdbcMultiWriter(JdbcConnectionFactory factory, int connections, int maxQueuedRecordsPerConnection, String tableName) throws DataException Creates a writer usingPreparedStatementInsertthat obtains its connections from the factory when opened.- Throws:
DataException
-
-
Method Details
-
getConnections
public int getConnections()Returns the number of connections, each written to by its own thread. -
getJdbcWriter
Returns the writer for the connection at the 0-based index ornullbeforeopen(). -
getAsyncWriter
Returns the asynchronous writer feeding the connection at the 0-based index ornullbeforeopen(). -
getBatchSize
public int getBatchSize()Returns the number of records to chunk together in batch updates; 1 or less (the default is -1) disables batching. -
setBatchSize
Sets the number of records to chunk together in batch updates. Updates are not batched if this value is 1 or less. JdbcWriter defaults to non batching updates. -
isCommitBatch
public boolean isCommitBatch()Indicates if this writer should call commit on each connection after every batch is sent, otherwise, commit is called after the final batch update (default is false). -
setCommitBatch
Indicates if this writer should call commit on each connection after every batch is sent, otherwise, commit is called after the final batch update (default is false). -
getInsert
Returns the insert strategy; each connection's writer uses its own clone. -
setJdbcType
The given Java object will be converted to the given targetSqlType before being sent to the database.
Note that this method may be used to pass database-specific abstract data types.
- Parameters:
fieldName-jdbcType- the object containing the JDBC Type parameter value
-
setJdbcType
Forces field values of the specified Java class type to be sent to the database usingPreparedStatement.setObject(parameterIndex, fieldValue, jdbcType)(instead of the appropriatePreparedStatement.setXXX()method for its field's type). This method may be used to pass database-specific abstract data types.- Parameters:
type- the Java class type to override.jdbcType- one of theTypesconstants or a database specific value.
-
getJdbcType
TheTypesconstant (or a database specific value) assigned to the specified Java class type usingsetJdbcType(Class, int)or null if none was set.- Returns:
- one of the
Typesconstants or a database specific value.
-
isDebug
public boolean isDebug()Indicates if the generated SQL should be logged (default false). -
setDebug
Indicates if the generated SQL should be logged (default false). -
open
Description copied from class:DataEndpointMakes this endpoint ready for reading or writing.- Overrides:
openin classProxyWriter- Throws:
DataException
-
createJdbcWriter
protected JdbcWriter createJdbcWriter(Connection connection, String tableName, IInsert insertStrategy) Creates the writer for a connection obtained inopen(); the default copies this writer's settings and makes the new writer close the connection. -
writeImpl
Description copied from class:DataWriterOverridden by subclasses to write the specified record to thisDataWriter.Contract for subclasses (see also
docs/authoring/DataWriter.md):- Do not call this method directly —
DataWriter.write(Record)is the template method that wraps exceptions, increments the record count, and attaches the offending record to thrownDataExceptions. - Do not call
DataEndpoint.incrementRecordCount()here;DataWriter.write(Record)already does. - Throw raw exceptions;
DataWriter.write(Record)wraps them viaexception(throwable).setRecord(record).
- Overrides:
writeImplin classProxyWriter- Throws:
Throwable
- Do not call this method directly —
-
getException
Returns an exception thrown by one of the internal AsyncWriters if any. -
getExceptions
Returns all exceptions thrown by the internal AsyncWriters (the list will not be null, but may contain no elements). -
rethrowAsyncException
Re-throws an exception thrown by one of the internal AsyncWriters or returns silently if no exceptions were thrown.- Throws:
DataException
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classProxyWriter
-