Package org.datanucleus.store.connection
Class AbstractManagedConnection
java.lang.Object
org.datanucleus.store.connection.AbstractManagedConnection
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprotected boolean
Whether we should close() when release() of the connection is called.protected boolean
Whether we should commit() the connection on release().protected Object
The underlying (datastore-specific) connection.protected List
<ManagedConnectionResourceListener> Listeners for the connection.protected boolean
Whether the connection is locked for use.(package private) boolean
protected int
Count on the number of outstanding uses of this connection. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(ManagedConnectionResourceListener listener) Registers a ManagedConnectionResourceListener to be notified of events.void
close()
Close the connection to the datastore.boolean
Convenience method for whether this connection should be closed after the end of transaction.boolean
boolean
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 void
boolean
isLocked()
void
lock()
void
release()
Release this connection back to us so we can pool it if required.void
releaseSavepoint
(String name) Release the named savepoint (or do nothing if not supported).void
Deregister a ManagedConnectionResourceListener.void
rollbackToSavepoint
(String name) Rollback the connection to the named savepoint (or do nothing if not supported).void
setCloseOnRelease
(boolean close) void
setCommitOnRelease
(boolean commit) void
setSavepoint
(String name) Set this position in the txn as a savepoint with the provided name (if supported, otherwise do nothing).toString()
Method to return a string form of this object for convenience debug.void
Flush the connection.void
Prepare the connection for end of transaction.void
unlock()
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 Details
-
conn
The underlying (datastore-specific) connection. -
closeOnRelease
protected boolean closeOnReleaseWhether we should close() when release() of the connection is called. -
commitOnRelease
protected boolean commitOnReleaseWhether we should commit() the connection on release(). -
locked
protected boolean lockedWhether the connection is locked for use. -
listeners
Listeners for the connection. -
useCount
protected int useCountCount on the number of outstanding uses of this connection. Incremented on get. Decremented on release(). -
processingClose
boolean processingClose
-
-
Constructor Details
-
AbstractManagedConnection
public AbstractManagedConnection()
-
-
Method Details
-
incrementUseCount
protected void incrementUseCount() -
close
public void close()Description copied from interface:ManagedConnection
Close the connection to the datastore. It most invoke the operationsManagedConnectionResourceListener.managedConnectionPreClose()
andManagedConnectionResourceListener.managedConnectionPostClose()
. The listeners are unregistered after this method is invoked.- Specified by:
close
in 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:
release
in interfaceManagedConnection
-
transactionFlushed
public void transactionFlushed()Description copied from interface:ManagedConnection
Flush the connection. It must invoke the operationManagedConnectionResourceListener.transactionFlushed()
- Specified by:
transactionFlushed
in interfaceManagedConnection
-
transactionPreClose
public void transactionPreClose()Description copied from interface:ManagedConnection
Prepare the connection for end of transaction. It must invoke the operationManagedConnectionResourceListener.transactionPreClose()
- Specified by:
transactionPreClose
in interfaceManagedConnection
-
setCloseOnRelease
public void setCloseOnRelease(boolean close) - Specified by:
setCloseOnRelease
in interfaceManagedConnection
-
setCommitOnRelease
public void setCommitOnRelease(boolean commit) - Specified by:
setCommitOnRelease
in interfaceManagedConnection
-
closeOnRelease
public boolean closeOnRelease()- Specified by:
closeOnRelease
in interfaceManagedConnection
-
commitOnRelease
public boolean commitOnRelease()- Specified by:
commitOnRelease
in interfaceManagedConnection
-
addListener
Description copied from interface:ManagedConnection
Registers a ManagedConnectionResourceListener to be notified of events.- Specified by:
addListener
in interfaceManagedConnection
- Parameters:
listener
- The listener
-
removeListener
Description copied from interface:ManagedConnection
Deregister a ManagedConnectionResourceListener.- Specified by:
removeListener
in interfaceManagedConnection
- Parameters:
listener
- The listener
-
isLocked
public boolean isLocked()- Specified by:
isLocked
in interfaceManagedConnection
-
lock
public void lock()- Specified by:
lock
in interfaceManagedConnection
-
unlock
public void unlock()- Specified by:
unlock
in interfaceManagedConnection
-
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 interfaceManagedConnection
- Returns:
- The XA resource
-
closeAfterTransactionEnd
public boolean closeAfterTransactionEnd()Description copied from interface:ManagedConnection
Convenience 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:
closeAfterTransactionEnd
in interfaceManagedConnection
- Returns:
- Whether the ConnectionManager should call close() on it when a txn ends
-
setSavepoint
Description copied from interface:ManagedConnection
Set this position in the txn as a savepoint with the provided name (if supported, otherwise do nothing).- Specified by:
setSavepoint
in interfaceManagedConnection
- Parameters:
name
- Name of savepoint
-
releaseSavepoint
Description copied from interface:ManagedConnection
Release the named savepoint (or do nothing if not supported).- Specified by:
releaseSavepoint
in interfaceManagedConnection
- Parameters:
name
- Name of savepoint
-
rollbackToSavepoint
Description copied from interface:ManagedConnection
Rollback the connection to the named savepoint (or do nothing if not supported).- Specified by:
rollbackToSavepoint
in interfaceManagedConnection
- Parameters:
name
- Name of savepoint
-
toString
Method to return a string form of this object for convenience debug.
-