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
public abstract class DBAdapter extends java.lang.Object implements IDBAdapter
A useful base class for implementing customDB adapters.- Author:
- Eike Stepper
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDBAdapter.FieldInfo
-
Field Summary
-
Fields inherited from interface org.eclipse.net4j.db.IDBAdapter
REGISTRY
-
-
Constructor Summary
Constructors Constructor Description DBAdapter(java.lang.String name, java.lang.String version)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DBTypeadaptType(DBType type)Provide a way for the DBAdapter to override unsupported DB types with replacements.protected voidaddIndex(java.sql.Connection connection, IDBTable table, java.lang.String name, IDBIndex.Type type, java.util.List<DBAdapter.FieldInfo> fieldInfos)protected voidaddIndexField(java.lang.StringBuilder builder, IDBField field)protected voidalterTable(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)protected voidappendFieldDefs(java.lang.Appendable appendable, IDBTable table, java.lang.String[] defs)voidappendFieldNames(java.lang.Appendable appendable, IDBTable table)java.lang.StringconvertString(java.sql.PreparedStatement preparedStatement, int parameterIndex, java.lang.String value)java.lang.StringconvertString(java.sql.ResultSet resultSet, int columnIndex, java.lang.String value)java.lang.StringconvertString(java.sql.ResultSet resultSet, java.lang.String columnLabel, java.lang.String value)java.lang.ObjectconvertToSQL(java.lang.Object value)IDBConnectionProvidercreateConnectionProvider(javax.sql.DataSource dataSource)protected java.lang.StringcreateConstraints(IDBTable table)protected voidcreateField(java.sql.Connection connection, java.lang.String tableName, IDBField field)protected java.lang.StringcreateFieldDefinition(IDBField field)protected java.lang.String[]createFieldDefinitions(IDBTable table)protected voidcreateIndex(java.sql.Connection connection, IDBIndex index, IDBIndexDelta delta)protected voidcreateIndex(IDBIndex index, java.lang.StringBuilder builder)protected voidcreateIndex(IDBIndex index, java.sql.Statement statement, int num)protected voidcreateIndexFields(IDBIndex index, java.lang.StringBuilder builder)javax.sql.DataSourcecreateJDBCDataSource()Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).protected voidcreatePrimaryKey(IDBIndex index, java.lang.StringBuilder builder)protected voidcreateTable(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)booleancreateTable(IDBTable table, java.sql.Statement statement)java.util.Set<IDBTable>createTables(java.lang.Iterable<? extends IDBTable> tables, java.sql.Connection connection)protected voiddoCreateTable(IDBTable table, java.sql.Statement statement)protected voiddropField(java.sql.Connection connection, java.lang.String tableName, java.lang.String fieldName)protected voiddropIndex(java.sql.Connection connection, IDBIndex index, IDBIndexDelta delta)protected voiddropIndex(IDBIndex index, java.lang.StringBuilder builder)protected voiddropPrimaryKey(IDBIndex index, java.lang.StringBuilder builder)protected voiddropTable(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)booleandropTable(IDBTable table, java.sql.Statement statement)java.util.Collection<IDBTable>dropTables(java.lang.Iterable<? extends IDBTable> tables, java.sql.Connection connection)java.lang.Stringformat(java.sql.PreparedStatement stmt)java.lang.Stringformat(java.sql.ResultSet resultSet)protected static voidgenerateReservedWords(java.sql.Connection connection, java.lang.String[] words)static intgetDefaultDBLength(DBType type)protected java.lang.StringgetDropTableSQL(IDBTable table)intgetFieldLength(DBType type)Returns the column length for the given database type.java.sql.DrivergetJDBCDriver()Deprecated.As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).intgetMaxFieldNameLength()intgetMaxTableNameLength()java.lang.StringgetName()java.lang.String[]getSQL92ReservedWords()protected java.lang.StringgetTypeName(IDBField field)java.lang.StringgetVersion()booleanisColumnNotFoundException(java.sql.SQLException ex)booleanisDuplicateKeyException(java.sql.SQLException ex)Check if an exception indicates a constraint violation (duplicate key)protected booleanisPrimaryKeyShadow(java.sql.Connection connection, IDBTable table, java.lang.String name, IDBIndex.Type type, IDBField[] fields)booleanisReservedWord(java.lang.String word)booleanisTableNotFoundException(java.sql.SQLException ex)booleanisTypeIndexable(DBType type)booleanisValidFirstChar(char ch)Check if a character is valid as first character.java.sql.ConnectionmodifyConnection(java.sql.Connection connection)IDBSchemaTransactionopenSchemaTransaction(IDBDatabase database, IDBConnection currentConnection)protected voidreadFields(java.sql.Connection connection, IDBTable table)protected voidreadIndices(java.sql.Connection connection, java.sql.DatabaseMetaData metaData, IDBTable table, java.lang.String schemaName)protected voidreadIndices(java.sql.Connection connection, java.sql.ResultSet resultSet, IDBTable table, int indexNameColumn, int indexTypeColumn, int fieldNameColumn, int fieldPositionColumn)IDBSchemareadSchema(java.sql.Connection connection, java.lang.String name)voidreadSchema(java.sql.Connection connection, IDBSchema schema)protected java.sql.ResultSetreadTables(java.sql.Connection connection, java.sql.DatabaseMetaData metaData, java.lang.String schemaName)protected java.lang.StringsqlModifyField(java.lang.String tableName, java.lang.String fieldName, java.lang.String definition)java.lang.StringsqlModifyField(IDBField field)java.lang.StringsqlRenameField(IDBField field, java.lang.String oldName)java.lang.StringtoString()voidupdateSchema(java.sql.Connection connection, IDBSchema schema, IDBSchemaDelta delta)protected voidvalidateTable(IDBTable table, java.sql.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
-
-
-
-
Method Detail
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceIDBAdapter
-
getVersion
public java.lang.String getVersion()
- Specified by:
getVersionin interfaceIDBAdapter
-
getJDBCDriver
@Deprecated public java.sql.Driver 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 public javax.sql.DataSource 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
-
createConnectionProvider
public IDBConnectionProvider createConnectionProvider(javax.sql.DataSource dataSource)
- Specified by:
createConnectionProviderin interfaceIDBAdapter- Since:
- 4.3
-
modifyConnection
public java.sql.Connection modifyConnection(java.sql.Connection connection)
- Specified by:
modifyConnectionin interfaceIDBAdapter- Since:
- 4.5
-
openSchemaTransaction
public IDBSchemaTransaction openSchemaTransaction(IDBDatabase database, IDBConnection currentConnection)
- Since:
- 4.9
-
readSchema
public IDBSchema readSchema(java.sql.Connection connection, java.lang.String name)
- Specified by:
readSchemain interfaceIDBAdapter- Since:
- 4.2
-
readSchema
public void readSchema(java.sql.Connection connection, IDBSchema schema)- Specified by:
readSchemain interfaceIDBAdapter- Since:
- 4.2
-
readTables
protected java.sql.ResultSet readTables(java.sql.Connection connection, java.sql.DatabaseMetaData metaData, java.lang.String schemaName) throws java.sql.SQLException- Throws:
java.sql.SQLException- Since:
- 4.3
-
readFields
protected void readFields(java.sql.Connection connection, IDBTable table) throws java.sql.SQLException- Throws:
java.sql.SQLException- Since:
- 4.2
-
readIndices
protected void readIndices(java.sql.Connection connection, java.sql.DatabaseMetaData metaData, IDBTable table, java.lang.String schemaName) throws java.sql.SQLException- Throws:
java.sql.SQLException- Since:
- 4.2
-
readIndices
protected void readIndices(java.sql.Connection connection, java.sql.ResultSet resultSet, IDBTable table, int indexNameColumn, int indexTypeColumn, int fieldNameColumn, int fieldPositionColumn) throws java.sql.SQLException- Throws:
java.sql.SQLException- Since:
- 4.2
-
addIndex
protected void addIndex(java.sql.Connection connection, IDBTable table, java.lang.String name, IDBIndex.Type type, java.util.List<DBAdapter.FieldInfo> fieldInfos)- Since:
- 4.2
-
isPrimaryKeyShadow
protected boolean isPrimaryKeyShadow(java.sql.Connection connection, IDBTable table, java.lang.String name, IDBIndex.Type type, IDBField[] fields)- Since:
- 4.2
-
updateSchema
public void updateSchema(java.sql.Connection connection, IDBSchema schema, IDBSchemaDelta delta) throws DBException- Specified by:
updateSchemain interfaceIDBAdapter- Throws:
DBException- Since:
- 4.2
-
createTable
protected void createTable(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)- Since:
- 4.2
-
dropTable
protected void dropTable(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)- Since:
- 4.2
-
alterTable
protected void alterTable(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)- Since:
- 4.2
-
createField
protected void createField(java.sql.Connection connection, java.lang.String tableName, IDBField field)- Since:
- 4.6
-
dropField
protected void dropField(java.sql.Connection connection, java.lang.String tableName, java.lang.String fieldName)- Since:
- 4.6
-
createIndex
protected void createIndex(java.sql.Connection connection, IDBIndex index, IDBIndexDelta delta)- Since:
- 4.2
-
createPrimaryKey
protected void createPrimaryKey(IDBIndex index, java.lang.StringBuilder builder)
- Since:
- 4.2
-
createIndex
protected void createIndex(IDBIndex index, java.lang.StringBuilder builder)
- Since:
- 4.2
-
createIndexFields
protected void createIndexFields(IDBIndex index, java.lang.StringBuilder builder)
- Since:
- 4.2
-
dropIndex
protected void dropIndex(java.sql.Connection connection, IDBIndex index, IDBIndexDelta delta)- Since:
- 4.2
-
dropPrimaryKey
protected void dropPrimaryKey(IDBIndex index, java.lang.StringBuilder builder)
- Since:
- 4.2
-
dropIndex
protected void dropIndex(IDBIndex index, java.lang.StringBuilder builder)
- Since:
- 4.2
-
createTables
public java.util.Set<IDBTable> createTables(java.lang.Iterable<? extends IDBTable> tables, java.sql.Connection connection) throws DBException
- Specified by:
createTablesin interfaceIDBAdapter- Throws:
DBException
-
createTable
public boolean createTable(IDBTable table, java.sql.Statement statement) throws DBException
- Specified by:
createTablein interfaceIDBAdapter- Throws:
DBException
-
dropTables
public java.util.Collection<IDBTable> dropTables(java.lang.Iterable<? extends IDBTable> tables, java.sql.Connection connection) throws DBException
- Specified by:
dropTablesin interfaceIDBAdapter- Throws:
DBException
-
dropTable
public boolean dropTable(IDBTable table, java.sql.Statement statement)
- Specified by:
dropTablein interfaceIDBAdapter
-
getDropTableSQL
protected java.lang.String getDropTableSQL(IDBTable table)
-
getMaxTableNameLength
public int getMaxTableNameLength()
- Specified by:
getMaxTableNameLengthin interfaceIDBAdapter- Since:
- 2.0
-
getMaxFieldNameLength
public int getMaxFieldNameLength()
- Specified by:
getMaxFieldNameLengthin interfaceIDBAdapter- Since:
- 2.0
-
getFieldLength
public int getFieldLength(DBType type)
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
public boolean isTypeIndexable(DBType type)
- Specified by:
isTypeIndexablein interfaceIDBAdapter
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
convertString
public java.lang.String convertString(java.sql.PreparedStatement preparedStatement, int parameterIndex, java.lang.String value)- Since:
- 4.3
-
convertString
public java.lang.String convertString(java.sql.ResultSet resultSet, int columnIndex, java.lang.String value)- Since:
- 4.3
-
convertString
public java.lang.String convertString(java.sql.ResultSet resultSet, java.lang.String columnLabel, java.lang.String value)- Since:
- 4.3
-
doCreateTable
protected void doCreateTable(IDBTable table, java.sql.Statement statement) throws java.sql.SQLException
- Throws:
java.sql.SQLException- Since:
- 2.0
-
createIndex
protected void createIndex(IDBIndex index, java.sql.Statement statement, int num) throws java.sql.SQLException
- Throws:
java.sql.SQLException- Since:
- 2.0
-
addIndexField
protected void addIndexField(java.lang.StringBuilder builder, IDBField field)
-
createConstraints
protected java.lang.String createConstraints(IDBTable table)
- Since:
- 2.0
-
createFieldDefinition
protected java.lang.String createFieldDefinition(IDBField field)
- Since:
- 2.0
-
getTypeName
protected java.lang.String getTypeName(IDBField field)
-
getSQL92ReservedWords
public java.lang.String[] getSQL92ReservedWords()
-
isReservedWord
public boolean isReservedWord(java.lang.String word)
- Specified by:
isReservedWordin interfaceIDBAdapter
-
validateTable
protected void validateTable(IDBTable table, java.sql.Statement statement) throws DBException
- Throws:
DBException- Since:
- 2.0
-
createFieldDefinitions
protected java.lang.String[] createFieldDefinitions(IDBTable table)
- Since:
- 4.2
-
appendFieldNames
public void appendFieldNames(java.lang.Appendable appendable, IDBTable table)
-
appendFieldDefs
protected void appendFieldDefs(java.lang.Appendable appendable, IDBTable table, java.lang.String[] defs)- Since:
- 4.2
-
adaptType
public DBType adaptType(DBType type)
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
public boolean isDuplicateKeyException(java.sql.SQLException ex)
Description copied from interface:IDBAdapterCheck if an exception indicates a constraint violation (duplicate key)- Specified by:
isDuplicateKeyExceptionin interfaceIDBAdapter- Since:
- 4.0
-
isTableNotFoundException
public boolean isTableNotFoundException(java.sql.SQLException ex)
- Specified by:
isTableNotFoundExceptionin interfaceIDBAdapter- Since:
- 4.2
-
isColumnNotFoundException
public boolean isColumnNotFoundException(java.sql.SQLException ex)
- Specified by:
isColumnNotFoundExceptionin interfaceIDBAdapter- Since:
- 4.2
-
sqlRenameField
public java.lang.String sqlRenameField(IDBField field, java.lang.String oldName)
- Specified by:
sqlRenameFieldin interfaceIDBAdapter- Since:
- 4.2
-
sqlModifyField
public java.lang.String sqlModifyField(IDBField field)
- Specified by:
sqlModifyFieldin interfaceIDBAdapter- Since:
- 4.2
-
sqlModifyField
protected java.lang.String sqlModifyField(java.lang.String tableName, java.lang.String fieldName, java.lang.String definition)- Since:
- 4.2
-
format
public java.lang.String format(java.sql.PreparedStatement stmt)
- Since:
- 4.2
-
format
public java.lang.String format(java.sql.ResultSet resultSet)
- Since:
- 4.2
-
convertToSQL
public java.lang.Object convertToSQL(java.lang.Object value)
- Since:
- 4.9
-
getDefaultDBLength
public static int getDefaultDBLength(DBType type)
- Since:
- 4.2
-
generateReservedWords
protected static void generateReservedWords(java.sql.Connection connection, java.lang.String[] words) throws java.sql.SQLException- Throws:
java.sql.SQLException- Since:
- 4.9
-
-