Class Upsert
java.lang.Object
com.northconcepts.datapipeline.jdbc.sql.SqlPart
com.northconcepts.datapipeline.sql.h2.H2SqlPart
com.northconcepts.datapipeline.sql.h2.Upsert
Generates an upsert statement for H2.
Sample Generated SQL:
INSERT INTO `tableName` (`col1`, `col2`)
VALUES (val1, val2),
(val1, val2,
(val1, val2)
ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a column-value pair to the current row.voidcollectSqlFragment(CodeWriter writer) Writes this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.Returns the last row.getRows()Returns the list of rows.getTable()Returns the table name.nextRow()Starts a new row for upserting.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),Methods inherited from class com.northconcepts.datapipeline.sql.h2.H2SqlPart
escapeKeyword, placeBackTicksMethods inherited from class com.northconcepts.datapipeline.jdbc.sql.SqlPart
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
-
Constructor Details
-
Upsert
Constructs an Upsert for the specified table.- Parameters:
table- the table name
-
-
Method Details
-
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`); -
getTable
Returns the table name.- Returns:
- the table name
-
nextRow
Starts a new row for upserting.- Returns:
- this instance
-
add
Adds a column-value pair to the current row.- Parameters:
columnName- the column namevalue- the value to upsert- Returns:
- this instance
-
getRows
Returns the list of rows.- Returns:
- the list of rows
-
getLastRow
Returns the last row.- Returns:
- the last row
-
collectSqlFragment
Description copied from class:SqlPartWrites this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.- Specified by:
collectSqlFragmentin classSqlPart
-