Class OracleUpsert
java.lang.Object
com.northconcepts.datapipeline.jdbc.upsert.OracleUpsert
A batch-able upsert strategy that relies on the SQL Merge statement.
Does not support key-only upsert due to a restriction Oracle has placed on columns referenced in the ON clause.
See: Restrictions on the merge_update_clause.
Sample Generated SQL:
MERGE INTO tableName target USING dual ON ( ID=? )
WHEN NOT MATCHED THEN INSERT (col1, col2, col3) VALUES (?, ?, ?)
WHEN MATCHED THEN UPDATE SET col1=?, col2=?, col3=?
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()Adds the applied values to the batch; called instead ofIUpsert.executeUpdate()when the writer is batching.voidaddExceptionProperties(DataException exception) Adds this strategy's details, such as the generated SQL, to the exception.clone()Returns a new, unprepared copy with the same settings;JdbcMultiUpsertWriteruses one for each connection.voidclose()Releases the statement(s); called when the writer is closed.voidExecutes the batch; called each time the writer's batch size is reached and on close if records remain.voidExecutes the upsert with the values applied; called after each record when the writer is not batching.Returns the generated MERGE SQL ornullbeforeprepare(JdbcUpsertWriter, Record)is called.Returns the prepared MERGE statement ornullbeforeprepare(JdbcUpsertWriter, Record)is called.booleanReturns true ifIUpsert.addBatch()andIUpsert.executeBatch()are supported; otherwiseJdbcUpsertWriter.setBatchSize(int)rejects batch sizes above 1.booleanisDebug()Indicates if the generated SQL should be logged (default false).booleanIndicates if the MERGE statement ends with a semicolon (default is false).voidprepare(JdbcUpsertWriter writer, Record record) Called once, with the first record written, to generate the SQL and create the statement(s).setDebug(boolean debug) Set totrueto log generated SQL (default false).setMergeCondition(String mergeCondition) setTerminateWithSemicolon(boolean terminateWithSemicolon) Indicates if the MERGE statement ends with a semicolon (default is false).voidsetValues(JdbcUpsertWriter writer, Record record) Applies the record's values to the pending statement(s); called for every record written.
-
Constructor Details
-
OracleUpsert
public OracleUpsert()
-
-
Method Details
-
getMergeSql
Returns the generated MERGE SQL ornullbeforeprepare(JdbcUpsertWriter, Record)is called. -
getMergeStatement
Returns the prepared MERGE statement ornullbeforeprepare(JdbcUpsertWriter, Record)is called. -
getMergeCondition
-
setMergeCondition
-
isTerminateWithSemicolon
public boolean isTerminateWithSemicolon()Indicates if the MERGE statement ends with a semicolon (default is false). -
setTerminateWithSemicolon
Indicates if the MERGE statement ends with a semicolon (default is false). -
isDebug
public boolean isDebug()Description copied from interface:IUpsertIndicates if the generated SQL should be logged (default false). -
setDebug
Description copied from interface:IUpsertSet totrueto log generated SQL (default false). -
prepare
Description copied from interface:IUpsertCalled once, with the first record written, to generate the SQL and create the statement(s). -
setValues
Description copied from interface:IUpsertApplies the record's values to the pending statement(s); called for every record written. -
executeUpdate
Description copied from interface:IUpsertExecutes the upsert with the values applied; called after each record when the writer is not batching.- Specified by:
executeUpdatein interfaceIUpsert- Throws:
Throwable
-
isBatchSupported
public boolean isBatchSupported()Description copied from interface:IUpsertReturns true ifIUpsert.addBatch()andIUpsert.executeBatch()are supported; otherwiseJdbcUpsertWriter.setBatchSize(int)rejects batch sizes above 1.- Specified by:
isBatchSupportedin interfaceIUpsert
-
addBatch
Description copied from interface:IUpsertAdds the applied values to the batch; called instead ofIUpsert.executeUpdate()when the writer is batching. -
executeBatch
Description copied from interface:IUpsertExecutes the batch; called each time the writer's batch size is reached and on close if records remain.- Specified by:
executeBatchin interfaceIUpsert- Throws:
Throwable
-
clone
Description copied from interface:IUpsertReturns a new, unprepared copy with the same settings;JdbcMultiUpsertWriteruses one for each connection. -
close
Description copied from interface:IUpsertReleases the statement(s); called when the writer is closed. -
addExceptionProperties
Description copied from interface:IUpsertAdds this strategy's details, such as the generated SQL, to the exception.- Specified by:
addExceptionPropertiesin interfaceIUpsert
-