org.firebirdsql.jca
Class FBManagedConnection

java.lang.Object
  extended byorg.firebirdsql.jca.FBManagedConnection
All Implemented Interfaces:
javax.resource.spi.ManagedConnection, javax.transaction.xa.XAResource

public class FBManagedConnection
extends java.lang.Object
implements javax.resource.spi.ManagedConnection, javax.transaction.xa.XAResource

The class FBManagedConnection implements both the ManagedConnection and XAResource interfaces.

Version:
1.0
Author:
David Jencks

Field Summary
 boolean autoCommit
           
protected  FBConnectionRequestInfo cri
          Describe variable cri here.
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Method Summary
 void addConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)
           Add an event listener.
 void associateConnection(java.lang.Object connection)
          Used by the container to change the association of an application-level connection handle with a ManagedConneciton instance.
 void cleanup()
          Application server calls this method to force any cleanup on the ManagedConnection instance.
 void clearWarnings()
          Clear warnings for this database connection.
 void close(AbstractConnection c)
           
 void closeBlob(isc_blob_handle blob)
           
 void closeStatement(isc_stmt_handle stmt, boolean deallocate)
           
 void commit(javax.transaction.xa.Xid id, boolean twoPhase)
          Commits a transaction.
 isc_blob_handle createBlobHandle(boolean segmented)
           
 void destroy()
          Destroys the physical connection to the underlying resource manager.
 void end(javax.transaction.xa.Xid id, int flags)
          Dissociates a resource from a global transaction.
 void executeImmediate(java.lang.String statement)
           
 void executeStatement(isc_stmt_handle stmt, boolean sendOutSqlda)
           
 void fetch(isc_stmt_handle stmt, int fetchSize)
           
 void forget(javax.transaction.xa.Xid id)
          Indicates that no further action will be taken on behalf of this transaction (after a heuristic failure).
 isc_stmt_handle getAllocatedStatement()
           
 java.lang.Integer getBlobBufferLength()
           
 byte[] getBlobSegment(isc_blob_handle blob, int len)
           
 java.lang.Object getConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cri)
          Creates a new connection handle for the underlying physical connection represented by the ManagedConnection instance.
 FBConnectionRequestInfo getConnectionRequestInfo()
          Get information about the current connection parameters.
 java.lang.String getDatabase()
           
 int getDatabaseProductMajorVersion()
           
 int getDatabaseProductMinorVersion()
           
 java.lang.String getDatabaseProductName()
           
 java.lang.String getDatabaseProductVersion()
           
 GDS getInternalAPIHandler()
          Get Firebird API handler (sockets/native/embeded/etc)
 isc_db_handle getIscDBHandle()
          Get connection handle for direct Firebird API access
 java.lang.String getIscEncoding()
           
 int getIscTransactionIsolation()
          Deprecated. you should not use internal transaction isolation levels directrly.
 javax.resource.spi.LocalTransaction getLocalTransaction()
          Returns an javax.resource.spi.LocalTransaction instance.
 java.io.PrintWriter getLogWriter()
          Gets the log writer for this ManagedConnection instance.
 javax.resource.spi.ManagedConnectionMetaData getMetaData()
          Gets the metadata information for this connection's underlying EIS resource manager instance.
 void getSqlCounts(isc_stmt_handle stmt)
           
 FBTpb getTpb()
           
 int getTransactionIsolation()
           
 java.lang.String getTransactionIsolationName()
           
 int getTransactionTimeout()
          Gets the transaction timeout.
 java.lang.String getUserName()
           
 java.util.List getWarnings()
          Get all warnings associated with current connection.
 javax.transaction.xa.XAResource getXAResource()
          In both javax.sql.XAConnection and javax.resource.spi.MangagedConnection Return an XA resource to the caller.
 void internalStart(javax.transaction.xa.Xid id, int flags)
           
 boolean inTransaction()
           
 boolean isReadOnly()
           
 boolean isSameRM(javax.transaction.xa.XAResource res)
           
 isc_blob_handle openBlobHandle(long blob_id, boolean segmented)
           
 int prepare(javax.transaction.xa.Xid id)
          Prepares a transaction to commit.
 void prepareSQL(isc_stmt_handle stmt, java.lang.String sql, boolean describeBind)
           
 void putBlobSegment(isc_blob_handle blob, byte[] buf)
           
 javax.transaction.xa.Xid[] recover(int flag)
           
 void registerStatement(isc_stmt_handle fbStatement)
           
 void removeConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)
           Remove an event listener.
 void rollback(javax.transaction.xa.Xid id)
          Rolls back the work, assuming it was done on behalf of the specified transaction.
 void setCursorName(isc_stmt_handle stmt, java.lang.String cursorName)
           
 void setIscTransactionIsolation(int isolation)
          Deprecated. you should not use internal transaction isolation levels directrly.
 void setLogWriter(java.io.PrintWriter out)
          Sets the log writer for this ManagedConnection instance.
 void setReadOnly(boolean readOnly)
           
 void setTransactionIsolation(int isolation)
           
 void setTransactionIsolationName(java.lang.String isolation)
           
 boolean setTransactionTimeout(int timeout)
          Sets the transaction timeout.
 void start(javax.transaction.xa.Xid id, int flags)
          Associates a JDBC connection with a global transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cri

protected FBConnectionRequestInfo cri
Describe variable cri here. Needed from mcf when killing a db handle when a new tx cannot be started.


autoCommit

public boolean autoCommit
Method Detail

getLocalTransaction

public javax.resource.spi.LocalTransaction getLocalTransaction()
Returns an javax.resource.spi.LocalTransaction instance. The LocalTransaction interface is used by the container to manage local transactions for a RM instance. Returns: LocalTransaction instance Throws: ResourceException - generic exception if operation fails NotSupportedException - if the operation is not supported ResourceAdapterInternalException - resource adapter internal error condition

Specified by:
getLocalTransaction in interface javax.resource.spi.ManagedConnection

getMetaData

public javax.resource.spi.ManagedConnectionMetaData getMetaData()
                                                         throws javax.resource.ResourceException
Gets the metadata information for this connection's underlying EIS resource manager instance. The ManagedConnectionMetaData interface provides information about the underlying EIS instance associated with the ManagedConenction instance. Returns: ManagedConnectionMetaData instance Throws: ResourceException - generic exception if operation fails NotSupportedException - if the operation is not supported

Specified by:
getMetaData in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
Sets the log writer for this ManagedConnection instance. The log writer is a character output stream to which all logging and tracing messages for this ManagedConnection instance will be printed. Application Server manages the association of output stream with the ManagedConnection instance based on the connection pooling requirements. When a ManagedConnection object is initially created, the default log writer associated with this instance is obtained from the ManagedConnectionFactory. An application server can set a log writer specific to this ManagedConnection to log/trace this instance using setLogWriter method. Parameters: out - Character Output stream to be associated Throws: ResourceException - generic exception if operation fails ResourceAdapterInternalException - resource adapter related error condition

Specified by:
setLogWriter in interface javax.resource.spi.ManagedConnection

getLogWriter

public java.io.PrintWriter getLogWriter()
Gets the log writer for this ManagedConnection instance. The log writer is a character output stream to which all logging and tracing messages for this ManagedConnection instance will be printed. ConnectionManager manages the association of output stream with the ManagedConnection instance based on the connection pooling requirements. The Log writer associated with a ManagedConnection instance can be one set as default from the ManagedConnectionFactory (that created this connection) or one set specifically for this instance by the application server. Returns: Character ourput stream associated with this Managed- Connection instance Throws: ResourceException - generic exception if operation fails

Specified by:
getLogWriter in interface javax.resource.spi.ManagedConnection

addConnectionEventListener

public void addConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)

Add an event listener.

Specified by:
addConnectionEventListener in interface javax.resource.spi.ManagedConnection

removeConnectionEventListener

public void removeConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)

Remove an event listener.

Specified by:
removeConnectionEventListener in interface javax.resource.spi.ManagedConnection

associateConnection

public void associateConnection(java.lang.Object connection)
                         throws javax.resource.ResourceException
Used by the container to change the association of an application-level connection handle with a ManagedConneciton instance. The container should find the right ManagedConnection instance and call the associateConnection method. The resource adapter is required to implement the associateConnection method. The method implementation for a ManagedConnection should dissociate the connection handle (passed as a parameter) from its currently associated ManagedConnection and associate the new connection handle with itself. Parameters: connection - Application-level connection handle Throws: ResourceException - Failed to associate the connection handle with this ManagedConnection instance IllegalStateException - Illegal state for invoking this method ResourceAdapterInternalException - Resource adapter internal error condition

Specified by:
associateConnection in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException

cleanup

public void cleanup()
             throws javax.resource.ResourceException
Application server calls this method to force any cleanup on the ManagedConnection instance. The method ManagedConnection.cleanup initiates a cleanup of the any client-specific state as maintained by a ManagedConnection instance. The cleanup should invalidate all connection handles that had been created using this ManagedConnection instance. Any attempt by an application component to use the connection handle after cleanup of the underlying ManagedConnection should result in an exception. The cleanup of ManagedConnection is always driven by an application server. An application server should not invoke ManagedConnection.cleanup when there is an uncompleted transaction (associated with a ManagedConnection instance) in progress. The invocation of ManagedConnection.cleanup method on an already cleaned-up connection should not throw an exception. The cleanup of ManagedConnection instance resets its client specific state and prepares the connection to be put back in to a connection pool. The cleanup method should not cause resource adapter to close the physical pipe and reclaim system resources associated with the physical connection. Throws: ResourceException - generic exception if operation fails ResourceAdapterInternalException - resource adapter internal error condition IllegalStateException - Illegal state for calling connection cleanup. Example - if a localtransaction is in progress that doesn't allow connection cleanup

Specified by:
cleanup in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException

getConnection

public java.lang.Object getConnection(javax.security.auth.Subject subject,
                                      javax.resource.spi.ConnectionRequestInfo cri)
                               throws javax.resource.ResourceException
Creates a new connection handle for the underlying physical connection represented by the ManagedConnection instance. This connection handle is used by the application code to refer to the underlying physical connection. A connection handle is tied to its ManagedConnection instance in a resource adapter implementation specific way. The ManagedConnection uses the Subject and additional ConnectionRequest Info (which is specific to resource adapter and opaque to application server) to set the state of the physical connection. Parameters: Subject - security context as JAAS subject cxRequestInfo - ConnectionRequestInfo instance Returns: generic Object instance representing the connection handle. For CCI, the connection handle created by a ManagedConnection instance is of the type javax.resource.cci.Connection. Throws: ResourceException - generic exception if operation fails ResourceAdapterInternalException - resource adapter internal error condition SecurityException - security related error condition CommException - failed communication with EIS instance EISSystemException - internal error condition in EIS instance - used if EIS instance is involved in setting state of ManagedConnection

Specified by:
getConnection in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException

destroy

public void destroy()
             throws javax.resource.ResourceException
Destroys the physical connection to the underlying resource manager. To manage the size of the connection pool, an application server can explictly call ManagedConnection.destroy to destroy a physical connection. A resource adapter should destroy all allocated system resources for this ManagedConnection instance when the method destroy is called. Throws: ResourceException - generic exception if operation failed IllegalStateException - illegal state for destroying connection

Specified by:
destroy in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException

getXAResource

public javax.transaction.xa.XAResource getXAResource()

In both javax.sql.XAConnection and javax.resource.spi.MangagedConnection

Return an XA resource to the caller.

Specified by:
getXAResource in interface javax.resource.spi.ManagedConnection
Returns:
the XAResource

commit

public void commit(javax.transaction.xa.Xid id,
                   boolean twoPhase)
            throws javax.transaction.xa.XAException
Commits a transaction.

Specified by:
commit in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), the transaction ID is wrong, the connection was set to Auto-Commit, or the commit on the underlying connection fails. The error code differs depending on the exact situation.

end

public void end(javax.transaction.xa.Xid id,
                int flags)
         throws javax.transaction.xa.XAException
Dissociates a resource from a global transaction.

Specified by:
end in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end called twice), or the transaction ID is wrong.

forget

public void forget(javax.transaction.xa.Xid id)
            throws javax.transaction.xa.XAException
Indicates that no further action will be taken on behalf of this transaction (after a heuristic failure). It is assumed this will be called after a failed commit or rollback. This should actually never be called since we don't use heuristic tx completion on timeout.

Specified by:
forget in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), or the transaction ID is wrong.

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Gets the transaction timeout.

Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource res)
                 throws javax.transaction.xa.XAException
Specified by:
isSameRM in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

prepare

public int prepare(javax.transaction.xa.Xid id)
            throws javax.transaction.xa.XAException
Prepares a transaction to commit.

Specified by:
prepare in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), the transaction ID is wrong, or the connection was set to Auto-Commit.

recover

public javax.transaction.xa.Xid[] recover(int flag)
                                   throws javax.transaction.xa.XAException
Specified by:
recover in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

rollback

public void rollback(javax.transaction.xa.Xid id)
              throws javax.transaction.xa.XAException
Rolls back the work, assuming it was done on behalf of the specified transaction.

Specified by:
rollback in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (end never called), the transaction ID is wrong, the connection was set to Auto-Commit, or the rollback on the underlying connection fails. The error code differs depending on the exact situation.

setTransactionTimeout

public boolean setTransactionTimeout(int timeout)
                              throws javax.transaction.xa.XAException
Sets the transaction timeout. This is saved, but the value is not used by the current implementation.

Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

start

public void start(javax.transaction.xa.Xid id,
                  int flags)
           throws javax.transaction.xa.XAException
Associates a JDBC connection with a global transaction. We assume that end will be called followed by prepare, commit, or rollback. If start is called after end but before commit or rollback, there is no way to distinguish work done by different transactions on the same connection). If start is called more than once before end, either it's a duplicate transaction ID or illegal transaction ID (since you can't have two transactions associated with one DB connection).

Specified by:
start in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException - Occurs when the state was not correct (start called twice), the transaction ID is wrong, or the instance has already been closed.

internalStart

public void internalStart(javax.transaction.xa.Xid id,
                          int flags)
                   throws javax.transaction.xa.XAException,
                          GDSException
Throws:
javax.transaction.xa.XAException
GDSException

getAllocatedStatement

public isc_stmt_handle getAllocatedStatement()
                                      throws GDSException
Throws:
GDSException

inTransaction

public boolean inTransaction()

prepareSQL

public void prepareSQL(isc_stmt_handle stmt,
                       java.lang.String sql,
                       boolean describeBind)
                throws GDSException,
                       java.sql.SQLException
Throws:
GDSException
java.sql.SQLException

executeStatement

public void executeStatement(isc_stmt_handle stmt,
                             boolean sendOutSqlda)
                      throws GDSException
Throws:
GDSException

executeImmediate

public void executeImmediate(java.lang.String statement)
                      throws GDSException
Throws:
GDSException

fetch

public void fetch(isc_stmt_handle stmt,
                  int fetchSize)
           throws GDSException
Throws:
GDSException

setCursorName

public void setCursorName(isc_stmt_handle stmt,
                          java.lang.String cursorName)
                   throws GDSException
Throws:
GDSException

closeStatement

public void closeStatement(isc_stmt_handle stmt,
                           boolean deallocate)
                    throws GDSException
Throws:
GDSException

close

public void close(AbstractConnection c)

registerStatement

public void registerStatement(isc_stmt_handle fbStatement)

openBlobHandle

public isc_blob_handle openBlobHandle(long blob_id,
                                      boolean segmented)
                               throws GDSException
Throws:
GDSException

createBlobHandle

public isc_blob_handle createBlobHandle(boolean segmented)
                                 throws GDSException
Throws:
GDSException

getBlobSegment

public byte[] getBlobSegment(isc_blob_handle blob,
                             int len)
                      throws GDSException
Throws:
GDSException

closeBlob

public void closeBlob(isc_blob_handle blob)
               throws GDSException
Throws:
GDSException

putBlobSegment

public void putBlobSegment(isc_blob_handle blob,
                           byte[] buf)
                    throws GDSException
Throws:
GDSException

getSqlCounts

public void getSqlCounts(isc_stmt_handle stmt)
                  throws GDSException
Throws:
GDSException

getDatabaseProductName

public java.lang.String getDatabaseProductName()

getDatabaseProductVersion

public java.lang.String getDatabaseProductVersion()

getDatabaseProductMajorVersion

public int getDatabaseProductMajorVersion()

getDatabaseProductMinorVersion

public int getDatabaseProductMinorVersion()

getDatabase

public java.lang.String getDatabase()

getUserName

public java.lang.String getUserName()

getTransactionIsolation

public int getTransactionIsolation()
                            throws javax.resource.ResourceException
Throws:
javax.resource.ResourceException

setTransactionIsolation

public void setTransactionIsolation(int isolation)
                             throws javax.resource.ResourceException
Throws:
javax.resource.ResourceException

getTransactionIsolationName

public java.lang.String getTransactionIsolationName()
                                             throws javax.resource.ResourceException
Throws:
javax.resource.ResourceException

setTransactionIsolationName

public void setTransactionIsolationName(java.lang.String isolation)
                                 throws javax.resource.ResourceException
Throws:
javax.resource.ResourceException

getIscTransactionIsolation

public int getIscTransactionIsolation()
                               throws javax.resource.ResourceException
Deprecated. you should not use internal transaction isolation levels directrly.

Throws:
javax.resource.ResourceException

setIscTransactionIsolation

public void setIscTransactionIsolation(int isolation)
                                throws javax.resource.ResourceException
Deprecated. you should not use internal transaction isolation levels directrly.

Throws:
javax.resource.ResourceException

setReadOnly

public void setReadOnly(boolean readOnly)

isReadOnly

public boolean isReadOnly()

getBlobBufferLength

public java.lang.Integer getBlobBufferLength()

getIscEncoding

public java.lang.String getIscEncoding()

getWarnings

public java.util.List getWarnings()
Get all warnings associated with current connection.

Returns:
list of GDSException instances representing warnings for this database connection.

clearWarnings

public void clearWarnings()
Clear warnings for this database connection.


getIscDBHandle

public isc_db_handle getIscDBHandle()
                             throws GDSException
Get connection handle for direct Firebird API access

Returns:
internal handle for connection
Throws:
GDSException

getInternalAPIHandler

public GDS getInternalAPIHandler()
Get Firebird API handler (sockets/native/embeded/etc)

Returns:
handler object for internal API calls

getConnectionRequestInfo

public FBConnectionRequestInfo getConnectionRequestInfo()
Get information about the current connection parameters.

Returns:
instance of FBConnectionRequestInfo.

getTpb

public FBTpb getTpb()


Copyright © 2001 David Jencks and other authors. All rights reserved.