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 protected
MssqlAdapter()
Empty constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
escapeText()
Determines whether backslashes (\) should be escaped in explicit SQL strings.void
generateLimits(Query query, long offset, int limit)
Modify a query to add limit and offset values for MSSQL.String
getIDMethodSQL(Object unused)
Returns the last value from an identity column (available on a per-session basis from the global variable@@identity
).IDMethod
getIDMethodType()
Returns the constant from theIDMethod
interface denoting which type of primary key generation method this type of RDBMS uses.String
getUpdateLockClause()
Returns the clause which acquires a write lock on a row when doing a select.String
ignoreCase(String in)
This method is used to ignore case.void
lockTable(Connection con, String table)
Locks the specified table.boolean
supportsNativeOffset()
Returns whether the database natively supports returning results starting at an offset position other than 0.String
toUpperCase(String in)
This method is used to ignore case.void
unlockTable(Connection con, String table)
Tries to unlock the specified table.boolean
useEscapeClauseForLike()
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:
toUpperCase
in interfaceAdapter
- Specified by:
toUpperCase
in 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:
ignoreCase
in interfaceAdapter
- Specified by:
ignoreCase
in 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:AbstractAdapter
Returns the constant from theIDMethod
interface denoting which type of primary key generation method this type of RDBMS uses.- Specified by:
getIDMethodType
in interfaceAdapter
- Specified by:
getIDMethodType
in 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:
getIDMethodSQL
in interfaceAdapter
- Specified by:
getIDMethodSQL
in 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:
getUpdateLockClause
in interfaceAdapter
- Overrides:
getUpdateLockClause
in 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:
lockTable
in interfaceAdapter
- Specified by:
lockTable
in 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:
unlockTable
in interfaceAdapter
- Specified by:
unlockTable
in 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:
supportsNativeOffset
in interfaceAdapter
- Overrides:
supportsNativeOffset
in 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:
generateLimits
in interfaceAdapter
- Overrides:
generateLimits
in 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:
escapeText
in interfaceAdapter
- Overrides:
escapeText
in 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:
useEscapeClauseForLike
in interfaceAdapter
- Overrides:
useEscapeClauseForLike
in classAbstractAdapter
- Returns:
- whether the escape clause should be appended or not.
-
-