3 Replies Latest reply on Dec 13, 2002 5:43 PM by Ryan Ramage

    Transparent Timestamp fields

    Ryan Ramage Newbie

      I am currently working to add temporal support to the underlying database. For all my entity beans I require some timestamp fields. I want these fields to be transparent to the application. Each update to the underlying db will result in this timestamp being changed. For example: each bean will have a validStart and validEnd timestamp.
      A current valid entry will have a validEnd timestamp as NULL.

      This affects the persistance SQL code. When a bean loads it will be changed from

      select * from Bean where id = primaryKey;
      to
      select * from Bean where id = primaryKey and validEnd is null;

      Deleting a bean will changed from
      delete from Bean where id = primary key
      to
      update Bean set validEnd = NOW() where id = primaryKey and validEnd is null; insert into Bean values(primaryKey,...,Now(), NULL);

      Same deal with updates and select. Hope you get the picture.

      Now I dont want to create fields in my bean as a timestamp (as I want it transparent). So I have to add something to the ejb container. Where would I look to do this? Any suggestions? Is there a way I could alter the SQL by adding an interceptor to the call stack? Or do I have to just hard code the sql? Anyone done anything like this before?


        • 1. Re: Transparent Timestamp fields
          Ryan Ramage Newbie

          I love JBoss! Looking at the source, it was not that hard to find out what to do. If anyone cares the steps are:

          1) Extend each of the JDBCCommand classes (eg JDBCRemoveEntityCommand) and change the SQL where needed.

          2) Create a subclass of org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager and as part of the Factory Pattern call each of the new classes from step 1.

          3) change the persistence-manager in standardjboss.xml to the class in step 2.

          Just that easy! =) Now just to make sure that my new sql does not mess anything up =)

          • 2. Re: Transparent Timestamp fields
            Ryan Ramage Newbie

            I love JBoss! Looking at the source, it was not that hard to find out what to do. If anyone cares the steps are:

            1) Extend each of the JDBCCommand classes (eg JDBCRemoveEntityCommand) and change the SQL where needed.

            2) Create a subclass of org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager and as part of the Factory Pattern call each of the new classes from step 1.

            3) change the persistence-manager in standardjboss.xml to the class in step 2.

            • 3. Re: Transparent Timestamp fields
              Ryan Ramage Newbie

              I love JBoss! Looking at the source, it was not that hard to find out what to do. If anyone cares the steps are:

              1) Extend each of the JDBCCommand classes (eg JDBCRemoveEntityCommand) and change the SQL where needed.

              2) Create a subclass of org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager and as part of the Factory Pattern call each of the new classes from step 1.

              3) change the persistence-manager in standardjboss.xml to the class in step 2.