Search in sources :

Example 16 with AuditReader

use of org.hibernate.envers.AuditReader in project Asqatasun by Asqatasun.

the class ProcessResultDAOImpl method getHistoryChanges.

@Override
public List<DefiniteResult> getHistoryChanges(ProcessResult processResultImpl) {
    List<DefiniteResult> history = new ArrayList<>();
    AuditReader auditReader = AuditReaderFactory.get(this.entityManager);
    Long id = processResultImpl.getId();
    if (id == null) {
        return new ArrayList<>();
    }
    List<Number> revisions = auditReader.getRevisions(processResultImpl.getClass(), id);
    DefiniteResult find;
    for (int i = 0; i < revisions.size(); i++) {
        Number revision = revisions.get(i);
        find = auditReader.find(DefiniteResultImpl.class, id, revision);
        history.add(find);
    }
    return history;
}
Also used : ArrayList(java.util.ArrayList) AuditReader(org.hibernate.envers.AuditReader)

Example 17 with AuditReader

use of org.hibernate.envers.AuditReader in project hibernate-orm by hibernate.

the class HibernateEnversOnWildflyTest method testEnversCompatibility.

@Test
public void testEnversCompatibility() throws Exception {
    // revision 1
    userTransaction.begin();
    entityManager.joinTransaction();
    AuditedEntity entity = new AuditedEntity(1, "Marco Polo");
    entityManager.persist(entity);
    userTransaction.commit();
    // revision 2
    userTransaction.begin();
    entityManager.joinTransaction();
    entity.setName("George Washington");
    entityManager.merge(entity);
    userTransaction.commit();
    entityManager.clear();
    // verify audit history revision counts
    userTransaction.begin();
    final AuditReader auditReader = AuditReaderFactory.get(entityManager);
    assertEquals(Arrays.asList(1, 2), auditReader.getRevisions(AuditedEntity.class, 1));
    userTransaction.commit();
}
Also used : AuditReader(org.hibernate.envers.AuditReader) Test(org.junit.Test)

Example 18 with AuditReader

use of org.hibernate.envers.AuditReader in project wildfly by wildfly.

the class SFSBHibernateEnversSessionFactory method retrieveOldStudentVersion.

// 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
    return student_rev;
}
Also used : AuditReader(org.hibernate.envers.AuditReader)

Example 19 with AuditReader

use of org.hibernate.envers.AuditReader in project wildfly by wildfly.

the class SFSB1 method retrieveOldEmployeeVersionforRollBack.

public String retrieveOldEmployeeVersionforRollBack(int id) {
    AuditReader reader = AuditReaderFactory.get(em);
    Employee emp1_rev = reader.find(Employee.class, id, 5);
    return emp1_rev.getAddress();
}
Also used : AuditReader(org.hibernate.envers.AuditReader)

Example 20 with AuditReader

use of org.hibernate.envers.AuditReader in project wildfly by wildfly.

the class SLSBAudit method verifyRevision.

public List<Object> verifyRevision(int id) {
    AuditReader reader = AuditReaderFactory.get(em);
    // boolean b;
    // String queryString = "select a.originalId.REV from " + "CUSTOMER_PHONE" + "_AUD a";
    // String queryString = "select column_name from information_schema.columns where table_name = 'CUSTOMER_PHONE_AUD'";
    // Query query = em.createQuery(queryString);
    List<Object> custHistory = new ArrayList<Object>();
    List<Number> revList = reader.getRevisions(Customer.class, id);
    for (Number revisionNumber : revList) {
        AuditQuery query = reader.createQuery().forEntitiesAtRevision(Customer.class, revisionNumber);
        query.add(AuditEntity.property("firstname").eq("MADHUMITA"));
        if (query.getResultList() != null && query.getResultList().size() > 0) {
            custHistory.add(query.getResultList());
        }
    }
    return custHistory;
}
Also used : AuditQuery(org.hibernate.envers.query.AuditQuery) ArrayList(java.util.ArrayList) AuditReader(org.hibernate.envers.AuditReader)

Aggregations

AuditReader (org.hibernate.envers.AuditReader)51 Test (org.junit.Test)27 Car (org.hibernate.envers.test.integration.query.entities.Car)8 EntityManager (javax.persistence.EntityManager)6 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 AuditQuery (org.hibernate.envers.query.AuditQuery)4 List (java.util.List)2 Map (java.util.Map)2 Query (javax.persistence.Query)2 Session (org.hibernate.Session)2 DefaultRevisionEntity (org.hibernate.envers.DefaultRevisionEntity)2 CustomRevEntity (org.hibernate.envers.test.entities.reventity.CustomRevEntity)2 AuditedDataPoint (org.hibernate.osgi.test.client.AuditedDataPoint)2 ServiceReference (org.osgi.framework.ServiceReference)2 Date (java.util.Date)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 SessionFactory (org.hibernate.SessionFactory)1 CustomPropertyAccessRevEntity (org.hibernate.envers.test.entities.reventity.CustomPropertyAccessRevEntity)1