Package org.hibernate

Examples of org.hibernate.ScrollableResults


    session.close();

    session = openSession();

    ScrollableResults sr = session.createQuery( query )
       .setResultTransformer(Transformers.aliasToBean(Animal.class)).scroll();
    assertTrue( "Incorrect result size", sr.next() );
    assertTrue( "Incorrect return type", sr.get(0) instanceof Animal );
    assertFalse(session.contains(sr.get(0)));
    sr.close();

    session.close();

    session = openSession();
View Full Code Here


    session.close();

    session = openSession();

    ScrollableResults sr = session.createQuery( query )
       .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).scroll();
    assertTrue( "Incorrect result size", sr.next() );
    assertTrue( "Incorrect return type", sr.get(0) instanceof Map );
    assertFalse(session.contains(sr.get(0)));
    sr.close();

    session.close();

    destroyTestBaseData();
  }
View Full Code Here

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

    SimpleJtaTransactionManagerImpl.getInstance().getTransaction().commit();

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

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

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

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

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

      public List transformList(List arg0)
      {
        return arg0;
      }
    });
    ScrollableResults sr = q.scroll();
    sr.first();
    Object[] row = sr.get();
    assertEquals(1, row.length);
    Object obj = row[0];
    assertTrue(obj instanceof PartnerA);
    PartnerA obj2 = (PartnerA) obj;
    assertEquals("Partner A", obj2.getName());
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

    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

    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

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

    // first, as a control, make sure there are no results
    int size = s.createQuery( query ).setString( "desc", "root%" ).list().size();
    assertEquals( 0, size );

    // now get the scrollable results
    ScrollableResults results = s.createQuery( query ).setString( "desc", "root%" ).scroll();

    assertFalse( results.isFirst() );
    assertFalse( results.isLast() );

    assertFalse( results.next() );
    assertFalse( results.isFirst() );
    assertFalse( results.isLast() );

    assertFalse( results.previous() );
    assertFalse( results.isFirst() );
    assertFalse( results.isLast() );

    results.beforeFirst();
    assertFalse( results.isFirst() );
    assertFalse( results.isLast() );
    assertFalse( results.next() );

    assertFalse( results.first() );
    assertFalse( results.isFirst() );
    assertFalse( results.isLast() );
    assertFalse( results.next() );

    results.afterLast();
    assertFalse( results.isFirst() );
    assertFalse( results.isLast() );
    assertFalse( results.next() );

    assertFalse( results.last() );
    assertFalse( results.isFirst() );
    assertFalse( results.isLast() );
    assertFalse( results.next() );

    for ( int i=1; i<3; i++ ) {
      assertFalse( results.scroll( i ) );
      assertFalse( results.isFirst() );
      assertFalse( results.isLast() );

      assertFalse( results.scroll( - i ) );
      assertFalse( results.isFirst() );
      assertFalse( results.isLast() );

      assertFalse( results.setRowNumber( i ) );
      assertFalse( results.isFirst() );
      assertFalse( results.isLast() );

      assertFalse( results.setRowNumber( - i ) );
      assertFalse( results.isFirst() );
      assertFalse( results.isLast() );
    }

    txn.commit();
    s.close();
  }
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.