org.ow2.jonas.dbm.internal.cm
Class JManagedConnection

java.lang.Object
  extended by org.ow2.jonas.dbm.internal.cm.JManagedConnection
All Implemented Interfaces:
Comparable, PooledConnection, XAConnection, Synchronization, XAResource, Enlistable

public class JManagedConnection
extends Object
implements Comparable, XAConnection, XAResource, Synchronization, Enlistable

This class represents the physical connection, managed by the pool. It implements the PooledConnection interface, in fact via the derived XAConnection interface.

Author:
durieuxp

Field Summary
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
JManagedConnection(Connection conn, ConnectionManager ds)
           
 
Method Summary
 void addConnectionEventListener(ConnectionEventListener listener)
          Add an event listener.
 void afterCompletion(int status)
          synchronization implementation
 void beforeCompletion()
          synchronization implementation
 void close()
          Close the database connection.
 void commit(Xid xid, boolean onePhase)
          Commit the global transaction specified by xid.
 int compareTo(Object o)
          Compare is based on the number of PrepareStatement cached in this Connection.
 void delistConnection(Transaction transaction)
          delistConnection: used for Stateful beans at postInvoke.
 void end(Xid xid, int flags)
          Ends the work performed on behalf of a transaction branch.
 void enlistConnection(Transaction transaction)
          Enlist Connection in the Transaction
 void forget(Xid xid)
          Tell the resource manager to forget about a heuristically completed transaction branch.
 List getCloserThreadInfos()
           
 Connection getConnection()
          Create an object handle for a database connection.
 long getCreationTime()
           
 int getIdent()
           
 int getOpenCount()
           
 List getOpenerThreadInfos()
           
 long getOpeningTime()
           
 String getRMID()
           
 int getTransactionTimeout()
          Obtain the current transaction timeout value set for this XAResource instance.
 Transaction getTx()
           
 XAResource getXAResource()
          Return an XA resource to the caller.
 void hold()
          Notify as opened
 boolean inactive()
          Check if the connection has been unused for too long time.
 boolean isAged()
           
 boolean isClosed()
           
 boolean isOpen()
           
 boolean isRME()
           
 boolean isSameRM(XAResource xares)
          Determine if the resource manager instance represented by the target object is the same as the resource manager instance represented by the parameter xares
 void notifyClose()
           
 void notifyError(SQLException ex)
           
 void notifyPsClose(JStatement ps)
          A PreparedStatement has been logically closed.
 int prepare(Xid xid)
          Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 PreparedStatement prepareStatement(String sql)
          Try to find a PreparedStatement in the pool
 PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
          Try to find a PreparedStatement in the pool
 int psNumber()
           
 Xid[] recover(int flag)
          Obtain a list of prepared transaction branches from a resource manager.
 boolean release()
          notify as closed
 void remove()
          remove this item, ignoring exception on close.
 void removeConnectionEventListener(ConnectionEventListener listener)
          Remove an event listener.
 void rollback(Xid xid)
          Inform the resource manager to roll back work done on behalf of a transaction branch
 void setPstmtMax(int max)
          Dynamically change the prepared statement pool size
 void setRME(boolean rme)
          set/unset as RME
 boolean setTransactionTimeout(int seconds)
          Set the current transaction timeout value for this XAResource instance.
 void setTx(Transaction tx)
          Set the associated transaction
 void start(Xid xid, int flags)
          Start work on behalf of a transaction branch specified in xid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JManagedConnection

public JManagedConnection(Connection conn,
                          ConnectionManager ds)
Method Detail

getIdent

public int getIdent()
Returns:
The ident of this JManagedConnection

setPstmtMax

public void setPstmtMax(int max)
Dynamically change the prepared statement pool size


commit

public void commit(Xid xid,
                   boolean onePhase)
            throws XAException
Commit the global transaction specified by xid.

Specified by:
commit in interface XAResource
Parameters:
xid - transaction xid
onePhase - true if one phase commit
Throws:
XAException - XA protocol error

end

public void end(Xid xid,
                int flags)
         throws XAException
Ends the work performed on behalf of a transaction branch.

Specified by:
end in interface XAResource
Parameters:
xid - transaction xid
flags - currently unused
Throws:
XAException - XA protocol error

forget

public void forget(Xid xid)
            throws XAException
Tell the resource manager to forget about a heuristically completed transaction branch.

Specified by:
forget in interface XAResource
Parameters:
xid - transaction xid
Throws:
XAException - XA protocol error

getTransactionTimeout

public int getTransactionTimeout()
                          throws XAException
Obtain the current transaction timeout value set for this XAResource instance.

Specified by:
getTransactionTimeout in interface XAResource
Returns:
the current transaction timeout in seconds
Throws:
XAException - XA protocol error

isSameRM

public boolean isSameRM(XAResource xares)
                 throws XAException
Determine if the resource manager instance represented by the target object is the same as the resource manager instance represented by the parameter xares

Specified by:
isSameRM in interface XAResource
Parameters:
xares - An XAResource object
Returns:
True if same RM instance, otherwise false.
Throws:
XAException - XA protocol error

prepare

public int prepare(Xid xid)
            throws XAException
Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.

Specified by:
prepare in interface XAResource
Parameters:
xid - transaction xid
Throws:
XAException - XA protocol error

recover

public Xid[] recover(int flag)
              throws XAException
Obtain a list of prepared transaction branches from a resource manager.

Specified by:
recover in interface XAResource
Returns:
an array of transaction Xids
Throws:
XAException - XA protocol error

rollback

public void rollback(Xid xid)
              throws XAException
Inform the resource manager to roll back work done on behalf of a transaction branch

Specified by:
rollback in interface XAResource
Parameters:
xid - transaction xid
Throws:
XAException - XA protocol error

setTransactionTimeout

public boolean setTransactionTimeout(int seconds)
                              throws XAException
Set the current transaction timeout value for this XAResource instance.

Specified by:
setTransactionTimeout in interface XAResource
Parameters:
seconds - timeout value, in seconds.
Returns:
always true
Throws:
XAException - XA protocol error

start

public void start(Xid xid,
                  int flags)
           throws XAException
Start work on behalf of a transaction branch specified in xid

Specified by:
start in interface XAResource
Parameters:
xid - transaction xid
Throws:
XAException - XA protocol error

getXAResource

public XAResource getXAResource()
                         throws SQLException
Return an XA resource to the caller.

Specified by:
getXAResource in interface XAConnection
Returns:
The XAResource
Throws:
SQLException - - if a database-access error occurs

compareTo

public int compareTo(Object o)
Compare is based on the number of PrepareStatement cached in this Connection.

Specified by:
compareTo in interface Comparable

psNumber

public int psNumber()

getConnection

public Connection getConnection()
                         throws SQLException
Create an object handle for a database connection.

Specified by:
getConnection in interface PooledConnection
Throws:
SQLException - - if a database-access error occurs

close

public void close()
           throws SQLException
Close the database connection. This will physically close the Connection.

Specified by:
close in interface PooledConnection
Throws:
SQLException - - if a database-access error occurs

addConnectionEventListener

public void addConnectionEventListener(ConnectionEventListener listener)
Add an event listener.

Specified by:
addConnectionEventListener in interface PooledConnection
Parameters:
listener - event listener

removeConnectionEventListener

public void removeConnectionEventListener(ConnectionEventListener listener)
Remove an event listener.

Specified by:
removeConnectionEventListener in interface PooledConnection
Parameters:
listener - event listener

enlistConnection

public void enlistConnection(Transaction transaction)
                      throws SystemException
Enlist Connection in the Transaction

Specified by:
enlistConnection in interface Enlistable
Parameters:
transaction - the transaction that has begun
Throws:
SystemException - if an exception occurs

delistConnection

public void delistConnection(Transaction transaction)
delistConnection: used for Stateful beans at postInvoke.

Specified by:
delistConnection in interface Enlistable
Parameters:
transaction - the transaction that has begun

beforeCompletion

public void beforeCompletion()
synchronization implementation

Specified by:
beforeCompletion in interface Synchronization

afterCompletion

public void afterCompletion(int status)
synchronization implementation

Specified by:
afterCompletion in interface Synchronization

isAged

public boolean isAged()
Returns:
true if connection max age has expired

isOpen

public boolean isOpen()
Returns:
true if connection is still open

getOpenCount

public int getOpenCount()
Returns:
open count

inactive

public boolean inactive()
Check if the connection has been unused for too long time. This occurs usually when the caller forgot to call close().

Returns:
true if open time has been reached, and not involved in a tx.

isClosed

public boolean isClosed()
Returns:
true if connection is closed

getOpeningTime

public long getOpeningTime()
Returns:
the time when that connection was used for the first time in a sequence.

getCreationTime

public long getCreationTime()
Returns:
the time when that connection was created (new instance).

getOpenerThreadInfos

public List getOpenerThreadInfos()
Returns:
the list of stack traces of clients that have opened this connection.

getCloserThreadInfos

public List getCloserThreadInfos()
Returns:
the list of stack traces of clients that have closed this connection.

hold

public void hold()
Notify as opened


release

public boolean release()
notify as closed

Returns:
true if normal close.

setTx

public void setTx(Transaction tx)
Set the associated transaction

Parameters:
tx - Transaction

getTx

public Transaction getTx()
Returns:
the Transaction

isRME

public boolean isRME()
Returns:
true if registered as RME

setRME

public void setRME(boolean rme)
set/unset as RME


remove

public void remove()
remove this item, ignoring exception on close.


prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          int resultSetType,
                                          int resultSetConcurrency)
                                   throws SQLException
Try to find a PreparedStatement in the pool

Throws:
SQLException

prepareStatement

public PreparedStatement prepareStatement(String sql)
                                   throws SQLException
Try to find a PreparedStatement in the pool

Throws:
SQLException

notifyPsClose

public void notifyPsClose(JStatement ps)
A PreparedStatement has been logically closed.


getRMID

public String getRMID()

notifyClose

public void notifyClose()

notifyError

public void notifyError(SQLException ex)


Copyright © 2010 OW2 Consortium. All Rights Reserved.