net.sf.colle.sql.schema
Class RDBMSRuntime

java.lang.Object
  extended bynet.sf.colle.sql.schema.RDBMSRuntime
Direct Known Subclasses:
MSSQLRuntime, MySQLRuntime, OracleRuntime

public abstract class RDBMSRuntime
extends Object

Abstraction of known differences in RDBMS systems. Created: 21 Feb 2001

Version:
$Revision: 1.10 $, $Date: 2004/09/13 05:05:50 $
Author:
Dwayne Schultz

Field Summary
static int ERROR_CONSTRAINT_VIOLATED
           
static int ERROR_DUPLICATE_ROW
           
static int ERROR_UNKNOWN
           
 
Constructor Summary
RDBMSRuntime()
           
 
Method Summary
abstract  void createSequence(String psSequenceName, int pnStartWith, int pnIncrementBy, Connection pxConnection)
          Create a new sequence.
abstract  void dropSequence(String psSequenceName, Connection pxConnection)
          Drop the sequence from the database.
 String getCreatTableSuffix()
          Returns the vendor specific text to put at the end of a create table call so MySQL can turn on transactions.
 String getDatabaseURL(String psServer, String psDatabase, Integer pnPort)
          Forms a DBMS specific database URL from the information provided.
abstract  int getErrorCode(SQLException pxException)
          Return error code (ERROR_*) for SQLException.
static RDBMSRuntime getInstance()
           
abstract  int getNextValue(String psSequenceName, Connection pxConnection)
          Request a unique identifier for the following sequence name.
abstract  ResultSet getTables(String psTable, Connection pxConnection)
          Wraps calls to DatabaseMetaData.getTables().
 String getTruncName(String psName)
          Truncate a name value to a maximum size for a specific database.
 boolean isIndexRequiredOnForeignKey()
          Returns true if RDBMS requires an explicit index on content before creating a foreign key.
abstract  void loadCSVFile(Table pxTable, String psCSVFile, Connection pxConnection)
          Loads a CSV file into a table.
 void lockTable(String psTableName, Connection pxConnection)
          Locks a table for multiple operations.
 void lockTables(String[] pxTableNames, Connection pxConnection)
          Locks several tables at once.
 String mapJDBCType(String psJDBCType, int pnLength, boolean pbNullable)
          Re-maps JDBC data types to vendor specific data types.
 void unlockTable(String psTableName, Connection pxConnection)
          Unlocks a table previously locked with lockTable.
 void unlockTables(String[] pxTableNames, Connection pxConnection)
          Unlocks tables previously locked with lockTables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_UNKNOWN

public static final int ERROR_UNKNOWN
See Also:
Constant Field Values

ERROR_DUPLICATE_ROW

public static final int ERROR_DUPLICATE_ROW
See Also:
Constant Field Values

ERROR_CONSTRAINT_VIOLATED

public static final int ERROR_CONSTRAINT_VIOLATED
See Also:
Constant Field Values
Constructor Detail

RDBMSRuntime

public RDBMSRuntime()
Method Detail

getInstance

public static RDBMSRuntime getInstance()

getErrorCode

public abstract int getErrorCode(SQLException pxException)
Return error code (ERROR_*) for SQLException.

Parameters:
pxException - SQL Exception
Returns:
Code of the error

getTruncName

public String getTruncName(String psName)
Truncate a name value to a maximum size for a specific database.

Parameters:
psName - name to be truncated
Returns:
truncated name

getTables

public abstract ResultSet getTables(String psTable,
                                    Connection pxConnection)
                             throws SQLException
Wraps calls to DatabaseMetaData.getTables().

Throws:
SQLException

loadCSVFile

public abstract void loadCSVFile(Table pxTable,
                                 String psCSVFile,
                                 Connection pxConnection)
Loads a CSV file into a table.


mapJDBCType

public String mapJDBCType(String psJDBCType,
                          int pnLength,
                          boolean pbNullable)
Re-maps JDBC data types to vendor specific data types.


getCreatTableSuffix

public String getCreatTableSuffix()
Returns the vendor specific text to put at the end of a create table call so MySQL can turn on transactions.


isIndexRequiredOnForeignKey

public boolean isIndexRequiredOnForeignKey()
Returns true if RDBMS requires an explicit index on content before creating a foreign key.


dropSequence

public abstract void dropSequence(String psSequenceName,
                                  Connection pxConnection)
Drop the sequence from the database.

Parameters:
psSequenceName - name to sequence
pxConnection - database connection

createSequence

public abstract void createSequence(String psSequenceName,
                                    int pnStartWith,
                                    int pnIncrementBy,
                                    Connection pxConnection)
Create a new sequence.

Parameters:
psSequenceName - name to sequence
pnStartWith - starting value of the sequence
pnIncrementBy - increment by
pxConnection - database connection

getNextValue

public abstract int getNextValue(String psSequenceName,
                                 Connection pxConnection)
Request a unique identifier for the following sequence name.

Parameters:
psSequenceName - name to sequence
pxConnection - database connection
Returns:
return the next value in the sequence

getDatabaseURL

public String getDatabaseURL(String psServer,
                             String psDatabase,
                             Integer pnPort)
Forms a DBMS specific database URL from the information provided. If the net.sf.colle.sql.ConnectionManager.databaseURL system property is defined this method will not be called.

Parameters:
psServer - IP address or computer name of the server. Will not be null.
psDatabase - name of the database. May be null if the application does not define.
pnPort - port number of the server. May be null if the application does not define.

lockTable

public void lockTable(String psTableName,
                      Connection pxConnection)
               throws SQLException
Locks a table for multiple operations. This method should be used very sparingly when a large number of write operations will be performed on most of the records in the table. Calling this method may be a no-op as RDBMSRuntimes are not required to implement it. If locked, the table will remain locked until one of the following conditions is met: 1. unlockTable is called. 2. The current transaction is committed. 3. The connection is closed. Which of these conditions actually cause the table to become unlocked depends on the DBMS. It is therefore recommended that when possible all conditions are met to maintain compatibility across DBMSs.

Throws:
SQLException

lockTables

public void lockTables(String[] pxTableNames,
                       Connection pxConnection)
                throws SQLException
Locks several tables at once. Implementations do need to override lockTable() as the default version of lockTable() calls lockTables().

Throws:
SQLException
See Also:
lockTable(java.lang.String, java.sql.Connection)

unlockTable

public void unlockTable(String psTableName,
                        Connection pxConnection)
                 throws SQLException
Unlocks a table previously locked with lockTable. Calling this method may be a no-op as RDBMSRuntimes are not required to implement it. Some RDBMSs may unlock all currently locked tables when this method is called.

Throws:
SQLException

unlockTables

public void unlockTables(String[] pxTableNames,
                         Connection pxConnection)
                  throws SQLException
Unlocks tables previously locked with lockTables. Implementations do need to override unlockTable() as the default version of unlockTable() calls unlockTables().

Throws:
SQLException
See Also:
unlockTable(java.lang.String, java.sql.Connection)