Class JdbcAdapter

java.lang.Object
org.apache.cayenne.dba.JdbcAdapter
All Implemented Interfaces:
DbAdapter
Direct Known Subclasses:
DB2Adapter, DerbyAdapter, FirebirdAdapter, FrontBaseAdapter, H2Adapter, HSQLDBAdapter, IngresAdapter, MySQLAdapter, OracleAdapter, PostgresAdapter, SQLiteAdapter, SQLServerAdapter, SybaseAdapter

public class JdbcAdapter extends Object implements DbAdapter
A generic DbAdapter implementation. Can be used as a default adapter or as a superclass of a concrete adapter implementation.
  • Field Details

    • quotingStrategy

      protected QuotingStrategy quotingStrategy
    • defaultCharColumnLength

      protected int defaultCharColumnLength
    • nativeColumnTypes

      protected Map<Integer, NativeColumnType[]> nativeColumnTypes
    • extendedTypes

      protected ExtendedTypeMap extendedTypes
    • supportsBatchUpdates

      protected boolean supportsBatchUpdates
    • supportsUniqueConstraints

      protected boolean supportsUniqueConstraints
    • supportsGeneratedKeys

      protected boolean supportsGeneratedKeys
    • caseInsensitiveCollations

      protected boolean caseInsensitiveCollations
    • logger

      @Deprecated(since="5.0", forRemoval=true) protected SQLLogger logger
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Constructor Details

  • Method Details

    • getBatchTerminator

      public String getBatchTerminator()
      Returns default separator - a semicolon.
      Specified by:
      getBatchTerminator in interface DbAdapter
      Since:
      1.0.4
    • getSQLLogger

      @Deprecated(since="5.0", forRemoval=true) public SQLLogger getSQLLogger()
      Deprecated, for removal: This API element is subject to removal in a future version.
      logger should be taken from the DataNode
      Since:
      3.1
    • createNativeTypes

      protected NativeColumnType[] createNativeTypes()
      Returns the database-native types supported by this adapter.
      Since:
      5.0
    • configureExtendedTypes

      protected void configureExtendedTypes(ExtendedTypeMap map)
      Called from initExtendedTypes(List, List, List, ValueObjectTypeRegistry) to load adapter-specific types into the ExtendedTypeMap right after the default types are loaded, but before the DI overrides are. This method has specific implementations in JdbcAdapter subclasses.
    • initExtendedTypes

      protected void initExtendedTypes(List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ValueObjectTypeRegistry valueObjectTypeRegistry)
      Since:
      3.1
    • createPkGenerator

      public PkGenerator createPkGenerator()
      Returns a generic PK generator based on the "AUTO_PK_SUPPORT" lookup table.
      Specified by:
      createPkGenerator in interface DbAdapter
    • supportsUniqueConstraints

      public boolean supportsUniqueConstraints()
      Returns true.
      Specified by:
      supportsUniqueConstraints in interface DbAdapter
      Since:
      1.1
    • supportsCatalogsOnReverseEngineering

      public boolean supportsCatalogsOnReverseEngineering()
      Returns true.
      Specified by:
      supportsCatalogsOnReverseEngineering in interface DbAdapter
      Since:
      4.0
    • setSupportsUniqueConstraints

      public void setSupportsUniqueConstraints(boolean flag)
      Since:
      1.1
    • typeSupportsLength

      public boolean typeSupportsLength(int type)
      Returns true if supplied type can have a length attribute as a part of column definition
      Specified by:
      typeSupportsLength in interface DbAdapter
      Since:
      4.0
    • typeSupportsScale

      public boolean typeSupportsScale(int type)
      Returns true if supplied type can have a scale attribute as a part of column definition.
      Specified by:
      typeSupportsScale in interface DbAdapter
      Parameters:
      type - sql type code
      Returns:
      true if a given type supports scale
      Since:
      5.0
    • defaultCharColumnLength

      public int defaultCharColumnLength()
      Description copied from interface: DbAdapter
      Returns the length to use for an unconstrained character column (a CHAR/VARCHAR-family column with no max length) when this database requires a length.
      Specified by:
      defaultCharColumnLength in interface DbAdapter
      Since:
      5.0
    • dropTableStatements

      public Collection<String> dropTableStatements(DbEntity table)
      Description copied from interface: DbAdapter
      Returns a collection of SQL statements needed to drop a database table.
      Specified by:
      dropTableStatements in interface DbAdapter
      Since:
      3.0
    • createTable

      public String createTable(DbEntity entity)
      Returns a SQL string that can be used to create database table corresponding to ent parameter.
      Specified by:
      createTable in interface DbAdapter
    • createTableAppendPKClause

      protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity)
      Since:
      1.2
    • createTableAppendColumn

      public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)
      Appends SQL for column creation to CREATE TABLE buffer.
      Specified by:
      createTableAppendColumn in interface DbAdapter
      Parameters:
      sqlBuffer - the StringBuffer to append the column type to
      column - the DbAttribute defining the column to append type for
      Since:
      1.2
    • sizeAndPrecision

      @Deprecated(since="5.0", forRemoval=true) public static String sizeAndPrecision(DbAdapter adapter, DbAttribute column)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • sizeAndScale

      public static String sizeAndScale(DbAdapter adapter, DbAttribute column)
    • getType

      @Deprecated(since="5.0", forRemoval=true) public static String getType(DbAdapter adapter, DbAttribute column)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • createUniqueConstraint

      public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns)
      Returns a DDL string to create a unique constraint over a set of columns.
      Specified by:
      createUniqueConstraint in interface DbAdapter
      Since:
      1.1
    • createFkConstraint

      public String createFkConstraint(DbRelationship rel)
      Returns a SQL string that can be used to create a foreign key constraint for the relationship.
      Specified by:
      createFkConstraint in interface DbAdapter
    • externalTypesForJdbcType

      @Deprecated(since="5.0", forRemoval=true) public String[] externalTypesForJdbcType(int type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: DbAdapter
      Returns an array of RDBMS types that can be used with JDBC type. Valid JDBC types are defined in java.sql.Types.
      Specified by:
      externalTypesForJdbcType in interface DbAdapter
    • nativeColumnTypes

      public NativeColumnType[] nativeColumnTypes(int type)
      Description copied from interface: DbAdapter
      Returns the database-native types that the given JDBC type (see Types) maps to, or null if the type is not supported. The first variant is used for column DDL.
      Specified by:
      nativeColumnTypes in interface DbAdapter
      Since:
      5.0
    • getExtendedTypes

      public ExtendedTypeMap getExtendedTypes()
      Description copied from interface: DbAdapter
      Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.
      Specified by:
      getExtendedTypes in interface DbAdapter
    • buildAttribute

      public DbAttribute buildAttribute(String name, String typeName, int type, int maxLength, int scale, boolean allowNulls)
      Description copied from interface: DbAdapter
      Creates and returns a DbAttribute based on supplied parameters (usually obtained from database metadata).
      Specified by:
      buildAttribute in interface DbAdapter
      Parameters:
      name - database column name
      typeName - database specific type name, may be used as a hint to determine the right JDBC type.
      type - JDBC column type
      maxLength - database column size (ignored if less than zero)
      scale - database column scale, i.e. the number of decimal digits (ignored if less than zero)
      allowNulls - database column nullable parameter
    • tableTypeForTable

      public String tableTypeForTable()
      Description copied from interface: DbAdapter
      Returns the name of the table type (as returned by DatabaseMetaData.getTableTypes) for a simple user table.
      Specified by:
      tableTypeForTable in interface DbAdapter
    • tableTypeForView

      public String tableTypeForView()
      Description copied from interface: DbAdapter
      Returns the name of the table type (as returned by DatabaseMetaData.getTableTypes) for a view table.
      Specified by:
      tableTypeForView in interface DbAdapter
    • getAction

      public SQLAction getAction(Query query, DataNode node)
      Uses JdbcActionBuilder to create the right action.
      Specified by:
      getAction in interface DbAdapter
      Since:
      1.2
    • getSelectTranslator

      public SelectTranslator getSelectTranslator(Select<?> query, EntityResolver entityResolver)
      Description copied from interface: DbAdapter
      Returns the SelectTranslator for the given query. The default implementation ignores the query, but the parameter is retained so adapters can pick a translator based on it.
      Specified by:
      getSelectTranslator in interface DbAdapter
    • getProcedureTranslator

      public ProcedureTranslator getProcedureTranslator(ProcedureQuery<?> query, EntityResolver entityResolver)
      Description copied from interface: DbAdapter
      Returns the ProcedureTranslator for the given query. The default implementation ignores the query, but the parameter is retained so adapters can pick a translator based on it.
      Specified by:
      getProcedureTranslator in interface DbAdapter
    • getSqlTreeProcessor

      public SQLTreeProcessor getSqlTreeProcessor()
      Specified by:
      getSqlTreeProcessor in interface DbAdapter
      Returns:
      SQLTreeProcessor that can adjust SQL tree to specific database flavour
    • bindParameter

      public void bindParameter(PreparedStatement statement, PSParameter<?> parameter) throws Exception
      Description copied from interface: DbAdapter
      Binds an object value to PreparedStatement's parameter.
      Specified by:
      bindParameter in interface DbAdapter
      Throws:
      Exception
    • bindParameter

      public void bindParameter(CallableStatement statement, CSParameter<?> parameter) throws Exception
      Description copied from interface: DbAdapter
      Binds an object value to CallableStatement's parameter.
      Specified by:
      bindParameter in interface DbAdapter
      Throws:
      Exception
    • bind

      protected void bind(PreparedStatement statement, Object value, int psPosition, int psType, int psScale, ExtendedType binder) throws Exception
      Binds a raw value to a statement parameter. This is the single extension point shared by both bindParameter overloads; adapters that need database-specific handling (e.g. of NULLs) should override this method rather than the public overloads.
      Throws:
      Exception
      Since:
      5.0
    • supportsBatchUpdates

      public boolean supportsBatchUpdates()
      Description copied from interface: DbAdapter
      Returns true if the target database supports batch updates.
      Specified by:
      supportsBatchUpdates in interface DbAdapter
    • setSupportsBatchUpdates

      public void setSupportsBatchUpdates(boolean flag)
    • supportsGeneratedKeys

      public boolean supportsGeneratedKeys()
      Description copied from interface: DbAdapter
      Returns true if a target database supports key autogeneration. This feature also requires JDBC3-compliant driver.
      Specified by:
      supportsGeneratedKeys in interface DbAdapter
      Since:
      1.2
    • setSupportsGeneratedKeys

      public void setSupportsGeneratedKeys(boolean flag)
      Since:
      1.2
    • getSystemCatalogs

      public List<String> getSystemCatalogs()
      Specified by:
      getSystemCatalogs in interface DbAdapter
      Returns:
      list of system catalogs
    • getSystemSchemas

      public List<String> getSystemSchemas()
      Specified by:
      getSystemSchemas in interface DbAdapter
      Returns:
      list of system schemas
    • createQuotingStrategy

      protected QuotingStrategy createQuotingStrategy()
    • getQuotingStrategy

      public QuotingStrategy getQuotingStrategy()
      Description copied from interface: DbAdapter
      Returns the SQL identifier quoting style (start/end quote characters) for this adapter. Whether quoting is applied is decided by the caller, which uses this instance when quoting is enabled and QuotingStrategy.NONE otherwise.
      Specified by:
      getQuotingStrategy in interface DbAdapter
    • getQuotingStrategy

      public QuotingStrategy getQuotingStrategy(DbEntity entity)
      Description copied from interface: DbAdapter
      Resolves the QuotingStrategy to use for the given entity: this adapter's strategy when the entity's DataMap enables SQL identifier quoting, and QuotingStrategy.NONE otherwise.
      Specified by:
      getQuotingStrategy in interface DbAdapter
    • unwrap

      public DbAdapter unwrap()
      Simply returns this, as JdbcAdapter is not a wrapper.
      Specified by:
      unwrap in interface DbAdapter
      Since:
      4.0