Class PostgreSqlUpsert
java.lang.Object
com.northconcepts.datapipeline.jdbc.upsert.PostgreSqlUpsert
A batch-able upsert strategy that relies on the SQL Merge statement.
Sample Generated SQL:
INSERT INTO tableName (col1, col2, col3) VALUES (?, ?, ?)
ON CONFLICT (ID) DO UPDATE SET col1=?, col2=?, col3=?
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe action taken when an insert conflicts on the key fields: update the existing row or do nothing. -
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 action to perform on conflict (default ConflictAction.UPDATE).Returns the INSERT part of the generated SQL ornullbeforeprepare(JdbcUpsertWriter, Record)is called.Returns the generatedINSERT ... ON CONFLICTSQL ornullbeforeprepare(JdbcUpsertWriter, Record)is called.Returns the prepared upsert 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).voidprepare(JdbcUpsertWriter writer, Record record) Called once, with the first record written, to generate the SQL and create the statement(s).setConflictAction(PostgreSqlUpsert.ConflictAction conflictAction) Indicates the action to perform on conflict (default ConflictAction.UPDATE).setDebug(boolean debug) Set totrueto log generated SQL (default false).voidsetUpsertSql(String upsertSql) voidsetUpsertStatement(PreparedStatement upsertStatement) voidsetValues(JdbcUpsertWriter writer, Record record) Applies the record's values to the pending statement(s); called for every record written.
-
Constructor Details
-
PostgreSqlUpsert
public PostgreSqlUpsert()
-
-
Method Details
-
getInsertSql
Returns the INSERT part of the generated SQL ornullbeforeprepare(JdbcUpsertWriter, Record)is called. -
getUpsertSql
Returns the generatedINSERT ... ON CONFLICTSQL ornullbeforeprepare(JdbcUpsertWriter, Record)is called. -
setUpsertSql
-
getUpsertStatement
Returns the prepared upsert statement ornullbeforeprepare(JdbcUpsertWriter, Record)is called. -
setUpsertStatement
-
getConflictAction
Returns the action to perform on conflict (default ConflictAction.UPDATE). -
setConflictAction
Indicates the action to perform on conflict (default ConflictAction.UPDATE). -
isDebug
public boolean isDebug()Indicates if the generated SQL should be logged (default false). -
setDebug
Set 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
-