Class MySqlInsertWriter
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
- Direct Known Subclasses:
MySqlUpsertWriter
Generates MySQL insert statement from records.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected booleanprotected final StringFields 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
ConstructorsConstructorDescriptionMySqlInsertWriter(String tableName, File file) MySqlInsertWriter(String tableName, File file, boolean append) MySqlInsertWriter(String tableName, Writer writer) -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.voidclose()Indicates that this endpoint has finished reading or writing.intReturns the number of records to chunk together in batch inserts; inserts are not batched if it is 1 or less (default -1).protected StringgetSqlValueLiteral(Field field) Returns the SQL literal written for a field's value:null, a quoted string, a number,TRUE/FALSE, a JDBC escape such as{d '...'}for dates and times, a JSON string for records, orX'...'for blobs.booleanIndicates if inserts are batched, i.e.booleanisPretty()Indicates if line breaks and indentations should be added to the output insert statements (default false).setBatchSize(int batchSize) Sets the number of records to chunk together in batch inserts.setFieldNamesInFirstRow(boolean fieldNamesInFirstRow) Indicates if a header row of field names is written before the first record (default is true); must be called beforeAbstractWriter.open().setPretty(boolean pretty) Indicates if line breaks and indentations should be added to output insert statement (default false).
Example output (pretty = true):
INSERT INTO `tableName` (`col1`, `col2`, `col3`)
VALUES (val1, val2, val3),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.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
-
Field Details
-
pretty
protected boolean pretty -
batchSize
protected int batchSize -
batchedInserts
protected int batchedInserts -
tableName
-
-
Constructor Details
-
MySqlInsertWriter
-
MySqlInsertWriter
-
MySqlInsertWriter
-
-
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.- Specified by:
writeRecordin classAbstractWriter- Throws:
Throwable
-
close
public void close()Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classTextWriter
-
getTableName
-
isPretty
public boolean isPretty()Indicates if line breaks and indentations should be added to the output insert statements (default false). -
setPretty
Indicates if line breaks and indentations should be added to output insert statement (default false).
Example output (pretty = true):
INSERT INTO `tableName` (`col1`, `col2`, `col3`)
VALUES (val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3),...
Example output (pretty = false):
INSERT INTO `tableName` (`col1`, `col2`, `col3`) VALUES (val1, val2, val3), (val1, val2, val3), (val1, val2, val3),... -
getBatchSize
public int getBatchSize()Returns the number of records to chunk together in batch inserts; inserts are not batched if it is 1 or less (default -1). -
setBatchSize
Sets the number of records to chunk together in batch inserts. Inserts are not batched if this value is 1 or less. MySqlInsertWriter defaults to non batching inserts.
Example output (batchSize = 2):
INSERT INTO `tableName` (`col1`, `col2`, `col3`)
VALUES (val1, val2, val3),
(val1, val2, val3);
Example output (batchSize = 0):
INSERT INTO `tableName` (`col1`, `col2`, `col3`) VALUES (val1, val2, val3);
INSERT INTO `tableName` (`col1`, `col2`, `col3`) VALUES (val1, val2, val3); -
isBatchMode
public boolean isBatchMode()Indicates if inserts are batched, i.e. the batch size is greater than 1. -
setFieldNamesInFirstRow
Description copied from class:AbstractWriterIndicates if a header row of field names is written before the first record (default is true); must be called beforeAbstractWriter.open().- Overrides:
setFieldNamesInFirstRowin classAbstractWriter
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classTextWriter
-
getSqlValueLiteral
Returns the SQL literal written for a field's value:null, a quoted string, a number,TRUE/FALSE, a JDBC escape such as{d '...'}for dates and times, a JSON string for records, orX'...'for blobs.
-