-
-
Save nitsh/0795cafbd983114a1d2f88de866a5c06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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:(Connection) => T):Option[T] = { | |
| val conn:Connection = play.db.DB.getConnection | |
| val auto:Boolean = conn.getAutoCommit | |
| try { | |
| conn.setAutoCommit(false) | |
| query(conn) | |
| } catch { | |
| case e: Exception => | |
| conn.rollback | |
| throw e | |
| } finally { | |
| conn.commit | |
| conn.setAutoCommit(auto) | |
| conn.close() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment