Package org.hibernate.envers

Examples of org.hibernate.envers.AuditReader


        return orgHistory;
    }

    public Organization retrieveOldOrgbyId(int id) {

        AuditReader reader = AuditReaderFactory.get(em);
        Organization org1_rev = reader.find(Organization.class, id, 2);
        return org1_rev;
    }
View Full Code Here


        em.remove(em.merge(p));
    }

    public int retrieveOldPhoneListSizeFromCustomer(int id) {

        AuditReader reader = AuditReaderFactory.get(em);
        List<Number> revList = reader.getRevisions(CustomerMO.class, id);
        CustomerMO cust_rev = reader.find(CustomerMO.class, id, revList.get(revList.size() - 1));
        return cust_rev.getPhones().size();
    }
View Full Code Here

        CustomerMO cust_rev = reader.find(CustomerMO.class, id, revList.get(revList.size() - 1));
        return cust_rev.getPhones().size();
    }

    public String retrieveOldPhoneListVersionFromCustomer(int id) {
        AuditReader reader = AuditReaderFactory.get(em);

        CustomerMO cust_rev = reader.find(CustomerMO.class, id, 1);
        return cust_rev.getPhones().get(0).getType();
    }
View Full Code Here

        return student;
    }

    // fetch Audited entity from Audit tables
    public StudentAudited retrieveOldStudentVersion(int id) {
        AuditReader reader = AuditReaderFactory.get(sessionFactory.openSession());
        StudentAudited student_rev = reader.find(StudentAudited.class, id, 1);
        List<Number> revlist = reader.getRevisions(StudentAudited.class, id);
        // this is for checking revision size hence not removing this S.o.p
        System.out.println("Size of revisionList:--" + revlist.size());
        return student_rev;
    }
View Full Code Here

 
  public List<Object[]> getHistoricalBook(Long id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    AuditReader auditReader = AuditReaderFactory.get(session);
    // List<Number>revisions = auditReader.getRevisions(Book.class, id); // not that useful just returns the revision numbers
   
    AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(Book.class, false, true).add(new IdentifierEqAuditExpression(id, true));
   
    List<Object[]> bookRevisions = query.getResultList();
   
    session.getTransaction().commit();
    return bookRevisions;
View Full Code Here

    manager.deleteBook(book.getBookId());
   
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    AuditReader auditReader = AuditReaderFactory.get(session);
    AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(Book.class, false /* complete revision data: if true just return Book objects */, true /* return deleted entities */).add(new IdentifierEqAuditExpression(book.getBookId(), true));
   
    List<Object[]> bookRevisions = query.getResultList();
   
    assertTrue("The entity does not have 4 revision records",bookRevisions.size() == 4);
   
View Full Code Here

  @PersistenceContext
  private EntityManager entityManager;
 
  @Transactional(readOnly=true)
  public List<Entry> findAuditById(Long id) {
    AuditReader auditReader = AuditReaderFactory.get(entityManager);
    List<Number> revisions = auditReader.getRevisions(Entry.class, id);
   
    revisions = Lists.reverse(revisions);

    List<Entry> entries = new ArrayList<Entry>();
    Entry entry;
    for (Number revision: revisions) {
      entry = auditReader.find(Entry.class, id, revision);
      entries.add(entry);
    }
    return entries;
  }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public Revision<N, T> findLastChangeRevision(ID id) {

    Class<T> type = entityInformation.getJavaType();
    AuditReader reader = AuditReaderFactory.get(entityManager);

    List<Number> revisions = reader.getRevisions(type, id);

    if (revisions.isEmpty()) {
      return null;
    }

    N latestRevision = (N) revisions.get(revisions.size() - 1);

    Class<?> revisionEntityClass = revisionEntityInformation.getRevisionEntityClass();

    Object revisionEntity = reader.findRevision(revisionEntityClass, latestRevision);
    RevisionMetadata<N> metadata = (RevisionMetadata<N>) getRevisionMetadata(revisionEntity);
    return new Revision<N, T>(metadata, reader.find(type, id, latestRevision));
  }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public Revisions<N, T> findRevisions(ID id) {

    Class<T> type = entityInformation.getJavaType();
    AuditReader reader = AuditReaderFactory.get(entityManager);
    List<? extends Number> revisionNumbers = reader.getRevisions(type, id);

    return revisionNumbers.isEmpty() ? new Revisions<N, T>(Collections.EMPTY_LIST) : getEntitiesForRevisions(
        (List<N>) revisionNumbers, id, reader);
  }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public Page<Revision<N, T>> findRevisions(ID id, Pageable pageable) {

    Class<T> type = entityInformation.getJavaType();
    AuditReader reader = AuditReaderFactory.get(entityManager);
    List<Number> revisionNumbers = reader.getRevisions(type, id);

    if (pageable.getOffset() > revisionNumbers.size()) {
      return new PageImpl<Revision<N, T>>(Collections.<Revision<N, T>> emptyList(), pageable, 0);
    }

View Full Code Here

TOP

Related Classes of org.hibernate.envers.AuditReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.