Search in sources :

Example 1 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 2 with AuditReader

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

the class TestConsole method printAddressAtRevision.

private void printAddressAtRevision(StringBuilder sb, int addressId, int revision) {
    AuditReader reader = AuditReaderFactory.get(entityManager);
    Address a = reader.find(Address.class, addressId, revision);
    if (a == null) {
        sb.append("This address does not exist at that revision.");
    } else {
        printAddress(sb, a);
    }
}
Also used : AuditReader(org.hibernate.envers.AuditReader)

Example 3 with AuditReader

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

the class TestConsole method printPersonAtRevision.

private void printPersonAtRevision(StringBuilder sb, int personId, int revision) {
    AuditReader reader = AuditReaderFactory.get(entityManager);
    Person p = reader.find(Person.class, personId, revision);
    if (p == null) {
        sb.append("This person does not exist at that revision.");
    } else {
        printPerson(sb, p);
    }
}
Also used : AuditReader(org.hibernate.envers.AuditReader)

Example 4 with AuditReader

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

the class EmbeddableWithDeclaredDataTest method testEmbeddableThatExtendsMappedSuperclass.

@Test
@FailureExpected(jiraKey = "HHH-9193")
public void testEmbeddableThatExtendsMappedSuperclass() {
    // Reload and Compare Revision
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    EntityWithEmbeddableWithDeclaredData entityLoaded = em.find(EntityWithEmbeddableWithDeclaredData.class, id);
    AuditReader reader = AuditReaderFactory.get(em);
    List<Number> revs = reader.getRevisions(EntityWithEmbeddableWithDeclaredData.class, id);
    Assert.assertEquals(1, revs.size());
    EntityWithEmbeddableWithDeclaredData entityRev1 = reader.find(EntityWithEmbeddableWithDeclaredData.class, id, revs.get(0));
    em.getTransaction().commit();
    Assert.assertEquals(entityLoaded.getName(), entityRev1.getName());
    // only value.codeArt should be audited because it is the only audited field in EmbeddableWithDeclaredData;
    // fields in AbstractEmbeddable should not be audited.
    Assert.assertEquals(entityLoaded.getValue().getCodeart(), entityRev1.getValue().getCodeart());
    Assert.assertNull(entityRev1.getValue().getCode());
}
Also used : EntityManager(javax.persistence.EntityManager) AuditReader(org.hibernate.envers.AuditReader) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 5 with AuditReader

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

the class Custom method testFindRevision.

@Test
public void testFindRevision() {
    AuditReader vr = getAuditReader();
    long rev1Timestamp = vr.findRevision(CustomRevEntity.class, 1).getCustomTimestamp();
    assert rev1Timestamp > timestamp1;
    assert rev1Timestamp <= timestamp2;
    long rev2Timestamp = vr.findRevision(CustomRevEntity.class, 2).getCustomTimestamp();
    assert rev2Timestamp > timestamp2;
    assert rev2Timestamp <= timestamp3;
}
Also used : CustomRevEntity(org.hibernate.envers.test.entities.reventity.CustomRevEntity) AuditReader(org.hibernate.envers.AuditReader) Test(org.junit.Test)

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