Package org.datanucleus.store.connection
Class AbstractManagedConnection
- java.lang.Object
-
- org.datanucleus.store.connection.AbstractManagedConnection
-
- All Implemented Interfaces:
ManagedConnection
public abstract class AbstractManagedConnection extends Object implements ManagedConnection
Abstract implementation of a managed connection. There are three primary modes for a connection.- Transactional - the commit of connection is controlled external to this class, and when we release the connection it is handed back into a pooled state, available for reuse.
- Non-transactional (1) - the commit of the connection happens at close and when we release the connection it closes the connection (after committing it).
- Non-transactional (2) - the commit of the connection happens at release, and when we release the connection it is handed back into a pooled state, available for reuse.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancloseOnReleaseWhether we should close() when release() of the connection is called.protected booleancommitOnReleaseWhether we should commit() the connection on release().protected ObjectconnThe underlying (datastore-specific) connection.protected List<ManagedConnectionResourceListener>listenersListeners for the connection.protected booleanlockedWhether the connection is locked for use.protected intuseCountCount on the number of outstanding uses of this connection.
-
Constructor Summary
Constructors Constructor Description AbstractManagedConnection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(ManagedConnectionResourceListener listener)Registers a ManagedConnectionResourceListener to be notified of events.voidclose()Close the connection to the datastore.booleancloseAfterTransactionEnd()Convenience method for whether this connection should be closed after the end of transaction.booleancloseOnRelease()booleancommitOnRelease()XAResourcegetXAResource()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).protected voidincrementUseCount()booleanisLocked()voidlock()voidrelease()Release this connection back to us so we can pool it if required.voidreleaseSavepoint(String name)Release the named savepoint (or do nothing if not supported).voidremoveListener(ManagedConnectionResourceListener listener)Deregister a ManagedConnectionResourceListener.voidrollbackToSavepoint(String name)Rollback the connection to the named savepoint (or do nothing if not supported).voidsetCloseOnRelease(boolean close)voidsetCommitOnRelease(boolean commit)voidsetSavepoint(String name)Set this position in the txn as a savepoint with the provided name (if supported, otherwise do nothing).StringtoString()Method to return a string form of this object for convenience debug.voidtransactionFlushed()Flush the connection.voidtransactionPreClose()Prepare the connection for end of transaction.voidunlock()-
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
getConnection
-
-
-
-
Field Detail
-
conn
protected 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 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().
-
-
Method Detail
-
incrementUseCount
protected void incrementUseCount()
-
close
public void close()
Description copied from interface:ManagedConnectionClose the connection to the datastore. It most invoke the operationsManagedConnectionResourceListener.managedConnectionPreClose()andManagedConnectionResourceListener.managedConnectionPostClose(). The listeners are unregistered after this method is invoked.- Specified by:
closein interfaceManagedConnection
-
release
public void release()
Release this 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:
releasein interfaceManagedConnection
-
transactionFlushed
public void transactionFlushed()
Description copied from interface:ManagedConnectionFlush the connection. It must invoke the operationManagedConnectionResourceListener.transactionFlushed()- Specified by:
transactionFlushedin interfaceManagedConnection
-
transactionPreClose
public void transactionPreClose()
Description copied from interface:ManagedConnectionPrepare the connection for end of transaction. It must invoke the operationManagedConnectionResourceListener.transactionPreClose()- Specified by:
transactionPreClosein interfaceManagedConnection
-
setCloseOnRelease
public void setCloseOnRelease(boolean close)
- Specified by:
setCloseOnReleasein interfaceManagedConnection
-
setCommitOnRelease
public void setCommitOnRelease(boolean commit)
- Specified by:
setCommitOnReleasein interfaceManagedConnection
-
closeOnRelease
public boolean closeOnRelease()
- Specified by:
closeOnReleasein interfaceManagedConnection
-
commitOnRelease
public boolean commitOnRelease()
- Specified by:
commitOnReleasein interfaceManagedConnection
-
addListener
public void addListener(ManagedConnectionResourceListener listener)
Description copied from interface:ManagedConnectionRegisters a ManagedConnectionResourceListener to be notified of events.- Specified by:
addListenerin interfaceManagedConnection- Parameters:
listener- The listener
-
removeListener
public void removeListener(ManagedConnectionResourceListener listener)
Description copied from interface:ManagedConnectionDeregister a ManagedConnectionResourceListener.- Specified by:
removeListenerin interfaceManagedConnection- Parameters:
listener- The listener
-
isLocked
public boolean isLocked()
- Specified by:
isLockedin interfaceManagedConnection
-
lock
public void lock()
- Specified by:
lockin interfaceManagedConnection
-
unlock
public void unlock()
- Specified by:
unlockin interfaceManagedConnection
-
getXAResource
public 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:
getXAResourcein interfaceManagedConnection- Returns:
- The XA resource
-
closeAfterTransactionEnd
public boolean closeAfterTransactionEnd()
Description copied from interface:ManagedConnectionConvenience method for whether this connection should be closed after the end of transaction. In DN 2.x, 3.0, 3.1 this was always true, and a connection lasted until txn commit, and then had to get a new connection. In DN 3.2+ this is configurable per datastore connection factory.- Specified by:
closeAfterTransactionEndin interfaceManagedConnection- Returns:
- Whether the ConnectionManager should call close() on it when a txn ends
-
setSavepoint
public void setSavepoint(String name)
Description copied from interface:ManagedConnectionSet this position in the txn as a savepoint with the provided name (if supported, otherwise do nothing).- Specified by:
setSavepointin interfaceManagedConnection- Parameters:
name- Name of savepoint
-
releaseSavepoint
public void releaseSavepoint(String name)
Description copied from interface:ManagedConnectionRelease the named savepoint (or do nothing if not supported).- Specified by:
releaseSavepointin interfaceManagedConnection- Parameters:
name- Name of savepoint
-
rollbackToSavepoint
public void rollbackToSavepoint(String name)
Description copied from interface:ManagedConnectionRollback the connection to the named savepoint (or do nothing if not supported).- Specified by:
rollbackToSavepointin interfaceManagedConnection- Parameters:
name- Name of savepoint
-
-