Search in sources :

Example 41 with AuditReader

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

the class AssociationToOneLeftJoinQueryTest method testEntitiesWithANullRelatedIdAreNotJoinedToOtherEntities.

/**
	 * In a first attempt to implement left joins in Envers, a full join
	 * has been performed and than the entities has been filtered in the
	 * where clause. However, this approach did only work for inner joins
	 * but not for left joins. One of the defects in this approach is,
	 * that audit entities, which have a null 'relatedId' are and do not
	 * match the query criterias, still joined to other entities which matched
	 * match the query criterias.
	 * This test ensures that this defect is no longer in the current implementation.
	 */
@Test
public void testEntitiesWithANullRelatedIdAreNotJoinedToOtherEntities() {
    final AuditReader auditReader = getAuditReader();
    List<Car> resultList = auditReader.createQuery().forEntitiesAtRevision(Car.class, 1).traverseRelation("owner", JoinType.LEFT, "p").up().add(AuditEntity.and(AuditEntity.property("make").eq("car3"), AuditEntity.property("p", "age").eq(30))).getResultList();
    assertTrue("Expected no cars to be returned, because car3 does not have an owner", resultList.isEmpty());
}
Also used : Car(org.hibernate.envers.test.integration.query.entities.Car) AuditReader(org.hibernate.envers.AuditReader) Test(org.junit.Test)

Example 42 with AuditReader

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

the class DataPointServiceImpl method getRevisions.

public Map<Number, DefaultRevisionEntity> getRevisions(long id) {
    Session s = hibernateUtil.getSession();
    AuditReader reader = AuditReaderFactory.get(s);
    List<Number> revisionNums = reader.getRevisions(DataPoint.class, id);
    return reader.findRevisions(DefaultRevisionEntity.class, new HashSet<Number>(revisionNums));
}
Also used : AuditReader(org.hibernate.envers.AuditReader) Session(org.hibernate.Session)

Example 43 with AuditReader

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

the class SLSBAudit method retrieveOldPhoneListVersionFromCustomer.

public String retrieveOldPhoneListVersionFromCustomer(int id) {
    AuditReader reader = AuditReaderFactory.get(em);
    Customer cust_rev = reader.find(Customer.class, id, 2);
    return cust_rev.getPhones().get(1).getType();
}
Also used : AuditReader(org.hibernate.envers.AuditReader)

Example 44 with AuditReader

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

the class SLSBAudit method retrieveOldPhoneListSizeFromCustomer.

public int retrieveOldPhoneListSizeFromCustomer(int id, int revnumber) {
    AuditReader reader = AuditReaderFactory.get(em);
    Customer cust_rev = reader.find(Customer.class, id, revnumber);
    return cust_rev.getPhones().size();
}
Also used : AuditReader(org.hibernate.envers.AuditReader)

Example 45 with AuditReader

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

the class SLSBAudit method verifyOtherFields.

public List<Object> verifyOtherFields(int id) {
    AuditReader reader = AuditReaderFactory.get(em);
    boolean b;
    Customer cust1_rev = reader.find(Customer.class, id, 3);
    String queryString = "select a.originalId.phones_id from CUSTOMER_PHONE_AUD a";
    Query query = em.createQuery(queryString);
    List<Object> custHistory = query.getResultList();
    return custHistory;
}
Also used : Query(javax.persistence.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) 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