org.apache.torque.adapter
Class DB

java.lang.Object
  extended byorg.apache.torque.adapter.DB
All Implemented Interfaces:
IDMethod, java.io.Serializable
Direct Known Subclasses:
DBAxion, DBCloudscape, DBDB2App, DBDB2Net, DBDerby, DBHypersonicSQL, DBInformix, DBInstantDB, DBInterbase, DBMM, DBNone, DBOdbc, DBOracle, DBPostgres, DBSapDB, DBSybase, DBWeblogic

public abstract class DB
extends java.lang.Object
implements java.io.Serializable, IDMethod

DB defines the interface for a Torque database adapter. Support for new databases is added by subclassing DB and implementing its abstract interface, and by registering the new database adapter and its corresponding JDBC driver in the service configuration file.

The Torque database adapters exist to present a uniform interface to database access across all available databases. Once the necessary adapters have been written and configured, transparent swapping of databases is theoretically supported with zero code changes and minimal configuration file modifications.

Torque uses the driver class name to find the right adapter. A JDBC driver corresponding to your adapter must be added to the properties file, using the fully-qualified class name of the driver. If no driver is specified for your database, driver.default is used.

 #### MySQL MM Driver
 database.default.driver=org.gjt.mm.mysql.Driver
 database.default.url=jdbc:mysql://localhost/DATABASENAME
 

Version:
$Id: DB.java 239636 2005-08-24 12:38:09Z henning $
Author:
Jon S. Stevens, Brett McLaughlin, Daniel Rall, Augustin Vidovic
See Also:
Serialized Form

Field Summary
static java.lang.String ADAPTER_KEY
          Key for the configuration which contains database adapters
static int LIMIT_STYLE_DB2
          
static int LIMIT_STYLE_MYSQL
          SELECT ...
static int LIMIT_STYLE_NONE
          Database does not support limiting result sets.
static int LIMIT_STYLE_ORACLE
          
static int LIMIT_STYLE_POSTGRES
          SELECT ...
static int LIMIT_STYLE_SYBASE
          SET ROWCOUNT <offset> SELECT ...
 
Fields inherited from interface org.apache.torque.adapter.IDMethod
AUTO_INCREMENT, ID_BROKER, NATIVE, NO_ID_METHOD, SEQUENCE
 
Constructor Summary
protected DB()
          Empty constructor.
 
Method Summary
 boolean escapeText()
          This method is for the SqlExpression.quoteAndEscape rules.
 java.lang.String getBooleanString(java.lang.Boolean b)
          This method is used to format a boolean string.
 java.lang.String getDateString(java.util.Date date)
          This method is used to format any date string.
abstract  java.lang.String getIDMethodSQL(java.lang.Object obj)
          Returns SQL used to get the most recently inserted primary key.
abstract  java.lang.String getIDMethodType()
          Returns the constant from the IDMethod interface denoting which type of primary key generation method this type of RDBMS uses.
 int getLimitStyle()
          This method is used to check whether the database supports limiting the size of the resultset.
 char getStringDelimiter()
          Returns the character used to indicate the beginning and end of a piece of text used in a SQL statement (generally a single quote).
abstract  java.lang.String ignoreCase(java.lang.String in)
          This method is used to ignore case.
 java.lang.String ignoreCaseInOrderBy(java.lang.String in)
          This method is used to ignore case in an ORDER BY clause.
abstract  void lockTable(java.sql.Connection con, java.lang.String table)
          Locks the specified table.
 boolean supportsNativeLimit()
          This method is used to check whether the database natively supports limiting the size of the resultset.
 boolean supportsNativeOffset()
          This method is used to check whether the database natively supports returning results starting at an offset position other than 0.
abstract  java.lang.String toUpperCase(java.lang.String in)
          This method is used to ignore case.
abstract  void unlockTable(java.sql.Connection con, java.lang.String table)
          Unlocks the specified table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIMIT_STYLE_NONE

public static final int LIMIT_STYLE_NONE
Database does not support limiting result sets.

See Also:
Constant Field Values

LIMIT_STYLE_POSTGRES

public static final int LIMIT_STYLE_POSTGRES
SELECT ... LIMIT , [<offset>]

See Also:
Constant Field Values

LIMIT_STYLE_MYSQL

public static final int LIMIT_STYLE_MYSQL
SELECT ... LIMIT [, ] <offset>

See Also:
Constant Field Values

LIMIT_STYLE_SYBASE

public static final int LIMIT_STYLE_SYBASE
SET ROWCOUNT <offset> SELECT ... SET ROWCOUNT 0

See Also:
Constant Field Values

LIMIT_STYLE_ORACLE

public static final int LIMIT_STYLE_ORACLE
SELECT ... WHERE ... AND ROWNUM < 

See Also:
Constant Field Values

LIMIT_STYLE_DB2

public static final int LIMIT_STYLE_DB2
SELECT ... WHERE ... AND ROW_NUMBER() OVER() < 

See Also:
Constant Field Values

ADAPTER_KEY

public static final java.lang.String ADAPTER_KEY
Key for the configuration which contains database adapters

See Also:
Constant Field Values
Constructor Detail

DB

protected DB()
Empty constructor.

Method Detail

toUpperCase

public abstract java.lang.String toUpperCase(java.lang.String in)
This method is used to ignore case.

Parameters:
in - The string to transform to upper case.
Returns:
The upper case string.

getStringDelimiter

public char getStringDelimiter()
Returns the character used to indicate the beginning and end of a piece of text used in a SQL statement (generally a single quote).

Returns:
The text delimeter.

getIDMethodType

public abstract java.lang.String getIDMethodType()
Returns the constant from the IDMethod interface denoting which type of primary key generation method this type of RDBMS uses.

Returns:
IDMethod constant

getIDMethodSQL

public abstract java.lang.String getIDMethodSQL(java.lang.Object obj)
Returns SQL used to get the most recently inserted primary key. Databases which have no support for this return null.

Parameters:
obj - Information used for key generation.
Returns:
The most recently inserted database key.

lockTable

public abstract void lockTable(java.sql.Connection con,
                               java.lang.String table)
                        throws java.sql.SQLException
Locks the specified table.

Parameters:
con - The JDBC connection to use.
table - The name of the table to lock.
Throws:
java.sql.SQLException - No Statement could be created or executed.

unlockTable

public abstract void unlockTable(java.sql.Connection con,
                                 java.lang.String table)
                          throws java.sql.SQLException
Unlocks the specified table.

Parameters:
con - The JDBC connection to use.
table - The name of the table to unlock.
Throws:
java.sql.SQLException - No Statement could be created or executed.

ignoreCase

public abstract java.lang.String ignoreCase(java.lang.String in)
This method is used to ignore case.

Parameters:
in - The string whose case to ignore.
Returns:
The string in a case that can be ignored.

ignoreCaseInOrderBy

public java.lang.String ignoreCaseInOrderBy(java.lang.String in)
This method is used to ignore case in an ORDER BY clause. Usually it is the same as ignoreCase, but some databases (Interbase for example) does not use the same SQL in ORDER BY and other clauses.

Parameters:
in - The string whose case to ignore.
Returns:
The string in a case that can be ignored.

supportsNativeLimit

public boolean supportsNativeLimit()
This method is used to check whether the database natively supports limiting the size of the resultset.

Returns:
True if the database natively supports limiting the size of the resultset.

supportsNativeOffset

public boolean supportsNativeOffset()
This method is used to check whether the database natively supports returning results starting at an offset position other than 0.

Returns:
True if the database natively supports returning results starting at an offset position other than 0.

escapeText

public boolean escapeText()
This method is for the SqlExpression.quoteAndEscape rules. The rule is, any string in a SqlExpression with a BACKSLASH will either be changed to "\\" or left as "\". SapDB does not need the escape character.

Returns:
true if the database needs to escape text in SqlExpressions.

getLimitStyle

public int getLimitStyle()
This method is used to check whether the database supports limiting the size of the resultset.

Returns:
The limit style for the database.

getDateString

public java.lang.String getDateString(java.util.Date date)
This method is used to format any date string. Database can use different default date formats.

Parameters:
date - the Date to format
Returns:
The proper date formatted String.

getBooleanString

public java.lang.String getBooleanString(java.lang.Boolean b)
This method is used to format a boolean string.

Parameters:
b - the Boolean to format
Returns:
The proper date formatted String.


Copyright © 2000-2006 Apache Software Foundation. All Rights Reserved.