10 Replies Latest reply on Nov 23, 2008 8:22 AM by Adam Warski

    Version Tagging

    Corneil du Plessis Newbie

      I am interested in using envers and require version tagging.
      This means that a specific version of an object gets labeled. This label should then be used in the query to retrieve the relevant versions of objects.
      It is important that only 1 version of an object can have a specific tag, however the tag can be moved to other versions of the same object. Obviously the same tag can be applied to many instances.

      At the moment it seems as if the solution lies with creating a related class where id, version and tag can be stored and then combined in a VersionQuery. I am not sure how to do a VersionQuery that would retrieve a revision where the version number is derived from a value in another class.

      I would hope this could become a feature of envers in the future.

      Regards

      Corneil

        • 1. Re: Version Tagging
          Adam Warski Master

          Hello,

          maybe using a revision entity would help? (http://www.jboss.org/envers/revision_log.html) It's not class-specific but revision-specific, but maybe you could use it (I don't know your exact use-case)?

          Currently it's not easily possible to specify contraints on the revision entity when creating a query, but it's something to add to the query system. (Right now, I think that adding a contraint on "originalId._revision.field_name" should work)

          --
          Adam

          • 2. Re: Version Tagging
            Corneil du Plessis Newbie

            My usecase can be described as follows:
            Three entities name Artefact, DeploymentEnvironment, UnitTest.
            Deployment Environment exists to describe potential named execution environments (Development, QA, Production)
            Artefact is top of an object tree representing objects that will be used by the execution environment.
            UnitTest represents testcases that need to be executed when an Artefact is modified. If the unit test passes the artefact is tagged as Active.
            When the user want to deploy the version tagged as Active is also tagged with the name of the Environment. Thus when the execution environment requests Artefacts the name is used to find the versions tagged as such.
            A specific tag applies to only one version of an instance.

            • 3. Re: Version Tagging
              Adam Warski Master

              So what you really need, is finding the newest Artefact that is tagged with "active".

              Let's assume a simple case, that the Artefact entity has a boolean flag - "active" (in your case, I suppose it would be relation to the Tag entity, but that doesn't change much really). Also, the Artefact entity would be versioned.

              To retrieve the newest Artefact that is tagged as active, you should execute a revisions-of-entity query:

              versionsReader.createQuery()
               .forRevisionsOfEntity(Registration.class, true)
               .add(VersionsRestrictions.maximizeProperty("revision.id")
               .add(VersionsRestrictions.idEq(artefactId))
               .add(VersionsRestrictions.eq("active", true))
               .getSingleResult();
              


              This query maximalizes the "revision" property throughout entities, which have "active" set to "true".

              Does that sound resonable?

              Adam

              • 4. Re: Version Tagging
                Corneil du Plessis Newbie

                When I use the term active I am referring to a label of a tag and not the latest version.

                I need to be able to tag versions with a label after they have been created.
                I want to retrieve all instances of objects corresponding to a tag.
                This is pretty much the same as tagging in Subversion or CVS.
                A specific tag can only be assigned to one version of an instance.
                I also want to be able to move a tag to a different version.

                Thus locating all Artefacts tagged as 'QA' or 'PROD' would then be easy if the version-number of an instance can be related to a specific tag.

                I cannot see how to relate the version number of one entity to the value of another entity in a query.

                • 5. Re: Version Tagging
                  Adam Warski Master

                  Hello,

                  well, I'm not sure if you could use Envers without any modifications... but if you execute the query above, it should work.

                  If you want to find all entities, which are as new as possible, but all tagged with some tag, the following query will work: (assuming you are using trunk version)

                  auditReader.createQuery()
                   .forRevisionsOfEntity(Artefact.class, false, true)
                   .add(AuditEntity.revision().maximize()
                   .add(AuditEntity.property("tag").equal("QA"))
                   .getResultList()
                  


                  --
                  Adam

                  • 6. Re: Version Tagging
                    Corneil du Plessis Newbie

                    I have created an issue http://opensource.atlassian.com/projects/hibernate/browse/HHH-3614 for a version tagging feature.
                    I am prepared to work on this.
                    Should I start by getting the trunk or 1.1.0 GA?

                    • 7. Re: Version Tagging
                      Adam Warski Master

                      Hello,

                      I've posted my comments in JIRA.

                      I think it'd be much better to work on trunk - it has quite a lot of modifications (mainly renaming) comparing to 1.1.0.GA.

                      --
                      Adam

                      • 8. Re: Version Tagging
                        Corneil du Plessis Newbie

                        I have prepared some interfaces and commented classes.
                        Would you mind taking a look and point out where I might be off track.
                        Can I mail you a .zip with the code? Or should I post it here?

                        • 9. Re: Version Tagging
                          Adam Warski Master

                          Hello,

                          great! :) Yes, sure, you can send it to my e-mail or just attach it to the JIRA case.

                          --
                          Adam

                          • 10. Re: Version Tagging
                            Adam Warski Master

                            Hello,

                            great! :) Yes, sure, you can send it to my e-mail or just attach it to the JIRA case.

                            --
                            Adam