Hi there,
Your solution will work and you can put your overridden
"writeProperty" in your own custom superclass of DataObjects thus
changing default Cayenne behavior.
Here is another solution however - override "validateForSave" to add
your timestamp logic:
http://objectstyle.org/cayenne/userguide/dataobjects/validation.html
See, even if an object is marked as modified on "setXYZ" call when
there was no real modification, this fact will be detected by Cayenne
later on commit, and the object will not be committed, and its
validate* methods won't be called.
Hope this helps.
Andrus
On Aug 26, 2005, at 2:03 PM, Sean Tan wrote:
> I'm attempting to use Cayenne v1.1.2 with the idea of having a field
> that mimics the behavior of MySql's TimeStamp dbtype.
>
> The timestamp will only update if at least a change is detected in the
> rest of the columns.
>
> I'm trying to rely on the PersistenceState of CayenneDataObject but I
> realized that the PersistenceState is set to Modified even when the
> new
> value being introduced is the same as the old value. This poses a
> problem, especially in the context of webframeworks like Tapestry
> which
> all bounded fields will be updated, meaning the writeProperty(String
> propName, Object val) of the CayenneDataObject will always be
> called....
> PersistenceState being set to Modified although no change is made.
>
> One usage scenario is when you create a HTML table of records which
> allows the user to change the records inline, and click on a update
> button.
>
> Thus, I'm proposing that perhaps the writeProperty method could be
> adjusted to do additional check as below to suit this purpose.
> ----
> public void writeProperty(String propName, Object val) {
> resolveFault();
>
> // 1. retain object snapshot to allow clean changes tracking
> // 2. change object state
> Object oldVal = readPropertyDirectly(propName);
> if (persistenceState == PersistenceState.COMMITTED &&
> oldVal.equals(val) == false) {
> persistenceState = PersistenceState.MODIFIED;
> dataContext.getObjectStore().retainSnapshot(this);
> }
> // else....
> // other persistence states can't be changed to MODIFIED
>
> writePropertyDirectly(propName, val);
> }
> -----
>
> Or am I missing out a better way to do this?
>
> --
> Sean Tan
This archive was generated by hypermail 2.0.0 : Fri Aug 26 2005 - 06:55:13 EDT