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


    data.prepare();

    Session s = openSession();
    Transaction txn = s.beginTransaction();

    ScrollableResults results = s
            .createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
            .setString( "desc", "root%" )
        .scroll( ScrollMode.FORWARD_ONLY );

    int counter = 0;
    while ( results.next() ) {
      counter++;
      Animal animal = ( Animal ) results.get( 0 );
      checkResult( animal );
    }
    assertEquals( "unexpected result count", 2, counter );

    txn.commit();
View Full Code Here

    data.prepare();

    Session s = openSession();
    Transaction txn = s.beginTransaction();

    ScrollableResults results = s
            .createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
            .setString( "desc", "root%" )
            .scroll();

    results.afterLast();

    int counter = 0;
    while ( results.previous() ) {
      counter++;
      Animal animal = ( Animal ) results.get( 0 );
      checkResult( animal );
    }
    assertEquals( "unexpected result count", 2, counter );

    txn.commit();
View Full Code Here

    data.prepare();

    Session s = openSession();
    Transaction txn = s.beginTransaction();

    ScrollableResults results = s
            .createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
            .setString( "desc", "root%" )
            .scroll();

    results.first();
    Animal animal = ( Animal ) results.get( 0 );
    assertEquals( "first() did not return expected row", data.root1Id, animal.getId() );

    results.scroll( 1 );
    animal = ( Animal ) results.get( 0 );
    assertEquals( "scroll(1) did not return expected row", data.root2Id, animal.getId() );

    results.scroll( -1 );
    animal = ( Animal ) results.get( 0 );
    assertEquals( "scroll(-1) did not return expected row", data.root1Id, animal.getId() );

    results.setRowNumber( 1 );
    animal = ( Animal ) results.get( 0 );
    assertEquals( "setRowNumber(1) did not return expected row", data.root1Id, animal.getId() );

    results.setRowNumber( 2 );
    animal = ( Animal ) results.get( 0 );
    assertEquals( "setRowNumber(2) did not return expected row", data.root2Id, animal.getId() );

    txn.commit();
    s.close();
View Full Code Here

            .createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
            .setString( "desc", "root%" )
            .list()
        .isEmpty() );

    ScrollableResults results = s
            .createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
            .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

    assertNotNull(s
            .createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
            .setString( "desc", "root%" )
            .uniqueResult() );

    ScrollableResults results = s
            .createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
            .setString( "desc", "root%" )
            .scroll();

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

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

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

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

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

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

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

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

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

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

    assertTrue( results.first() );
    assertTrue( results.isFirst() );
    assertTrue( results.isLast() );   

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

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

      assertTrue( results.setRowNumber( 1 ) );
      assertTrue( results.isFirst() );
      assertTrue( results.isLast() );

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

      if ( i != 1 ) {
        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

    rs = s.iterate("select new Foo(fo.x) from Foo fo");
    assertTrue( "projection iterate (results)", rs.hasNext() );
    assertTrue( "projection iterate (return check)", Foo.class.isAssignableFrom( rs.next().getClass() ) );

    ScrollableResults sr = s.createQuery("select new Foo(fo.x) from Foo fo").scroll();
    assertTrue( "projection scroll (results)", sr.next() );
    assertTrue( "projection scroll (return check)", Foo.class.isAssignableFrom( sr.get(0).getClass() ) );

    list = s.find("select foo.long, foo.component.name, foo, foo.foo from Foo foo");
    rs = list.iterator();
    int count=0;
    while ( rs.hasNext() ) {
View Full Code Here

      s.save( new Foo() );
      s.save( new Foo() );
      s.save( new Bar() );
      Query query = s.createQuery("select f, f.integer from Foo f");
      assertTrue( query.getReturnTypes().length==2 );
      ScrollableResults iter = query.scroll();
      assertTrue( iter.next() );
      assertTrue( iter.scroll(1) );
      FooProxy f2 = (FooProxy) iter.get()[0];
      assertTrue( f2!=null );
      assertTrue( iter.scroll(-1) );
      Object f1 = iter.get(0);
      iter.next();
      assertTrue( f1!=null && iter.get(0)==f2 );
      iter.getInteger(1);

      assertTrue( !iter.scroll(100) );
      assertTrue( iter.first() );
      assertTrue( iter.scroll(3) );
      Object f4 = iter.get(0);
      assertTrue( f4!=null );
      assertTrue( !iter.next() );
      assertTrue( iter.first() );
      assertTrue( iter.get(0)==f1 );
      assertTrue( iter.last() );
      assertTrue( iter.get(0)==f4 );
      assertTrue( iter.previous() );
      txn.commit();
      s.close();

      s = openSession();
      txn = s.beginTransaction();
      query = s.createQuery("select f, f.integer from Foo f");
      assertTrue( query.getReturnTypes().length==2 );
      iter = query.scroll();
      assertTrue( iter.next() );
      assertTrue( iter.scroll(1) );
      f2 = (FooProxy) iter.get()[0];
      assertTrue( f2!=null );
      assertTrue( f2.getString()!=null  && f2.getComponent().getImportantDates().length > 0 );
      assertTrue( iter.scroll(-1) );
      f1 = iter.get(0);
      iter.next();
      assertTrue( f1!=null && iter.get(0)==f2 );
      iter.getInteger(1);

      assertTrue( !iter.scroll(100) );
      assertTrue( iter.first() );
      assertTrue( iter.scroll(3) );
      f4 = iter.get(0);
      assertTrue( f4!=null );
      assertTrue( !iter.next() );
      assertTrue( iter.first() );
      assertTrue( iter.get(0)==f1 );
      assertTrue( iter.last() );
      assertTrue( iter.get(0)==f4 );
      assertTrue( iter.previous() );
      assertTrue( s.delete("from Foo")==4 );
      s.flush();
      assertTrue( s.find("from java.lang.Object").size()==0 );
      txn.commit();
      s.close();
View Full Code Here

  public void testScroll() {
    try {
      insertTestData();
      Session s = openSession();
      ScrollableResults results = s.createQuery( QUERY ).scroll();
      List list = new ArrayList();
      while ( results.next() ) {
        list.add( results.get( 0 ) );
      }
      assertResultFromAllUsers( list );
      s.close();
    }
    finally {
View Full Code Here

  public void testScrollOrderParentAsc() {
    try {
      insertTestData();
      Session s = openSession();
      ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
      List list = new ArrayList();
      while ( results.next() ) {
        list.add( results.get( 0 ) );
      }
      assertResultFromAllUsers( list );
      s.close();
    }
    finally {
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.