org.apache.torque.adapter
Interface DB

All Superinterfaces:
IDMethod, java.io.Serializable
All Known Implementing Classes:
AbstractDBAdapter, DBAxion, DBCloudscape, DBDB2400, DBDB2App, DBDB2Net, DBDerby, DBFirebird, DBHypersonicSQL, DBInformix, DBInstantDB, DBInterbase, DBMM, DBMSSQL, DBNone, DBOdbc, DBOracle, DBPostgres, DBSapDB, DBSybase, DBWeblogic

public interface DB
extends java.io.Serializable, IDMethod

DB defines the interface for a Torque database adapter. Support for new databases is added by implementing this interface. A couple of default settings is provided by subclassing AbstractDBAdapter. The new database adapter and its corresponding JDBC driver need to be registered 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. All database adapters need to be thread safe, as they are instantiated only once fore a given configured database and may be accessed simultaneously from several threads.

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 643209 2008-03-31 23:33:41Z gmonroe $
Author:
Jon S. Stevens, Brett McLaughlin, Daniel Rall, Augustin Vidovic, Thomas Vandahl, Greg Monroe

Field Summary
static java.lang.String ADAPTER_KEY
          Key for the configuration which contains database adapters.
static java.lang.String DRIVER_KEY
          Key for the configuration which contains database drivers.
static int LIMIT_STYLE_DB2
          Deprecated. This should not be exposed to the outside
static int LIMIT_STYLE_MYSQL
          Deprecated. This should not be exposed to the outside
static int LIMIT_STYLE_NONE
          Deprecated. This should not be exposed to the outside
static int LIMIT_STYLE_ORACLE
          Deprecated. This should not be exposed to the outside
static int LIMIT_STYLE_POSTGRES
          Deprecated. This should not be exposed to the outside
static int LIMIT_STYLE_SYBASE
          Deprecated. This should not be exposed to the outside
 
Fields inherited from interface org.apache.torque.adapter.IDMethod
AUTO_INCREMENT, ID_BROKER, NATIVE, NO_ID_METHOD, SEQUENCE
 
Method Summary
 boolean escapeText()
          Whether backslashes (\) should be escaped in explicit SQL strings.
 void generateLimits(Query query, int offset, int limit)
          This method is used to generate the database specific query extension to limit the number of record returned.
 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.
 java.lang.Class getFunctionClass(FunctionEnum function)
          Return the class which implements the SQLFunction interface for the specified function.
 java.lang.String getIDMethodSQL(java.lang.Object obj)
          Returns SQL used to get the most recently inserted primary key.
 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()
          Deprecated. This should not be exposed to the outside
 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).
 java.lang.String ignoreCase(java.lang.String in)
          Modifies a SQL snippet such that its case is ignored by the database.
 java.lang.String ignoreCaseInOrderBy(java.lang.String in)
          This method is used to ignore case in an ORDER BY clause.
 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.
 java.lang.String toUpperCase(java.lang.String in)
          This method is used to ignore case.
 void unlockTable(java.sql.Connection con, java.lang.String table)
          Unlocks the specified table.
 boolean useEscapeClauseForLike()
          Whether an escape clause in like should be used.
 boolean useIlike()
          Whether ILIKE should be used for case insensitive like clauses.
 

Field Detail

LIMIT_STYLE_NONE

static final int LIMIT_STYLE_NONE
Deprecated. This should not be exposed to the outside
Database does not support limiting result sets.

See Also:
Constant Field Values

LIMIT_STYLE_POSTGRES

static final int LIMIT_STYLE_POSTGRES
Deprecated. This should not be exposed to the outside
SELECT ... LIMIT , [<offset>]

See Also:
Constant Field Values

LIMIT_STYLE_MYSQL

static final int LIMIT_STYLE_MYSQL
Deprecated. This should not be exposed to the outside
SELECT ... LIMIT [, ] <offset>

See Also:
Constant Field Values

LIMIT_STYLE_SYBASE

static final int LIMIT_STYLE_SYBASE
Deprecated. This should not be exposed to the outside
SET ROWCOUNT <offset> SELECT ... SET ROWCOUNT 0

See Also:
Constant Field Values

LIMIT_STYLE_ORACLE

static final int LIMIT_STYLE_ORACLE
Deprecated. This should not be exposed to the outside
SELECT ... WHERE ... AND ROWNUM < 

See Also:
Constant Field Values

LIMIT_STYLE_DB2

static final int LIMIT_STYLE_DB2
Deprecated. This should not be exposed to the outside
SELECT ... WHERE ... AND ROW_NUMBER() OVER() < 

See Also:
Constant Field Values

ADAPTER_KEY

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

See Also:
Constant Field Values

DRIVER_KEY

static final java.lang.String DRIVER_KEY
Key for the configuration which contains database drivers.

See Also:
Constant Field Values
Method Detail

toUpperCase

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

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

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

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

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

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

java.lang.String ignoreCase(java.lang.String in)
Modifies a SQL snippet such that its case is ignored by the database. The SQL snippet can be a column name (like AURHOR.NAME), an quoted explicit sql string (like 'abc') or any other sql value (like a number etc.).

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

ignoreCaseInOrderBy

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

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

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.

generateLimits

void generateLimits(Query query,
                    int offset,
                    int limit)
                    throws TorqueException
This method is used to generate the database specific query extension to limit the number of record returned.

Parameters:
query - The query to modify
offset - the offset Value
limit - the limit Value
Throws:
TorqueException - if any error occurs when building the query

escapeText

boolean escapeText()
Whether backslashes (\) should be escaped in explicit SQL strings. If true is returned, a BACKSLASH will be changed to "\\". If false is returned, a BACKSLASH will be left as "\".

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

getLimitStyle

int getLimitStyle()
Deprecated. This should not be exposed to the outside

This method is used to check whether the database supports limiting the size of the resultset.

Returns:
The limit style for the database.

getDateString

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

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.

useIlike

boolean useIlike()
Whether ILIKE should be used for case insensitive like clauses.

Returns:
true if ilike should be used for case insensitive likes, false if ignoreCase should be applied to the compared strings.

useEscapeClauseForLike

boolean useEscapeClauseForLike()
Whether an escape clause in like should be used. Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';

Returns:
whether the escape clause should be appended or not.

getFunctionClass

java.lang.Class getFunctionClass(FunctionEnum function)
Return the class which implements the SQLFunction interface for the specified function. This class must have an empty constructor and can be a single level inner class (or not).

Parameters:
function - The function to get the class for.
Returns:
The SQLFunction implementation for a function of this type that will work with this type of DB. Null indicates a class was not found.
See Also:
SQLFunction, AbstractFunction, Aggregate


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