开发者

In GAE entities, how can I execute code automatically every time an entity object is created or deleted?

If the solution is to override init() and del() from db.Model / db.Expando / db.PolyModel, then do I need to开发者_JAVA百科 call the superclass functions?

Would be great to see some example code in the answers or on links. Thanks a lot.


I've written a couple of blog posts on this subject: One on high level pre- and post- put hooks, and one on the low level hook support. One of these is probably what you're looking for.


I think that the best way to accomplish what you want to do is to use datastore API hooks.

Using that approach will allow you to avoid messing directly with the classes and superclasses. That could get complex and messy and buggy very quickly.


If this is the java implementation, you can implement javax.jdo.listener.StoreCallback on your domain model and then define method jdoPreStore(). This method will automatically be called each time you persist to the datastore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜