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
-
Field Summary
Fields inherited from interface org.eclipse.net4j.db.IDBAdapter
REGISTRY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionProvide a way for the DBAdapter to override unsupported DB types with replacements.protected void
addIndex
(Connection connection, IDBTable table, String name, IDBIndex.Type type, List<DBAdapter.FieldInfo> fieldInfos) protected void
addIndexField
(StringBuilder builder, IDBField field) protected void
alterTable
(Connection connection, IDBTable table, IDBTableDelta delta) protected void
appendFieldDefs
(Appendable appendable, IDBTable table, String[] defs) void
appendFieldNames
(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 String
createConstraints
(IDBTable table) protected void
createField
(Connection connection, String tableName, IDBField field) protected String
createFieldDefinition
(IDBField field) protected String[]
createFieldDefinitions
(IDBTable table) protected void
createIndex
(Connection connection, IDBIndex index, IDBIndexDelta delta) protected void
createIndex
(IDBIndex index, StringBuilder builder) protected void
createIndex
(IDBIndex index, Statement statement, int num) protected void
createIndexFields
(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 void
createPrimaryKey
(IDBIndex index, StringBuilder builder) void
createSchema
(Connection connection, String schemaName) protected void
createTable
(Connection connection, IDBTable table, IDBTableDelta delta) boolean
createTable
(IDBTable table, Statement statement) createTables
(Iterable<? extends IDBTable> tables, Connection connection) protected void
doCreateTable
(IDBTable table, Statement statement) protected void
dropField
(Connection connection, String tableName, String fieldName) protected void
dropIndex
(Connection connection, IDBIndex index, IDBIndexDelta delta) protected void
dropIndex
(IDBIndex index, StringBuilder builder) protected void
dropPrimaryKey
(IDBIndex index, StringBuilder builder) protected void
dropTable
(Connection connection, IDBTable table, IDBTableDelta delta) boolean
dropTables
(Iterable<? extends IDBTable> tables, Connection connection) format
(PreparedStatement stmt) protected static void
generateReservedWords
(Connection connection, String[] words) static int
getDefaultDBLength
(DBType type) getDefaultSchemaName
(Connection connection) protected String
getDropTableSQL
(IDBTable table) int
getFieldLength
(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).int
int
getName()
protected String
String[]
protected String
getTypeName
(IDBField field) boolean
boolean
boolean
Check if an exception indicates a constraint violation (duplicate key)protected boolean
isPrimaryKeyShadow
(Connection connection, IDBTable table, String name, IDBIndex.Type type, IDBField[] fields) boolean
isReservedWord
(String word) boolean
boolean
isTypeIndexable
(DBType type) boolean
isValidFirstChar
(char ch) Check if a character is valid as first character.modifyConnection
(Connection connection) openSchemaTransaction
(IDBDatabase database, IDBConnection currentConnection) protected void
readFields
(Connection connection, IDBTable table) protected void
readIndices
(Connection connection, DatabaseMetaData metaData, IDBTable table, String schemaName) protected void
readIndices
(Connection connection, ResultSet resultSet, IDBTable table, int indexNameColumn, int indexTypeColumn, int fieldNameColumn, int fieldPositionColumn) readSchema
(Connection connection, String name) void
readSchema
(Connection connection, IDBSchema schema) protected ResultSet
readTables
(Connection connection, DatabaseMetaData metaData, String schemaName) protected String
sqlModifyField
(String tableName, String fieldName, String definition) sqlModifyField
(IDBField field) sqlRenameField
(IDBField field, String oldName) toString()
void
updateSchema
(Connection connection, IDBSchema schema, IDBSchemaDelta delta) protected void
validateTable
(IDBTable table, Statement statement) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.net4j.db.IDBAdapter
getReservedWords
-
Constructor Details
-
DBAdapter
-
-
Method Details
-
getName
- Specified by:
getName
in interfaceIDBAdapter
-
getVersion
- Specified by:
getVersion
in interfaceIDBAdapter
-
isCaseSensitive
public boolean isCaseSensitive()- Specified by:
isCaseSensitive
in interfaceIDBAdapter
-
getDefaultSchemaName
- Specified by:
getDefaultSchemaName
in interfaceIDBAdapter
-
createConnectionProvider
- Specified by:
createConnectionProvider
in interfaceIDBAdapter
- Since:
- 4.3
-
modifyConnection
- Specified by:
modifyConnection
in interfaceIDBAdapter
- Since:
- 4.5
-
createSchema
- Specified by:
createSchema
in interfaceIDBAdapter
-
openSchemaTransaction
public IDBSchemaTransaction openSchemaTransaction(IDBDatabase database, IDBConnection currentConnection) - Since:
- 4.9
-
readSchema
- Specified by:
readSchema
in interfaceIDBAdapter
- Since:
- 4.2
-
readSchema
- Specified by:
readSchema
in 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:
updateSchema
in 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:
createTables
in interfaceIDBAdapter
- Throws:
DBException
-
createTable
- Specified by:
createTable
in interfaceIDBAdapter
- Throws:
DBException
-
dropTables
public Collection<IDBTable> dropTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException - Specified by:
dropTables
in interfaceIDBAdapter
- Throws:
DBException
-
dropTable
- Specified by:
dropTable
in interfaceIDBAdapter
-
getDropTableSQL
-
getMaxTableNameLength
public int getMaxTableNameLength()- Specified by:
getMaxTableNameLength
in interfaceIDBAdapter
- Since:
- 2.0
-
getMaxFieldNameLength
public int getMaxFieldNameLength()- Specified by:
getMaxFieldNameLength
in interfaceIDBAdapter
- Since:
- 2.0
-
getFieldLength
Description copied from interface:IDBAdapter
Returns the column length for the given database type.- Specified by:
getFieldLength
in interfaceIDBAdapter
- Parameters:
type
- theDBType
to check.- Returns:
- the supported column length for the type.
- Since:
- 4.2
-
isTypeIndexable
- Specified by:
isTypeIndexable
in 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:
isReservedWord
in interfaceIDBAdapter
-
validateTable
- Throws:
DBException
- Since:
- 2.0
-
createFieldDefinitions
- Since:
- 4.2
-
appendFieldNames
-
appendFieldDefs
- Since:
- 4.2
-
adaptType
Description copied from interface:IDBAdapter
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.- Specified by:
adaptType
in interfaceIDBAdapter
- Since:
- 3.0
-
isValidFirstChar
public boolean isValidFirstChar(char ch) Description copied from interface:IDBAdapter
Check if a character is valid as first character. (e.g., underscores are forbidden as first character in Derby elements.- Specified by:
isValidFirstChar
in interfaceIDBAdapter
- Since:
- 4.0
-
isDuplicateKeyException
Description copied from interface:IDBAdapter
Check if an exception indicates a constraint violation (duplicate key)- Specified by:
isDuplicateKeyException
in interfaceIDBAdapter
- Since:
- 4.0
-
isTableNotFoundException
- Specified by:
isTableNotFoundException
in interfaceIDBAdapter
- Since:
- 4.2
-
isColumnNotFoundException
- Specified by:
isColumnNotFoundException
in interfaceIDBAdapter
- Since:
- 4.2
-
sqlRenameField
- Specified by:
sqlRenameField
in interfaceIDBAdapter
- Since:
- 4.2
-
sqlModifyField
- Specified by:
sqlModifyField
in 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:
getJDBCDriver
in 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:
createJDBCDataSource
in interfaceIDBAdapter
- Since:
- 4.2
-