Class MySqlUpsert
java.lang.Object
com.northconcepts.datapipeline.jdbc.upsert.MySqlUpsert
A batch-able upsert strategy where when a row to be inserted would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row occurs.
Sample Generated SQL:
INSERT INTO tableName (col1, col2, col3) VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE 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.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).setDebug(boolean debug) Set totrueto log generated SQL (default false).voidsetValues(JdbcUpsertWriter writer, Record record) Applies the record's values to the pending statement(s); called for every record written.
-
Constructor Details
-
MySqlUpsert
public MySqlUpsert()
-
-
Method Details
-
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
-