Interface IOTransactional
-
- All Superinterfaces:
- AutoCloseable, Closeable, Transactional
- All Known Subinterfaces:
- TransactionalOutputStream, TransactionalUncheckedOutputStream, TransactionalUncheckedWriter, TransactionalWriter
public interface IOTransactional extends Transactional, CloseableA transactional operation on a closable resource.A transactional operation is an atomic operation on data that may be defined incrementally. Between the creation and termination of the operation, creation of other transactional operations may be prevented, to ensure that each operation starts with the latest state of the associated data.
This interface defines two methods that terminate a transactional operation. These methods change the state of the transactional object to
terminated. In theterminatedstate, invocations of these methods have no effect and invocations of other operations may throw anIllegalStateException.The terminating methods are
commit()andabort(). Thecommitmethod must be called after the operation has been fully defined to actually perform the operation on the data. Otherwise, theabortmethod must be called, to ensure that temporary resources are released, other transactional operations on the data can be created, and a subsequent invocation ofcommit(), even by accident, has no effect.The above description means that one may call
commit()after callingabort()or callabort()after callingcommit(); in either case, the second method invocation will have no effect. Thus, it is possible and convenient to callcommit()at the end of atrybody and callabort()in afinallyclause of the sametrystatement. Even more conveniently, if the transactional writer is created and used within a try-with-resources statement, no explicit invocation ofabort()is required, because it will be called implicitly (asclose()is defined to callabort()).