Added AtomicTemplate to allow atomic blocks from Java code
This commit is contained in:
parent
0268f6f847
commit
0f3803d111
1 changed files with 19 additions and 0 deletions
|
|
@ -22,6 +22,25 @@ import org.multiverse.stms.alpha.AlphaStm
|
|||
class NoTransactionInScopeException extends RuntimeException
|
||||
class TransactionRetryException(message: String) extends RuntimeException(message)
|
||||
|
||||
/**
|
||||
* FIXDOC: document AtomicTemplate
|
||||
* AtomicTemplate can be used to create atomic blocks from Java code.
|
||||
* <pre>
|
||||
* User newUser = new AtomicTemplate[User]() {
|
||||
* User atomic() {
|
||||
* ... // create user atomically
|
||||
* return user;
|
||||
* }
|
||||
* }.execute();
|
||||
* </pre>
|
||||
*/
|
||||
trait AtomicTemplate[T] {
|
||||
def atomic: T
|
||||
def execute: T = Transaction.Local.atomic {
|
||||
atomic
|
||||
}
|
||||
}
|
||||
|
||||
object Transaction {
|
||||
val idFactory = new AtomicLong(-1L)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue