val timeout = 60 * 1000 // 1 minute
val dispatcher = Dispatchers.newExecutorBasedEventDrivenWorkStealingDispatcher("transaction-provider-dispatcher")
.setMaxPoolSize(25) // should be same as max number of connection in DB pool
* Will create a new transaction if none is in progress and commit it upon completion or rollback on exceptions.
* If a transaction already exists, it has no effect, the block will execute in the context
* of the existing transaction. The commit/rollback is handled in this case by the parent transaction block.
def inTransaction[T](f: ⇒ T): T = DB.use(DefaultConnectionIdentifier)(conn ⇒ f)
* Causes a new transaction to begin and commit after the block’s execution,
* or rollback if an exception occurs. Invoking a transaction always cause a new one to be created,
* even if called in the context of an existing transaction.
def newTransaction[T](f: ⇒ T): T = Future(DB.use(DefaultConnectionIdentifier)(conn ⇒ f), timeout)(dispatcher).get