9 Replies Latest reply on Nov 20, 2008 9:20 AM by adamw

    Date-based versioning

    twoilseree

      Nice!

      What also would be cool is to have point in time functionality.

      Suppose you set a date '01/01/2008' you should be able to view the full database as it was on '01/01/2008'. That would be cool!

        • 1. Re: Date-based versioning
          adamw

          Hello,

          good idea! :) With each revision its timestamp is recorded, so adding this is really just a matter of adding a simple method to VersionsReader, getRevisionForDate(Date date), which would return the earliest revision after the specified date. I'll add that in the next release.

          Adam

          • 2. Re: Date-based versioning
            genman

            You probably mean the latest revision before that specified date...

            • 3. Re: Date-based versioning
              adamw

              Yes, of course :)

              Adam

              • 4. Re: Date-based versioning
                adamw

                Hello,

                I've uploaded a development version of the library:
                http://www.jboss.org/envers/downloads/development/
                which includes the mentioned method: VersionsReader.getRevisionNumberForDate(Date date).

                Adam

                • 5. Re: Date-based versioning
                  alessandro.moreira

                  Dear Adam,

                  I know that's a old post but It's exactly what I am looking for. We need to get:

                  1. Revisions for a Date. ( What were the Revision at 2008/11/19 ? )
                  2. The stated Revision for a Date ( What was the deleted/modified/inserted Revison at 2008/11/19 ? )
                  3. Revisons for a Period. ( What were the Revison from 2008/11/01 to 2008/11/19 ? )

                  It is realy important to our reports. Please I studied your API a lot and didn't find a way to resolve these.

                  Regards.

                  Alessandro Moreira
                  Brazil, Ceara, Fortaleza

                  • 6. Re: Date-based versioning
                    adamw

                    Hello,

                    1. and 2. are in VersionsReader/AuditReader.

                    For 3, you can create a revisions-of-entity query. Using the trunk version:

                    auditReader.createQuer()
                     .forRevisionsOfEntity(YourEntity.class, false, true)
                     .addProjection(AuditEntity.revisionNumber())
                     .add(AuditEntity.revisionProperty("timestamp").ge(startDate))
                     .add(AuditEntity.revisionProperty("timestamp").le(endDate))
                     .getResultList();
                    


                    --
                    Adam

                    • 7. Re: Date-based versioning
                      alessandro.moreira

                      Dear Adam,

                      I didn't study the Envers Lib after moving to Hibernate. I am still using 1.1.0.GA release (for Hibernate 3.3.x). So, do you mind to post an exemplo for each one Lib to case 1 and 2 ?

                      • 8. Re: Date-based versioning
                        alessandro.moreira

                        Please Adam don't think I am lazy. I just didn't find out how to answer question 1 and 2 by the API, precisely in VersionsReader.

                        In question 1 I was not refering to Revison Numbers but the EntityRevison Object.

                        And in question 2 either. How to get a EntityRevison with stated "deleted" ( DEL) at a given date, for exemplo ???

                        Therefore, I ask for your helping ! :-D

                        • 9. Re: Date-based versioning
                          adamw

                          Hello,

                          as for 1 and 2 in 1.1.0, just take a look here:
                          http://www.jboss.org/files/envers/api/org/jboss/envers/VersionsReader.html

                          I think that the getRevisionDate and getRevisionNumberForDate methods will meet your needs.

                          I don't understand the question: "How to get a EntityRevison with stated "deleted" ( DEL) at a given date, for exemplo ???"

                          For a given date, there is a corresponding revision number. At that revision, some entities may have been removed, and then they will have revision type "DEL". So, you can read the revision number for a date, look for your entity at that revision and check the revision type.

                          --
                          Adam