Created
June 6, 2011 00:11
-
-
Save blt/1009570 to your computer and use it in GitHub Desktop.
Revisions
-
blt created this gist
Jun 6, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ 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) } } }