Package org.apache.torque.adapter
Class MssqlAdapter
- java.lang.Object
-
- org.apache.torque.adapter.AbstractAdapter
-
- org.apache.torque.adapter.MssqlAdapter
-
- All Implemented Interfaces:
Serializable,Adapter
public class MssqlAdapter extends AbstractAdapter
This is used to connect to a MSSQL database. This is tested with the jtds driver from sourceforge.- Version:
- $Id: MssqlAdapter.java 1848527 2018-12-09 16:27:22Z tv $
- Author:
- Gonzalo Diethelm
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.apache.torque.adapter.Adapter
ADAPTER_KEY, AUTODETECT_ADAPTER, DRIVER_KEY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMssqlAdapter()Empty constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanescapeText()Determines whether backslashes (\) should be escaped in explicit SQL strings.voidgenerateLimits(Query query, long offset, int limit)Modify a query to add limit and offset values for MSSQL.StringgetIDMethodSQL(Object unused)Returns the last value from an identity column (available on a per-session basis from the global variable@@identity).IDMethodgetIDMethodType()Returns the constant from theIDMethodinterface denoting which type of primary key generation method this type of RDBMS uses.StringgetUpdateLockClause()Returns the clause which acquires a write lock on a row when doing a select.StringignoreCase(String in)This method is used to ignore case.voidlockTable(Connection con, String table)Locks the specified table.booleansupportsNativeOffset()Returns whether the database natively supports returning results starting at an offset position other than 0.StringtoUpperCase(String in)This method is used to ignore case.voidunlockTable(Connection con, String table)Tries to unlock the specified table.booleanuseEscapeClauseForLike()Whether an escape clause in like should be used.-
Methods inherited from class org.apache.torque.adapter.AbstractAdapter
getStringDelimiter, ignoreCaseInOrderBy, setCapabilities, supportsNativeLimit, useGetGeneratedKeys, useIlike, useMinusForExcept
-
-
-
-
Method Detail
-
toUpperCase
public String toUpperCase(String in)
This method is used to ignore case.- Specified by:
toUpperCasein interfaceAdapter- Specified by:
toUpperCasein classAbstractAdapter- Parameters:
in- The string to transform to upper case.- Returns:
- The upper case string.
-
ignoreCase
public String ignoreCase(String in)
This method is used to ignore case.- Specified by:
ignoreCasein interfaceAdapter- Specified by:
ignoreCasein classAbstractAdapter- Parameters:
in- The string whose case to ignore.- Returns:
- The string in a case that can be ignored.
-
getIDMethodType
public IDMethod getIDMethodType()
Description copied from class:AbstractAdapterReturns the constant from theIDMethodinterface denoting which type of primary key generation method this type of RDBMS uses.- Specified by:
getIDMethodTypein interfaceAdapter- Specified by:
getIDMethodTypein classAbstractAdapter- Returns:
- IDMethod constant
- See Also:
Adapter.getIDMethodType()
-
getIDMethodSQL
public String getIDMethodSQL(Object unused)
Returns the last value from an identity column (available on a per-session basis from the global variable@@identity).- Specified by:
getIDMethodSQLin interfaceAdapter- Specified by:
getIDMethodSQLin classAbstractAdapter- Parameters:
unused- Information used for key generation.- Returns:
- The most recently inserted database key.
- See Also:
Adapter.getIDMethodSQL(Object obj)
-
getUpdateLockClause
public String getUpdateLockClause()
Returns the clause which acquires a write lock on a row when doing a select.- Specified by:
getUpdateLockClausein interfaceAdapter- Overrides:
getUpdateLockClausein classAbstractAdapter- Returns:
- the SQL clause to acquire a write lock. This implementation returns "WITH (UPDLOCK)";
-
lockTable
public void lockTable(Connection con, String table) throws SQLException
Locks the specified table.- Specified by:
lockTablein interfaceAdapter- Specified by:
lockTablein classAbstractAdapter- 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
Tries to unlock the specified table. This implementation does nothing as tables in MSSQL are unlocked when a commit or rollback is issued. This has unintended side effects, as well as we do not know whether to use commit or rollback. The lock will go away automatically when the transaction is ended.- Specified by:
unlockTablein interfaceAdapter- Specified by:
unlockTablein classAbstractAdapter- Parameters:
con- The JDBC connection to use.table- The name of the table to unlock.- Throws:
SQLException- No Statement could be created or executed.
-
supportsNativeOffset
public boolean supportsNativeOffset()
Returns whether the database natively supports returning results starting at an offset position other than 0. Return false for MSSQL- Specified by:
supportsNativeOffsetin interfaceAdapter- Overrides:
supportsNativeOffsetin classAbstractAdapter- Returns:
- true if the database natively supports returning results starting at an offset position other than 0.
-
generateLimits
public void generateLimits(Query query, long offset, int limit) throws TorqueException
Modify a query to add limit and offset values for MSSQL.- Specified by:
generateLimitsin interfaceAdapter- Overrides:
generateLimitsin classAbstractAdapter- Parameters:
query- The query to modifyoffset- the offset Valuelimit- the limit Value- Throws:
TorqueException- if any error occurs when building the query
-
escapeText
public boolean escapeText()
Determines 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 "\". Sybase (and MSSQL) doesn't define a default escape character, so false is returned.- Specified by:
escapeTextin interfaceAdapter- Overrides:
escapeTextin classAbstractAdapter- Returns:
- false
- See Also:
Adapter.escapeText()
-
useEscapeClauseForLike
public boolean useEscapeClauseForLike()
Whether an escape clause in like should be used. Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\'; MSSQL needs this, so this implementation always returnstrue.- Specified by:
useEscapeClauseForLikein interfaceAdapter- Overrides:
useEscapeClauseForLikein classAbstractAdapter- Returns:
- whether the escape clause should be appended or not.
-
-