public class JdbcWriter extends DataWriter
DataEndpoint.State
Modifier and Type | Field and Description |
---|---|
protected Record |
currentRecord |
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEY
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZE
id, log, name, TIMESTAMP_FORMAT
Constructor and Description |
---|
JdbcWriter(Connection connection,
String tableName)
Creates a new instance with the
autoCloseConnection property set to false . |
JdbcWriter(Connection connection,
String tableName,
IInsert insert)
Creates a new instance with the
autoCloseConnection property set to false . |
JdbcWriter(JdbcConnectionFactory factory,
String tableName)
Creates a new instance with the
autoCloseConnection property set to true . |
JdbcWriter(JdbcConnectionFactory factory,
String tableName,
IInsert insert)
Creates a new instance with the
autoCloseConnection property set to true . |
Modifier and Type | Method and Description |
---|---|
DataException |
addExceptionProperties(DataException exception)
Adds this endpoint's current state to a
DataException . |
void |
close()
Indicates that this endpoint has finished reading or writing.
|
boolean |
getAutoCloseConnection()
Indicates if the database connection in this endpoint should be closed when the endpoint is closed.
|
int |
getBatchSize() |
Connection |
getConnection() |
IInsert |
getInsert() |
Integer |
getJdbcType(Class<?> type)
The
Types constant (or a database specific value) assigned to the specified Java class type using setJdbcType(Class, int) or null if none was set. |
Integer |
getJdbcType(String fieldName)
The
Types constant (or a database specific value) assigned to the specified field using setJdbcType(String, int) or null if none was set. |
String |
getTableName() |
boolean |
isBatchMode() |
boolean |
isCommitBatch()
Indicates if this writer should call commit on the connection after every batch is sent,
otherwise, commit is called after the final batch update (default is false).
|
boolean |
isDebug()
Indicates if the generated SQL should be logged (default false).
|
void |
open()
Makes this endpoint ready for reading or writing.
|
JdbcWriter |
setAutoCloseConnection(boolean closeConnection)
Indicates if the database connection in this endpoint should be closed when the endpoint is closed.
|
JdbcWriter |
setBatchSize(int batchSize)
Sets the number of records to chunk together in batch updates.
|
JdbcWriter |
setCommitBatch(boolean commitBatch)
Indicates if this writer should call commit on the connection after every batch is sent,
otherwise, commit is called after the final batch update (default is false).
|
JdbcWriter |
setDebug(boolean debug)
Indicates if the generated SQL should be logged (default false).
|
JdbcWriter |
setDescription(String description) |
JdbcWriter |
setJdbcType(Class<?> type,
int jdbcType)
Forces field values of the specified Java class type to be sent to the database using
PreparedStatement.setObject(parameterIndex, fieldValue, jdbcType)
(instead of the appropriate PreparedStatement.setXXX() method for its field's type). |
JdbcWriter |
setJdbcType(String fieldName,
int jdbcType)
Forces the specified field's values to be sent to the database using
PreparedStatement.setObject(parameterIndex, fieldValue, jdbcType)
(instead of the appropriate PreparedStatement.setXXX() method for its field's type). |
void |
setParameterValue(Field field,
PreparedStatement statement,
int parameterIndex) |
void |
write(Record record)
Writes the specified record to this
DataWriter and increases the record-count by 1. |
protected void |
writeImpl(Record record)
Overridden by subclasses to write the specified record to this
DataWriter . |
available, getNestedEndpoint, getNestedWriter, getRootEndpoint, getRootWriter
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toString
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime
protected Record currentRecord
public JdbcWriter(Connection connection, String tableName, IInsert insert)
autoCloseConnection
property set to false
.connection
- tableName
- insert
- public JdbcWriter(Connection connection, String tableName)
autoCloseConnection
property set to false
.connection
- tableName
- public JdbcWriter(JdbcConnectionFactory factory, String tableName, IInsert insert)
autoCloseConnection
property set to true
.factory
- tableName
- insert
- public JdbcWriter(JdbcConnectionFactory factory, String tableName)
autoCloseConnection
property set to true
.factory
- tableName
- public Connection getConnection()
public String getTableName()
public boolean getAutoCloseConnection()
false
if this instance was constructed with a Connection
or true
if constructed with a JdbcConnectionFactory
.public JdbcWriter setAutoCloseConnection(boolean closeConnection)
false
if this instance was constructed with a Connection
or true
if constructed with a JdbcConnectionFactory
.public int getBatchSize()
public JdbcWriter setBatchSize(int batchSize)
public boolean isBatchMode()
public boolean isCommitBatch()
public JdbcWriter setCommitBatch(boolean commitBatch)
public JdbcWriter setDescription(String description)
setDescription
in class Endpoint
public IInsert getInsert()
public JdbcWriter setJdbcType(String fieldName, int jdbcType)
PreparedStatement.setObject(parameterIndex, fieldValue, jdbcType)
(instead of the appropriate PreparedStatement.setXXX()
method for its field's type). This method may be used to pass database-specific abstract data types.fieldName
- the field to override.jdbcType
- one of the Types
constants or a database specific value.public Integer getJdbcType(String fieldName)
Types
constant (or a database specific value) assigned to the specified field using setJdbcType(String, int)
or null if none was set.Types
constants or a database specific value.public JdbcWriter setJdbcType(Class<?> type, int jdbcType)
PreparedStatement.setObject(parameterIndex, fieldValue, jdbcType)
(instead of the appropriate PreparedStatement.setXXX()
method for its field's type). This method may be used to pass database-specific abstract data types.type
- the Java class type to override.jdbcType
- one of the Types
constants or a database specific value.public Integer getJdbcType(Class<?> type)
Types
constant (or a database specific value) assigned to the specified Java class type using setJdbcType(Class, int)
or null if none was set.Types
constants or a database specific value.public boolean isDebug()
public JdbcWriter setDebug(boolean debug)
public DataException addExceptionProperties(DataException exception)
Endpoint
DataException
. Since this method is called whenever an
exception is thrown, subclasses should override it to add their specific information.addExceptionProperties
in class DataWriter
public void setParameterValue(Field field, PreparedStatement statement, int parameterIndex) throws SQLException
SQLException
public void write(Record record) throws DataException
DataWriter
DataWriter
and increases the record-count by 1.
Any exception raised while writing will be converted to a DataException
using DataObject.exception(Throwable)
.
Subclasses generally do not need to override this method, instead they should implement DataWriter.writeImpl(Record)
.
write
in class DataWriter
DataException
protected void writeImpl(Record record) throws Throwable
DataWriter
DataWriter
.writeImpl
in class DataWriter
Throwable
public void open()
DataEndpoint
open
in class DataEndpoint
public void close()
DataEndpoint
close
in class DataEndpoint
Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.