org.apache.torque.adapter
Class DerbyAdapter

java.lang.Object
  extended by org.apache.torque.adapter.AbstractAdapter
      extended by org.apache.torque.adapter.DerbyAdapter
All Implemented Interfaces:
Serializable, Adapter

public class DerbyAdapter
extends AbstractAdapter

This is used to connect to an embedded Apache Derby Database using the supplied JDBC driver.

Version:
$Id: DerbyAdapter.java 1373827 2012-08-16 13:34:35Z tfischer $
Author:
Henning P. Schmiedehausen, tins
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.torque.adapter.Adapter
ADAPTER_KEY, AUTODETECT_ADAPTER, DRIVER_KEY
 
Constructor Summary
protected DerbyAdapter()
          Empty constructor.
 
Method Summary
 boolean escapeText()
          Whether backslashes (\) should be escaped in explicit SQL strings.
 void generateLimits(Query query, long offset, int limit)
          Build Derby-style query with limit or offset.
 String getIDMethodSQL(Object obj)
          Returns the SQL to get the database key of the last row inserted, which in this case is VALUES IDENTITY_VAL_LOCAL().
 IDMethod getIDMethodType()
          Returns the constant from the IDMethod interface denoting which type of primary key generation method this type of RDBMS uses.
 String ignoreCase(String str)
          This method is used to ignore case.
 void lockTable(Connection con, String table)
          Locks the specified table.
 boolean supportsNativeLimit()
          Returns whether the database can natively limit the size of the ResultSet of a query.
 boolean supportsNativeOffset()
          Returns whether the database natively supports returning results starting at an offset position other than 0.
 String toUpperCase(String str)
          This method is used to ignore case.
 void unlockTable(Connection con, String table)
          Unlocks the specified table.
 boolean useEscapeClauseForLike()
          Whether an escape clause in like should be used.
 
Methods inherited from class org.apache.torque.adapter.AbstractAdapter
getStringDelimiter, getUpdateLockClause, ignoreCaseInOrderBy, useIlike
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DerbyAdapter

protected DerbyAdapter()
Empty constructor.

Method Detail

toUpperCase

public String toUpperCase(String str)
This method is used to ignore case.

Specified by:
toUpperCase in interface Adapter
Specified by:
toUpperCase in class AbstractAdapter
Parameters:
str - The string to transform to upper case.
Returns:
The upper case string.

ignoreCase

public String ignoreCase(String str)
This method is used to ignore case.

Specified by:
ignoreCase in interface Adapter
Specified by:
ignoreCase in class AbstractAdapter
Parameters:
str - The string whose case to ignore.
Returns:
The string in a case that can be ignored.

getIDMethodType

public IDMethod getIDMethodType()
Description copied from class: AbstractAdapter
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 Adapter
Specified by:
getIDMethodType in class AbstractAdapter
Returns:
IDMethod constant
See Also:
Adapter.getIDMethodType()

getIDMethodSQL

public String getIDMethodSQL(Object obj)
Returns the SQL to get the database key of the last row inserted, which in this case is VALUES IDENTITY_VAL_LOCAL().

Specified by:
getIDMethodSQL in interface Adapter
Specified by:
getIDMethodSQL in class AbstractAdapter
Parameters:
obj - Information used for key generation.
Returns:
The most recently inserted database key.
See Also:
Adapter.getIDMethodSQL(Object obj)

lockTable

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

Specified by:
lockTable in interface Adapter
Specified by:
lockTable in class AbstractAdapter
Parameters:
con - The JDBC connection to use.
table - The name of the table to lock.
Throws:
SQLException - No Statement could be created or executed.

unlockTable

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

Specified by:
unlockTable in interface Adapter
Specified by:
unlockTable in class AbstractAdapter
Parameters:
con - The JDBC connection to use.
table - The name of the table to unlock.
Throws:
SQLException - No Statement could be created or executed.

escapeText

public 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 "\". As derby does not need escaping of Backslashes, this method always returns false.

Specified by:
escapeText in interface Adapter
Overrides:
escapeText in class AbstractAdapter
Returns:
true if the database needs to escape backslashes in SqlExpressions.

useEscapeClauseForLike

public boolean useEscapeClauseForLike()
Whether an escape clause in like should be used. Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\'; Derby needs this, so this implementation always returns true.

Specified by:
useEscapeClauseForLike in interface Adapter
Overrides:
useEscapeClauseForLike in class AbstractAdapter
Returns:
whether the escape clause should be appended or not.

supportsNativeLimit

public boolean supportsNativeLimit()
Returns whether the database can natively limit the size of the ResultSet of a query. Limit is supported since Derby 10.5.1.1.

Specified by:
supportsNativeLimit in interface Adapter
Overrides:
supportsNativeLimit in class AbstractAdapter
Returns:
true.

supportsNativeOffset

public boolean supportsNativeOffset()
Returns whether the database natively supports returning results starting at an offset position other than 0. Offset is supported since Derby 10.5.1.1.

Specified by:
supportsNativeOffset in interface Adapter
Overrides:
supportsNativeOffset in class AbstractAdapter
Returns:
true.

generateLimits

public void generateLimits(Query query,
                           long offset,
                           int limit)
Build Derby-style query with limit or offset. The resulting query may look like this:
  select * from TABLENAME fetch next 3 rows only;
  select * from TABLENAME offset 3 rows fetch next 3 rows only;
 

Specified by:
generateLimits in interface Adapter
Overrides:
generateLimits in class AbstractAdapter
Parameters:
query - The query to modify.
offset - the offset value.
limit - the limit value.


Copyright © 2000-2013 The Apache Software Foundation. All Rights Reserved.