0 Replies Latest reply on Aug 11, 2003 11:45 AM by Holger (David) Wagner

    Last-Modified with CMP-Beans

    Holger (David) Wagner Newbie

      Hi forum,

      In our application, we need to know when the last modification of a Bean took place. For that, we have a field "lastModified" that should be updated with the current date whenever any of the setters has been called and the new value is different from the old value.

      E.g. assuming that name == "Smith"
      bean.setName("Smith");
      => last modified remains as it was
      bean.setName("Agent");
      => last modified has the current date

      Since setters are abstract with CMP-Beans, I don't know where to put the relevant code for checking whether the value has changed and if so, updating the timestamp.

      How can that be achieved?


      An issue that may make things more complicated is that it may be necessary to not use the current date but a specific date given by the caller. Usually, updates happen in some sort of "batch" - so one solution might be adding yet another field, e.g. "lastModification". This would be set at the beginning of the transaction, and then could be used instead of the current date, though...

      That way, things would look something like:
      Assuming:
      name == "Smith"
      lastModified == "2003-08-09T09:00"

      bean.setLastModification("2003-08-10T15:30");
      bean.setName("Smith");
      => lastModified == "2003-08-09T09:00"

      bean.setLastModification("2003-08-10T15:30");
      bean.setName("Agent");
      => lastModified == "2003-08-10T15:30"


      Would that be a good approach or are there better ways to achieve such a behavior in the J2EE environment?

      regards,
      david