public class Upsert extends H2SqlPart
Generates an upsert statement for H2.
INSERT INTO `tableName` (`col1`, `col2`)
VALUES (val1, val2),
(val1, val2,
(val1, val2)
ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
| Constructor and Description |
|---|
Upsert(String table)
Constructs an Upsert for the specified table.
|
| Modifier and Type | Method and Description |
|---|---|
Upsert |
add(String columnName,
Object value)
Adds a column-value pair to the current row.
|
void |
collectSqlFragment(CodeWriter writer) |
InsertRow |
getLastRow()
Returns the last row.
|
List<InsertRow> |
getRows()
Returns the list of rows.
|
String |
getTable()
Returns the table name.
|
Upsert |
nextRow()
Starts a new row for upserting.
|
Upsert |
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`) |
escapeKeyword, placeBackTickscollectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toStringpublic Upsert(String table)
table - the table namepublic Upsert setPretty(boolean pretty)
INSERT INTO `tableName` (`col1`, `col2`)
VALUES (val1, val2),
(val1, val2),
(val1, val2)
ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
INSERT INTO `tableName` (`col1`, `col2`) VALUES (val1, val2), (val1, val2), (val1, val2) ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);public String getTable()
public Upsert nextRow()
public Upsert add(String columnName, Object value)
columnName - the column namevalue - the value to upsertpublic InsertRow getLastRow()
public void collectSqlFragment(CodeWriter writer)
collectSqlFragment in class SqlPartCopyright (c) 2006-2026 North Concepts Inc. All Rights Reserved.