Package io.micronaut.transaction.jdbc
Class JdbcTransactionObjectSupport
- java.lang.Object
-
- io.micronaut.transaction.jdbc.JdbcTransactionObjectSupport
-
- All Implemented Interfaces:
SavepointManager
,SmartTransactionObject
,java.io.Flushable
@Internal public abstract class JdbcTransactionObjectSupport extends java.lang.Object implements SavepointManager, SmartTransactionObject
Convenient base class for JDBC-aware transaction objects. Can contain aConnectionHolder
with a JDBCConnection
, and implements theSavepointManager
interface based on thatConnectionHolder
.Allows for programmatic management of JDBC
Savepoints
.DefaultTransactionStatus
automatically delegates to this, as it autodetects transaction objects which implement theSavepointManager
interface.- Since:
- 1.1
- Author:
- Juergen Hoeller, graemerocher
- See Also:
DataSourceTransactionManager
-
-
Constructor Summary
Constructors Constructor Description JdbcTransactionObjectSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
createSavepoint()
This 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.ConnectionHolder
getConnectionHolder()
Retrieves the connection holder.protected ConnectionHolder
getConnectionHolderForSavepoint()
TransactionDefinition.Isolation
getPreviousIsolationLevel()
boolean
hasConnectionHolder()
boolean
isSavepointAllowed()
void
releaseSavepoint(java.lang.Object savepoint)
This implementation releases the given JDBC 3.0 Savepoint.void
rollbackToSavepoint(java.lang.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
-
-
-
-
Method Detail
-
setConnectionHolder
public void setConnectionHolder(@Nullable ConnectionHolder connectionHolder)
Sets the connection holder.- Parameters:
connectionHolder
- The connection holder
-
getConnectionHolder
@NonNull public ConnectionHolder 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
@Nullable public TransactionDefinition.Isolation 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 interfacejava.io.Flushable
- Specified by:
flush
in interfaceSmartTransactionObject
-
createSavepoint
public java.lang.Object createSavepoint() throws TransactionException
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:
Connection.setSavepoint()
-
rollbackToSavepoint
public void rollbackToSavepoint(java.lang.Object savepoint) throws TransactionException
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:
Connection.rollback(java.sql.Savepoint)
-
releaseSavepoint
public void releaseSavepoint(java.lang.Object savepoint) throws TransactionException
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:
Connection.releaseSavepoint(java.sql.Savepoint)
-
getConnectionHolderForSavepoint
protected ConnectionHolder getConnectionHolderForSavepoint() throws TransactionException
- Returns:
- The connection holder for the save point
- Throws:
TransactionException
- If an error occurs retrieving the connection holder
-
-