Class PostgreSqlUpsertWriter
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.postgresql.PostgreSqlInsertWriter
com.northconcepts.datapipeline.sql.postgresql.PostgreSqlUpsertWriter
Generates PostgreSQL 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.postgresql.PostgreSqlInsertWriter
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
ConstructorsConstructorDescriptionPostgreSqlUpsertWriter(String table, File file, boolean append, String... keyFieldNames) Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required.PostgreSqlUpsertWriter(String table, File file, boolean append, List<String> keyFieldNames) Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required.PostgreSqlUpsertWriter(String table, File file, String... keyFieldNames) Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required.PostgreSqlUpsertWriter(String table, File file, List<String> keyFieldNames) Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required.PostgreSqlUpsertWriter(String table, Writer writer, String... keyFieldNames) Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required.PostgreSqlUpsertWriter(String table, Writer writer, List<String> keyFieldNames) Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Indicates that this endpoint has finished reading or writing.Indicates the action to perform on conflict, or null if not set, in which caseConflictAction.UPDATEis used.Returns the key fields listed in theON CONFLICTclause.setBatchSize(int batchSize) Sets the number of records to chunk together in batch upserts.setConflictAction(ConflictAction conflictAction) Indicates the action to perform on conflict (default ConflictAction.UPDATE).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", "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.sql.postgresql.PostgreSqlInsertWriter
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
-
PostgreSqlUpsertWriter
Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required. -
PostgreSqlUpsertWriter
Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required. -
PostgreSqlUpsertWriter
Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required. -
PostgreSqlUpsertWriter
Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required. -
PostgreSqlUpsertWriter
Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required. -
PostgreSqlUpsertWriter
Creates a writer of upserts intotablethat use the given key fields forON CONFLICT; at least one is required.
-
-
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 classPostgreSqlInsertWriter- Throws:
Throwable
-
close
public void close()Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classPostgreSqlInsertWriter
-
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", "col3")
VALUES (val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3)
ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3";
Example output (pretty = false):
INSERT INTO "tableName" ("col1", "col2", "col3") VALUES (val1, val2, val3), (val1, val2, val3), (val1, val2, val3) ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3";- Overrides:
setPrettyin classPostgreSqlInsertWriter
-
setBatchSize
Sets the number of records to chunk together in batch upserts. Upserts are not batched if this value is 1 or less. PostgreSqlUpsertWriter defaults to non batching upserts.
Example output (batchSize = 2):
INSERT INTO "tableName" ("col1", "col2", "col3")
VALUES (val1, val2, val3),
(val1, val2, val3),
ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3";
Example output (batchSize = 0):
INSERT INTO "tableName" ("col1", "col2", "col3") VALUES (val1, val2, val3) ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3";
INSERT INTO "tableName" ("col1", "col2", "col3") VALUES (val1, val2, val3) ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3";- Overrides:
setBatchSizein classPostgreSqlInsertWriter
-
getKeyFieldNames
Returns the key fields listed in theON CONFLICTclause. -
getConflictAction
Indicates the action to perform on conflict, or null if not set, in which caseConflictAction.UPDATEis used. -
setConflictAction
Indicates the action to perform on conflict (default ConflictAction.UPDATE).
-