创建发布-订阅模式以集成到 DAO 模式
基于问题(如何为 web 应用程序创建客户端通知服务或者我应该使用观察者模式?)我想知道。
我有一个完全实现的 DAO,其中实体 bean 仅包含 getter 和 setter 方法。每个实体都映射到一个 EntityManager。
目前,无法通知用户对持久存储(例如数据库)添加/删除/更新的任何更改。
我想知道,如何实现发布-订阅模式(也称为观察者模式),这样我就不必扩展当前的 DAO 架构。我不希望我的实体继承发布者,因为并非所有实体都可以更新。
如果有任何工具/框架/库适合我的情况,请告诉我。另外,我根本没有使用任何持久化框架(Hibernate 之类的框架),DAO 管理器和 Factory 完全是我从头开始编写的。
问候,
Based on the question (How to create a client notification service for a webapp or should I use an Observer Pattern?) I will like to know.
I have a fully implemented DAO with Entity beans containing only getters and setters method. Each entity is mapped to an EntityManager.
Currently there are no way of notifying users of any changes added/deleted/updated to a persistent storage such as a database.
I want to know, how will I implement the Publish-Subscribe pattern (also known as Observer pattern) such that I don't have to extend my current DAO architecture. I don't want my entities to inherit the Publisher because not all entities are update-able.
If there are any tools/frameworks/libraries that I can use for my situation, please let me know. Also, I'm not using any persistent framework at all (framework such as Hibernate), the DAO manager and Factory was completely written from scratch by me.
Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在构建一个类似的概念......我不关心所有事件,在项目中我们想要关心不同的事件。因此,我们正在构建一种模式,其中所有 DAO 操作都提交到 DROOLS Fusion,并基于规则和一些时间推理,它通过通知架构通知侦听器。根据您的需求,该架构可以是简单的侦听器、JMS 或电子邮件……等等。如果您没有条件,只需关心 DAO 事件的回调,然后让您的 DAO 插入、更新、删除操作将对象提交给侦听器或某种类型的 JMS 队列。
希望这很清楚......
保罗
I am building a similar concept... I don't care about all events and within projects we want to care about different events. So, we are building a pattern where all DAO operations are submitted to DROOLS Fusion and based on rules and some temporal reasoning, it notifies listeners via a notification architecture. Depending on your needs, the architecture could be simple listeners or JMS or email... whatever. If you have no criteria, just care about a callback for DAO events, then have your DAO insert, update, delete operations submit the object to listeners or some type of JMS queue.
Hope that was clear...
Paul
我的第一个建议是在 DAO 中嵌入一个可观察对象。然后你会让你的潜艇看看这个物体(我过去做过类似的事情)。
我的另一个建议是您可以向数据库本身添加一个触发器。如果您的应用程序之外有任何内容可能会更改您想要通知子系统的数据库,那么这将特别有用。
祝你好运。
The first suggestion I would have is to embed an observable object within your DAO. Then you would have your subs look at this object (I've done similar things in the past).
The other suggestion I have is that you could add a trigger to the database itself. This would be especially useful if there is anything outside of your app that could change the DB that you want to notify your sub of.
Good luck.