Package org.hibernate

Examples of org.hibernate.ScrollableResults


  public void testScrollOrderParentDesc() {
    try {
      insertTestData();
      Session s = openSession();
      ScrollableResults results = s.createQuery( QUERY + " order by p.name desc" ).scroll();
      List list = new ArrayList();
      while ( results.next() ) {
        list.add( results.get( 0 ) );
      }
      assertResultFromAllUsers( list );
      s.close();
    }
    finally {
View Full Code Here


  public void testScrollOrderParentAscChildrenAsc() {
    try {
      insertTestData();
      Session s = openSession();
      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.close();
    }
    finally {
View Full Code Here

  public void testScrollOrderParentAscChildrenDesc() {
    try {
      insertTestData();
      Session s = openSession();
      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.close();
    }
    finally {
View Full Code Here

    assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
    // but should not effect the cumulative row count
    assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
    Hibernate.close( itr );

    ScrollableResults scrollableResults = s.createQuery( continents ).scroll();
    // same deal with scroll()...
    assertEquals( "unexpected execution count", 3, continentStats.getExecutionCount() );
    assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
    // scroll through data because SybaseASE15Dialect throws NullPointerException
    // if data is not read before closing the ResultSet
    while ( scrollableResults.next() ) {
      // do nothing
    }
    scrollableResults.close();
    tx.commit();
    s.close();

    // explicitly check that statistics for "split queries" get collected
    // under the original query
View Full Code Here

    DummyTransactionManager.INSTANCE.getTransaction().commit();

    // First, test partially scrolling the result with out closing
    DummyTransactionManager.INSTANCE.begin();
    s = getSessions().getCurrentSession();
    ScrollableResults results = s.createQuery( "from Item" ).scroll();
    results.next();
    DummyTransactionManager.INSTANCE.getTransaction().commit();

    // Next, test partially scrolling the result with closing
    DummyTransactionManager.INSTANCE.begin();
    s = getSessions().getCurrentSession();
    results = s.createQuery( "from Item" ).scroll();
    results.next();
    results.close();
    DummyTransactionManager.INSTANCE.getTransaction().commit();

    // Next, scroll the entire result (w/o closing)
    DummyTransactionManager.INSTANCE.begin();
    s = getSessions().getCurrentSession();
    results = s.createQuery( "from Item" ).scroll();
    while ( results.next() ) {
      // do nothing
    }

    DummyTransactionManager.INSTANCE.getTransaction().commit();

    // Next, scroll the entire result (closing)
    DummyTransactionManager.INSTANCE.begin();
    s = getSessions().getCurrentSession();
    results = s.createQuery( "from Item" ).scroll();
    while ( results.next() ) {
      // do nothing
    }
    results.close();
    DummyTransactionManager.INSTANCE.getTransaction().commit();

    DummyTransactionManager.INSTANCE.begin();
    s = getSessions().getCurrentSession();
    s.createQuery( "delete from Item" ).executeUpdate();
View Full Code Here

    set.add("Simple 1"); set.add("foo");
    q.setParameterList( "name_list", set );
    q.setParameter("count", new Integer(-1) );
    assertTrue( q.list().size()==1 );

    ScrollableResults sr = s.createQuery("from Simple s").scroll();
    sr.next();
    sr.get(0);
    sr.close();

    s.delete(other);
    s.delete(simple);
    s.delete(min);
    t.commit();
View Full Code Here

   
    s = openSession();
    s.setCacheMode(CacheMode.IGNORE);
    t = s.beginTransaction();
    int i = 0;
    ScrollableResults sr = s.createQuery("from DataPoint dp order by dp.x asc")
        .setReadOnly(true)
        .scroll(ScrollMode.FORWARD_ONLY);
    while ( sr.next() ) {
      DataPoint dp = (DataPoint) sr.get(0);
      if (++i==50) {
        s.setReadOnly(dp, false);
      }
      dp.setDescription("done!");
    }
View Full Code Here

    course.setCourseCode("HIB");
    course.setDescription("Hibernate Training");
    session.persist(course);
    session.flush();
    session.clear();
    ScrollableResults sr = session.createCriteria(Course.class).scroll();
    assertTrue( sr.next() );
    course = (Course) sr.get(0);
    assertNotNull(course);
    sr.close();
    session.delete(course);
   
    t.commit();
    session.close();
   
View Full Code Here

    s.flush();

    // both scroll() and iterate() cause the batcher to hold on
    // to resources, which should make aggresive-release not release
    // the connection (and thus cause serialization to fail)
    ScrollableResults sr = s.createQuery( "from Silly" ).scroll();

    try {
      SerializationHelper.serialize( s );
      fail( "Serialization allowed on connected session; or aggressive release released connection with open resources" );
    }
    catch( IllegalStateException e ) {
      // expected behavior
    }

    // getting the first row only because SybaseASE15Dialect throws NullPointerException
    // if data is not read before closing the ResultSet
    sr.next();

    // Closing the ScrollableResults does currently force the batcher to
    // aggressively release the connection
    sr.close();
    SerializationHelper.serialize( s );

    s.delete( silly );
    s.flush();
View Full Code Here

    Session s = getSessionUnderTest();
    Silly silly = new Silly( "silly" );
    s.save( silly );
    s.flush();

    ScrollableResults sr = s.createQuery( "from Silly" ).scroll();
    assertTrue( sr.next() );
    Silly silly2 = ( Silly ) sr.get( 0 );
    assertEquals( silly, silly2 );
    sr.close();

    sr = s.createQuery( "from Silly" ).scroll();
    ScrollableResults sr2 = s.createQuery( "from Silly where name = 'silly'" ).scroll();

    assertTrue( sr.next() );
    assertEquals( silly, sr.get( 0 ) );
    assertTrue( sr2.next() );
    assertEquals( silly, sr2.get( 0 ) );

    sr.close();
    sr2.close();

    s.delete( silly );
    s.flush();

    release( s );
View Full Code Here

TOP

Related Classes of org.hibernate.ScrollableResults

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.