Created
June 6, 2011 00:11
-
-
Save blt/1009570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case object transaction { | |
import java.sql.Connection | |
def apply[T](query: => T):Option[T] = { | |
val conn:Connection = play.db.DB.getConnection | |
val auto:Boolean = conn.getAutoCommit | |
try { | |
conn.setAutoCommit(false) | |
Some(query) | |
} catch { | |
case e: Exception => | |
conn.rollback | |
None | |
} finally { | |
conn.commit | |
conn.setAutoCommit(auto) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{
val conn:Connection = play.db.DB.getConnection
transaction(conn) {
SQL(...)
SQL(...)
}
}
case object transaction {
import java.sql.Connection
def apply[T](connection : java.sql.Connection)(query: => T):Option[T] = {
}
}