Package io.micronaut.transaction.jdbc
Class JdbcTransactionObjectSupport
java.lang.Object
io.micronaut.transaction.jdbc.JdbcTransactionObjectSupport
- All Implemented Interfaces:
SavepointManager
,SmartTransactionObject
,Flushable
@Internal
public abstract class JdbcTransactionObjectSupport
extends Object
implements SavepointManager, SmartTransactionObject
Convenient base class for JDBC-aware transaction objects. Can contain a
ConnectionHolder
with a JDBC Connection
, and implements the
SavepointManager
interface based on that ConnectionHolder
.
Allows for programmatic management of JDBC Savepoints
.
DefaultTransactionStatus
automatically delegates to this, as it autodetects transaction objects which
implement the SavepointManager
interface.
- Since:
- 1.1
- Author:
- Juergen Hoeller, graemerocher
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThis implementation creates a JDBC 3.0 Savepoint and returns it.void
flush()
Flush the underlying sessions to the datastore, if applicable: for example, all affected Hibernate/JPA sessions.Retrieves the connection holder.protected ConnectionHolder
boolean
boolean
void
releaseSavepoint
(Object savepoint) This implementation releases the given JDBC 3.0 Savepoint.void
rollbackToSavepoint
(Object savepoint) This implementation rolls back to the given JDBC 3.0 Savepoint.void
setConnectionHolder
(ConnectionHolder connectionHolder) Sets the connection holder.void
setPreviousIsolationLevel
(TransactionDefinition.Isolation previousIsolationLevel) Sets the previous isolation level.void
setSavepointAllowed
(boolean savepointAllowed) Sets whether save points are allowed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.transaction.support.SmartTransactionObject
isRollbackOnly
-
Constructor Details
-
JdbcTransactionObjectSupport
public JdbcTransactionObjectSupport()
-
-
Method Details
-
setConnectionHolder
Sets the connection holder.- Parameters:
connectionHolder
- The connection holder
-
getConnectionHolder
Retrieves the connection holder.- Returns:
- The connection holder
-
hasConnectionHolder
public boolean hasConnectionHolder()- Returns:
- Whether a connection holder is present
-
setPreviousIsolationLevel
public void setPreviousIsolationLevel(@Nullable TransactionDefinition.Isolation previousIsolationLevel) Sets the previous isolation level.- Parameters:
previousIsolationLevel
- The isolation level
-
getPreviousIsolationLevel
- Returns:
- The previous isolation level
-
setSavepointAllowed
public void setSavepointAllowed(boolean savepointAllowed) Sets whether save points are allowed.- Parameters:
savepointAllowed
- True if they are allowed
-
isSavepointAllowed
public boolean isSavepointAllowed()- Returns:
- Whether the save point is allowed
-
flush
public void flush()Description copied from interface:SmartTransactionObject
Flush the underlying sessions to the datastore, if applicable: for example, all affected Hibernate/JPA sessions.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfaceSmartTransactionObject
-
createSavepoint
This implementation creates a JDBC 3.0 Savepoint and returns it.- Specified by:
createSavepoint
in interfaceSavepointManager
- Returns:
- a savepoint object, to be passed into
SavepointManager.rollbackToSavepoint(java.lang.Object)
orSavepointManager.releaseSavepoint(java.lang.Object)
- Throws:
NestedTransactionNotSupportedException
- if the underlying transaction does not support savepointsTransactionException
- if the savepoint could not be created, for example because the transaction is not in an appropriate state- See Also:
-
rollbackToSavepoint
This implementation rolls back to the given JDBC 3.0 Savepoint.- Specified by:
rollbackToSavepoint
in interfaceSavepointManager
- Parameters:
savepoint
- the savepoint to roll back to- Throws:
NestedTransactionNotSupportedException
- if the underlying transaction does not support savepointsTransactionException
- if the rollback failed- See Also:
-
releaseSavepoint
This implementation releases the given JDBC 3.0 Savepoint.- Specified by:
releaseSavepoint
in interfaceSavepointManager
- Parameters:
savepoint
- the savepoint to release- Throws:
NestedTransactionNotSupportedException
- if the underlying transaction does not support savepointsTransactionException
- if the release failed- See Also:
-
getConnectionHolderForSavepoint
- Returns:
- The connection holder for the save point
- Throws:
TransactionException
- If an error occurs retrieving the connection holder
-