Package fi.jubic.easyutils.transactional
Class Transactional<T,C>
- java.lang.Object
-
- fi.jubic.easyutils.transactional.Transactional<T,C>
-
- Type Parameters:
T- the type of the result.C- the type of transaction context.
- Direct Known Subclasses:
Transactional10,Transactional2,Transactional3,Transactional4,Transactional5,Transactional6,Transactional7,Transactional8,Transactional9
public class Transactional<T,C> extends Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTransactional(Function<C,T> procedure, TransactionProvider<C> provider)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T0,T1,T2,T3,T4,T5,T6,T7,T8,C>
Transactional9<T0,T1,T2,T3,T4,T5,T6,T7,T8,C>all(Transactional<T0,C> t0, Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7, Transactional<T8,C> t8)A utility method for combining multipleTransactionalresults.static <T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,C>
Transactional10<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,C>all(Transactional<T0,C> t0, Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7, Transactional<T8,C> t8, Transactional<T9,C> t9)A utility method for combining multipleTransactionalresults.static <T1,T2,C>
Transactional2<T1,T2,C>all(Transactional<T1,C> t1, Transactional<T2,C> t2)A utility method for combining multipleTransactionalresults.static <T1,T2,T3,C>
Transactional3<T1,T2,T3,C>all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3)A utility method for combining multipleTransactionalresults.static <T1,T2,T3,T4,C>
Transactional4<T1,T2,T3,T4,C>all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4)A utility method for combining multipleTransactionalresults.static <T1,T2,T3,T4,T5,C>
Transactional5<T1,T2,T3,T4,T5,C>all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5)A utility method for combining multipleTransactionalresults.static <T1,T2,T3,T4,T5,T6,C>
Transactional6<T1,T2,T3,T4,T5,T6,C>all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6)A utility method for combining multipleTransactionalresults.static <T1,T2,T3,T4,T5,T6,T7,C>
Transactional7<T1,T2,T3,T4,T5,T6,T7,C>all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7)A utility method for combining multipleTransactionalresults.static <T1,T2,T3,T4,T5,T6,T7,T8,C>
Transactional8<T1,T2,T3,T4,T5,T6,T7,T8,C>all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7, Transactional<T8,C> t8)A utility method for combining multipleTransactionalresults.Tbypass()Returns the result acquired by performing the contained procedure without the transactional scope.<U> Transactional<U,C>flatMap(Function<T,Transactional<U,C>> mapper)Returns aTransactionaldescribing the result acquired by chaining two transactional procedures together.Tget()Returns the result acquired by performing the contained procedure in a transactional scope.<U> Transactional<U,C>map(Function<T,U> mapper)Returns aTransactionaldescribing the result of applying the given mapping function to the result of the contained procedure.static <T,C>
Transactional<T,C>of(Function<C,T> materialize, TransactionProvider<C> provider)Returns aTransactionaldescribing the result of the given procedure performed in a transactional scope provided by theTransactionProvider.static <T> Transactional<T,Void>of(Supplier<T> materialize, TransactionProvider<Void> provider)Returns aTransactionaldescribing the result fo the given procedure performed in a transactional scope of the thread callingget().Transactional<T,C>peek(Consumer<T> action)Returns a newTransactionaldescribing the result of this transaction, additionally performing the provided action on the result.Transactional<T,C>peekMap(Function<T,Transactional<Void,C>> procedure)Returns a newTransactionaldescribing the result of this transaction, additionally performing the provided procedure on the result and appending theTransactionalreturned from the procedure to the new procedure chain.
-
-
-
Constructor Detail
-
Transactional
protected Transactional(Function<C,T> procedure, TransactionProvider<C> provider)
-
-
Method Detail
-
get
public T get()
Returns the result acquired by performing the contained procedure in a transactional scope. If an exception is thrown during the procedure, the transaction is rolled back and the exception is rethrown. Otherwise the transaction is committed and the result is returned.- Returns:
- the acquired result
-
bypass
public T bypass()
Returns the result acquired by performing the contained procedure without the transactional scope. TheTransactionProviderimplementation may not necessarily support this operation and can throw aUnsupportedOperationException.- Returns:
- the acquired result.
-
map
public <U> Transactional<U,C> map(Function<T,U> mapper)
Returns aTransactionaldescribing the result of applying the given mapping function to the result of the contained procedure. If the mapping function throws anException, the transaction will be rolled back as if the procedure had failed.- Type Parameters:
U- the type of the result returned from the mapping function- Parameters:
mapper- the mapping function- Returns:
- the new
Transactional
-
flatMap
public <U> Transactional<U,C> flatMap(Function<T,Transactional<U,C>> mapper)
Returns aTransactionaldescribing the result acquired by chaining two transactional procedures together. The resulting procedure will call the mapping function with the result of the contained procedure and then it will perform the procedure returned by the mapping function.- Type Parameters:
U- the type of the result of theTransactionalreturned from the mapping function- Parameters:
mapper- the mapping function- Returns:
- the new
Transactional
-
peek
public Transactional<T,C> peek(Consumer<T> action)
Returns a newTransactionaldescribing the result of this transaction, additionally performing the provided action on the result.- Parameters:
action- A non-interfering action to be performed on the result before yielding it- Returns:
- the new
Transactional
-
peekMap
public Transactional<T,C> peekMap(Function<T,Transactional<Void,C>> procedure)
Returns a newTransactionaldescribing the result of this transaction, additionally performing the provided procedure on the result and appending theTransactionalreturned from the procedure to the new procedure chain.- Parameters:
procedure- the procedure to be applied to the procedure chain- Returns:
- the new
Transactional
-
of
public static <T,C> Transactional<T,C> of(Function<C,T> materialize, TransactionProvider<C> provider)
Returns aTransactionaldescribing the result of the given procedure performed in a transactional scope provided by theTransactionProvider.- Type Parameters:
T- the type of the result of the contained procedureC- the type of the transaction context- Parameters:
materialize- the contained procedureprovider- the provider for the procedure's transaction context.- Returns:
- the new
Transactional
-
of
public static <T> Transactional<T,Void> of(Supplier<T> materialize, TransactionProvider<Void> provider)
Returns aTransactionaldescribing the result fo the given procedure performed in a transactional scope of the thread callingget().This is a helper creator intended to be used with thread context
TransactionProviders.- Type Parameters:
T- the type of the result of the contained procedure- Parameters:
materialize- the contained procedureprovider- the thread context transaction context provider- Returns:
- the new
Transactional
-
all
public static <T1,T2,C> Transactional2<T1,T2,C> all(Transactional<T1,C> t1, Transactional<T2,C> t2)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T1,T2,T3,C> Transactional3<T1,T2,T3,C> all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T1,T2,T3,T4,C> Transactional4<T1,T2,T3,T4,C> all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T1,T2,T3,T4,T5,C> Transactional5<T1,T2,T3,T4,T5,C> all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T1,T2,T3,T4,T5,T6,C> Transactional6<T1,T2,T3,T4,T5,T6,C> all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T1,T2,T3,T4,T5,T6,T7,C> Transactional7<T1,T2,T3,T4,T5,T6,T7,C> all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T1,T2,T3,T4,T5,T6,T7,T8,C> Transactional8<T1,T2,T3,T4,T5,T6,T7,T8,C> all(Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7, Transactional<T8,C> t8)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T0,T1,T2,T3,T4,T5,T6,T7,T8,C> Transactional9<T0,T1,T2,T3,T4,T5,T6,T7,T8,C> all(Transactional<T0,C> t0, Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7, Transactional<T8,C> t8)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
all
public static <T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,C> Transactional10<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,C> all(Transactional<T0,C> t0, Transactional<T1,C> t1, Transactional<T2,C> t2, Transactional<T3,C> t3, Transactional<T4,C> t4, Transactional<T5,C> t5, Transactional<T6,C> t6, Transactional<T7,C> t7, Transactional<T8,C> t8, Transactional<T9,C> t9)
A utility method for combining multipleTransactionalresults. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
-
-