Class JtdsConnection

java.lang.Object
net.sourceforge.jtds.jdbc.JtdsConnection
All Implemented Interfaces:
AutoCloseable, Connection, Wrapper

public class JtdsConnection extends Object implements Connection
jTDS implementation of the java.sql.Connection interface.

Implementation notes:

  1. Environment setting code carried over from old jTDS otherwise generally a new implementation of Connection.
  2. Connection properties and SQLException text messages are loaded from a properties file.
  3. Character set choices are also loaded from a resource file and the original Encoder class has gone.
  4. Prepared SQL statements are converted to procedures in the prepareSQL method.
  5. Use of Stored procedures is optional and controlled via connection property.
  6. This Connection object maintains a table of weak references to associated statements. This allows the connection object to control the statements (for example to close them) but without preventing them being garbage collected in a pooled environment.
Version:
$Id: JtdsConnection.java,v 1.119.2.14 2010-05-17 10:27:00 ickzon Exp $
Author:
Mike Hutchinson, Alin Sinpalean
  • Field Details

    • SYBASE_SERVER_CHARSET_QUERY

      private static final String SYBASE_SERVER_CHARSET_QUERY
      SQL query to determine the server charset on Sybase.
      See Also:
    • SQL_SERVER_65_CHARSET_QUERY

      private static final String SQL_SERVER_65_CHARSET_QUERY
      SQL query to determine the server charset on MS SQL Server 6.5.
      See Also:
    • SYBASE_INITIAL_SQL

      private static final String SYBASE_INITIAL_SQL
      Sybase initial connection string.
      See Also:
    • SQL_SERVER_INITIAL_SQL

      private static final String SQL_SERVER_INITIAL_SQL
      SQL Server initial connection string. Also contains a SELECT @@MAX_PRECISION query to retrieve the maximum precision for DECIMAL/NUMERIC data.
      See Also:
    • TRANSACTION_SNAPSHOT

      public static final int TRANSACTION_SNAPSHOT
      SQL Server custom transaction isolation level.
      See Also:
    • url

      private final String url
      The orginal connection URL.
    • serverName

      private String serverName
      The server host name.
    • portNumber

      private int portNumber
      The server port number.
    • serverType

      private int serverType
      The make of SQL Server (sybase/microsoft).
    • instanceName

      private String instanceName
      The SQL Server instance.
    • databaseName

      private String databaseName
      The requested database name.
    • currentDatabase

      private String currentDatabase
      The current database name.
    • domainName

      private String domainName
      The Windows Domain name.
    • user

      private String user
      The database user ID.
    • password

      private String password
      The user password.
    • serverCharset

      private String serverCharset
      The server character set.
    • appName

      private String appName
      The application name.
    • progName

      private String progName
      The program name.
    • wsid

      private String wsid
      Workstation ID.
    • language

      private String language
      The server message language.
    • macAddress

      private String macAddress
      The client MAC Address.
    • tdsVersion

      private int tdsVersion
      The server protocol version.
    • socket

      private final SharedSocket socket
      The network TCP/IP socket.
    • baseTds

      private final TdsCore baseTds
      The cored TDS protocol object.
    • netPacketSize

      private int netPacketSize
      The initial network packet size.
    • packetSize

      private int packetSize
      User requested packet size.
    • collation

      private byte[] collation
      SQL Server 2000 collation.
    • charsetSpecified

      private boolean charsetSpecified
      True if user specifies an explicit charset.
    • databaseProductName

      private String databaseProductName
      The database product name eg SQL SERVER.
    • databaseProductVersion

      private String databaseProductVersion
      The product version eg 11.92.
    • databaseMajorVersion

      private int databaseMajorVersion
      The major version number eg 11.
    • databaseMinorVersion

      private int databaseMinorVersion
      The minor version number eg 92.
    • closed

      private boolean closed
      True if this connection is closed.
    • readOnly

      private boolean readOnly
      True if this connection is read only.
    • statements

      private final ArrayList statements
      List of statements associated with this connection.
    • transactionIsolation

      private int transactionIsolation
      Default transaction isolation level.
    • autoCommit

      private boolean autoCommit
      Default auto commit state.
    • messages

      private final SQLDiagnostic messages
      Diagnostc messages for this connection.
    • rowCount

      private int rowCount
      Connection's current rowcount limit.
    • textSize

      private int textSize
      Connection's current maximum field size limit.
    • maxPrecision

      private int maxPrecision
      Maximum decimal precision.
    • spSequenceNo

      private int spSequenceNo
      Stored procedure unique ID number.
    • cursorSequenceNo

      private int cursorSequenceNo
      Cursor unique ID number.
    • procInTran

      private final ArrayList procInTran
      Procedures in this transaction.
    • charsetInfo

      private CharsetInfo charsetInfo
      Java charset for encoding.
    • prepareSql

      private int prepareSql
      Method for preparing SQL used in Prepared Statements.
    • lobBuffer

      private long lobBuffer
      The amount of LOB data to buffer in memory.
    • maxStatements

      private int maxStatements
      The maximum number of statements to keep open.
    • statementCache

      private StatementCache statementCache
      Statement cache.
    • useUnicode

      private boolean useUnicode
      Send parameters as unicode.
    • namedPipe

      private boolean namedPipe
      Use named pipe IPC instead of TCP/IP sockets.
    • lastUpdateCount

      private boolean lastUpdateCount
      Only return the last update count.
    • tcpNoDelay

      private boolean tcpNoDelay
      TCP_NODELAY
    • loginTimeout

      private int loginTimeout
      Login timeout value in seconds or 0.
    • sybaseInfo

      private int sybaseInfo
      Sybase capability mask.
    • xaTransaction

      private boolean xaTransaction
      True if running distributed transaction.
    • xaState

      private int xaState
      Current emulated XA State eg start/end/prepare etc.
    • xid

      private Object xid
      Current XA Transaction ID.
    • xaEmulation

      private boolean xaEmulation
      True if driver should emulate distributed transactions.
    • mutex

      private final Semaphore mutex
      Mutual exclusion lock to control access to connection.
    • socketTimeout

      private int socketTimeout
      Socket timeout value in seconds or 0.
    • socketKeepAlive

      private boolean socketKeepAlive
      True to enable socket keep alive.
    • processId

      private static Integer processId
      The process ID to report to a server when connecting.
    • ssl

      private String ssl
      SSL setting.
    • batchSize

      private int batchSize
      The maximum size of a batch.
    • useMetadataCache

      private boolean useMetadataCache
      Use metadata cache for prepared statements.
    • useCursors

      private boolean useCursors
      Use fast forward cursors for forward only result sets.
    • bufferDir

      private File bufferDir
      The directory to buffer data to
    • bufferMaxMemory

      private int bufferMaxMemory
      The global buffer memory limit for all connections (in kilobytes).
    • bufferMinPackets

      private int bufferMinPackets
      The minimum number of packets per statement to buffer to memory.
    • useLOBs

      private boolean useLOBs
      Map large types (IMAGE and TEXT/NTEXT) to LOBs by default.
    • cachedTds

      private TdsCore cachedTds
      A cached TdsCore instance to reuse on new statements.
    • bindAddress

      private String bindAddress
      The local address to bind to when connecting to a database via TCP/IP.
    • useJCIFS

      private boolean useJCIFS
      Force use of jCIFS library on Windows when connecting via named pipes.
    • useNTLMv2

      private boolean useNTLMv2
      When doing NTLM authentication, send NTLMv2 response rather than regular response
    • useKerberos

      private boolean useKerberos
      Force Kerberos authentication
    • connections

      private static int[] connections
      the number of currently open connections
    • savepoints

      private ArrayList savepoints
      The list of savepoints.
    • savepointProcInTran

      private Map savepointProcInTran
      Maps each savepoint to a list of temp procedures created since the savepoint
    • savepointId

      private int savepointId
      Counter for generating unique savepoint identifiers
  • Constructor Details

    • JtdsConnection

      private JtdsConnection()
      Default constructor.

      Used for testing.

    • JtdsConnection

      JtdsConnection(String url, Properties info) throws SQLException
      Create a new database connection.
      Parameters:
      url - The connection URL starting jdbc:jtds:.
      info - The additional connection properties.
      Throws:
      SQLException
  • Method Details

    • finalize

      protected void finalize() throws Throwable
      Ensure all resources are released.
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • createNamedPipe

      private SharedSocket createNamedPipe(JtdsConnection connection) throws IOException
      Creates a SharedSocket object representing a connection to a named pipe. If the os.name system property starts with "Windows" (case-insensitive) and the useJCIFS parameter is false, a SharedLocalNamedPipe object is created. Else a SharedNamedPipe is created which uses jCIFS to provide a pure-Java implementation of Windows named pipes.

      This method will retry for loginTimeout seconds to create a named pipe if an IOException continues to be thrown stating, "All pipe instances are busy". If loginTimeout is set to zero (e.g., not set), a default of 20 seconds will be used.

      Parameters:
      connection - the connection object
      Returns:
      an object representing the named pipe connection
      Throws:
      IOException - on error; if an IOException is thrown with a message stating "All pipe instances are busy", then the method timed out after loginTimeout milliseconds attempting to create a named pipe.
    • getSocket

      SharedSocket getSocket()
      Retrive the shared socket.
      Returns:
      The SharedSocket object.
    • getTdsVersion

      int getTdsVersion()
      Retrieve the TDS protocol version.
      Returns:
      The TDS version as an int.
    • getProcName

      String getProcName()
      Retrieves the next unique stored procedure name.

      Notes:

      1. Some versions of Sybase require an id with a length of <= 10.
      2. The format of this name works for sybase and Microsoft and allows for 16M names per session.
      3. The leading '#jtds' indicates this is a temporary procedure and the '#' is removed by the lower level TDS5 routines.
      Not synchronized because it's only called from the synchronized prepareSQL(net.sourceforge.jtds.jdbc.JtdsPreparedStatement, java.lang.String, net.sourceforge.jtds.jdbc.ParamInfo[], boolean, boolean) method.
      Returns:
      the next temporary SP name as a String
    • getCursorName

      String getCursorName()
      Retrieves the next unique cursor name.
      Returns:
      the next cursor name as a String
    • prepareSQL

      String prepareSQL(JtdsPreparedStatement pstmt, String sql, ParamInfo[] params, boolean returnKeys, boolean cursorNeeded) throws SQLException
      Try to convert the SQL statement into a statement prepare.

      Synchronized because it accesses the procedure cache and the baseTds, but the method call also needs to made in a synchronized (connection) block together with the execution (if the prepared statement is actually executed) to ensure the transaction isn't rolled back between this method call and the actual execution.

      Parameters:
      pstmt - the target prepared statement
      sql - the SQL statement to prepare
      params - the parameters
      returnKeys - indicates whether the statement will return generated keys
      cursorNeeded - indicates whether a cursor prepare is needed
      Returns:
      the SQL procedure name as a String or null if the SQL cannot be prepared
      Throws:
      SQLException
    • addCachedProcedure

      void addCachedProcedure(String key, ProcEntry proc)
      Add a stored procedure to the cache.

      Not explicitly synchronized because it's only called by synchronized methods.

      Parameters:
      key - The signature of the procedure to cache.
      proc - The stored procedure descriptor.
    • removeCachedProcedure

      void removeCachedProcedure(String key)
      Remove a stored procedure from the cache.

      Not explicitly synchronized because it's only called by synchronized methods.

      Parameters:
      key - The signature of the procedure to remove from the cache.
    • getMaxStatements

      int getMaxStatements()
      Retrieves the maximum statement cache size.
      Returns:
      the maximum statement cache size
    • getServerType

      public int getServerType()
      Retrieves the server type.
      Returns:
      the server type as an int where 1 == SQLSERVER and 2 == SYBASE.
    • setNetPacketSize

      void setNetPacketSize(int size)
      Sets the network packet size.
      Parameters:
      size - the new packet size
    • getNetPacketSize

      int getNetPacketSize()
      Retrieves the network packet size.
      Returns:
      the packet size as an int
    • getRowCount

      int getRowCount()
      Retrieves the current row count on this connection.
      Returns:
      the row count as an int
    • setRowCount

      void setRowCount(int count)
      Sets the current row count on this connection.
      Parameters:
      count - the new row count
    • getTextSize

      public int getTextSize()
      Retrieves the current maximum textsize on this connection.
      Returns:
      the maximum textsize as an int
    • setTextSize

      public void setTextSize(int textSize)
      Sets the current maximum textsize on this connection.
      Parameters:
      textSize - the new maximum textsize
    • getLastUpdateCount

      boolean getLastUpdateCount()
      Retrieves the status of the lastUpdateCount flag.
      Returns:
      the lastUpdateCount flag as a boolean
    • getMaxPrecision

      int getMaxPrecision()
      Retrieves the maximum decimal precision.
      Returns:
      the precision as an int
    • getLobBuffer

      long getLobBuffer()
      Retrieves the LOB buffer size.
      Returns:
      the LOB buffer size as a long
    • getPrepareSql

      int getPrepareSql()
      Retrieves the Prepared SQL method.
      Returns:
      the Prepared SQL method
    • getBatchSize

      int getBatchSize()
      Retrieves the batch size to be used internally.
      Returns:
      the batch size as an int
    • getUseMetadataCache

      boolean getUseMetadataCache()
      Retrieves the boolean indicating whether metadata caching is enabled.
      Returns:
      true if metadata caching is enabled, false if caching is disabled
    • getUseCursors

      boolean getUseCursors()
      Indicates whether fast forward only cursors should be used for forward only result sets.
      Returns:
      true if fast forward cursors are requested
    • getUseLOBs

      boolean getUseLOBs()
      Indicates whether large types (IMAGE and TEXT/NTEXT) should be mapped by default to LOB types or String and byte[] respectively.
      Returns:
      true if the default mapping should be to LOBs, false otherwise
    • getUseNTLMv2

      boolean getUseNTLMv2()
      Indicates whether, when doing Windows authentication to an MS SQL server, NTLMv2 should be used. When this is set to "false", LM and NTLM responses are sent to the server, which should work fine in most cases. However, some servers are configured to require LMv2 and NTLMv2. In these rare cases, this property should be set to "true".
    • getUseKerberos

      boolean getUseKerberos()
      Return whether to use Kerberos authentication for MS SQL Server.
    • getAppName

      String getAppName()
      Retrieves the application name for this connection.
      Returns:
      the application name
    • getBindAddress

      String getBindAddress()
      Retrieves the bind address for this connection.
      Returns:
      the bind address
    • getBufferDir

      File getBufferDir()
      Returns the directory where data should be buffered to.
      Returns:
      the directory where data should be buffered to.
    • getBufferMaxMemory

      int getBufferMaxMemory()
      Retrieves the maximum amount of memory in Kb to buffer for all connections.
      Returns:
      the maximum amount of memory in Kb to buffer for all connections
    • getBufferMinPackets

      int getBufferMinPackets()
      Retrieves the minimum number of packets to buffer per Statement for this connection.
      Returns:
      the minimum number of packets to buffer per Statement
    • getDatabaseName

      String getDatabaseName()
      Retrieves the database name for this connection.
      Returns:
      the database name
    • getDomainName

      String getDomainName()
      Retrieves the domain name for this connection.
      Returns:
      the domain name
    • getInstanceName

      String getInstanceName()
      Retrieves the instance name for this connection.
      Returns:
      the instance name
    • getLoginTimeout

      int getLoginTimeout()
      Retrieves the login timeout for this connection.
      Returns:
      the login timeout
    • getSocketTimeout

      int getSocketTimeout()
      Retrieves the socket timeout for this connection.
      Returns:
      the socket timeout
    • getSocketKeepAlive

      boolean getSocketKeepAlive()
      Retrieves whether to enable socket keep alive.
      Returns:
      true if the socket keep alive is enabled
    • getProcessId

      int getProcessId()
      Retrieves the process ID to send to a server when a connection is established.
      Returns:
      the process ID
    • getMacAddress

      String getMacAddress()
      Retrieves the MAC (ethernet) address for this connection.
      Returns:
      the MAC (ethernet) address
    • getNamedPipe

      boolean getNamedPipe()
      Retrieves the named pipe setting for this connection.
      Returns:
      the named pipe setting
    • getPacketSize

      int getPacketSize()
      Retrieves the packet size for this connection.
      Returns:
      the packet size
    • getPassword

      String getPassword()
      Retrieves the password for this connection.
      Returns:
      the password
    • getPortNumber

      int getPortNumber()
      Retrieves the port number for this connection.
      Returns:
      the port number
    • getProgName

      String getProgName()
      Retrieves the program name for this connection.
      Returns:
      the program name
    • getServerName

      String getServerName()
      Retrieves the server name for this connection.
      Returns:
      the server name
    • getTcpNoDelay

      boolean getTcpNoDelay()
      Retrieves the tcpNoDelay setting for this connection.
      Returns:
      the tcpNoDelay setting
    • getUseJCIFS

      boolean getUseJCIFS()
      Retrieves the useJCIFS setting for this connection.
      Returns:
      the useJCIFS setting
    • getUser

      String getUser()
      Retrieves the user for this connection.
      Returns:
      the user
    • getWsid

      String getWsid()
      Retrieves the workstation ID (WSID) for this connection.
      Returns:
      the workstation ID (WSID)
    • unpackProperties

      protected void unpackProperties(Properties info) throws SQLException
      Transfers the properties to the local instance variables.
      Parameters:
      info - The connection properties Object.
      Throws:
      SQLException - If an invalid property value is found.
    • parseBooleanProperty

      private static boolean parseBooleanProperty(Properties info, String key) throws SQLException
      Parse a string property value into an boolean value.
      Parameters:
      info - The connection properties object.
      key - The message key used to retrieve the property name.
      Returns:
      The boolean value of the string property value.
      Throws:
      SQLException - If the property value can't be parsed.
    • parseIntegerProperty

      private static int parseIntegerProperty(Properties info, String key) throws SQLException
      Parse a string property value into an integer value.
      Parameters:
      info - The connection properties object.
      key - The message key used to retrieve the property name.
      Returns:
      The integer value of the string property value.
      Throws:
      SQLException - If the property value can't be parsed.
    • parseLongProperty

      private static long parseLongProperty(Properties info, String key) throws SQLException
      Parse a string property value into a long value.
      Parameters:
      info - The connection properties object.
      key - The message key used to retrieve the property name.
      Returns:
      The long value of the string property value.
      Throws:
      SQLException - If the property value can't be parsed.
    • getCharset

      protected String getCharset()
      Retrieve the Java charset to use for encoding.
      Returns:
      the Charset name as a String
    • isWideChar

      protected boolean isWideChar()
      Retrieve the multibyte status of the current character set.
      Returns:
      boolean true if a multi byte character set
    • getCharsetInfo

      protected CharsetInfo getCharsetInfo()
      Retrieve the CharsetInfo instance used by this connection.
      Returns:
      the default CharsetInfo for this connection
    • getUseUnicode

      protected boolean getUseUnicode()
      Retrieve the sendParametersAsUnicode flag.
      Returns:
      boolean true if parameters should be sent as unicode.
    • getSybaseInfo

      protected boolean getSybaseInfo(int flag)
      Retrieve the Sybase capability data.
      Returns:
      Capability bit mask as an int.
    • setSybaseInfo

      protected void setSybaseInfo(int mask)
      Set the Sybase capability data.
      Parameters:
      mask - The capability bit mask.
    • setServerCharset

      protected void setServerCharset(String charset) throws SQLException
      Called by the protocol to change the current character set.
      Parameters:
      charset - the server character set name
      Throws:
      SQLException
    • loadCharset

      private void loadCharset(String charset) throws SQLException
      Load the Java charset to match the server character set.
      Parameters:
      charset - the server character set
      Throws:
      SQLException
    • loadCharset

      private void loadCharset(CharsetInfo ci, String ref) throws SQLException
      Load the Java charset to match the server character set.
      Parameters:
      ci - the CharsetInfo to load
      Throws:
      SQLException
    • determineServerCharset

      private String determineServerCharset() throws SQLException
      Discovers the server charset for server versions that do not send ENVCHANGE packets on login ack, by executing a DB vendor/version specific query.

      Will throw an SQLException if used on SQL Server 7.0 or 2000; the idea is that the charset should already be determined from ENVCHANGE packets for these DB servers.

      Should only be called from the constructor.

      Returns:
      the default server charset
      Throws:
      SQLException - if an error condition occurs
    • setCollation

      void setCollation(byte[] collation) throws SQLException
      Set the default collation for this connection.

      Set by a SQL Server 2000 environment change packet. The collation consists of the following fields:

      • bits 0-19 - The locale eg 0x0409 for US English which maps to code page 1252 (Latin1_General).
      • bits 20-31 - Reserved.
      • bits 32-39 - Sort order (csid from syscharsets)
      If the sort order is non-zero it determines the character set, otherwise the character set is determined by the locale id.
      Parameters:
      collation - The new collation.
      Throws:
      SQLException
    • getCollation

      byte[] getCollation()
      Retrieve the SQL Server 2000 default collation.
      Returns:
      The collation as a byte[5].
    • isCharsetSpecified

      boolean isCharsetSpecified()
      Retrieves whether a specific charset was requested on creation. If this is the case, all character data should be encoded/decoded using that charset.
    • setDatabase

      protected void setDatabase(String newDb, String oldDb) throws SQLException
      Called by the protcol to change the current database context.
      Parameters:
      newDb - The new database selected on the server.
      oldDb - The old database as known by the server.
      Throws:
      SQLException
    • setDBServerInfo

      protected void setDBServerInfo(String databaseProductName, int databaseMajorVersion, int databaseMinorVersion, int buildNumber)
      Update the connection instance with information about the server.
      Parameters:
      databaseProductName - The server name eg SQL Server.
      databaseMajorVersion - The major version eg 11
      databaseMinorVersion - The minor version eg 92
      buildNumber - The server build number.
    • removeStatement

      void removeStatement(JtdsStatement statement) throws SQLException
      Removes a statement object from the list maintained by the connection and cleans up the statement cache if necessary.

      Synchronized because it accesses the statement list, the statement cache and the baseTds.

      Parameters:
      statement - the statement to remove
      Throws:
      SQLException
    • addStatement

      void addStatement(JtdsStatement statement)
      Adds a statement object to the list maintained by the connection.

      WeakReferences are used so that statements can still be closed and garbage collected even if not explicitly closed by the connection.

      Parameters:
      statement - statement to add
    • checkOpen

      void checkOpen() throws SQLException
      Checks that the connection is still open.
      Throws:
      SQLException - if the connection is closed
    • checkLocal

      void checkLocal(String method) throws SQLException
      Checks that this connection is in local transaction mode.
      Parameters:
      method - the method name being tested
      Throws:
      SQLException - if in XA distributed transaction mode
    • notImplemented

      static void notImplemented(String method) throws SQLException
      Reports that user tried to call a method which has not been implemented.
      Parameters:
      method - the method name to report in the error message
      Throws:
      SQLException - always, with the not implemented message
    • getDatabaseMajorVersion

      public int getDatabaseMajorVersion()
      Retrieves the DBMS major version.
      Returns:
      the version as an int
    • getDatabaseMinorVersion

      public int getDatabaseMinorVersion()
      Retrieves the DBMS minor version.
      Returns:
      the version as an int
    • getDatabaseProductName

      String getDatabaseProductName()
      Retrieves the DBMS product name.
      Returns:
      the name as a String
    • getDatabaseProductVersion

      String getDatabaseProductVersion()
      Retrieves the DBMS product version.
      Returns:
      the version as a String
    • getURL

      String getURL()
      Retrieves the original connection URL.
      Returns:
      the connection url as a String
    • getRmHost

      public String getRmHost()
      Retrieves the host and port for this connection.

      Used to identify same resource manager in XA transactions.

      Returns:
      the hostname and port as a String
    • setClosed

      void setClosed()
      Forces the closed status on the statement if an I/O error has occurred.
    • sendXaPacket

      byte[][] sendXaPacket(int[] args, byte[] data) throws SQLException
      Invokes the xp_jtdsxa extended stored procedure on the server.

      Synchronized because it accesses the baseTds.

      Parameters:
      args - the arguments eg cmd, rmid, flags etc.
      data - option byte data eg open string xid etc.
      Returns:
      optional byte data eg OLE cookie
      Throws:
      SQLException - if an error condition occurs
    • enlistConnection

      void enlistConnection(byte[] oleTranID) throws SQLException
      Enlists the current connection in a distributed transaction.
      Parameters:
      oleTranID - the OLE transaction cookie or null to delist
      Throws:
      SQLException - if an error condition occurs
    • setXid

      void setXid(Object xid)
      Sets the XA transaction ID when running in emulation mode.
      Parameters:
      xid - the XA Transaction ID
    • getXid

      Object getXid()
      Gets the XA transaction ID when running in emulation mode.
      Returns:
      the transaction ID as an Object
    • setXaState

      void setXaState(int value)
      Sets the XA state variable.
      Parameters:
      value - the XA state value
    • getXaState

      int getXaState()
      Retrieves the XA state variable.
      Returns:
      the xa state variable as an int
    • isXaEmulation

      boolean isXaEmulation()
      Retrieves the XA Emulation flag.
      Returns:
      True if in XA emulation mode.
    • getMutex

      Semaphore getMutex()
      Retrieves the connection mutex and acquires an exclusive lock on the network connection.
      Returns:
      the mutex object as a Semaphore
    • releaseTds

      void releaseTds(TdsCore tds) throws SQLException
      Releases (either closes or caches) a TdsCore.
      Parameters:
      tds - the TdsCore instance to release
      Throws:
      SQLException - if an error occurs while closing or cleaning up
    • getCachedTds

      TdsCore getCachedTds()
      Retrieves the cached TdsCore or null if nothing is cached and resets the cache (sets it to null).
      Returns:
      the value of cachedTds
      To do:
      Should probably synchronize on another object
    • getHoldability

      public int getHoldability() throws SQLException
      Specified by:
      getHoldability in interface Connection
      Throws:
      SQLException
    • getTransactionIsolation

      public int getTransactionIsolation() throws SQLException
      Specified by:
      getTransactionIsolation in interface Connection
      Throws:
      SQLException
    • clearWarnings

      public void clearWarnings() throws SQLException
      Specified by:
      clearWarnings in interface Connection
      Throws:
      SQLException
    • close

      public void close() throws SQLException
      Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.

      Calling the method close on a Connection object that is already closed is a no-op.

      Note: A Connection object is automatically closed when it is garbage collected. Certain fatal errors also close a Connection object.

      Synchronized because it accesses the statement list and the baseTds.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Connection
      Throws:
      SQLException - if a database access error occurs
    • commit

      public void commit() throws SQLException
      Specified by:
      commit in interface Connection
      Throws:
      SQLException
    • rollback

      public void rollback() throws SQLException
      Specified by:
      rollback in interface Connection
      Throws:
      SQLException
    • getAutoCommit

      public boolean getAutoCommit() throws SQLException
      Specified by:
      getAutoCommit in interface Connection
      Throws:
      SQLException
    • isClosed

      public boolean isClosed() throws SQLException
      Specified by:
      isClosed in interface Connection
      Throws:
      SQLException
    • isReadOnly

      public boolean isReadOnly() throws SQLException
      Specified by:
      isReadOnly in interface Connection
      Throws:
      SQLException
    • setHoldability

      public void setHoldability(int holdability) throws SQLException
      Specified by:
      setHoldability in interface Connection
      Throws:
      SQLException
    • setTransactionIsolation

      public void setTransactionIsolation(int level) throws SQLException
      Specified by:
      setTransactionIsolation in interface Connection
      Throws:
      SQLException
    • setAutoCommit

      public void setAutoCommit(boolean autoCommit) throws SQLException
      Specified by:
      setAutoCommit in interface Connection
      Throws:
      SQLException
    • setReadOnly

      public void setReadOnly(boolean readOnly) throws SQLException
      Specified by:
      setReadOnly in interface Connection
      Throws:
      SQLException
    • getCatalog

      public String getCatalog() throws SQLException
      Specified by:
      getCatalog in interface Connection
      Throws:
      SQLException
    • setCatalog

      public void setCatalog(String catalog) throws SQLException
      Specified by:
      setCatalog in interface Connection
      Throws:
      SQLException
    • getMetaData

      public DatabaseMetaData getMetaData() throws SQLException
      Specified by:
      getMetaData in interface Connection
      Throws:
      SQLException
    • getWarnings

      public SQLWarning getWarnings() throws SQLException
      Specified by:
      getWarnings in interface Connection
      Throws:
      SQLException
    • createStatement

      public Statement createStatement() throws SQLException
      Specified by:
      createStatement in interface Connection
      Throws:
      SQLException
    • createStatement

      public Statement createStatement(int type, int concurrency) throws SQLException
      Specified by:
      createStatement in interface Connection
      Throws:
      SQLException
    • createStatement

      public Statement createStatement(int type, int concurrency, int holdability) throws SQLException
      Specified by:
      createStatement in interface Connection
      Throws:
      SQLException
    • getTypeMap

      public Map getTypeMap() throws SQLException
      Specified by:
      getTypeMap in interface Connection
      Throws:
      SQLException
    • setTypeMap

      public void setTypeMap(Map map) throws SQLException
      Specified by:
      setTypeMap in interface Connection
      Throws:
      SQLException
    • nativeSQL

      public String nativeSQL(String sql) throws SQLException
      Specified by:
      nativeSQL in interface Connection
      Throws:
      SQLException
    • prepareCall

      public CallableStatement prepareCall(String sql) throws SQLException
      Specified by:
      prepareCall in interface Connection
      Throws:
      SQLException
    • prepareCall

      public CallableStatement prepareCall(String sql, int type, int concurrency) throws SQLException
      Specified by:
      prepareCall in interface Connection
      Throws:
      SQLException
    • prepareCall

      public CallableStatement prepareCall(String sql, int type, int concurrency, int holdability) throws SQLException
      Specified by:
      prepareCall in interface Connection
      Throws:
      SQLException
    • prepareStatement

      public PreparedStatement prepareStatement(String sql) throws SQLException
      Specified by:
      prepareStatement in interface Connection
      Throws:
      SQLException
    • prepareStatement

      public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
      Specified by:
      prepareStatement in interface Connection
      Throws:
      SQLException
    • prepareStatement

      public PreparedStatement prepareStatement(String sql, int type, int concurrency) throws SQLException
      Specified by:
      prepareStatement in interface Connection
      Throws:
      SQLException
    • prepareStatement

      public PreparedStatement prepareStatement(String sql, int type, int concurrency, int holdability) throws SQLException
      Specified by:
      prepareStatement in interface Connection
      Throws:
      SQLException
    • prepareStatement

      public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
      Specified by:
      prepareStatement in interface Connection
      Throws:
      SQLException
    • prepareStatement

      public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
      Specified by:
      prepareStatement in interface Connection
      Throws:
      SQLException
    • setSavepoint

      private void setSavepoint(SavepointImpl savepoint) throws SQLException
      Add a savepoint to the list maintained by this connection.
      Parameters:
      savepoint - The savepoint object to add.
      Throws:
      SQLException
    • clearSavepoints

      private void clearSavepoints()
      Releases all savepoints. Used internally when committing or rolling back a transaction.
    • releaseSavepoint

      public void releaseSavepoint(Savepoint savepoint) throws SQLException
      Specified by:
      releaseSavepoint in interface Connection
      Throws:
      SQLException
    • rollback

      public void rollback(Savepoint savepoint) throws SQLException
      Specified by:
      rollback in interface Connection
      Throws:
      SQLException
    • setSavepoint

      public Savepoint setSavepoint() throws SQLException
      Specified by:
      setSavepoint in interface Connection
      Throws:
      SQLException
    • setSavepoint

      public Savepoint setSavepoint(String name) throws SQLException
      Specified by:
      setSavepoint in interface Connection
      Throws:
      SQLException
    • getNextSavepointId

      private int getNextSavepointId()
      Returns the next savepoint identifier.
      Returns:
      the next savepoint identifier
    • addCachedProcedure

      void addCachedProcedure(String key)
      Add a stored procedure to the savepoint cache.
      Parameters:
      key - The signature of the procedure to cache.
    • createArrayOf

      public Array createArrayOf(String typeName, Object[] elements) throws SQLException
      Specified by:
      createArrayOf in interface Connection
      Throws:
      SQLException
    • createBlob

      public Blob createBlob() throws SQLException
      Specified by:
      createBlob in interface Connection
      Throws:
      SQLException
    • createClob

      public Clob createClob() throws SQLException
      Specified by:
      createClob in interface Connection
      Throws:
      SQLException
    • createNClob

      public NClob createNClob() throws SQLException
      Specified by:
      createNClob in interface Connection
      Throws:
      SQLException
    • createSQLXML

      public SQLXML createSQLXML() throws SQLException
      Specified by:
      createSQLXML in interface Connection
      Throws:
      SQLException
    • createStruct

      public Struct createStruct(String typeName, Object[] attributes) throws SQLException
      Specified by:
      createStruct in interface Connection
      Throws:
      SQLException
    • getClientInfo

      public Properties getClientInfo() throws SQLException
      Specified by:
      getClientInfo in interface Connection
      Throws:
      SQLException
    • getClientInfo

      public String getClientInfo(String name) throws SQLException
      Specified by:
      getClientInfo in interface Connection
      Throws:
      SQLException
    • isValid

      public boolean isValid(int timeout) throws SQLException
      Specified by:
      isValid in interface Connection
      Throws:
      SQLException
    • setClientInfo

      public void setClientInfo(Properties properties) throws SQLClientInfoException
      Specified by:
      setClientInfo in interface Connection
      Throws:
      SQLClientInfoException
    • setClientInfo

      public void setClientInfo(String name, String value) throws SQLClientInfoException
      Specified by:
      setClientInfo in interface Connection
      Throws:
      SQLClientInfoException
    • isWrapperFor

      public boolean isWrapperFor(Class arg0) throws SQLException
      Specified by:
      isWrapperFor in interface Wrapper
      Throws:
      SQLException
    • unwrap

      public Object unwrap(Class arg0) throws SQLException
      Specified by:
      unwrap in interface Wrapper
      Throws:
      SQLException
    • setSchema

      public void setSchema(String schema) throws SQLException
      Specified by:
      setSchema in interface Connection
      Throws:
      SQLException
    • getSchema

      public String getSchema() throws SQLException
      Specified by:
      getSchema in interface Connection
      Throws:
      SQLException
    • abort

      public void abort(Executor executor) throws SQLException
      Specified by:
      abort in interface Connection
      Throws:
      SQLException
    • setNetworkTimeout

      public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
      Specified by:
      setNetworkTimeout in interface Connection
      Throws:
      SQLException
    • getNetworkTimeout

      public int getNetworkTimeout() throws SQLException
      Specified by:
      getNetworkTimeout in interface Connection
      Throws:
      SQLException