Package org.eclipse.net4j.spi.db
Class DBAdapter
java.lang.Object
org.eclipse.net4j.spi.db.DBAdapter
- All Implemented Interfaces:
IDBAdapter
- Direct Known Subclasses:
DerbyAdapter,H2Adapter,HSQLDBAdapter,MYSQLAdapter,PostgreSQLAdapter
A useful base class for implementing custom
DB adapters.- Author:
- Eike Stepper
-
Nested Class Summary
Nested Classes -
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) convertString(PreparedStatement preparedStatement, int parameterIndex, String value) convertString(ResultSet resultSet, int columnIndex, String value) convertString(ResultSet resultSet, String columnLabel, String value) convertToSQL(Object value) createConnectionProvider(DataSource dataSource) protected StringcreateConstraints(IDBTable table) protected voidcreateField(Connection connection, String tableName, 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) 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) format(PreparedStatement stmt) 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.Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).intintgetName()protected StringString[]protected StringgetTypeName(IDBField field) booleanbooleanbooleanCheck if an exception indicates a constraint violation (duplicate key)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) 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) readSchema(Connection connection, String name) voidreadSchema(Connection connection, IDBSchema schema) protected ResultSetreadTables(Connection connection, DatabaseMetaData metaData, String schemaName) protected StringsqlModifyField(String tableName, String fieldName, String definition) sqlModifyField(IDBField field) sqlRenameField(IDBField field, String oldName) toString()voidupdateSchema(Connection connection, IDBSchema schema, IDBSchemaDelta delta) protected voidvalidateTable(IDBTable table, Statement statement) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.net4j.db.IDBAdapter
getReservedWords
-
Constructor Details
-
DBAdapter
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceIDBAdapter
-
getVersion
- Specified by:
getVersionin interfaceIDBAdapter
-
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) - Since:
- 4.9
-
readSchema
- Specified by:
readSchemain interfaceIDBAdapter- Since:
- 4.2
-
readSchema
- Specified by:
readSchemain interfaceIDBAdapter- Since:
- 4.2
-
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
-
readIndices
protected void readIndices(Connection connection, ResultSet resultSet, IDBTable table, int indexNameColumn, int indexTypeColumn, int fieldNameColumn, int fieldPositionColumn) 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.6
-
dropField
- Since:
- 4.6
-
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
- Since:
- 4.3
-
convertString
- Since:
- 4.3
-
convertString
- 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
-
isReservedWord
- Specified by:
isReservedWordin interfaceIDBAdapter
-
validateTable
- Throws:
DBException- Since:
- 2.0
-
createFieldDefinitions
- Since:
- 4.2
-
appendFieldNames
-
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
-
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
-
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
-
format
- Since:
- 4.2
-
format
- Since:
- 4.2
-
convertToSQL
- Since:
- 4.9
-
getDefaultDBLength
- Since:
- 4.2
-
generateReservedWords
protected static void generateReservedWords(Connection connection, String[] words) throws SQLException - Throws:
SQLException- Since:
- 4.9
-
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
-