Package org.springframework.transaction.support

# Class SimpleTransactionStatus

java.lang.Object
org.springframework.transaction.support.AbstractTransactionStatus
org.springframework.transaction.support.SimpleTransactionStatus

All Implemented Interfaces:
  `Flushable`, `SavepointManager`, `TransactionExecution`, `TransactionStatus`

public class SimpleTransactionStatus extends AbstractTransactionStatus
A simple `TransactionStatus` implementation. Derives from `AbstractTransactionStatus` and adds an explicit `"newTransaction"` flag.

This class is not used by any of Spring's pre-built `PlatformTransactionManager` implementations. It is mainly provided as a start for custom transaction manager implementations and as a static mock for testing transactional code (either as part of a mock `PlatformTransactionManager` or as argument passed into a `TransactionCallback` to be tested).

Since:
  1.2.3
Author:
  Juergen Hoeller
See Also:
  - `TransactionCallback.doInTransaction(org.springframework.transaction.TransactionStatus)`

## Constructor Summary

Constructors
Constructor
Description
`SimpleTransactionStatus()`
Create a new `SimpleTransactionStatus` instance, indicating a new transaction.
`SimpleTransactionStatus(boolean newTransaction)`
Create a new `SimpleTransactionStatus` instance.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`isNewTransaction()`
Return whether the transaction manager considers the present transaction as new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.

### Methods inherited from class org.springframework.transaction.support.AbstractTransactionStatus

`createAndHoldSavepoint, createSavepoint, getSavepoint, getSavepointManager, hasSavepoint, isCompleted, isGlobalRollbackOnly, isLocalRollbackOnly, isRollbackOnly, releaseHeldSavepoint, releaseSavepoint, rollbackToHeldSavepoint, rollbackToSavepoint, setCompleted, setRollbackOnly, setSavepoint`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.transaction.TransactionExecution

`getTransactionName, hasTransaction, isNested, isReadOnly`

### Methods inherited from interface org.springframework.transaction.TransactionStatus

`flush`

## Constructor Details

### SimpleTransactionStatus

public SimpleTransactionStatus()
Create a new `SimpleTransactionStatus` instance, indicating a new transaction.

### SimpleTransactionStatus

public SimpleTransactionStatus(boolean newTransaction)
Create a new `SimpleTransactionStatus` instance.

Parameters:
  `newTransaction` - whether to indicate a new transaction

## Method Details

### isNewTransaction

public boolean isNewTransaction()
Description copied from interface: `TransactionExecution`
Return whether the transaction manager considers the present transaction as new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.

This is primarily here for transaction manager state handling. Prefer the use of `TransactionExecution.hasTransaction()` for application purposes since this is usually semantically appropriate.

The "new" status can be transaction manager specific, for example, returning `true` for an actual nested transaction but potentially `false` for a savepoint-based nested transaction scope if the savepoint management is explicitly exposed (such as on `TransactionStatus`). A combined check for any kind of nested execution is provided by `TransactionExecution.isNested()`.

The default implementation returns `true`.

See Also:
  - `TransactionExecution.hasTransaction()`
  - `TransactionExecution.isNested()`
  - `TransactionStatus.hasSavepoint()`