Class StandardDialect

java.lang.Object
org.seasar.doma.jdbc.dialect.StandardDialect
All Implemented Interfaces:
Dialect
Direct Known Subclasses:
Db2Dialect, H212126Dialect, HsqldbDialect, Mssql2008Dialect, MysqlDialect, Oracle11Dialect, PostgresDialect, SqliteDialect

public class StandardDialect extends Object implements Dialect
A standard implementation of Dialect.
  • Field Details

    • OPEN_QUOTE

      protected static final char OPEN_QUOTE
      the quotation mark of the start
      See Also:
    • CLOSE_QUOTE

      protected static final char CLOSE_QUOTE
      the quotation mark of the end
      See Also:
    • UNIQUE_CONSTRAINT_VIOLATION_STATE_CODES

      protected static final Set<String> UNIQUE_CONSTRAINT_VIOLATION_STATE_CODES
      the set of SQLState code that represents unique violation
    • jdbcMappingVisitor

      protected final JdbcMappingVisitor jdbcMappingVisitor
      the visitor that maps Wrapper to JdbcType
    • sqlLogFormattingVisitor

      protected final SqlLogFormattingVisitor sqlLogFormattingVisitor
      the visitor that maps Wrapper to SqlLogFormatter
    • expressionFunctions

      protected final ExpressionFunctions expressionFunctions
      the aggregation of expression functions
  • 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
      Returns:
      the name of this dialect
    • transformSelectSqlNode

      public SqlNode transformSelectSqlNode(SqlNode sqlNode, SelectOptions options)
      Description copied from interface: Dialect
      Transforms the SQL node for a SELECT statement according to the specified options.

      This method is responsible for applying database-specific transformations to SELECT statements, such as adding pagination (LIMIT/OFFSET), FOR UPDATE clauses, or other dialect-specific syntax.

      Specified by:
      transformSelectSqlNode in interface Dialect
      Parameters:
      sqlNode - the SQL node representing the SELECT statement to transform
      options - the options that specify how to transform the SQL, including pagination and locking settings
      Returns:
      the transformed SQL node with dialect-specific modifications applied
    • toCountCalculatingSqlNode

      protected SqlNode toCountCalculatingSqlNode(SqlNode sqlNode)
    • toPagingSqlNode

      protected SqlNode toPagingSqlNode(SqlNode sqlNode, long offset, long limit)
    • toForUpdateSqlNode

      protected SqlNode toForUpdateSqlNode(SqlNode sqlNode, SelectForUpdateType forUpdateType, int waitSeconds, String... aliases)
    • transformSelectSqlNodeForGettingCount

      public SqlNode transformSelectSqlNodeForGettingCount(SqlNode sqlNode)
      Description copied from interface: Dialect
      Transforms the SQL node to create a query that returns the total count of rows.

      This method is typically used for pagination scenarios where the total number of results needs to be known. It transforms a regular SELECT statement into a COUNT query that returns the total number of rows that would be returned by the original query without pagination.

      The implementation should handle removing ORDER BY clauses and other elements that are not necessary for counting rows, while preserving the WHERE conditions and JOIN clauses.

      Specified by:
      transformSelectSqlNodeForGettingCount in interface Dialect
      Parameters:
      sqlNode - the SQL node representing the original SELECT statement
      Returns:
      the transformed SQL node that will return the total row count
    • toCountGettingSqlNode

      protected SqlNode toCountGettingSqlNode(SqlNode sqlNode)
    • 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
      Parameters:
      sqlException - the SQL exception to analyze
      Returns:
      true if the exception represents a unique constraint violation, false otherwise
    • getSQLState

      protected String getSQLState(SQLException sqlException)
    • getErrorCode

      protected int getErrorCode(SQLException sqlException)
    • getCauseSQLException

      protected SQLException getCauseSQLException(SQLException sqlException)
    • getRootCause

      public Throwable getRootCause(SQLException sqlException)
      Description copied from interface: Dialect
      Returns the root cause of the SQL exception.
      Specified by:
      getRootCause in interface Dialect
      Parameters:
      sqlException - the SQL exception
      Returns:
      the root cause
    • 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
      Returns:
      true if this dialect supports retrieving auto-generated keys, false otherwise
    • supportsBatchUpdateResults

      public boolean supportsBatchUpdateResults()
      Description copied from interface: Dialect
      Determines whether this dialect supports reliable results from Statement.executeBatch().

      Some database systems do not correctly report the number of affected rows for each statement in a batch operation. This method indicates whether the dialect can rely on these results.

      Specified by:
      supportsBatchUpdateResults in interface Dialect
      Returns:
      true if this dialect supports reliable batch update results, false otherwise
    • 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
      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
      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
      Returns:
      true if this dialect supports identity reservation, false otherwise
    • includesIdentityColumn

      public boolean includesIdentityColumn()
      Description copied from interface: Dialect
      Determines whether this dialect includes IDENTITY columns in SQL INSERT statements.

      Some database systems require that IDENTITY columns be excluded from INSERT statements, while others allow or require them to be included.

      Specified by:
      includesIdentityColumn in interface Dialect
      Returns:
      true if this dialect includes IDENTITY columns in INSERT statements, 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
      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
      Returns:
      true if this dialect supports result sets as OUT parameters, 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
      Returns:
      the JdbcType object for the ResultSet class
    • getIdentitySelectSql

      public Sql<?> 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
      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
      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
    • 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
      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)
    • applyQuote

      public String applyQuote(String name)
      Description copied from interface: Dialect
      Encloses the name with quotation marks.
      Specified by:
      applyQuote in interface Dialect
      Parameters:
      name - the name of a database object such as a table, a column, and so on
      Returns:
      the name that is enclosed with quotation marks
    • removeQuote

      public String removeQuote(String name)
      Description copied from interface: Dialect
      Removes quotation marks from the name
      Specified by:
      removeQuote in interface Dialect
      Parameters:
      name - the name of a database object such as a table, a column, and so on
      Returns:
      the name that has no enclosing quotation marks
    • getJdbcMappingVisitor

      public JdbcMappingVisitor getJdbcMappingVisitor()
      Description copied from interface: Dialect
      Returns the visitor that maps Wrapper to JdbcType.
      Specified by:
      getJdbcMappingVisitor in interface Dialect
      Returns:
      the visitor
    • getSqlLogFormattingVisitor

      public SqlLogFormattingVisitor getSqlLogFormattingVisitor()
      Description copied from interface: Dialect
      Returns the visitor that maps Wrapper to SqlLogFormatter.
      Specified by:
      getSqlLogFormattingVisitor in interface Dialect
      Returns:
      the visitor
    • getExpressionFunctions

      public ExpressionFunctions getExpressionFunctions()
      Description copied from interface: Dialect
      Returns the aggregation of the expression functions that are available in the SQL templates.
      Specified by:
      getExpressionFunctions in interface Dialect
      Returns:
      the aggregation of the expression functions
    • 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
      Returns:
      the context object
    • getScriptBlockDelimiter

      public String getScriptBlockDelimiter()
      Description copied from interface: Dialect
      Returns the delimiter that is used as the end of an SQL block in a script.
      Specified by:
      getScriptBlockDelimiter in interface Dialect
      Returns:
      the delimiter
    • getAutoGeneratedKeysType

      public AutoGeneratedKeysType getAutoGeneratedKeysType()
      Description copied from interface: Dialect
      Returns the type of the auto generated keys.
      Specified by:
      getAutoGeneratedKeysType in interface Dialect
      Returns:
      the type of the auto generated keys
    • 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
      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
      Parameters:
      context - the UpsertAssemblerContext object
      Returns:
      the UpsertAssembler object for the given context
    • getMultiInsertAssembler

      public <ENTITY> MultiInsertAssembler getMultiInsertAssembler(MultiInsertAssemblerContext<ENTITY> context)
      Description copied from interface: Dialect
      Provides an implementation of MultiInsertAssembler based on the given context.
      Specified by:
      getMultiInsertAssembler in interface Dialect
      Type Parameters:
      ENTITY - the type of the entity to be handled by the assembler
      Parameters:
      context - the context that holds the information required to create the MultiInsertAssembler
      Returns:
      an instance of MultiInsertAssembler specific to the provided entity context
    • getInsertAssembler

      public <ENTITY> InsertAssembler getInsertAssembler(InsertAssemblerContext<ENTITY> context)
      Description copied from interface: Dialect
      Provides an implementation of InsertAssembler based on the given context.
      Specified by:
      getInsertAssembler in interface Dialect
      Type Parameters:
      ENTITY - the type of the entity to be handled by the assembler
      Parameters:
      context - the context that holds the information required to create the InsertAssembler
      Returns:
      an instance of InsertAssembler specific to the provided entity context
    • getUpdateAssembler

      public <ENTITY> UpdateAssembler getUpdateAssembler(UpdateAssemblerContext<ENTITY> context)
      Description copied from interface: Dialect
      Provides an implementation of UpdateAssembler based on the given context.
      Specified by:
      getUpdateAssembler in interface Dialect
      Type Parameters:
      ENTITY - the type of the entity to be handled by the assembler
      Parameters:
      context - the context that holds the information required to create the UpdateAssembler
      Returns:
      an instance of UpdateAssembler specific to the provided entity context
    • getDeleteAssembler

      public <ENTITY> DeleteAssembler getDeleteAssembler(DeleteAssemblerContext<ENTITY> context)
      Description copied from interface: Dialect
      Provides an implementation of DeleteAssembler based on the given context.
      Specified by:
      getDeleteAssembler in interface Dialect
      Type Parameters:
      ENTITY - the type of the entity to be handled by the assembler
      Parameters:
      context - the context that holds the information required to create the DeleteAssembler
      Returns:
      an instance of DeleteAssembler specific to the provided entity context