org.eclipse.net4j.spi.db
Class DBAdapter

java.lang.Object
  extended by org.eclipse.net4j.spi.db.DBAdapter
All Implemented Interfaces:
IDBAdapter
Direct Known Subclasses:
DerbyAdapter, H2Adapter, HSQLDBAdapter, MYSQLAdapter, PostgreSQLAdapter

public abstract class DBAdapter
extends Object
implements IDBAdapter

A useful base class for implementing custom DB adapters.


Field Summary
 
Fields inherited from interface org.eclipse.net4j.db.IDBAdapter
REGISTRY
 
Constructor Summary
DBAdapter(String name, String version)
           
 
Method Summary
 DBType adaptType(DBType type)
          Provide a way for the DBAdapter to override unsupported DB types with replacements.
protected  void addIndexField(StringBuilder builder, IDBField field)
           
 void appendFieldNames(Appendable appendable, IDBTable table)
           
protected  String createConstraints(IDBTable table)
           
protected  String createFieldDefinition(IDBField field)
           
protected  void createIndex(IDBIndex index, Statement statement, int num)
           
 boolean createTable(IDBTable table, Statement statement)
           
 Set<IDBTable> createTables(Iterable<? extends IDBTable> tables, Connection connection)
           
protected  void doCreateTable(IDBTable table, Statement statement)
           
 boolean dropTable(IDBTable table, Statement statement)
           
 Collection<IDBTable> dropTables(Iterable<? extends IDBTable> tables, Connection connection)
           
protected  String getDropTableSQL(IDBTable table)
           
 int getMaxFieldNameLength()
           
 int getMaxTableNameLength()
           
 String getName()
           
 String[] getSQL92ReservedWords()
           
protected  String getTypeName(IDBField field)
           
 String getVersion()
           
 boolean isDuplicateKeyException(SQLException ex)
          Check if an exception indicates a constraint violation (duplicate key)
 boolean isReservedWord(String word)
           
 boolean isTypeIndexable(DBType type)
           
 boolean isValidFirstChar(char ch)
          Check if a character is valid as first character.
 String toString()
           
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
createJDBCDataSource, getJDBCDriver, getReservedWords
 

Constructor Detail

DBAdapter

public DBAdapter(String name,
                 String version)
Method Detail

getName

public String getName()
Specified by:
getName in interface IDBAdapter

getVersion

public String getVersion()
Specified by:
getVersion in interface IDBAdapter

createTables

public Set<IDBTable> createTables(Iterable<? extends IDBTable> tables,
                                  Connection connection)
                           throws DBException
Specified by:
createTables in interface IDBAdapter
Throws:
DBException

createTable

public boolean createTable(IDBTable table,
                           Statement statement)
                    throws DBException
Specified by:
createTable in interface IDBAdapter
Throws:
DBException

dropTables

public Collection<IDBTable> dropTables(Iterable<? extends IDBTable> tables,
                                       Connection connection)
                                throws DBException
Specified by:
dropTables in interface IDBAdapter
Throws:
DBException

dropTable

public boolean dropTable(IDBTable table,
                         Statement statement)
Specified by:
dropTable in interface IDBAdapter

getDropTableSQL

protected 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

isTypeIndexable

public boolean isTypeIndexable(DBType type)
Specified by:
isTypeIndexable in interface IDBAdapter

toString

public String toString()
Overrides:
toString in class Object

doCreateTable

protected void doCreateTable(IDBTable table,
                             Statement statement)
                      throws SQLException
Throws:
SQLException
Since:
2.0

createIndex

protected void createIndex(IDBIndex index,
                           Statement statement,
                           int num)
                    throws SQLException
Throws:
SQLException
Since:
2.0

addIndexField

protected void addIndexField(StringBuilder builder,
                             IDBField field)

createConstraints

protected String createConstraints(IDBTable table)
Since:
2.0

createFieldDefinition

protected String createFieldDefinition(IDBField field)
Since:
2.0

getTypeName

protected String getTypeName(IDBField field)

getSQL92ReservedWords

public String[] getSQL92ReservedWords()

isReservedWord

public boolean isReservedWord(String word)
Specified by:
isReservedWord in interface IDBAdapter

validateTable

protected void validateTable(IDBTable table,
                             Statement statement)
                      throws DBException
Throws:
DBException
Since:
2.0

appendFieldNames

public void appendFieldNames(Appendable appendable,
                             IDBTable table)

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(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


Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.