Created
September 29, 2012 00:36
-
-
Save seratch/3802747 to your computer and use it in GitHub Desktop.
Play20 Transactional Action sample
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
| // zentasks example | |
| object Projects extends Controller with Secured with Tx { | |
| /** | |
| * Display the dashboard. | |
| */ | |
| def index = localTx { IsAuthenticated { username => _ => | |
| User.findByEmail(username).map { user => | |
| Ok( | |
| html.dashboard( | |
| Project.findInvolving(username), | |
| Task.findTodoInvolving(username), | |
| user | |
| ) | |
| ) | |
| }.getOrElse(Forbidden) | |
| }} | |
| } |
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
| trait Tx { self: Controller => | |
| def localTx[A](action: Action[A]) = LocalTxActionDecorator[A](action) | |
| } | |
| case class LocalTxActionDecorator[A](action: Action[A]) extends Action[A] { | |
| def parser: BodyParser[A] = action.parser | |
| override def apply() = DB localTx { implicit s => action.apply() } | |
| def apply(request: Request[A]): Result = DB localTx { implicit s => action.apply(request) } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment