Package com.onec.schema
Enum Class SqlDialect
- All Implemented Interfaces:
Serializable,Comparable<SqlDialect>,Constable
Identifies the target database so upsert helpers can emit portable SQL.
Table DDL produced by SchemaGenerator is already portable, but the
seed/upsert statements for @Enumeration values and constants are not:
H2 understands MERGE INTO t (cols) KEY(k) VALUES (...), while
PostgreSQL only accepts INSERT ... ON CONFLICT (k) DO UPDATE ...
(PG 9.5+). H2 in turn does not support ON CONFLICT ... DO UPDATE, so a
single statement cannot satisfy both engines — we branch on the dialect here.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic SqlDialectdetect(Connection connection) Detects the dialect from a live JDBC connection, defaulting toH2(the in-memory engine used by tests) when the product is unknown.Builds a portable "insert or update" statement.upsertIncrement(String table, List<String> keyColumns, List<String> incrementColumns, List<String> values) Builds an atomic "insert or increment" statement for accumulator tables: when the key row exists, every increment column is bumped by its bound value; otherwise the row is inserted.static SqlDialectReturns the enum constant of this class with the specified name.static SqlDialect[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
H2
-
POSTGRESQL
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
detect
Detects the dialect from a live JDBC connection, defaulting toH2(the in-memory engine used by tests) when the product is unknown. -
upsert
public String upsert(String table, List<String> columns, List<String> keyColumns, List<String> values) Builds a portable "insert or update" statement.- Parameters:
table- target table namecolumns- every column being written, in orderkeyColumns- the conflict/primary key columnsvalues- value tokens (literals or named binds like:id), aligned withcolumns
-
upsertIncrement
public String upsertIncrement(String table, List<String> keyColumns, List<String> incrementColumns, List<String> values) Builds an atomic "insert or increment" statement for accumulator tables: when the key row exists, every increment column is bumped by its bound value; otherwise the row is inserted. A single statement, so two transactions hitting the same new key cannot race the way a SELECT-then-INSERT/UPDATE pair can.- Parameters:
table- target table namekeyColumns- the conflict/primary key columnsincrementColumns- columns added to on conflictvalues- value tokens (named binds like:qty), aligned withkeyColumnsfollowed byincrementColumns
-