Search in sources :

Example 6 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class OrderByLimitQuery method testEntitiesOrderLimitByQueryRev2.

@Test
public void testEntitiesOrderLimitByQueryRev2() {
    List res_0_to_1 = getAuditReader().createQuery().forEntitiesAtRevision(IntTestEntity.class, 2).addOrder(AuditEntity.property("number").desc()).setFirstResult(0).setMaxResults(2).getResultList();
    List res_2_to_3 = getAuditReader().createQuery().forEntitiesAtRevision(IntTestEntity.class, 2).addOrder(AuditEntity.property("number").desc()).setFirstResult(2).setMaxResults(2).getResultList();
    List res_4 = getAuditReader().createQuery().forEntitiesAtRevision(IntTestEntity.class, 2).addOrder(AuditEntity.property("number").desc()).setFirstResult(4).setMaxResults(2).getResultList();
    assert Arrays.asList(new IntTestEntity(15, id4), new IntTestEntity(8, id3)).equals(res_0_to_1);
    assert Arrays.asList(new IntTestEntity(5, id2), new IntTestEntity(3, id5)).equals(res_2_to_3);
    assert Arrays.asList(new IntTestEntity(0, id1)).equals(res_4);
}
Also used : List(java.util.List) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test)

Example 7 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class OrderByLimitQuery method testEntitiesOrderLimitByQueryRev1.

@Test
public void testEntitiesOrderLimitByQueryRev1() {
    List res_0_to_1 = getAuditReader().createQuery().forEntitiesAtRevision(IntTestEntity.class, 1).addOrder(AuditEntity.property("number").desc()).setFirstResult(0).setMaxResults(2).getResultList();
    List res_2_to_3 = getAuditReader().createQuery().forEntitiesAtRevision(IntTestEntity.class, 1).addOrder(AuditEntity.property("number").desc()).setFirstResult(2).setMaxResults(2).getResultList();
    List res_empty = getAuditReader().createQuery().forEntitiesAtRevision(IntTestEntity.class, 1).addOrder(AuditEntity.property("number").desc()).setFirstResult(4).setMaxResults(2).getResultList();
    assert Arrays.asList(new IntTestEntity(12, id1), new IntTestEntity(8, id3)).equals(res_0_to_1);
    assert Arrays.asList(new IntTestEntity(5, id2), new IntTestEntity(1, id4)).equals(res_2_to_3);
    assert Arrays.asList().equals(res_empty);
}
Also used : List(java.util.List) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test)

Example 8 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class QueryCache method testCacheFindAfterRevisionsOfEntityQuery.

@Test
public void testCacheFindAfterRevisionsOfEntityQuery() {
    List entsFromQuery = getAuditReader().createQuery().forRevisionsOfEntity(IntTestEntity.class, true, false).getResultList();
    IntTestEntity entFromFindRev1 = getAuditReader().find(IntTestEntity.class, id1, 1);
    IntTestEntity entFromFindRev2 = getAuditReader().find(IntTestEntity.class, id1, 2);
    assert entFromFindRev1 == entsFromQuery.get(0);
    assert entFromFindRev2 == entsFromQuery.get(1);
}
Also used : List(java.util.List) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test)

Example 9 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class QueryCache method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    IntTestEntity ite = new IntTestEntity(10);
    em.persist(ite);
    id1 = ite.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ite = em.find(IntTestEntity.class, id1);
    ite.setNumber(20);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 10 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class Simple method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    IntTestEntity ite = new IntTestEntity(10);
    em.persist(ite);
    id1 = ite.getId();
    em.getTransaction().commit();
    em.getTransaction().begin();
    ite = em.find(IntTestEntity.class, id1);
    ite.setNumber(20);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

IntTestEntity (org.hibernate.envers.test.entities.IntTestEntity)13 Test (org.junit.Test)12 EntityManager (javax.persistence.EntityManager)7 Priority (org.hibernate.envers.test.Priority)6 List (java.util.List)3 UnusualIdNamingEntity (org.hibernate.envers.test.entities.ids.UnusualIdNamingEntity)1 SessionImpl (org.hibernate.internal.SessionImpl)1