Search in sources :

Example 11 with ScrollableResults

use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.

the class HQLScrollFetchTest method testScroll.

@Test
public void testScroll() {
    Session s = openSession();
    s.beginTransaction();
    ScrollableResults results = s.createQuery(QUERY + " order by p.name asc, c.name asc").scroll();
    List list = new ArrayList();
    while (results.next()) {
        list.add(results.get(0));
    }
    assertResultFromAllUsers(list);
    s.getTransaction().commit();
    s.close();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test)

Example 12 with ScrollableResults

use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.

the class HQLScrollFetchTest method testScrollOrderParentAscChildrenAsc.

@Test
@TestForIssue(jiraKey = "HHH-1283")
public void testScrollOrderParentAscChildrenAsc() {
    Session s = openSession();
    s.beginTransaction();
    ScrollableResults results = s.createQuery(QUERY + " order by p.name asc, c.name asc").scroll();
    List list = new ArrayList();
    while (results.next()) {
        list.add(results.get(0));
    }
    assertResultFromAllUsers(list);
    s.getTransaction().commit();
    s.close();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 13 with ScrollableResults

use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.

the class HQLScrollFetchTest method testScrollOrderParentAscChildrenDesc.

@Test
@TestForIssue(jiraKey = "HHH-1283")
public void testScrollOrderParentAscChildrenDesc() {
    Session s = openSession();
    s.beginTransaction();
    ScrollableResults results = s.createQuery(QUERY + " order by p.name asc, c.name desc").scroll();
    List list = new ArrayList();
    while (results.next()) {
        list.add(results.get(0));
    }
    assertResultFromAllUsers(list);
    s.getTransaction().commit();
    s.close();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 14 with ScrollableResults

use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.

the class HQLScrollFetchTest method testIncompleteScrollSecondResult.

@Test
@TestForIssue(jiraKey = "HHH-1283")
public void testIncompleteScrollSecondResult() {
    Session s = openSession();
    s.beginTransaction();
    ScrollableResults results = s.createQuery(QUERY + " order by p.name asc").scroll();
    results.next();
    Parent p = (Parent) results.get(0);
    assertResultFromOneUser(p);
    results.next();
    p = (Parent) results.get(0);
    assertResultFromOneUser(p);
    s.getTransaction().commit();
    s.close();
}
Also used : ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 15 with ScrollableResults

use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.

the class HQLScrollFetchTest method testIncompleteScroll.

@Test
@TestForIssue(jiraKey = "HHH-1283")
public void testIncompleteScroll() {
    Session s = openSession();
    s.beginTransaction();
    ScrollableResults results = s.createQuery(QUERY + " order by p.name asc").scroll();
    results.next();
    Parent p = (Parent) results.get(0);
    assertResultFromOneUser(p);
    // get the other parent entity from the persistence context along with its first child
    // retrieved from the resultset.
    Parent pOther = null;
    Child cOther = null;
    for (Object entity : ((SessionImplementor) s).getPersistenceContext().getEntitiesByKey().values()) {
        if (Parent.class.isInstance(entity)) {
            if (entity != p) {
                if (pOther != null) {
                    fail("unexpected parent found.");
                }
                pOther = (Parent) entity;
            }
        } else if (Child.class.isInstance(entity)) {
            if (!p.getChildren().contains(entity)) {
                if (cOther != null) {
                    fail("unexpected child entity found");
                }
                cOther = (Child) entity;
            }
        } else {
            fail("unexpected type of entity.");
        }
    }
    // check that the same second parent is obtained by calling Session.get()
    assertNull(pOther);
    assertNull(cOther);
    s.getTransaction().commit();
    s.close();
}
Also used : SessionImplementor(org.hibernate.engine.spi.SessionImplementor) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

ScrollableResults (org.hibernate.ScrollableResults)60 Session (org.hibernate.Session)56 Test (org.junit.Test)52 Transaction (org.hibernate.Transaction)35 List (java.util.List)25 BigDecimal (java.math.BigDecimal)13 ArrayList (java.util.ArrayList)13 TestForIssue (org.hibernate.testing.TestForIssue)12 Query (org.hibernate.Query)9 Iterator (java.util.Iterator)7 SkipForDialect (org.hibernate.testing.SkipForDialect)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 StatelessSession (org.hibernate.StatelessSession)3 DB2Dialect (org.hibernate.dialect.DB2Dialect)3 HSQLDialect (org.hibernate.dialect.HSQLDialect)3 SybaseDialect (org.hibernate.dialect.SybaseDialect)3 Query (org.hibernate.query.Query)3 Date (java.util.Date)2