Class MySqlUpsertWriter
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.core.DataEndpoint
com.northconcepts.datapipeline.core.DataWriter
com.northconcepts.datapipeline.core.AbstractWriter
com.northconcepts.datapipeline.core.TextWriter
com.northconcepts.datapipeline.sql.mysql.MySqlInsertWriter
com.northconcepts.datapipeline.sql.mysql.MySqlUpsertWriter
Generates MySQL upsert statement from records.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.sql.mysql.MySqlInsertWriter
batchedInserts, batchSize, pretty, tableNameFields inherited from class com.northconcepts.datapipeline.core.AbstractWriter
currentRecordFields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionMySqlUpsertWriter(String table, File file) MySqlUpsertWriter(String table, File file, boolean append) MySqlUpsertWriter(String table, Writer writer) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Indicates that this endpoint has finished reading or writing.setBatchSize(int batchSize) Sets the number of records to chunk together in batch upserts.setPretty(boolean pretty) Indicates if line breaks and indentations should be added to output upsert statement (default false).
Example output (pretty = true):
INSERT INTO `tableName` (`col1`, `col2`)
VALUES (val1, val2),protected voidwriteRecord(Record record) Writes one row; called first for the header row (seeAbstractWriter.isHeaderRow()) when field names are written, then for each record.Methods inherited from class com.northconcepts.datapipeline.sql.mysql.MySqlInsertWriter
addExceptionProperties, getBatchSize, getSqlValueLiteral, getTableName, isBatchMode, isPretty, setFieldNamesInFirstRowMethods inherited from class com.northconcepts.datapipeline.core.TextWriter
getFile, getWriter, isAppend, isAutoCloseWriter, isFieldNamesInFirstRow, isFlushOnWrite, setAutoCloseWriter, setFlushOnWrite, writeMethods inherited from class com.northconcepts.datapipeline.core.AbstractWriter
createHeaderRecord, isHeaderRow, open, writeImplMethods inherited from class com.northconcepts.datapipeline.core.DataWriter
available, getNestedEndpoint, getNestedWriter, getRootEndpoint, getRootWriter, getWriterMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Constructor Details
-
MySqlUpsertWriter
-
MySqlUpsertWriter
-
MySqlUpsertWriter
-
-
Method Details
-
writeRecord
Description copied from class:AbstractWriterWrites one row; called first for the header row (seeAbstractWriter.isHeaderRow()) when field names are written, then for each record.- Overrides:
writeRecordin classMySqlInsertWriter- Throws:
Throwable
-
close
public void close()Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classMySqlInsertWriter
-
setPretty
Indicates if line breaks and indentations should be added to output upsert statement (default false).
Example output (pretty = true):
INSERT INTO `tableName` (`col1`, `col2`)
VALUES (val1, val2),
(val1, val2),
(val1, val2)
ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
Example output (pretty = false):
INSERT INTO `tableName` (`col1`, `col2`) VALUES (val1, val2), (val1, val2), (val1, val2) ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);- Overrides:
setPrettyin classMySqlInsertWriter
-
setBatchSize
Sets the number of records to chunk together in batch upserts. Upserts are not batched if this value is 1 or less. MySqlUpsertWriter defaults to non batching inserts.
Example output (batchSize = 2):
INSERT INTO `tableName` (`col1`, `col2`)
VALUES (val1, val2),
(val1, val2,
(val1, val2)
ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
Example output (batchSize = 0):
INSERT INTO `tableName` (`col1`, `col2`) VALUES (val1, val2) ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
INSERT INTO `tableName` (`col1`, `col2`) VALUES (val1, val2) ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);- Overrides:
setBatchSizein classMySqlInsertWriter
-