Class H2InsertWriter
Generates H2 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
ConstructorsConstructorDescriptionH2InsertWriter(String tableName, File file) Constructs an H2InsertWriter for the specified table and file.H2InsertWriter(String tableName, File file, boolean append) Constructs an H2InsertWriter for the specified table, file, and append mode.H2InsertWriter(String tableName, Writer writer) Constructs an H2InsertWriter for the specified table and 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 batch size.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.Returns the table name.booleanReturns whether batch mode is enabled.booleanisPretty()Returns whether pretty formatting is enabled.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
-
H2InsertWriter
Constructs an H2InsertWriter for the specified table, file, and append mode.- Parameters:
tableName- the name of the tablefile- the file to write toappend- true to append to existing file
-
H2InsertWriter
Constructs an H2InsertWriter for the specified table and file.- Parameters:
tableName- the name of the tablefile- the file to write to
-
H2InsertWriter
Constructs an H2InsertWriter for the specified table and writer.- Parameters:
tableName- the name of the tablewriter- the writer to write to
-
-
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
Returns the table name.- Returns:
- the table name
-
isPretty
public boolean isPretty()Returns whether pretty formatting is enabled.- Returns:
- true if pretty formatting is enabled
-
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 batch size.- Returns:
- the batch size
-
setBatchSize
Sets the number of records to chunk together in batch inserts. Inserts are not batched if this value is 1 or less. H2InsertWriter 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()Returns whether batch mode is enabled.- Returns:
- true if batch mode is enabled
-
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.
-