org.apache.torque.adapter
Class AbstractDBAdapter

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

public abstract class AbstractDBAdapter
extends java.lang.Object
implements DB

This class is the abstract base for any database adapter Support for new databases is added by subclassing this class and implementing its abstract methods, 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 393063 2006-04-10 20:59:16Z tfischer $
Author:
Jon S. Stevens, Brett McLaughlin, Daniel Rall, Augustin Vidovic, Greg Monroe
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.torque.adapter.DB
ADAPTER_KEY, DRIVER_KEY, LIMIT_STYLE_DB2, LIMIT_STYLE_MYSQL, LIMIT_STYLE_NONE, LIMIT_STYLE_ORACLE, LIMIT_STYLE_POSTGRES, LIMIT_STYLE_SYBASE
 
Fields inherited from interface org.apache.torque.adapter.IDMethod
AUTO_INCREMENT, ID_BROKER, NATIVE, NO_ID_METHOD, SEQUENCE
 
Constructor Summary
protected AbstractDBAdapter()
          Empty constructor.
 
Method Summary
 boolean escapeText()
          This method is for the SqlExpression.quoteAndEscape rules.
 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.
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()
          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).
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.
 boolean useEscapeClauseForLike()
          Whether an escape clause in like should be used.
 boolean useIlike()
          Whether ILIKE should be used for case insensitive like clauses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDBAdapter

protected AbstractDBAdapter()
Empty constructor.

Method Detail

toUpperCase

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

Specified by:
toUpperCase in interface DB
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).

Specified by:
getStringDelimiter in interface DB
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.

Specified by:
getIDMethodType in interface DB
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.

Specified by:
getIDMethodSQL in interface DB
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.

Specified by:
lockTable in interface DB
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.

Specified by:
unlockTable in interface DB
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.

Specified by:
ignoreCase in interface DB
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.

Specified by:
ignoreCaseInOrderBy in interface DB
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.

Specified by:
supportsNativeLimit in interface DB
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.

Specified by:
supportsNativeOffset in interface DB
Returns:
True if the database natively supports returning results starting at an offset position other than 0.

generateLimits

public 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.

Specified by:
generateLimits in interface DB
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

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.

Specified by:
escapeText in interface DB
Returns:
true if the database needs to escape text in SqlExpressions.

getLimitStyle

public 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.

Specified by:
getLimitStyle in interface DB
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.

Specified by:
getDateString in interface DB
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.

Specified by:
getBooleanString in interface DB
Parameters:
b - the Boolean to format
Returns:
The proper date formatted String.

useIlike

public boolean useIlike()
Whether ILIKE should be used for case insensitive like clauses. As most databases do not use ILIKE, this implementation returns false. This behaviour may be overwritten in subclasses.

Specified by:
useIlike in interface DB
Returns:
true if ilike should be used for case insensitive likes, false if ignoreCase should be applied to the compared strings.

useEscapeClauseForLike

public boolean useEscapeClauseForLike()
Whether an escape clause in like should be used. Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\'; As most databases do not need the escape clause, this implementation always returns false. This behaviour can be overwritten in subclasses.

Specified by:
useEscapeClauseForLike in interface DB
Returns:
whether the escape clause should be appended or not.

getFunctionClass

public java.lang.Class getFunctionClass(FunctionEnum function)
Return the class which implements the SQLFunction interface for the specified function.

Specified by:
getFunctionClass in interface DB
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.