Package org.apache.cayenne.dba
Interface DbAdapter
- All Known Implementing Classes:
AutoAdapter,DB2Adapter,DerbyAdapter,FirebirdAdapter,FrontBaseAdapter,H2Adapter,HSQLDBAdapter,IngresAdapter,JdbcAdapter,MySQLAdapter,OracleAdapter,PostgresAdapter,SQLiteAdapter,SQLServerAdapter,SybaseAdapter
public interface DbAdapter
A Cayenne extension point that abstracts the differences between specifics of
JDBC interfaces to various databases. Cayenne already ships with a number of
built-in adapters for most common databases and users can provide their own
custom adapters.
-
Method Summary
Modifier and TypeMethodDescriptionvoidbindParameter(CallableStatement statement, CSParameter<?> parameter) Binds an object value to CallableStatement's parameter.voidbindParameter(PreparedStatement statement, PSParameter<?> parameter) Binds an object value to PreparedStatement's parameter.buildAttribute(String name, String typeName, int type, int size, int scale, boolean allowNulls) Creates and returns a DbAttribute based on supplied parameters (usually obtained from database metadata).Returns a SQL string that can be used to create a foreign key constraint for the relationship, or null if foreign keys are not supported.Returns a new primary key generator of the default type associated with this adapter.createTable(DbEntity entity) Returns a SQL string that can be used to create database table corresponding toentityparameter.voidcreateTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) Append the column type part of a "create table" to the givenStringBuffercreateUniqueConstraint(DbEntity source, Collection<DbAttribute> columns) Returns a DDL string to create a unique constraint over a set of columns, or null if the unique constraints are not supported.intReturns the length to use for an unconstrained character column (a CHAR/VARCHAR-family column with no max length) when this database requires a length.dropTableStatements(DbEntity table) Returns a collection of SQL statements needed to drop a database table.String[]externalTypesForJdbcType(int type) Deprecated, for removal: This API element is subject to removal in a future version.Returns an instance of SQLAction that should handle the query.Returns a String used to terminate a batch in command-line tools.Returns theEJBQLTranslatorfor EJBQL to SQL translation.default EJBQLTranslatorDeprecated, for removal: This API element is subject to removal in a future version.in favor ofgetEjbqlTranslator().Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.getProcedureTranslator(ProcedureQuery query, EntityResolver entityResolver) Returns theProcedureTranslatorfor the given query.Deprecated, for removal: This API element is subject to removal in a future version.in favor ofgetQuotingStrategy(DbEntity)getQuotingStrategy(DbEntity entity) Resolves theQuotingStrategyto use for the given entity: this adapter's strategy when the entity's DataMap enables SQL identifier quoting, andQuotingStrategy.NONEotherwise.getSelectTranslator(Select<?> query, EntityResolver entityResolver) Returns theSelectTranslatorfor the given query.nativeColumnTypes(int type) Returns the database-native types that the given JDBCtype(seeTypes) maps to, or null if the type is not supported.default intpreferredBindingType(int jdbcType) Returns the JDBC type that this adapter prefers to bind for a given mapped JDBC type.default NativeColumnTypepreferredNativeColumnType(DbAttribute column) booleanReturnstrueif the target database supports batch updates.booleanReturns true if a target database supports catalogs on reverse engineering.booleanReturns true if a target database supports key autogeneration.default booleanReturns true if a target database supports key autogeneration in a batch insert.booleanReturns true if a target database supports UNIQUE constraints.Returns the name of the table type (as returned byDatabaseMetaData.getTableTypes) for a simple user table.Returns the name of the table type (as returned byDatabaseMetaData.getTableTypes) for a view table.booleantypeSupportsLength(int type) booleantypeSupportsScale(int type) Returns true if supplied type can have a scale attribute as a part of column definition.unwrap()Allows the users to get access to the adapter decorated by a given adapter.
-
Method Details
-
getBatchTerminator
String getBatchTerminator()Returns a String used to terminate a batch in command-line tools. E.g. ";" on Oracle or "go" on Sybase.- Since:
- 1.0.4
-
getSelectTranslator
Returns theSelectTranslatorfor the given query. The default implementation ignores the query, but the parameter is retained so adapters can pick a translator based on it.- Since:
- 4.2
-
getProcedureTranslator
Returns theProcedureTranslatorfor the given query. The default implementation ignores the query, but the parameter is retained so adapters can pick a translator based on it.- Since:
- 5.0
-
getSqlTreeProcessor
SQLTreeProcessor getSqlTreeProcessor()- Returns:
SQLTreeProcessorthat can adjust SQL tree to specific database flavour- Since:
- 4.2
-
getAction
Returns an instance of SQLAction that should handle the query.- Since:
- 1.2
-
supportsUniqueConstraints
boolean supportsUniqueConstraints()Returns true if a target database supports UNIQUE constraints.- Since:
- 1.1
-
supportsCatalogsOnReverseEngineering
boolean supportsCatalogsOnReverseEngineering()Returns true if a target database supports catalogs on reverse engineering.- Since:
- 4.0
-
supportsGeneratedKeys
boolean supportsGeneratedKeys()Returns true if a target database supports key autogeneration. This feature also requires JDBC3-compliant driver.- Since:
- 1.2
-
supportsGeneratedKeysForBatchInserts
default boolean supportsGeneratedKeysForBatchInserts()Returns true if a target database supports key autogeneration in a batch insert.- Since:
- 4.2
- See Also:
-
supportsBatchUpdates
boolean supportsBatchUpdates()Returnstrueif the target database supports batch updates. -
typeSupportsLength
boolean typeSupportsLength(int type) -
typeSupportsScale
boolean typeSupportsScale(int type) Returns true if supplied type can have a scale attribute as a part of column definition.- Since:
- 5.0
-
defaultCharColumnLength
int defaultCharColumnLength()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.- Since:
- 5.0
-
preferredNativeColumnType
- Since:
- 5.0
-
dropTableStatements
Returns a collection of SQL statements needed to drop a database table.- Since:
- 3.0
-
createTable
Returns a SQL string that can be used to create database table corresponding toentityparameter. -
createUniqueConstraint
Returns a DDL string to create a unique constraint over a set of columns, or null if the unique constraints are not supported.- Since:
- 1.1
-
createFkConstraint
Returns a SQL string that can be used to create a foreign key constraint for the relationship, or null if foreign keys are not supported. -
externalTypesForJdbcType
Deprecated, for removal: This API element is subject to removal in a future version.Returns an array of RDBMS types that can be used with JDBCtype. Valid JDBC types are defined in java.sql.Types. -
nativeColumnTypes
Returns the database-native types that the given JDBCtype(seeTypes) maps to, or null if the type is not supported. The first variant is used for column DDL.- Since:
- 5.0
-
getExtendedTypes
ExtendedTypeMap getExtendedTypes()Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer. -
createPkGenerator
PkGenerator createPkGenerator()Returns a new primary key generator of the default type associated with this adapter. DataNode would use this generator, unless explicitly overridden. DbAdapter does not cache the generator as it is often stateful.- Since:
- 5.0
-
buildAttribute
DbAttribute buildAttribute(String name, String typeName, int type, int size, int scale, boolean allowNulls) Creates and returns a DbAttribute based on supplied parameters (usually obtained from database metadata).- Parameters:
name- database column nametypeName- database specific type name, may be used as a hint to determine the right JDBC type.type- JDBC column typesize- 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
-
bindParameter
Binds an object value to PreparedStatement's parameter.- Throws:
Exception- Since:
- 5.0
-
bindParameter
Binds an object value to CallableStatement's parameter.- Throws:
Exception- Since:
- 5.0
-
preferredBindingType
default int preferredBindingType(int jdbcType) Returns the JDBC type that this adapter prefers to bind for a given mapped JDBC type. The default implementation is an identity function; adapters whose drivers require a different type (e.g. remapping theN*character types to their non-national counterparts) override this. The returned type is resolved into thePSParameterat binding creation time, so it matches the type actually sent to the PreparedStatement.- Since:
- 5.0
-
tableTypeForTable
String tableTypeForTable()Returns the name of the table type (as returned byDatabaseMetaData.getTableTypes) for a simple user table. -
tableTypeForView
String tableTypeForView()Returns the name of the table type (as returned byDatabaseMetaData.getTableTypes) for a view table. -
createTableAppendColumn
Append the column type part of a "create table" to the givenStringBuffer- Parameters:
sqlBuffer- theStringBufferto append the column type tocolumn- theDbAttributedefining the column to append type for- Since:
- 3.0
-
getQuotingStrategy
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofgetQuotingStrategy(DbEntity)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 andQuotingStrategy.NONEotherwise.- Since:
- 4.0
-
getQuotingStrategy
Resolves theQuotingStrategyto use for the given entity: this adapter's strategy when the entity's DataMap enables SQL identifier quoting, andQuotingStrategy.NONEotherwise.- Since:
- 5.0
-
unwrap
DbAdapter unwrap()Allows the users to get access to the adapter decorated by a given adapter.- Since:
- 4.0
-
getEjbqlTranslator
EJBQLTranslator getEjbqlTranslator()Returns theEJBQLTranslatorfor EJBQL to SQL translation.- Since:
- 5.0
-
getEjbqlTranslatorFactory
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofgetEjbqlTranslator(). -
getSystemCatalogs
- Returns:
- list of system catalogs
- Since:
- 4.1
-
getSystemSchemas
- Returns:
- list of system schemas
- Since:
- 4.1
-
nativeColumnTypes(int)