org.datanucleus.store.connection
Class AbstractManagedConnection

java.lang.Object
  extended by org.datanucleus.store.connection.AbstractManagedConnection
All Implemented Interfaces:
ManagedConnection

public abstract class AbstractManagedConnection
extends java.lang.Object
implements ManagedConnection

Abstract implementation of a managed connection. There are three primary modes for a connection.


Field Summary
protected  boolean closeOnRelease
          Whether we should close() when release() of the connection is called.
protected  boolean commitOnRelease
          Whether we should commit() the connection on release().
protected  java.lang.Object conn
          The underlying (datastore-specific) connection.
protected  java.util.List<ManagedConnectionResourceListener> listeners
          Listeners for the connection.
protected  boolean locked
          Whether the connection is locked for use.
protected  int useCount
          Count on the number of outstanding uses of this connection.
 
Constructor Summary
AbstractManagedConnection()
           
 
Method Summary
 void addListener(ManagedConnectionResourceListener listener)
          Registers a ManagedConnectionResourceListener
 void flush()
          Flush the connection.
 javax.transaction.xa.XAResource getXAResource()
          Obtain an XAResource which can be enlisted in a transaction Override this if you intend on supporting this as an XA resource (default = not supported).
 boolean isLocked()
          whether access to this ManagedConnection has been locked.
 void lock()
          lock the access to this ManagedConnection
 void release()
          Release this connection.
 void removeListener(ManagedConnectionResourceListener listener)
          Deregister a ManagedConnectionResourceListener
 void setManagedResource()
          Method to set that this connection is "managed".
 void setPooled()
          Method to set that this connection is "pooled".
 java.lang.String toString()
          Method to return a string form of this object for convenience debug.
 void unlock()
          unlock the access to this ManagedConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.datanucleus.store.connection.ManagedConnection
close, getConnection
 

Field Detail

conn

protected java.lang.Object conn
The underlying (datastore-specific) connection.


closeOnRelease

protected boolean closeOnRelease
Whether we should close() when release() of the connection is called.


commitOnRelease

protected boolean commitOnRelease
Whether we should commit() the connection on release().


locked

protected boolean locked
Whether the connection is locked for use.


listeners

protected java.util.List<ManagedConnectionResourceListener> listeners
Listeners for the connection.


useCount

protected int useCount
Count on the number of outstanding uses of this connection. Incremented on get. Decremented on release().

Constructor Detail

AbstractManagedConnection

public AbstractManagedConnection()
Method Detail

release

public void release()
Release this connection. This releases the connection back to us so we can pool it if required. In the case of a transactional connection it is allocated and released and always pooled (not committed) during the transaction. With non-transactional connections, they can be pooled (where selected), or not (default).

Specified by:
release in interface ManagedConnection

setManagedResource

public void setManagedResource()
Method to set that this connection is "managed". Means that it should not "commit" the connection (the commit is done elsewhere), nor should it close the connection when release() is called (the connection is retained for further use).

Specified by:
setManagedResource in interface ManagedConnection

setPooled

public void setPooled()
Method to set that this connection is "pooled". That is, when it is released it is not closed, and instead is pooled for the next request.


addListener

public void addListener(ManagedConnectionResourceListener listener)
Description copied from interface: ManagedConnection
Registers a ManagedConnectionResourceListener

Specified by:
addListener in interface ManagedConnection
Parameters:
listener - The listener

removeListener

public void removeListener(ManagedConnectionResourceListener listener)
Description copied from interface: ManagedConnection
Deregister a ManagedConnectionResourceListener

Specified by:
removeListener in interface ManagedConnection
Parameters:
listener - The listener

flush

public void flush()
Description copied from interface: ManagedConnection
Flush the connection. It must invoke the operation ManagedConnectionResourceListener.managedConnectionFlushed()

Specified by:
flush in interface ManagedConnection

isLocked

public boolean isLocked()
Description copied from interface: ManagedConnection
whether access to this ManagedConnection has been locked.

Specified by:
isLocked in interface ManagedConnection
Returns:
true if locked

lock

public void lock()
Description copied from interface: ManagedConnection
lock the access to this ManagedConnection

Specified by:
lock in interface ManagedConnection

unlock

public void unlock()
Description copied from interface: ManagedConnection
unlock the access to this ManagedConnection

Specified by:
unlock in interface ManagedConnection

getXAResource

public javax.transaction.xa.XAResource getXAResource()
Obtain an XAResource which can be enlisted in a transaction Override this if you intend on supporting this as an XA resource (default = not supported).

Specified by:
getXAResource in interface ManagedConnection
Returns:
The XA resource

toString

public java.lang.String toString()
Method to return a string form of this object for convenience debug.

Overrides:
toString in class java.lang.Object
Returns:
The String form


Copyright © 2011. All Rights Reserved.