Package org.datanucleus.store.connection
Interface ManagedConnection
- All Known Implementing Classes:
AbstractManagedConnection
public interface ManagedConnection
Wrapper for a connection to the datastore, allowing management.
A connection is handed out using
getConnection, and returned using
release.
-
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
Accessor for the datastore connection.An XAResoure for this datastore connection.boolean
isLocked()
void
lock()
void
release()
Method to release the datastore connection back.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).void
Flush the connection.void
Prepare the connection for end of transaction.void
unlock()
-
Method Details
-
getConnection
Object getConnection()Accessor for the datastore connection.- Returns:
- The underlying connection for this datastore
-
release
void release()Method to release the datastore connection back. Will have been handed out with a getConnection(). This may trigger a commit() of the connection depending on its operating mode at the time. -
transactionFlushed
void transactionFlushed()Flush the connection. It must invoke the operationManagedConnectionResourceListener.transactionFlushed()
-
transactionPreClose
void transactionPreClose()Prepare the connection for end of transaction. It must invoke the operationManagedConnectionResourceListener.transactionPreClose()
-
close
void close()Close the connection to the datastore. It most invoke the operationsManagedConnectionResourceListener.managedConnectionPreClose()
andManagedConnectionResourceListener.managedConnectionPostClose()
. The listeners are unregistered after this method is invoked. -
setCommitOnRelease
void setCommitOnRelease(boolean commit) -
setCloseOnRelease
void setCloseOnRelease(boolean close) -
commitOnRelease
boolean commitOnRelease() -
closeOnRelease
boolean closeOnRelease() -
getXAResource
XAResource getXAResource()An XAResoure for this datastore connection. Returns null if the connection is not usable in an XA sense- Returns:
- The XAResource
-
isLocked
boolean isLocked() -
lock
void lock() -
unlock
void unlock() -
addListener
Registers a ManagedConnectionResourceListener to be notified of events.- Parameters:
listener
- The listener
-
removeListener
Deregister a ManagedConnectionResourceListener.- Parameters:
listener
- The listener
-
closeAfterTransactionEnd
boolean closeAfterTransactionEnd()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.- Returns:
- Whether the ConnectionManager should call close() on it when a txn ends
-
setSavepoint
Set this position in the txn as a savepoint with the provided name (if supported, otherwise do nothing).- Parameters:
name
- Name of savepoint
-
releaseSavepoint
Release the named savepoint (or do nothing if not supported).- Parameters:
name
- Name of savepoint
-
rollbackToSavepoint
Rollback the connection to the named savepoint (or do nothing if not supported).- Parameters:
name
- Name of savepoint
-