[prev in list] [next in list] [prev in thread] [next in thread]
List: ojb-user
Subject: Repost: OTM & PBLifeCycleListener
From: Sebastian <nospam_st () gmx ! net>
Date: 2004-10-28 21:01:44
Message-ID: clrmnn$hgo$1 () sea ! gmane ! org
[Download RAW message or body]
Hi,
my basic question is, how can I have object properties auto updated on
insert, update or delete. Not only in the object instance that is
internally hold by OJB/OTM but also in the object instance on which the
OTMConnection.makePersistent method is called. I know that it's fairly
easy to create could create a delegate method and encapsulate the
makePersistent method and manually set the properties when an object is
persisted but this gets quite tricky when the object has references to
other persistable objects that are auto-persisted too. In this case it
would be great to use the PBLifeCycleListener events which obviously
don't work for the object instance handed over to the makePersistent method.
Thanks for any ideas.
Sebastian wrote:
> To persist objects I'm using the OTM.
>
> I have a class like this:
> class DataRecord {
> int id;
> Date lastModified;
> }
>
> and a PBLifeCylceListener added like this:
>
> OTMConnection conn =
> SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDefaultKey());
>
> ((BaseConnection) conn).getKernelBroker().addListener(
> new PBLifeCycleListener()
> {
> public void beforeInsert(PBLifeCycleEvent event)
> throws PersistenceBrokerException {
> DataRecord rec = (DataRecord) event.getTarget();
> rec.lastModified = new Date();
> }
>
> public void beforeUpdate(PBLifeCycleEvent event)
> throws PersistenceBrokerException {
> DataRecord rec = (DataRecord) event.getTarget();
> rec.lastModified = new Date();
> }
> }
> ...
> );
>
> After persisting the myDataRecord object using
> conn.makePersistent(myDataRecord) the object's propery "lastModified"
> still has the same value as before persisting it.
>
> I can retrieve a new object copy with conn.getObjectByIdentity(...) and
> the property "lastModified" has the updated value. But I'd like to have
> the "lastModified" property updated automatically in the object that I'm
> passing to the conn.makePersistent(...) method. Any ideas?
>
> Thanks in advance,
> Sebastian
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic