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();
}
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);
}
}
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);
}
}
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());
}
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;
}
Aggregations