Package org.eclipse.net4j.spi.db
Class DBAdapter
java.lang.Object
org.eclipse.net4j.spi.db.DBAdapter
- All Implemented Interfaces:
IDBAdapter,IDBAdapterID
- Direct Known Subclasses:
DerbyAdapter,H2Adapter,HSQLDBAdapter,MYSQLAdapter,PostgreSQLAdapter
A useful base class for implementing custom
DB adapters.
Service providers should subclass this type rather than implement
IDBAdapter directly. The subclass must provide a stable name and version
that identify the adapter's database system and behavior. The registry compares
names case-insensitively and compares dot-separated numeric version components;
trailing zero components do not create a distinct registration.
Providers contributing an adapter through the database adapter extension point should ensure that the descriptor's name and version agree with the adapter created by the provider. The descriptor identity is used for registration and lookup, and remains authoritative if the created adapter reports different metadata.
- Author:
- Eike Stepper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classNested classes/interfaces inherited from interface org.eclipse.net4j.db.IDBAdapter
IDBAdapter.Registry -
Field Summary
Fields inherited from interface org.eclipse.net4j.db.IDBAdapter
REGISTRY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionProvide a way for the DBAdapter to override unsupported DB types with replacements.protected voidaddIndex(Connection connection, IDBTable table, String name, IDBIndex.Type type, List<DBAdapter.FieldInfo> fieldInfos) protected voidaddIndexField(StringBuilder builder, IDBField field) protected voidalterTable(Connection connection, IDBTable table, IDBTableDelta delta) protected voidappendFieldDefs(Appendable appendable, IDBTable table, String[] defs) voidappendFieldNames(Appendable appendable, IDBTable table) Appends the field names used by the adapter's table SQL generation.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) protected StringcreateConstraints(IDBTable table) protected voidcreateField(Connection connection, String tableName, IDBField field) Deprecated.protected voidcreateField(Connection connection, IDBField field) protected StringcreateFieldDefinition(IDBField field) protected String[]createFieldDefinitions(IDBTable table) protected voidcreateIndex(Connection connection, IDBIndex index, IDBIndexDelta delta) protected voidcreateIndex(IDBIndex index, StringBuilder builder) protected voidcreateIndex(IDBIndex index, Statement statement, int num) protected voidcreateIndexFields(IDBIndex index, StringBuilder builder) Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).protected voidcreatePrimaryKey(IDBIndex index, StringBuilder builder) voidcreateSchema(Connection connection, String schemaName) protected voidcreateTable(Connection connection, IDBTable table, IDBTableDelta delta) booleancreateTable(IDBTable table, Statement statement) createTables(Iterable<? extends IDBTable> tables, Connection connection) protected voiddoCreateTable(IDBTable table, Statement statement) protected voiddropField(Connection connection, String tableName, String fieldName) Deprecated.As of 4.13 usedropField(Connection, IDBField)instead.protected voiddropField(Connection connection, IDBField field) protected voiddropIndex(Connection connection, IDBIndex index, IDBIndexDelta delta) protected voiddropIndex(IDBIndex index, StringBuilder builder) protected voiddropPrimaryKey(IDBIndex index, StringBuilder builder) protected voiddropTable(Connection connection, IDBTable table, IDBTableDelta delta) booleandropTables(Iterable<? extends IDBTable> tables, Connection connection) booleanprotected voidforEachTable(Connection connection, String schemaName, boolean caseSensitive, org.eclipse.net4j.util.ConsumerWithException<String, SQLException> tableNameConsumer) Enumerates the tables that belong to a schema while reading a database schema.format(PreparedStatement stmt) Formats a prepared statement for diagnostic output.Formats a result set for diagnostic output.protected static voidgenerateReservedWords(Connection connection, String[] words) static intgetDefaultDBLength(DBType type) getDefaultSchemaName(Connection connection) protected StringgetDropTableSQL(IDBTable table) intgetFieldLength(DBType type) Returns the column length for the given database type.static voidgetIndexInfos(DatabaseMetaData metaData, String schemaName, String tableName, Consumer<DBAdapter.IndexInfo> consumer) 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.protected StringString[]Returns the SQL-92 reserved words used by the adapter implementation.protected StringgetTypeName(IDBField field) Returns the provider's adapter version.inthashCode()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.protected booleanisPrimaryKeyShadow(Connection connection, IDBTable table, String name, IDBIndex.Type type, IDBField[] fields) 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.protected voidreadFields(Connection connection, IDBTable table) protected voidreadIndices(Connection connection, DatabaseMetaData metaData, IDBTable table, String schemaName) protected voidreadIndices(Connection connection, ResultSet resultSet, IDBTable table, int indexNameColumn, int indexTypeColumn, int fieldNameColumn, int fieldPositionColumn) Deprecated.As of 4.13 no longer supported.readSchema(Connection connection, String name) voidreadSchema(Connection connection, IDBSchema schema) protected ResultSetreadTables(Connection connection, DatabaseMetaData metaData, String schemaName) sqlCharIndex(Object substring, Object string) protected Stringprotected StringsqlModifyField(String tableName, String fieldName, String definition) sqlModifyField(IDBField field) sqlRenameField(IDBField field, String oldName) sqlSubstring(Object string, Object startIndex) sqlSubstring(Object string, Object startIndex, Object length) protected StringtoString()voidupdateSchema(Connection connection, IDBSchema schema, IDBSchemaDelta delta) protected voidvalidateTable(IDBTable table, Statement statement) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.net4j.db.IDBAdapter
getReservedWords
-
Constructor Details
-
DBAdapter
-
-
Method Details
-
getName
Description copied from interface:IDBAdapterReturns 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 interfaceIDBAdapter- Specified by:
getNamein interfaceIDBAdapterID- Returns:
- the adapter name
-
getVersion
Description copied from interface:IDBAdapterReturns 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 interfaceIDBAdapter- Specified by:
getVersionin interfaceIDBAdapterID- Returns:
- the adapter version
-
hashCode
public int hashCode() -
equals
-
isCaseSensitive
public boolean isCaseSensitive()- Specified by:
isCaseSensitivein interfaceIDBAdapter
-
getDefaultSchemaName
- Specified by:
getDefaultSchemaNamein interfaceIDBAdapter
-
createConnectionProvider
- Specified by:
createConnectionProviderin interfaceIDBAdapter- Since:
- 4.3
-
modifyConnection
- Specified by:
modifyConnectionin interfaceIDBAdapter- Since:
- 4.5
-
createSchema
- Specified by:
createSchemain interfaceIDBAdapter
-
openSchemaTransaction
public IDBSchemaTransaction openSchemaTransaction(IDBDatabase database, IDBConnection currentConnection) Description copied from interface:IDBAdapterOpens a schema transaction through the adapter extension point.- Specified by:
openSchemaTransactionin interfaceIDBAdapter- Since:
- 4.9
-
readSchema
- Specified by:
readSchemain interfaceIDBAdapter- Since:
- 4.2
-
readSchema
- Specified by:
readSchemain interfaceIDBAdapter- Since:
- 4.2
-
forEachTable
protected void forEachTable(Connection connection, String schemaName, boolean caseSensitive, org.eclipse.net4j.util.ConsumerWithException<String, SQLException> tableNameConsumer) Enumerates the tables that belong to a schema while reading a database schema.- Since:
- 4.14
-
readTables
protected ResultSet readTables(Connection connection, DatabaseMetaData metaData, String schemaName) throws SQLException - Throws:
SQLException- Since:
- 4.3
-
readFields
- Throws:
SQLException- Since:
- 4.2
-
readIndices
protected void readIndices(Connection connection, DatabaseMetaData metaData, IDBTable table, String schemaName) throws SQLException - Throws:
SQLException- Since:
- 4.2
-
addIndex
protected void addIndex(Connection connection, IDBTable table, String name, IDBIndex.Type type, List<DBAdapter.FieldInfo> fieldInfos) - Since:
- 4.2
-
isPrimaryKeyShadow
protected boolean isPrimaryKeyShadow(Connection connection, IDBTable table, String name, IDBIndex.Type type, IDBField[] fields) - Since:
- 4.2
-
updateSchema
public void updateSchema(Connection connection, IDBSchema schema, IDBSchemaDelta delta) throws DBException - Specified by:
updateSchemain interfaceIDBAdapter- Throws:
DBException- Since:
- 4.2
-
createTable
- Since:
- 4.2
-
dropTable
- Since:
- 4.2
-
alterTable
- Since:
- 4.2
-
createField
- Since:
- 4.13
-
dropField
- Since:
- 4.13
-
createIndex
- Since:
- 4.2
-
createPrimaryKey
- Since:
- 4.2
-
createIndex
- Since:
- 4.2
-
createIndexFields
- Since:
- 4.2
-
dropIndex
- Since:
- 4.2
-
dropPrimaryKey
- Since:
- 4.2
-
dropIndex
- Since:
- 4.2
-
createTables
public Set<IDBTable> createTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException - Specified by:
createTablesin interfaceIDBAdapter- Throws:
DBException
-
createTable
- Specified by:
createTablein interfaceIDBAdapter- Throws:
DBException
-
dropTables
public Collection<IDBTable> dropTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException - Specified by:
dropTablesin interfaceIDBAdapter- Throws:
DBException
-
dropTable
- Specified by:
dropTablein interfaceIDBAdapter
-
getDropTableSQL
-
getMaxTableNameLength
public int getMaxTableNameLength()- Specified by:
getMaxTableNameLengthin interfaceIDBAdapter- Since:
- 2.0
-
getMaxFieldNameLength
public int getMaxFieldNameLength()- Specified by:
getMaxFieldNameLengthin interfaceIDBAdapter- Since:
- 2.0
-
getFieldLength
Description copied from interface:IDBAdapterReturns the column length for the given database type.- Specified by:
getFieldLengthin interfaceIDBAdapter- Parameters:
type- theDBTypeto check.- Returns:
- the supported column length for the type.
- Since:
- 4.2
-
isTypeIndexable
- Specified by:
isTypeIndexablein interfaceIDBAdapter
-
toString
-
convertString
Description copied from interface:IDBAdapterConverts a string before it is bound to a prepared statement.- Specified by:
convertStringin interfaceIDBAdapter- Since:
- 4.3
-
convertString
Description copied from interface:IDBAdapterConverts a string read from a result-set column.- Specified by:
convertStringin interfaceIDBAdapter- Since:
- 4.3
-
convertString
Description copied from interface:IDBAdapterConverts a string read from a named result-set column.- Specified by:
convertStringin interfaceIDBAdapter- Since:
- 4.3
-
doCreateTable
- Throws:
SQLException- Since:
- 2.0
-
createIndex
- Throws:
SQLException- Since:
- 2.0
-
addIndexField
-
createConstraints
- Since:
- 2.0
-
createFieldDefinition
- Since:
- 2.0
-
getNullableConstraint
- Since:
- 4.12
-
getTypeName
-
getSQL92ReservedWords
Description copied from interface:IDBAdapterReturns the SQL-92 reserved words used by the adapter implementation.- Specified by:
getSQL92ReservedWordsin interfaceIDBAdapter
-
isReservedWord
- Specified by:
isReservedWordin interfaceIDBAdapter
-
validateTable
- Throws:
DBException- Since:
- 2.0
-
createFieldDefinitions
- Since:
- 4.2
-
appendFieldNames
Description copied from interface:IDBAdapterAppends the field names used by the adapter's table SQL generation.- Specified by:
appendFieldNamesin interfaceIDBAdapter
-
appendFieldDefs
- Since:
- 4.2
-
adaptType
Description copied from interface:IDBAdapterProvide 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.- Specified by:
adaptTypein interfaceIDBAdapter- Since:
- 3.0
-
getJDBCTypeForNull
Description copied from interface:IDBAdapterReturns the JDBC type to use when binding a null value for the given database type.- Specified by:
getJDBCTypeForNullin interfaceIDBAdapter- Since:
- 4.14
-
isValidFirstChar
public boolean isValidFirstChar(char ch) Description copied from interface:IDBAdapterCheck if a character is valid as first character. (e.g., underscores are forbidden as first character in Derby elements.- Specified by:
isValidFirstCharin interfaceIDBAdapter- Since:
- 4.0
-
isDuplicateKeyException
Description copied from interface:IDBAdapterCheck if an exception indicates a constraint violation (duplicate key)- Specified by:
isDuplicateKeyExceptionin interfaceIDBAdapter- Since:
- 4.0
-
isDuplicateKeyTransactionAbort
public boolean isDuplicateKeyTransactionAbort()Description copied from interface:IDBAdapterReturns whether a duplicate-key exception aborts the current JDBC transaction and therefore requires a savepoint to recover from it.- Specified by:
isDuplicateKeyTransactionAbortin interfaceIDBAdapter
-
isTableNotFoundException
- Specified by:
isTableNotFoundExceptionin interfaceIDBAdapter- Since:
- 4.2
-
isColumnNotFoundException
- Specified by:
isColumnNotFoundExceptionin interfaceIDBAdapter- Since:
- 4.2
-
sqlRenameField
- Specified by:
sqlRenameFieldin interfaceIDBAdapter- Since:
- 4.2
-
sqlModifyField
- Specified by:
sqlModifyFieldin interfaceIDBAdapter- Since:
- 4.2
-
sqlModifyField
- Since:
- 4.2
-
sqlCharIndex
- Specified by:
sqlCharIndexin interfaceIDBAdapter
-
sqlCharIndexFunction
- Since:
- 4.13
-
sqlSubstring
- Specified by:
sqlSubstringin interfaceIDBAdapter
-
sqlSubstring
- Specified by:
sqlSubstringin interfaceIDBAdapter
-
sqlSubstringFunction
- Since:
- 4.13
-
sqlConcat
- Specified by:
sqlConcatin interfaceIDBAdapter
-
format
Description copied from interface:IDBAdapterFormats a prepared statement for diagnostic output.- Specified by:
formatin interfaceIDBAdapter- Since:
- 4.2
-
format
Description copied from interface:IDBAdapterFormats a result set for diagnostic output.- Specified by:
formatin interfaceIDBAdapter- Since:
- 4.2
-
convertToSQL
Description copied from interface:IDBAdapterConverts a Java value to the value used by SQL query execution.- Specified by:
convertToSQLin interfaceIDBAdapter- Since:
- 4.9
-
getIndexInfos
public static void getIndexInfos(DatabaseMetaData metaData, String schemaName, String tableName, Consumer<DBAdapter.IndexInfo> consumer) throws SQLException - Throws:
SQLException- Since:
- 4.13
-
getDefaultDBLength
- Since:
- 4.2
-
generateReservedWords
protected static void generateReservedWords(Connection connection, String[] words) throws SQLException - Throws:
SQLException- Since:
- 4.9
-
readIndices
@Deprecated protected void readIndices(Connection connection, ResultSet resultSet, IDBTable table, int indexNameColumn, int indexTypeColumn, int fieldNameColumn, int fieldPositionColumn) throws SQLException Deprecated.As of 4.13 no longer supported. UsegetIndexInfos(DatabaseMetaData, String, String, Consumer)instead.- Throws:
SQLException- Since:
- 4.2
-
createField
Deprecated.As of 4.13 usecreateField(Connection, IDBField)instead.- Since:
- 4.6
-
dropField
Deprecated.As of 4.13 usedropField(Connection, IDBField)instead.- Since:
- 4.6
-
getJDBCDriver
Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).- Specified by:
getJDBCDriverin interfaceIDBAdapter- Since:
- 4.2
-
createJDBCDataSource
Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).- Specified by:
createJDBCDataSourcein interfaceIDBAdapter- Since:
- 4.2
-
createField(Connection, IDBField)instead.