public class JdbcUpsertWriter extends DataWriter
GenericUpsert
, however several other are provided: MergeUpsert
, VariableFieldsUpsert
, MySqlUpsert
.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 |
---|
JdbcUpsertWriter(Connection connection,
String tableName,
IUpsert upsert,
String... keyFieldNames) |
JdbcUpsertWriter(Connection connection,
String tableName,
String... keyFieldNames) |
JdbcUpsertWriter(JdbcConnectionFactory factory,
String tableName,
IUpsert upsert,
String... keyFieldNames) |
JdbcUpsertWriter(JdbcConnectionFactory factory,
String tableName,
String... keyFieldNames) |
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() |
int |
getBatchSize() |
Connection |
getConnection() |
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. |
FieldList |
getKeyFields() |
FieldList |
getNonUpdateFields()
Returns the list of fields that must not be updated if the recored already exists (default null).
|
String |
getTableName() |
IUpsert |
getUpsert() |
boolean |
isBatchMode() |
boolean |
isCommitBatch()
Returns true if this reader calls commit on the connection after every batch is sent.
|
boolean |
isDebug()
Indicates if the generated SQL should be logged (default false).
|
void |
open()
Makes this endpoint ready for reading or writing.
|
JdbcUpsertWriter |
setAutoCloseConnection(boolean closeConnection) |
JdbcUpsertWriter |
setBatchSize(int batchSize)
Sets the number of records to chunk together in batch updates.
|
JdbcUpsertWriter |
setCommitBatch(boolean commitBatch)
Indicates if this reader should call commit on the connection after every batch is sent,
otherwise commit is called after the final batch update.
|
JdbcUpsertWriter |
setDebug(boolean debug)
Indicates if the generated SQL should be logged (default false).
|
JdbcUpsertWriter |
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). |
JdbcUpsertWriter |
setJdbcType(String fieldName,
int jdbcType)
The given Java object will be converted to the given targetSqlType before being sent to the database.
|
JdbcUpsertWriter |
setNonUpdateFields(FieldList nonUpdateFields)
Assigns the list of fields that must not be updated if the recored already exists (default null).
|
JdbcUpsertWriter |
setNonUpdateFields(String... nonUpdateFields) |
void |
setParameterValue(Field field,
int fieldIndex,
PreparedStatement statement) |
void |
setParameterValue(Field field,
int fieldIndex,
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, setDescription
protected Record currentRecord
public JdbcUpsertWriter(Connection connection, String tableName, IUpsert upsert, String... keyFieldNames)
public JdbcUpsertWriter(Connection connection, String tableName, String... keyFieldNames)
public JdbcUpsertWriter(JdbcConnectionFactory factory, String tableName, IUpsert upsert, String... keyFieldNames)
public JdbcUpsertWriter(JdbcConnectionFactory factory, String tableName, String... keyFieldNames)
public Connection getConnection()
public String getTableName()
public boolean getAutoCloseConnection()
public JdbcUpsertWriter setAutoCloseConnection(boolean closeConnection)
public int getBatchSize()
public JdbcUpsertWriter setBatchSize(int batchSize)
public boolean isBatchMode()
public boolean isCommitBatch()
public JdbcUpsertWriter setCommitBatch(boolean commitBatch)
public FieldList getKeyFields()
public FieldList getNonUpdateFields()
null
or a list of empty fields.public JdbcUpsertWriter setNonUpdateFields(FieldList nonUpdateFields)
public JdbcUpsertWriter setNonUpdateFields(String... nonUpdateFields)
public IUpsert getUpsert()
public JdbcUpsertWriter setJdbcType(String fieldName, int jdbcType)
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.
fieldName
- jdbcType
- the object containing the JDBC Type parameter valuepublic 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 JdbcUpsertWriter 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 JdbcUpsertWriter 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, int fieldIndex, PreparedStatement statement) throws SQLException
SQLException
public void setParameterValue(Field field, int fieldIndex, 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.