6 Replies Latest reply on Feb 1, 2012 5:34 AM by vyacheslav86

    envers deploy to existing production / initial revision generation.

    vyacheslav86

      I need to deploy envers-audit functionality to already used database and main problem is creating initial revision for data already present in the db.

      I need that initial revision because user query for data existed at specified date, but if data was added before deployment of auditing functionality then it is not present in auditing tables by default.

      I could query for exact data if there is no entry in audit tables but some data could also be deleted after introduction of auditing, so some state could be lost even if it existed after start of use of audit functionality.

       

      So i need somehow write revision information for data which already exists. Here some more problems occur:

       

      1) i need to process not only entities which are implemented as rows in database, but also relations between them mapped using hibernate in a different ways: using join-table, using id filed mapping;

      I need to process such relations in order: row entities first - relations afterwards, because relation-implementation references row entity id;

      2) I need also to process self-relations of entities, so parent entities are inserted first, child entities second;

       

      I'm implementing that solution rigth now, but i'm using JDBC object representation and hardcoding model properties specified above instead of reflection based entity processing which should be done here.

       

      So i'm using code like that:

       


      /**

      * Returns entities in special order for creating revisions:

      * for OneToMany relationship owning side is created first.

      */

      @Override

      public List<Class<?>> getEntitiesListOrderedForRelationshipInitialCreationWithoutInheritedAbstractEntities() {


      List<Class<?>> classes = Arrays.asList(new Class<?>[] {




      PropertySafety.class, // before Property









      //Property.class, //before CapexContract









      Atm.class,




      Building.class,




      Facility.class,




      Land.class,




      AdvConstruction.class,









      CapexContract.class, // TODO problem CAPEX_ID









      CapexContractFileLink.class, // after CapexContract







      Contract.class, //after Property




      ContractFileLink.class, // after Contract




      PaymentsSheduleCondition.class, // after Contract














      //Contractor.class,




      BusinessPerson.class,




      LegalPerson.class,




      Person.class,









      Contact.class, // after Contractor, 2 reasons




      ContactInfo.class, // after Contractor









      ContractorFileLink.class, // after Contractor









      FnprShare.class, // after Contractor









      Management.class, // after Contractor, 2 reasons




      PaymentDetail.class, // after Contractor














      PropertyEstimation.class, // after Property




      PropertyFileLink.class, // after Property









      PropertyLifecycle.class, // after Property




      PropertyLifecyclePhase.class, // after PropertyLifecycle













      PropertyLifecyclePhaseFileLink.class, // after PropertyLifecyclePhase // commented out no auditable fields









      PropertyLink.class, // after Property, 2 reasons




      PropertyMixedDetails.class, // after Property




      PropertyOwner.class, // after Property, after Contractor




      PropertyPersonnel.class, // after Property




      PropertyPromoLink.class, // after Property









      PropertyRoom.class, // after Property




      PropertyRoomArea.class, // after PropertyRoom




      PropertyRoomFRC.class, // after PropertyRoom









      PropertyRsrOrder.class, // after Property, keep PROPERTY_ID









      PropertySumItem.class, // after Property




      PropertyUser.class, // after Property, after Contractor




      PropertyWorkhours.class // after Property


      });


      Set<Class<?>> set = new HashSet<Class<?>>();


      set.addAll(classes);


      assertAllAuditableClassesPresent(classes.size());


      assertEachClassIsAuditable(set);


      return classes;

      }

       

      In general i need to reproduce how existing data could be inserted in database and relations created there.

       

      I wonder if such functionality will be a part of Envers someday, because i think not only i deploy envers to already existing production database?