Search in sources :

Example 6 with AuditQuery

use of org.hibernate.envers.query.AuditQuery in project hibernate-orm by hibernate.

the class EmbeddableQuery method testAuditQueryUsingEmbeddableNotEquals.

@Test
public void testAuditQueryUsingEmbeddableNotEquals() {
    final NameInfo nameInfo = new NameInfo("Jane", "Doe");
    final AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(Person.class, 1);
    query.add(AuditEntity.property("nameInfo").ne(nameInfo));
    assertEquals(0, query.getResultList().size());
}
Also used : AuditQuery(org.hibernate.envers.query.AuditQuery) Test(org.junit.Test)

Example 7 with AuditQuery

use of org.hibernate.envers.query.AuditQuery in project hibernate-orm by hibernate.

the class AuditRelatedIdInTest method testCompany1EmployeeIn.

@Test
public void testCompany1EmployeeIn() {
    AuditQuery auditQuery = getAuditReader().createQuery().forRevisionsOfEntity(Employee.class, true, true);
    auditQuery.add(AuditEntity.relatedId("company").in(new Integer[] { company1Id }));
    final List<Employee> results = auditQuery.getResultList();
    assertEquals(2, results.size());
    final Employee employee1 = makeEmployee(employee1Id, "Employee1", company1Id, "COMPANY1");
    final Employee employee2 = makeEmployee(employee2Id, "Employee2", company1Id, "COMPANY1");
    assertThat(results.contains(employee1), is(true));
    assertThat(results.contains(employee2), is(true));
}
Also used : AuditQuery(org.hibernate.envers.query.AuditQuery) Test(org.junit.Test)

Example 8 with AuditQuery

use of org.hibernate.envers.query.AuditQuery in project hibernate-orm by hibernate.

the class AuditRelatedIdInTest method testCompany2EmployeeIn.

@Test
public void testCompany2EmployeeIn() {
    AuditQuery auditQuery = getAuditReader().createQuery().forRevisionsOfEntity(Employee.class, true, true);
    auditQuery.add(AuditEntity.relatedId("company").in(new Integer[] { company2Id }));
    final List<Employee> results = auditQuery.getResultList();
    assertEquals(2, results.size());
    final Employee employee1 = makeEmployee(employee2Id, "Employee2", company2Id, "COMPANY2");
    final Employee employee2 = makeEmployee(employee3Id, "Employee3", company2Id, "COMPANY2");
    assertThat(results.contains(employee1), is(true));
    assertThat(results.contains(employee2), is(true));
}
Also used : AuditQuery(org.hibernate.envers.query.AuditQuery) Test(org.junit.Test)

Example 9 with AuditQuery

use of org.hibernate.envers.query.AuditQuery 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)

Example 10 with AuditQuery

use of org.hibernate.envers.query.AuditQuery in project hibernate-orm by hibernate.

the class AuditRelatedIdInTest method testCompany3EmployeeIn.

@Test
public void testCompany3EmployeeIn() {
    AuditQuery auditQuery = getAuditReader().createQuery().forRevisionsOfEntity(Employee.class, true, true);
    auditQuery.add(AuditEntity.relatedId("company").in(new Integer[] { company3Id }));
    final List<Employee> results = auditQuery.getResultList();
    assertEquals(1, results.size());
    final Employee employee = makeEmployee(employee4Id, "Employee4", company3Id, "COMPANY3");
    assertEquals(results, TestTools.makeList(employee));
}
Also used : AuditQuery(org.hibernate.envers.query.AuditQuery) Test(org.junit.Test)

Aggregations

AuditQuery (org.hibernate.envers.query.AuditQuery)13 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 AuditReader (org.hibernate.envers.AuditReader)3 AuditException (org.hibernate.envers.exception.AuditException)1