Enum Class SqlDialect

java.lang.Object
java.lang.Enum<SqlDialect>
com.onec.schema.SqlDialect
All Implemented Interfaces:
Serializable, Comparable<SqlDialect>, Constable

public enum SqlDialect extends Enum<SqlDialect>
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.

  • Enum Constant Details

  • Method Details

    • values

      public static SqlDialect[] 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

      public static SqlDialect valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • detect

      public static SqlDialect detect(Connection connection)
      Detects the dialect from a live JDBC connection, defaulting to H2 (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 name
      columns - every column being written, in order
      keyColumns - the conflict/primary key columns
      values - value tokens (literals or named binds like :id), aligned with columns
    • 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 name
      keyColumns - the conflict/primary key columns
      incrementColumns - columns added to on conflict
      values - value tokens (named binds like :qty), aligned with keyColumns followed by incrementColumns