简体   繁体   English

使用正确的servlet过滤器将circumflex-orm集成到play 2.0 scala应用程序中

[英]integrate circumflex-orm in play 2.0 scala application with correct servlet filter

i am trying to integrate circumflex-orm into a play-2.0 scala app. 我正在尝试将circumflex-orm集成到play-2.0 scala应用程序中。 It works so far as i can retrieve and save elements into db. 它可以工作,因为我可以检索并将元素保存到数据库中。 What does not work is the cache handling - transaction management. 什么是行不通的缓存处理 - 事务管理。

For instance, retrieve a list of objects, change one, store it into db works fine. 例如,检索一个对象列表,更改一个,将其存储到db工作正常。 But if i retrieve the same list again, my object did not change. 但是,如果我再次检索相同的列表,我的对象没有改变。 It did not change in the meaning of, it did change in the database, but the cache doesn't know anything about it. 它的意思并没有改变,它确实在数据库中发生了变化,但缓存对此一无所知。

I did post a question at the circurmflex group and they said they do it with a servletfilter (this is the actual code for it: ( circumflex-orm transaction integration - look at main lifecycle). Something like this would be enough: 我确实在circurmflex组发了一个问题,他们说他们是用servletfilter做的(这是它的实际代码:( circumflex-orm事务集成 - 看看主生命周期)。这样的东西就足够了:

class CircumflexContextFilter extends ServletFilter {

  import ru.circumflex.core._

  def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain) {
    Context.executeInNew { ctx =>
      chain.doFilter(req, res)
    }
  } 
}

But i have no idea how to integrate this into a play 2.0 application. 但我不知道如何将其集成到Play 2.0应用程序中。

Thanks in Advance, Sven 谢谢你,斯文

It turned out to be easier than i thought, a guy at the irc (thanks noelw) pinpointed me to these docs: scala action composition Reading through that the answer is as easy as possible: 事实证明这比我想象的要容易,irc的一个人(感谢noelw)向我指出了这些文档: scala动作组合通过阅读,答案尽可能简单:

First, write your own action class like this: 首先,编写自己的动作类,如下所示:

import play.api.mvc.Action
import play.api.mvc.Request
import play.api.mvc.Result
import ru.circumflex.core.Context

case class ScircumflexOrmActionWrapper[A](action: Action[A]) extends Action[A] {

  def apply(request: Request[A]): Result = {
    Context.executeInNew { ctx =>
      action(request)
    }
  }

  lazy val parser = action.parser
}

And then call your actions like this: 然后像这样调用你的行为:

def index = ScircumflexOrmActionWrapper { Action { 
  val taskDbObj = Task AS "taskDb"
  val tasks = SELECT(taskDbObj.*).FROM(taskDbObj).ORDER_BY(taskDbObj.createdAt DESC).list 
  Ok(html.task.index(tasks))
}}

Thats it. 而已。 I also wrote i blop post for the integration of circumflex-orm into play, if anyone is interested: integrate circumflex-orm in play 2.0 - scala 如果有兴趣的话,我还写了一篇关于将circumflex-orm整合到游戏中的文章: 整合circumflex-orm in play 2.0 - scala

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM