Permalink
Browse files

Added appendPostTransaction for DefaultConnectionIdentifier, changed …

…test & deprecation messages. Refs #1102
  • Loading branch information...
1 parent 4c04f6f commit 4a5204c828a0121b10578efa7822ca4608cf40e8 @jeppenejsum jeppenejsum committed Sep 6, 2011
@@ -121,10 +121,10 @@ trait DB extends Loggable {
private def postCommit_=(lst: List[() => Unit]): Unit = _postCommitFuncs.set(lst)
/**
- * perform this function after transaction has ended. THis is helpful for sending messages to Actors after we know
- * a transaction has committed
+ * perform this function after transaction has ended. This is helpful for sending messages to Actors after we know
+ * a transaction has been either committed or rolled back
*/
- @deprecated("Use appendPostTransaction")
+ @deprecated("Use appendPostTransaction {committed => ...}")
def performPostCommit(f: => Unit) {
postCommit = (() => f) :: postCommit
}
@@ -293,7 +293,7 @@ trait DB extends Loggable {
/**
* Append a function to be invoked after the transaction has ended for the given connection identifier
*/
- @deprecated("Use appendPostTransaction")
+ @deprecated("Use appendPostTransaction (name, {committed => ...})")
def appendPostFunc(name: ConnectionIdentifier, func: () => Unit) {
appendPostTransaction(name, dontUse => func())
}
@@ -314,6 +314,12 @@ trait DB extends Loggable {
}
}
+ /**
+ * Append function to be invoked after the current transaction on DefaultConnectionIdentifier has ended
+ *
+ */
+ def appendPostTransaction(func: Boolean => Unit):Unit = appendPostTransaction(DefaultConnectionIdentifier, func)
+
private def runLogger(logged: Statement, time: Long) = logged match {
case st: DBLog => logFuncs.foreach(_(st, time))
case _ => // NOP
@@ -42,7 +42,7 @@ class DBSpec extends Specification with Mockito {
there was one(m).f(true)
}
- "call postCommit functions with false if transaction is rolledback" in {
+ "call postTransaction functions with false if transaction is rolled back" in {
val m = mock[CommitFunc]
val lw = DB.buildLoanWrapper(true)
@@ -77,7 +77,7 @@ class DBSpec extends Specification with Mockito {
there was one(m).f(true)
}
- "call postCommit functions with false if transaction is rolledback" in {
+ "call postTransaction functions with false if transaction is rolled back" in {
val m = mock[CommitFunc]
val lw = DB.buildLoanWrapper(false)
@@ -87,7 +87,7 @@ class DBSpec extends Specification with Mockito {
DB.exec(c, "more stuff") { dummy => }
}
DB.use(DefaultConnectionIdentifier) {c =>
- DB.appendPostTransaction(DefaultConnectionIdentifier, m.f _)
+ DB.appendPostTransaction (m.f _)
DB.exec(c, "stuff") {dummy => throw new RuntimeException("oh no")}
}
42
@@ -110,7 +110,7 @@ class DBSpec extends Specification with Mockito {
there was one(m).f(true)
}
- "call postTransaction functions with false if transaction is committed" in {
+ "call postTransaction functions with false if transaction is rolled back" in {
val m = mock[CommitFunc]
tryo(DB.use(DefaultConnectionIdentifier) {c =>
@@ -126,7 +126,7 @@ class DBSpec extends Specification with Mockito {
"appendPostTransaction" should {
"throw if called outside tx context" in {
- DB.appendPostTransaction(DefaultConnectionIdentifier, d => ()) must throwA[IllegalStateException]
+ DB.appendPostTransaction {committed => ()} must throwA[IllegalStateException]
}
}
}

0 comments on commit 4a5204c

Please sign in to comment.