File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
core/src/main/scala/scalikejdbc/async Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package scalikejdbc.async
1818import scala .concurrent ._
1919import scala .util .{ Failure , Success }
2020import scalikejdbc .async .ShortenedNames ._
21+ import scalikejdbc .async .internal .AsyncConnectionCommonImpl
2122
2223/**
2324 * Basic Database Accessor
@@ -54,14 +55,20 @@ object AsyncDB {
5455 AsyncConnectionPool ().borrow().toNonSharedConnection().map { nonSharedConnection =>
5556 TxAsyncDBSession (nonSharedConnection)
5657 }.flatMap { tx =>
57- tx.begin().flatMap { _ =>
58- op.apply(tx).andThen {
59- case Success (_) => tx.commit()
60- case Failure (e) => tx.rollback()
61- }.andThen {
62- case _ => tx.release()
63- }
58+ val p = Promise [A ]()
59+ val connection = tx.connection.asInstanceOf [AsyncConnectionCommonImpl ].underlying
60+
61+ connection.inTransaction(_ => op.apply(tx)).onComplete {
62+ case Success (result) =>
63+ tx.release()
64+ p.success(result)
65+ case Failure (e) =>
66+ // As documentation recommends - close connection after rollback
67+ connection.disconnect
68+ tx.release()
69+ p.failure(e)
6470 }
71+ p.future
6572 }
6673 }
6774
You can’t perform that action at this time.
0 commit comments