Package org.hibernate

Examples of org.hibernate.ScrollableResults


    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


    @Override
    public ScrollableResults scroll(QueryParameters queryParameters, SessionImplementor session)
        throws HibernateException {
        JoinFetchUsage usage = new JoinFetchUsage(queryParameters);

        ScrollableResults ret = super.scroll(queryParameters, session);

        usage.report("scroll");

        return ret;
    }
View Full Code Here

    clearCounts();

    s = openSession();
    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

    }

    assertInsertCount( 0 );
    assertUpdateCount( 0 );

    ScrollableResults sr = s.createQuery("from DataPoint dp order by dp.x asc")
        .setReadOnly(true)
        .scroll(ScrollMode.FORWARD_ONLY);

    assertInsertCount( 100 );
    assertUpdateCount( 0 );
    clearCounts();

    while ( sr.next() ) {
      DataPoint dp = (DataPoint) sr.get(0);
      assertFalse( s.isReadOnly( dp ) );
      s.delete( dp );
    }
    t.commit();
    s.close();
View Full Code Here

       
    doc2 = (Document) ss.createQuery("from Document where text is not null").uniqueResult();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
   
    ScrollableResults sr = ss.createQuery("from Document where text is not null")
      .scroll(ScrollMode.FORWARD_ONLY);
    sr.next();
    doc2 = (Document) sr.get(0);
    sr.close();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
       
    doc2 = (Document) ss.createSQLQuery("select * from Document")
      .addEntity(Document.class)
      .uniqueResult();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
       
    doc2 = (Document) ss.createCriteria(Document.class).uniqueResult();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
   
    sr = ss.createCriteria(Document.class).scroll(ScrollMode.FORWARD_ONLY);
    sr.next();
    doc2 = (Document) sr.get(0);
    sr.close();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());

    tx = ss.beginTransaction();
    ss.delete(doc);
View Full Code Here

    s = openSession();
    t = s.beginTransaction();
    DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class,  dp.getId() );
    assertFalse( s.isReadOnly( dpLast ) );
    int i = 0;
    ScrollableResults sr = s.createQuery("from DataPoint dp order by dp.x asc")
        .setReadOnly(true)
        .scroll(ScrollMode.FORWARD_ONLY);
    int nExpectedChanges = 0;
    while ( sr.next() ) {
      dp = (DataPoint) sr.get(0);
      if ( dp.getId() == dpLast.getId() ) {
        //dpLast existed in the session before executing the read-only query
        assertFalse( s.isReadOnly( dp ) );
      }
      else {
View Full Code Here

    dpLast.setDescription( "oy" );
    int i = 0;

    assertUpdateCount( 0 );

    ScrollableResults sr = s.createQuery("from DataPoint dp order by dp.x asc")
        .setReadOnly(false)
        .scroll(ScrollMode.FORWARD_ONLY);
    int nExpectedChanges = 0;
    while ( sr.next() ) {
      dp = (DataPoint) sr.get(0);
      if ( dp.getId() == dpLast.getId() ) {
        //dpLast existed in the session before executing the read-only query
        assertTrue( s.isReadOnly( dp ) );
      }
      else {
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

    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    ScrollableResults sr = s.getNamedQuery("Item.nameDesc").scroll();
    assertTrue( sr.next() );
    i1 = (Item) sr.get(0);
    assertTrue( sr.next() );
    i2 = (Item) sr.get(0);
    assertTrue( Hibernate.isInitialized(i1) );
    assertTrue( Hibernate.isInitialized(i2) );
    assertEquals( i1.getName(), "foo" );
    assertEquals( i2.getName(), "bar" );
    assertFalse( sr.next() );
    s.delete(i1);
    s.delete(i2);
    t.commit();
    s.close();
    assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
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

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.