Class PostgresDialect

java.lang.Object
org.seasar.doma.jdbc.dialect.StandardDialect
org.seasar.doma.jdbc.dialect.PostgresDialect
All Implemented Interfaces:
Dialect

public class PostgresDialect extends StandardDialect
A dialect for PostgreSQL.
  • Field Details

    • UNIQUE_CONSTRAINT_VIOLATION_STATE_CODE

      protected static final String UNIQUE_CONSTRAINT_VIOLATION_STATE_CODE
      the SQLState that represents unique violation
      See Also:
    • RESULT_SET

      protected static final JdbcType<ResultSet> RESULT_SET
      the JDBC type for ResultSet
  • Constructor Details

  • Method Details

    • getName

      public String getName()
      Description copied from interface: Dialect
      Returns the name of this dialect.

      The dialect name typically identifies the database system that this dialect supports. This name can be used for logging, debugging, or to make decisions based on the specific database being used.

      Each dialect implementation should return a unique and descriptive name.

      Specified by:
      getName in interface Dialect
      Overrides:
      getName in class StandardDialect
      Returns:
      the name of this dialect
    • toForUpdateSqlNode

      protected SqlNode toForUpdateSqlNode(SqlNode sqlNode, SelectForUpdateType forUpdateType, int waitSeconds, String... aliases)
      Overrides:
      toForUpdateSqlNode in class StandardDialect
    • toPagingSqlNode

      protected SqlNode toPagingSqlNode(SqlNode sqlNode, long offset, long limit)
      Overrides:
      toPagingSqlNode in class StandardDialect
    • isUniqueConstraintViolated

      public boolean isUniqueConstraintViolated(SQLException sqlException)
      Description copied from interface: Dialect
      Determines whether the given SQLException represents a unique constraint violation.

      Different database systems use different error codes and states to indicate unique constraint violations. This method abstracts these differences.

      Specified by:
      isUniqueConstraintViolated in interface Dialect
      Overrides:
      isUniqueConstraintViolated in class StandardDialect
      Parameters:
      sqlException - the SQL exception to analyze
      Returns:
      true if the exception represents a unique constraint violation, false otherwise
    • getIdentitySelectSql

      public PreparedSql getIdentitySelectSql(String catalogName, String schemaName, String tableName, String columnName, boolean isQuoteRequired, boolean isIdColumnQuoteRequired)
      Description copied from interface: Dialect
      Returns an SQL object to retrieve IDENTITY values that were generated during an insert operation.

      This method is used to create the SQL statement that retrieves the last generated identity value for a specific table and column.

      This method is available only if Dialect.supportsIdentity() returns true.

      Specified by:
      getIdentitySelectSql in interface Dialect
      Overrides:
      getIdentitySelectSql in class StandardDialect
      Parameters:
      catalogName - the catalog name of the table (may be null if not applicable)
      schemaName - the schema name of the table (may be null if not applicable)
      tableName - the name of the table containing the identity column
      columnName - the name of the identity column
      isQuoteRequired - whether the table name should be quoted in the SQL statement
      isIdColumnQuoteRequired - whether the identity column name should be quoted in the SQL statement
      Returns:
      the SQL object that can be executed to retrieve the generated identity value
    • getIdentityReservationSql

      public Sql<?> getIdentityReservationSql(String catalogName, String schemaName, String tableName, String columnName, boolean isQuoteRequired, boolean isIdColumnQuoteRequired, int reservationSize)
      Description copied from interface: Dialect
      Returns an SQL object to reserve identity in the database.

      This method is available, only if Dialect.supportsIdentityReservation() returns true.

      Specified by:
      getIdentityReservationSql in interface Dialect
      Overrides:
      getIdentityReservationSql in class StandardDialect
      Parameters:
      catalogName - the catalog name
      schemaName - the schema name
      tableName - the table name
      columnName - the IDENTITY column name
      isQuoteRequired - whether the quotation marks are required
      isIdColumnQuoteRequired - whether the quotation marks are required for the IDENTITY column
      reservationSize - the size of the reservation
      Returns:
      the SQL object
    • createIdentitySequenceFunctionExpression

      protected String createIdentitySequenceFunctionExpression(String catalogName, String schemaName, String tableName, String columnName, boolean isQuoteRequired, boolean isIdColumnQuoteRequired)
    • getSequenceNextValSql

      public PreparedSql getSequenceNextValSql(String qualifiedSequenceName, long allocationSize)
      Description copied from interface: Dialect
      Returns an SQL object to retrieve the next value from a database sequence.

      This method creates the SQL statement needed to get the next value from a sequence.

      The allocation size parameter can be used to optimize sequence access by retrieving multiple values at once in database systems that support this feature.

      This method is available only if Dialect.supportsSequence() returns true.

      Specified by:
      getSequenceNextValSql in interface Dialect
      Overrides:
      getSequenceNextValSql in class StandardDialect
      Parameters:
      qualifiedSequenceName - the fully qualified name of the sequence, which may include catalog and schema information depending on the database system
      allocationSize - the number of sequence values to allocate at once for optimization; a value greater than 1 may improve performance by reducing database calls
      Returns:
      the SQL object that can be executed to retrieve the next sequence value(s)
    • supportsIdentity

      public boolean supportsIdentity()
      Description copied from interface: Dialect
      Determines whether this dialect supports the IDENTITY column.

      An IDENTITY column is a column that automatically generates a unique value for each row when data is inserted. The exact implementation varies by database system.

      Specified by:
      supportsIdentity in interface Dialect
      Overrides:
      supportsIdentity in class StandardDialect
      Returns:
      true if this dialect supports IDENTITY columns, false otherwise
    • supportsSequence

      public boolean supportsSequence()
      Description copied from interface: Dialect
      Determines whether this dialect supports database sequences.

      A sequence is a database object that generates a sequence of unique numbers. Sequences are commonly used to generate primary key values.

      Specified by:
      supportsSequence in interface Dialect
      Overrides:
      supportsSequence in class StandardDialect
      Returns:
      true if this dialect supports sequences, false otherwise
    • supportsIdentityReservation

      public boolean supportsIdentityReservation()
      Description copied from interface: Dialect
      Determines whether this dialect supports reserving identity values in advance.

      Some database systems allow pre-allocating a range of identity values, which can improve performance in certain scenarios.

      Specified by:
      supportsIdentityReservation in interface Dialect
      Overrides:
      supportsIdentityReservation in class StandardDialect
      Returns:
      true if this dialect supports identity reservation, false otherwise
    • supportsSelectForUpdate

      public boolean supportsSelectForUpdate(SelectForUpdateType type, boolean withTargets)
      Description copied from interface: Dialect
      Determines whether this dialect supports pessimistic locking with the specified options.

      Pessimistic locking (SELECT FOR UPDATE) prevents other transactions from modifying selected rows. Different database systems support different variations of this feature.

      Specified by:
      supportsSelectForUpdate in interface Dialect
      Overrides:
      supportsSelectForUpdate in class StandardDialect
      Parameters:
      type - the type of pessimistic locking (e.g., standard FOR UPDATE, NOWAIT, WAIT)
      withTargets - true if specific columns are targeted for locking, false for row-level locking
      Returns:
      true if this dialect supports the specified locking options, false otherwise
    • supportsResultSetReturningAsOutParameter

      public boolean supportsResultSetReturningAsOutParameter()
      Description copied from interface: Dialect
      Determines whether this dialect supports result sets as OUT parameters in stored procedures.

      Some database systems allow stored procedures to return result sets through OUT parameters, while others use different mechanisms (like returning result sets directly).

      Specified by:
      supportsResultSetReturningAsOutParameter in interface Dialect
      Overrides:
      supportsResultSetReturningAsOutParameter in class StandardDialect
      Returns:
      true if this dialect supports result sets as OUT parameters, false otherwise
    • supportsAutoGeneratedKeys

      public boolean supportsAutoGeneratedKeys()
      Description copied from interface: Dialect
      Determines whether this dialect supports retrieving auto-generated keys via Statement.getGeneratedKeys().

      This feature allows retrieving values that were automatically generated during an insert operation, such as identity column values, without executing a separate query.

      Specified by:
      supportsAutoGeneratedKeys in interface Dialect
      Overrides:
      supportsAutoGeneratedKeys in class StandardDialect
      Returns:
      true if this dialect supports retrieving auto-generated keys, false otherwise
    • supportsBatchExecutionReturningGeneratedValues

      public boolean supportsBatchExecutionReturningGeneratedValues()
      Description copied from interface: Dialect
      Determines whether this dialect supports retrieving generated values from batch executions.

      Some database systems can return auto-generated values (like identity columns) even when executing statements in batch mode, while others cannot.

      The default implementation returns false.

      Returns:
      true if this dialect supports retrieving generated values from batch executions, false otherwise
    • getResultSetType

      public JdbcType<ResultSet> getResultSetType()
      Description copied from interface: Dialect
      Returns the JdbcType object that corresponds to the ResultSet class.

      This method is available, only if Dialect.supportsResultSetReturningAsOutParameter() is true.

      Specified by:
      getResultSetType in interface Dialect
      Overrides:
      getResultSetType in class StandardDialect
      Returns:
      the JdbcType object for the ResultSet class
    • createScriptBlockContext

      public ScriptBlockContext createScriptBlockContext()
      Description copied from interface: Dialect
      Creates the context object to process an SQL block in a script.
      Specified by:
      createScriptBlockContext in interface Dialect
      Overrides:
      createScriptBlockContext in class StandardDialect
      Returns:
      the context object
    • getCriteriaBuilder

      public CriteriaBuilder getCriteriaBuilder()
      Description copied from interface: Dialect
      Returns the criteria builder for this dialect.

      The criteria builder is used to construct SQL queries using the criteria API, which provides a type-safe way to build queries programmatically. The returned builder will generate SQL that is compatible with the specific database dialect.

      Specified by:
      getCriteriaBuilder in interface Dialect
      Overrides:
      getCriteriaBuilder in class StandardDialect
      Returns:
      the criteria builder for this dialect
    • getUpsertAssembler

      public UpsertAssembler getUpsertAssembler(UpsertAssemblerContext context)
      Description copied from interface: Dialect
      Returns the UpsertAssembler implementation for the given context.
      Specified by:
      getUpsertAssembler in interface Dialect
      Overrides:
      getUpsertAssembler in class StandardDialect
      Parameters:
      context - the UpsertAssemblerContext object
      Returns:
      the UpsertAssembler object for the given context