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
Send instant messages to your online friends http://asia.messenger.yahoo.com
This archive was generated by hypermail 2.0.0 : Fri Aug 26 2005 - 06:03:41 EDT