Package org.eclipse.net4j.db
Interface IDBAdapter
- All Superinterfaces:
IDBAdapterID
- All Known Implementing Classes:
DBAdapter,DelegatingDBAdapter,DerbyAdapter,EmbeddedDerbyAdapter,H2Adapter,HSQLDBAdapter,MYSQLAdapter,PostgreSQLAdapter
Abstracts all aspects of a database that are vendor-specific.
Consumers normally obtain an adapter from IDBAdapter.Registry.INSTANCE and use
its name and version as an identity. Adapter names are compared without regard to
case. Versions are compared numerically by dot-separated components, with missing
components treated as zero; consequently, versions such as 8,
8.0, and 8.0.0 have the same logical identity.
Service providers should extend DBAdapter. They must return stable
identity values from getName() and getVersion(), and should use
the version to distinguish incompatible or materially different adapter behavior.
The identity values declared by an extension descriptor are authoritative during
registry lookup, even if a provider-created adapter reports different metadata.
- Author:
- Eike Stepper
- No Implement
- This interface is not intended to be implemented by clients. Subclass
DBAdapterinstead.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.eclipse.net4j.util.registry.IRegistry<String, IDBAdapter> Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionProvide a way for the DBAdapter to override unsupported DB types with replacements.voidappendFieldNames(Appendable appendable, IDBTable table) Appends the field names used by the adapter's table SQL generation.default voidbindParameter(PreparedStatement stmt, int index, DBType type, Object value) Binds a converted value using the JDBC operation selected by this adapter for its logical database type and Java value type.convertString(PreparedStatement preparedStatement, int parameterIndex, String value) Converts a string before it is bound to a prepared statement.convertString(ResultSet resultSet, int columnIndex, String value) Converts a string read from a result-set column.convertString(ResultSet resultSet, String columnLabel, String value) Converts a string read from a named result-set column.convertToSQL(Object value) Converts a Java value to the value used by SQL query execution.createConnectionProvider(DataSource dataSource) Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).voidcreateSchema(Connection connection, String schemaName) booleancreateTable(IDBTable table, Statement statement) createTables(Iterable<? extends IDBTable> tables, Connection connection) booleandropTables(Iterable<? extends IDBTable> tables, Connection connection) format(PreparedStatement stmt) Formats a prepared statement for diagnostic output.Formats a result set for diagnostic output.default StringReturns an optional regular expression that constrains JDBC driver-name matching.default StringReturns an optional regular expression for additional JDBC product-name matching.default String[]Returns the JDBC database product names recognized by this adapter.default StringReturns an optional regular expression that constrains JDBC URL matching.getDefaultSchemaName(Connection connection) intgetFieldLength(DBType type) Returns the column length for the given database type.Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).intgetJDBCTypeForNull(DBType type) Returns the JDBC type to use when binding a null value for the given database type.intintgetName()Returns the provider's adapter name.String[]String[]Returns the SQL-92 reserved words used by the adapter implementation.Returns the provider's adapter version.booleanbooleanbooleanCheck if an exception indicates a constraint violation (duplicate key)booleanReturns whether a duplicate-key exception aborts the current JDBC transaction and therefore requires a savepoint to recover from it.booleanisReservedWord(String word) booleanbooleanisTypeIndexable(DBType type) booleanisValidFirstChar(char ch) Check if a character is valid as first character.modifyConnection(Connection connection) openSchemaTransaction(IDBDatabase database, IDBConnection currentConnection) Opens a schema transaction through the adapter extension point.quoteIdentifier(String identifier) Quotes one SQL identifier using the adapter's identifier delimiter.default StringquoteTableName(IDBTable table) Quotes the physical name of a table for use in SQL.readSchema(Connection connection, String name) voidreadSchema(Connection connection, IDBSchema schema) sqlCharIndex(Object substring, Object string) sqlModifyField(IDBField field) sqlRenameField(IDBField field, String oldName) sqlSubstring(Object string, Object startIndex) sqlSubstring(Object string, Object startIndex, Object length) voidupdateSchema(Connection connection, IDBSchema schema, IDBSchemaDelta delta) default booleanReturns whether a Java value's type may select a specialized JDBC setter when its logical database type is unknown.default voidvalidateSQLLiteral(Object value) Validates whether the given value can be rendered as a SQL literal by this adapter.
-
Field Details
-
REGISTRY
Deprecated.As of 4.14, useIDBAdapter.Registry.INSTANCEinstead.
-
-
Method Details
-
getName
String getName()Returns the provider's adapter name. Registry registration and lookup compare this value case-insensitively; the value returned by this method is not lowercased for the caller.- Specified by:
getNamein interfaceIDBAdapterID- Returns:
- the adapter name
-
getVersion
String getVersion()Returns the provider's adapter version. Registry registration and lookup compare dot-separated numeric components and ignore trailing zero components, while the original representation returned here remains available to callers.- Specified by:
getVersionin interfaceIDBAdapterID- Returns:
- the adapter version
-
getDatabaseProductNames
Returns the JDBC database product names recognized by this adapter. Product names are trimmed and compared case-insensitively. The default recognizes the adapter's declared name. Implementations may return additional aliases.- Returns:
- the exact JDBC product names recognized by this adapter
- Since:
- 4.15
-
getDatabaseProductNamePattern
Returns an optional regular expression for additional JDBC product-name matching. It is matched case-insensitively against the complete trimmed product name. A matching product name is required even when this pattern is configured.- Returns:
- a product-name regular expression, or
nullif none is needed - Since:
- 4.15
-
getDatabaseDriverNamePattern
Returns an optional regular expression that constrains JDBC driver-name matching. The complete driver name must match case-insensitively; a missing driver name does not match.- Returns:
- a JDBC driver-name regular expression, or
nullif no driver constraint applies - Since:
- 4.15
-
getDatabaseURLPattern
Returns an optional regular expression that constrains JDBC URL matching. The complete URL must match case-insensitively; a missing URL does not match.- Returns:
- a JDBC URL regular expression, or
nullif no URL constraint applies - Since:
- 4.15
-
isCaseSensitive
boolean isCaseSensitive()- Since:
- 4.12
-
getDefaultSchemaName
- Since:
- 4.12
-
createConnectionProvider
- Since:
- 4.3
-
modifyConnection
- Since:
- 4.5
-
createSchema
- Since:
- 4.12
-
openSchemaTransaction
Opens a schema transaction through the adapter extension point.- Since:
- 4.14
-
readSchema
- Since:
- 4.2
-
readSchema
- Since:
- 4.2
-
updateSchema
- Throws:
DBException- Since:
- 4.2
-
createTables
Set<IDBTable> createTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException - Throws:
DBException
-
createTable
- Throws:
DBException
-
dropTables
Collection<IDBTable> dropTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException - Throws:
DBException
-
dropTable
-
getReservedWords
String[] getReservedWords() -
isReservedWord
-
getMaxTableNameLength
int getMaxTableNameLength()- Since:
- 2.0
-
getMaxFieldNameLength
int getMaxFieldNameLength()- Since:
- 2.0
-
getFieldLength
Returns the column length for the given database type.- Parameters:
type- theDBTypeto check.- Returns:
- the supported column length for the type.
- Since:
- 4.2
-
isTypeIndexable
-
convertString
Converts a string before it is bound to a prepared statement.- Since:
- 4.14
-
convertString
Converts a string read from a result-set column.- Since:
- 4.14
-
convertString
Converts a string read from a named result-set column.- Since:
- 4.14
-
getSQL92ReservedWords
String[] getSQL92ReservedWords()Returns the SQL-92 reserved words used by the adapter implementation.- Since:
- 4.14
-
appendFieldNames
Appends the field names used by the adapter's table SQL generation.- Since:
- 4.14
-
adaptType
Provide a way for the DBAdapter to override unsupported DB types with replacements. The default implementation just returns the given type. Subclasses may override single types with replacements.- Since:
- 3.0
-
getJDBCTypeForNull
Returns the JDBC type to use when binding a null value for the given database type.- Since:
- 4.14
-
useJavaTypeForUnknownParameterType
default boolean useJavaTypeForUnknownParameterType()Returns whether a Java value's type may select a specialized JDBC setter when its logical database type is unknown. If this method returnsfalse, unknown non-null values usePreparedStatement.setObject(int, Object). If it returnstrue, supported scalar Java types may use their corresponding typed setter; unsupported values still usesetObject. This policy does not affect parameters with an inferred database type.- Returns:
trueto use supported Java scalar types for unknown parameters; otherwisefalse- Since:
- 4.15
-
bindParameter
default void bindParameter(PreparedStatement stmt, int index, DBType type, Object value) throws SQLException Binds a converted value using the JDBC operation selected by this adapter for its logical database type and Java value type. The value may benull. Implementations may specialize compatible scalar types; values without a supported specialization usePreparedStatement.setObject(int, Object). A null value with a known type uses this adapter'sgetJDBCTypeForNull(DBType)mapping. A null value with an unknown type may use generic object binding. The default preserves generic binding for adapters that do not override this operation.- Parameters:
stmt- the prepared statementindex- the one-based JDBC parameter indextype- the inferred logical database type, ornullif it cannot be inferredvalue- the converted Java value, possiblynull- Throws:
SQLException- if JDBC reports a binding failure- Since:
- 4.15
-
isValidFirstChar
boolean isValidFirstChar(char ch) Check if a character is valid as first character. (e.g., underscores are forbidden as first character in Derby elements.- Since:
- 4.0
-
isDuplicateKeyTransactionAbort
boolean isDuplicateKeyTransactionAbort()Returns whether a duplicate-key exception aborts the current JDBC transaction and therefore requires a savepoint to recover from it.- Since:
- 4.14
-
isDuplicateKeyException
Check if an exception indicates a constraint violation (duplicate key)- Since:
- 4.0
-
isTableNotFoundException
- Since:
- 4.2
-
isColumnNotFoundException
- Since:
- 4.2
-
quoteIdentifier
Quotes one SQL identifier using the adapter's identifier delimiter. Qualified names must be split into their individual components before calling this method. Quoting can be disabled globally withDBUtil.DISABLE_QUOTED_NAMES.- Parameters:
identifier- one unqualified SQL identifier- Returns:
- the identifier, quoted and escaped according to this adapter
- Since:
- 4.15
-
quoteTableName
Quotes the physical name of a table for use in SQL. When the table's schema enables qualified table names, the schema and table names are quoted independently and joined with a dot. This preserves the distinction between identifier components and avoids treating the dot as part of either identifier. Each component is escaped according to this adapter'squoteIdentifier(String)implementation, and the global quoted-name compatibility setting remains in effect.- Parameters:
table- the schema table to render- Returns:
- the adapter-specific table name, including its schema when configured
- Since:
- 4.15
-
validateSQLLiteral
Validates whether the given value can be rendered as a SQL literal by this adapter. The default implementation performs no additional validation; adapters with dialect-specific restrictions may reject values during DML compilation.- Parameters:
value- the Java value, possiblynull- Throws:
IllegalArgumentException- if the value is not supported- Since:
- 4.15
-
sqlRenameField
- Since:
- 4.2
-
sqlModifyField
- Since:
- 4.2
-
sqlCharIndex
- Since:
- 4.13
-
sqlSubstring
- Since:
- 4.13
-
sqlSubstring
- Since:
- 4.13
-
sqlConcat
- Since:
- 4.13
-
format
Formats a prepared statement for diagnostic output.- Since:
- 4.14
-
format
Formats a result set for diagnostic output.- Since:
- 4.14
-
convertToSQL
Converts a Java value to the value used by SQL query execution.- Since:
- 4.14
-
getJDBCDriver
Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs). -
createJDBCDataSource
Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).
-
IDBAdapter.Registry.INSTANCEinstead.