public interface TransactionComponent
Modifier and Type | Method and Description |
---|---|
<T> TransactionHandler |
creaateTransactionHandler(T dataSource)
Creates and returns a new TransactionHandler for the provided transaction
object (such as a database).
|
TransactionHandler |
createTransactionHandler()
Creates and returns a new TransactionHandler for the single Dbms defined
in the current Speedment Project.
|
Optional<Object> |
get(Thread thread)
Returns a transaction aware object (if any) for the given thread.
|
void |
put(Thread thread,
Object txObject)
Associates a transaction aware object with the given thread.
|
<D,T> void |
putDataSourceHandler(Class<D> dataSourceClass,
DataSourceHandler<D,T> dataSourceHandler)
Associates a certain data store class (e.g.
|
void |
remove(Thread thread)
Removes the thread association to a transaction aware object (if
previously associated).
|
Stream<Thread> |
threads(Object txObject)
Creates and returns a Stream of threads that are associated with the
given transaction aware object.
|
TransactionHandler createTransactionHandler()
IllegalStateException
- if there is not exactly one Dbms defined in
the current project.<T> TransactionHandler creaateTransactionHandler(T dataSource)
T
- Type of the data sourcedataSource
- the data source for which transactions are consistent.IllegalArgumentException
- if this TransactionComponent cannot
determine that the provided data source can be used with transactions.NullPointerException
- if the provided data source is null.<D,T> void putDataSourceHandler(Class<D> dataSourceClass, DataSourceHandler<D,T> dataSourceHandler)
Example:
tc.putDataSourceHandle(
Dbms.class,
DataSourceHandler.of(
connectionPoolComponent.getConnection(dbms),
Connection::close
)
)
D
- the type of the data source (e.g. Dbms)T
- the type of transaction aware object (e.g. Connection)dataSourceClass
- the class of the data source (e.g. Dbms.class)dataSourceHandler
- to associate with the classvoid put(Thread thread, Object txObject)
thread
- to associate the given transaction aware object totxObject
- transaction aware objectIllegalStateException
- if the thread is already associated with a
transaction aware object.NullPointerException
- if thread or txObject is nullOptional<Object> get(Thread thread)
thread
- to useNullPointerException
- if thread is nullvoid remove(Thread thread)
thread
- for which the association shall be removedNullPointerException
- if thread is nullCopyright © 2018 Speedment, Inc.. All rights reserved.