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 aConnectionHolderwith a JDBCConnection, and implements theSavepointManagerinterface based on thatConnectionHolder.Allows for programmatic management of JDBC
Savepoints.DefaultTransactionStatusautomatically delegates to this, as it autodetects transaction objects which implement theSavepointManagerinterface.- 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.ObjectcreateSavepoint()This implementation creates a JDBC 3.0 Savepoint and returns it.voidflush()Flush the underlying sessions to the datastore, if applicable: for example, all affected Hibernate/JPA sessions.ConnectionHoldergetConnectionHolder()Retrieves the connection holder.protected ConnectionHoldergetConnectionHolderForSavepoint()TransactionDefinition.IsolationgetPreviousIsolationLevel()booleanhasConnectionHolder()booleanisSavepointAllowed()voidreleaseSavepoint(java.lang.Object savepoint)This implementation releases the given JDBC 3.0 Savepoint.voidrollbackToSavepoint(java.lang.Object savepoint)This implementation rolls back to the given JDBC 3.0 Savepoint.voidsetConnectionHolder(ConnectionHolder connectionHolder)Sets the connection holder.voidsetPreviousIsolationLevel(TransactionDefinition.Isolation previousIsolationLevel)Sets the previous isolation level.voidsetSavepointAllowed(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:SmartTransactionObjectFlush the underlying sessions to the datastore, if applicable: for example, all affected Hibernate/JPA sessions.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin interfaceSmartTransactionObject
-
createSavepoint
public java.lang.Object createSavepoint() throws TransactionExceptionThis implementation creates a JDBC 3.0 Savepoint and returns it.- Specified by:
createSavepointin 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 TransactionExceptionThis implementation rolls back to the given JDBC 3.0 Savepoint.- Specified by:
rollbackToSavepointin 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 TransactionExceptionThis implementation releases the given JDBC 3.0 Savepoint.- Specified by:
releaseSavepointin 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
-
-