如何混合域对象的持久状态和瞬态状态?
我正在寻找一种模式/方法可以彻底解决以下问题:
在屏幕显示应用程序中(公共场所的液晶屏幕上显示各种信息),我有Hibernate持久POJO,可以在我的应用程序的管理部分中创建和更新。
在只读的“显示”部分中,我使用这些对象。它们必须始终保持最新的持久状态,但它们也有一个瞬态(永远不会存储在数据库中),其生命周期是整个用户 (HTTP) 会话(可以持续一整天或更长时间) )和特定于每个会话/用户(这里的“用户”是一个屏幕)。
如何(干净地)结合这两种状态,以维护内存中的瞬态状态(在 HTTP 会话中),同时定期从数据库刷新持久状态?使用同一个类并在需要时执行 Hibernate session.refresh() ?将这两种状态存储在不同的类中并将它们链接起来,例如使用 ID ?装饰器模式 ?
I'm looking for a pattern/method do cleanly solve the following problem :
In a on-screen display application (various information is displayed on LCD screens in public places), I have Hibernate persistent POJOs, that can be created and updated in the administration part of my app.
In the "display" part, which is read-only, I use these objects. They must be always up-to-date with the persisted state, but they also have a transient state (that is never stored in the DB) for which the lifespan is the whole user (HTTP) session (can last a whole day or more) and which is specific to each session/user (here a "user" is a screen).
How to (cleanly) combine both states in order to maintain the transient state in-memory (in the HTTP session), while regularly refreshing the persistent state from the DB ? Use the same class and do Hibernate session.refresh() when needed ? Store both states in different classes and link them e.g. with the ID ? Decorator pattern ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我是否理解。如果对象是只读的,什么样的信息是瞬态的?如果该对象是只读的,则它在所有会话中始终相同。也许你的意思是该对象不是只读的,但它不会被持久化回服务器?
Not sure I understand. If the object is read-only, what kind of information is transient? If the object is read-only, it will always be the same among all sessions. Maybe you mean that the object is not read-only, but it won't be persisted back to the server?