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 custom `DB adapters`.
  Author:
    Eike Stepper

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `protected static class` | `DBAdapter.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
    --- | --- | ---
    `DBType` | `adaptType​(DBType type)` | Provide a way for the DBAdapter to override unsupported DB types with replacements.
    `protected void` | `addIndex​(java.sql.Connection connection, IDBTable table, java.lang.String name, IDBIndex.Type type, java.util.List<DBAdapter.FieldInfo> fieldInfos)` |
    `protected void` | `addIndexField​(java.lang.StringBuilder builder, IDBField field)` |
    `protected void` | `alterTable​(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)` |
    `protected void` | `appendFieldDefs​(java.lang.Appendable appendable, IDBTable table, java.lang.String[] defs)` |
    `void` | `appendFieldNames​(java.lang.Appendable appendable, IDBTable table)` |
    `java.lang.String` | `convertString​(java.sql.PreparedStatement preparedStatement, int parameterIndex, java.lang.String value)` |
    `java.lang.String` | `convertString​(java.sql.ResultSet resultSet, int columnIndex, java.lang.String value)` |
    `java.lang.String` | `convertString​(java.sql.ResultSet resultSet, java.lang.String columnLabel, java.lang.String value)` |
    `java.lang.Object` | `convertToSQL​(java.lang.Object value)` |
    `IDBConnectionProvider` | `createConnectionProvider​(javax.sql.DataSource dataSource)` |
    `protected java.lang.String` | `createConstraints​(IDBTable table)` |
    `protected void` | `createField​(java.sql.Connection connection, java.lang.String tableName, IDBField field)` |
    `protected java.lang.String` | `createFieldDefinition​(IDBField field)` |
    `protected java.lang.String[]` | `createFieldDefinitions​(IDBTable table)` |
    `protected void` | `createIndex​(java.sql.Connection connection, IDBIndex index, IDBIndexDelta delta)` |
    `protected void` | `createIndex​(IDBIndex index, java.lang.StringBuilder builder)` |
    `protected void` | `createIndex​(IDBIndex index, java.sql.Statement statement, int num)` |
    `protected void` | `createIndexFields​(IDBIndex index, java.lang.StringBuilder builder)` |
    `javax.sql.DataSource` | `createJDBCDataSource()` | 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, java.lang.StringBuilder builder)` |
    `protected void` | `createTable​(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)` |
    `boolean` | `createTable​(IDBTable table, java.sql.Statement statement)` |
    `java.util.Set<IDBTable>` | `createTables​(java.lang.Iterable<? extends IDBTable> tables, java.sql.Connection connection)` |
    `protected void` | `doCreateTable​(IDBTable table, java.sql.Statement statement)` |
    `protected void` | `dropField​(java.sql.Connection connection, java.lang.String tableName, java.lang.String fieldName)` |
    `protected void` | `dropIndex​(java.sql.Connection connection, IDBIndex index, IDBIndexDelta delta)` |
    `protected void` | `dropIndex​(IDBIndex index, java.lang.StringBuilder builder)` |
    `protected void` | `dropPrimaryKey​(IDBIndex index, java.lang.StringBuilder builder)` |
    `protected void` | `dropTable​(java.sql.Connection connection, IDBTable table, IDBTableDelta delta)` |
    `boolean` | `dropTable​(IDBTable table, java.sql.Statement statement)` |
    `java.util.Collection<IDBTable>` | `dropTables​(java.lang.Iterable<? extends IDBTable> tables, java.sql.Connection connection)` |
    `java.lang.String` | `format​(java.sql.PreparedStatement stmt)` |
    `java.lang.String` | `format​(java.sql.ResultSet resultSet)` |
    `protected static void` | `generateReservedWords​(java.sql.Connection connection, java.lang.String[] words)` |
    `static int` | `getDefaultDBLength​(DBType type)` |
    `protected java.lang.String` | `getDropTableSQL​(IDBTable table)` |
    `int` | `getFieldLength​(DBType type)` | Returns the column length for the given database type.
    `java.sql.Driver` | `getJDBCDriver()` | Deprecated. As of 4.2 no longer supported because of IP issues for external build dependencies (the vendor driver libs).
    `int` | `getMaxFieldNameLength()` |
    `int` | `getMaxTableNameLength()` |
    `java.lang.String` | `getName()` |
    `java.lang.String[]` | `getSQL92ReservedWords()` |
    `protected java.lang.String` | `getTypeName​(IDBField field)` |
    `java.lang.String` | `getVersion()` |
    `boolean` | `isColumnNotFoundException​(java.sql.SQLException ex)` |
    `boolean` | `isDuplicateKeyException​(java.sql.SQLException ex)` | Check if an exception indicates a constraint violation (duplicate key)
    `protected boolean` | `isPrimaryKeyShadow​(java.sql.Connection connection, IDBTable table, java.lang.String name, IDBIndex.Type type, IDBField[] fields)` |
    `boolean` | `isReservedWord​(java.lang.String word)` |
    `boolean` | `isTableNotFoundException​(java.sql.SQLException ex)` |
    `boolean` | `isTypeIndexable​(DBType type)` |
    `boolean` | `isValidFirstChar​(char ch)` | Check if a character is valid as first character.
    `java.sql.Connection` | `modifyConnection​(java.sql.Connection connection)` |
    `IDBSchemaTransaction` | `openSchemaTransaction​(IDBDatabase database, IDBConnection currentConnection)` |
    `protected void` | `readFields​(java.sql.Connection connection, IDBTable table)` |
    `protected void` | `readIndices​(java.sql.Connection connection, java.sql.DatabaseMetaData metaData, IDBTable table, java.lang.String schemaName)` |
    `protected void` | `readIndices​(java.sql.Connection connection, java.sql.ResultSet resultSet, IDBTable table, int indexNameColumn, int indexTypeColumn, int fieldNameColumn, int fieldPositionColumn)` |
    `IDBSchema` | `readSchema​(java.sql.Connection connection, java.lang.String name)` |
    `void` | `readSchema​(java.sql.Connection connection, IDBSchema schema)` |
    `protected java.sql.ResultSet` | `readTables​(java.sql.Connection connection, java.sql.DatabaseMetaData metaData, java.lang.String schemaName)` |
    `protected java.lang.String` | `sqlModifyField​(java.lang.String tableName, java.lang.String fieldName, java.lang.String definition)` |
    `java.lang.String` | `sqlModifyField​(IDBField field)` |
    `java.lang.String` | `sqlRenameField​(IDBField field, java.lang.String oldName)` |
    `java.lang.String` | `toString()` |
    `void` | `updateSchema​(java.sql.Connection connection, IDBSchema schema, IDBSchemaDelta delta)` |
    `protected void` | `validateTable​(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`

- - ### Constructor Detail

    - #### DBAdapter

          public DBAdapter​(java.lang.String name,
                           java.lang.String version)

  - ### Method Detail

    - #### getName

          public java.lang.String getName()

      Specified by:
        `getName` in interface `IDBAdapter`

    - #### getVersion

          public java.lang.String getVersion()

      Specified by:
        `getVersion` in interface `IDBAdapter`

    - #### 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:
        `getJDBCDriver` in interface `IDBAdapter`
      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:
        `createJDBCDataSource` in interface `IDBAdapter`
      Since:
        4.2

    - #### createConnectionProvider

          public IDBConnectionProvider createConnectionProvider​(javax.sql.DataSource dataSource)

      Specified by:
        `createConnectionProvider` in interface `IDBAdapter`
      Since:
        4.3

    - #### modifyConnection

          public java.sql.Connection modifyConnection​(java.sql.Connection connection)

      Specified by:
        `modifyConnection` in interface `IDBAdapter`
      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:
        `readSchema` in interface `IDBAdapter`
      Since:
        4.2

    - #### readSchema

          public void readSchema​(java.sql.Connection connection,
                                 IDBSchema schema)

      Specified by:
        `readSchema` in interface `IDBAdapter`
      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:
        `updateSchema` in interface `IDBAdapter`
      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:
        `createTables` in interface `IDBAdapter`
      Throws:
        `DBException`

    - #### createTable

          public boolean createTable​(IDBTable table,
                                     java.sql.Statement statement)
                              throws DBException

      Specified by:
        `createTable` in interface `IDBAdapter`
      Throws:
        `DBException`

    - #### dropTables

          public java.util.Collection<IDBTable> dropTables​(java.lang.Iterable<? extends IDBTable> tables,
                                                           java.sql.Connection connection)
                                                    throws DBException

      Specified by:
        `dropTables` in interface `IDBAdapter`
      Throws:
        `DBException`

    - #### dropTable

          public boolean dropTable​(IDBTable table,
                                   java.sql.Statement statement)

      Specified by:
        `dropTable` in interface `IDBAdapter`

    - #### getDropTableSQL

          protected java.lang.String getDropTableSQL​(IDBTable table)

    - #### getMaxTableNameLength

          public int getMaxTableNameLength()

      Specified by:
        `getMaxTableNameLength` in interface `IDBAdapter`
      Since:
        2.0

    - #### getMaxFieldNameLength

          public int getMaxFieldNameLength()

      Specified by:
        `getMaxFieldNameLength` in interface `IDBAdapter`
      Since:
        2.0

    - #### getFieldLength

          public int getFieldLength​(DBType type)

      Description copied from interface: `IDBAdapter`
      Returns the column length for the given database type.
      Specified by:
        `getFieldLength` in interface `IDBAdapter`
      Parameters:
        `type` - the `DBType` to check.
      Returns:
        the supported column length for the type.
      Since:
        4.2

    - #### isTypeIndexable

          public boolean isTypeIndexable​(DBType type)

      Specified by:
        `isTypeIndexable` in interface `IDBAdapter`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.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:
        `isReservedWord` in interface `IDBAdapter`

    - #### 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: `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 interface `IDBAdapter`
      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 interface `IDBAdapter`
      Since:
        4.0

    - #### isDuplicateKeyException

          public boolean isDuplicateKeyException​(java.sql.SQLException ex)

      Description copied from interface: `IDBAdapter`
      Check if an exception indicates a constraint violation (duplicate key)
      Specified by:
        `isDuplicateKeyException` in interface `IDBAdapter`
      Since:
        4.0

    - #### isTableNotFoundException

          public boolean isTableNotFoundException​(java.sql.SQLException ex)

      Specified by:
        `isTableNotFoundException` in interface `IDBAdapter`
      Since:
        4.2

    - #### isColumnNotFoundException

          public boolean isColumnNotFoundException​(java.sql.SQLException ex)

      Specified by:
        `isColumnNotFoundException` in interface `IDBAdapter`
      Since:
        4.2

    - #### sqlRenameField

          public java.lang.String sqlRenameField​(IDBField field,
                                                 java.lang.String oldName)

      Specified by:
        `sqlRenameField` in interface `IDBAdapter`
      Since:
        4.2

    - #### sqlModifyField

          public java.lang.String sqlModifyField​(IDBField field)

      Specified by:
        `sqlModifyField` in interface `IDBAdapter`
      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