Search in sources :

Example 1 with DefaultRevisionEntity

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

the class TestConsole method printPersonHistory.

private void printPersonHistory(StringBuilder sb, int personId) {
    AuditReader reader = AuditReaderFactory.get(entityManager);
    List personHistory = reader.createQuery().forRevisionsOfEntity(Person.class, false, true).add(AuditEntity.id().eq(personId)).getResultList();
    if (personHistory.size() == 0) {
        sb.append("A person with id ").append(personId).append(" does not exist.\n");
    } else {
        for (Object historyObj : personHistory) {
            Object[] history = (Object[]) historyObj;
            DefaultRevisionEntity revision = (DefaultRevisionEntity) history[1];
            sb.append("revision = ").append(revision.getId()).append(", ");
            printPerson(sb, (Person) history[0]);
            sb.append(" (").append(revision.getRevisionDate()).append(")\n");
        }
    }
}
Also used : DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) List(java.util.List) AuditReader(org.hibernate.envers.AuditReader)

Example 2 with DefaultRevisionEntity

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

the class TestConsole method printAddressHistory.

private void printAddressHistory(StringBuilder sb, int addressId) {
    AuditReader reader = AuditReaderFactory.get(entityManager);
    List addressHistory = reader.createQuery().forRevisionsOfEntity(Address.class, false, true).add(AuditEntity.id().eq(addressId)).getResultList();
    if (addressHistory.size() == 0) {
        sb.append("A address with id ").append(addressId).append(" does not exist.\n");
    } else {
        for (Object historyObj : addressHistory) {
            Object[] history = (Object[]) historyObj;
            DefaultRevisionEntity revision = (DefaultRevisionEntity) history[1];
            sb.append("revision = ").append(revision.getId()).append(", ");
            printAddress(sb, (Address) history[0]);
            sb.append(" (").append(revision.getRevisionDate()).append(")\n");
        }
    }
}
Also used : DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) List(java.util.List) AuditReader(org.hibernate.envers.AuditReader)

Example 3 with DefaultRevisionEntity

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

the class GetRevisionsCommand method execute.

public Object execute(CommandSession session) throws Exception {
    Map<Number, DefaultRevisionEntity> revisions = dpService.getRevisions(Long.valueOf(id));
    for (Number revisionNum : revisions.keySet()) {
        DefaultRevisionEntity dre = revisions.get(revisionNum);
        System.out.println(revisionNum + ": " + dre.getId() + ", " + dre.getTimestamp());
    }
    return null;
}
Also used : DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity)

Example 4 with DefaultRevisionEntity

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

the class ImplementValidityAuditStrategyTestCase method testValidityStrategyActivationforEnvers.

@Test
@InSequence(2)
public void testValidityStrategyActivationforEnvers() throws Exception {
    SLSBValidityStrategyOrg slsbvalidityOrg = lookup("SLSBValidityStrategyOrg", SLSBValidityStrategyOrg.class);
    Organization o1 = slsbvalidityOrg.createOrg("REDHAT", "Software Co", "10/10/1994", "eternity", "Raleigh");
    Organization o2 = slsbvalidityOrg.createOrg("HALDIRAMS", "Food Co", "10/10/1974", "eternity", "Delhi");
    o2.setStartDate("10/10/1924");
    o2.setName("BIKANER");
    slsbvalidityOrg.updateOrg(o2);
    // check if REV END Date is populated
    List<Map<String, Object>> orgHistory = slsbvalidityOrg.verifyEndRevision(new Integer(o2.getId()));
    for (Map<String, Object> revisionEntity : orgHistory) {
        Assert.assertNotNull(revisionEntity);
        Date revendTimestamp = (Date) revisionEntity.get("REVEND_VALIDITY");
        DefaultRevisionEntity revEnd = (DefaultRevisionEntity) revisionEntity.get("REVEND");
        if (revendTimestamp != null) {
            Assert.assertEquals(revendTimestamp.getTime(), revEnd.getTimestamp());
        }
    }
}
Also used : SLSBValidityStrategyOrg(org.jboss.as.test.integration.jpa.hibernate.envers.SLSBValidityStrategyOrg) Organization(org.jboss.as.test.integration.jpa.hibernate.envers.Organization) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

DefaultRevisionEntity (org.hibernate.envers.DefaultRevisionEntity)4 List (java.util.List)2 AuditReader (org.hibernate.envers.AuditReader)2 Date (java.util.Date)1 Map (java.util.Map)1 InSequence (org.jboss.arquillian.junit.InSequence)1 Organization (org.jboss.as.test.integration.jpa.hibernate.envers.Organization)1 SLSBValidityStrategyOrg (org.jboss.as.test.integration.jpa.hibernate.envers.SLSBValidityStrategyOrg)1 Test (org.junit.Test)1