Package org.hibernate

Examples of org.hibernate.ScrollableResults


    Query query = parser.parse( "equiptype:Cisco" );
    org.hibernate.search.FullTextQuery hibQuery = session.createFullTextQuery( query, Departments.class );

    hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.DOCUMENT );

    ScrollableResults projections = hibQuery.scroll();
    assertNotNull( projections );

    projections.beforeFirst();
    projections.next();
    Object[] projection = projections.get();

    assertTrue( "DOCUMENT incorrect", projection[0] instanceof Departments );
    assertEquals( "id incorrect", 1, ((Departments)projection[0]).getId() );
    assertTrue( "DOCUMENT incorrect", projection[1] instanceof Document );
    assertEquals( "DOCUMENT size incorrect", 8, ( (Document) projection[1] ).getFields().size() );
    assertNotNull( "equiptype is null", ( (Document) projection[1] ).getField("equiptype") );
    assertEquals( "equiptype incorrect", "Cisco", ( (Document) projection[1] ).getField("equiptype" ).stringValue() );
    assertNotNull( "branchnetwork is null", ( (Document) projection[1] ).getField("branchnetwork") );
    assertEquals( "branchnetwork incorrect", "Salt Lake City 1A", ( (Document) projection[1] ).getField("branchnetwork" ).stringValue() );

    projections.next();
    projection = projections.get();

    assertTrue( "DOCUMENT incorrect", projection[0] instanceof Departments );
    assertEquals( "id incorrect", 4, ((Departments)projection[0]).getId() );
    assertTrue( "DOCUMENT incorrect", projection[1] instanceof Document );
    assertEquals( "DOCUMENT size incorrect", 8, ( (Document) projection[1] ).getFields().size() );
    assertNotNull( "equiptype is null", ( (Document) projection[1] ).getField("equiptype") );
    assertEquals( "equiptype incorrect", "Cisco", ( (Document) projection[1] ).getField("equiptype" ).stringValue() );
    assertNotNull( "branchnetwork is null", ( (Document) projection[1] ).getField("branchnetwork") );
    assertEquals( "branchnetwork incorrect", "St. George 1D", ( (Document) projection[1] ).getField("branchnetwork" ).stringValue() );

    assertTrue("incorrect result count returned", projections.isLast());
    //cleanup
    for (Object element : s.createQuery( "from " + Departments.class.getName() ).list()) s.delete( element );
    tx.commit();
    s.close();
  }
View Full Code Here


    tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "title", new StopAnalyzer() );

    Query query = parser.parse( "summary:noword" );
    org.hibernate.Query hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
    ScrollableResults result = hibQuery.scroll();
    assertNotNull( result );
    assertEquals( -1, result.getRowNumber() );
    assertEquals( false, result.next() );
    result.close();

    query = parser.parse( "summary:Festina Or brand:Seiko" );
    hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
    result = hibQuery.scroll();
    assertEquals( -1, result.getRowNumber() );
    result.beforeFirst();
    assertEquals( true, result.next() );
    assertTrue( result.isFirst() );
    assertTrue( result.scroll( 1 ) );
    assertTrue( result.isLast() );
    assertFalse( result.scroll( 1 ) );
    result.beforeFirst();
    while ( result.next() ) {
      s.delete( result.get()[0] );
    }
    for (Object element : s.createQuery( "from java.lang.Object" ).list()) s.delete( element );
    tx.commit();
    s.close();
  }
View Full Code Here

    Query query = parser.parse( "dept:ITech" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );

    ScrollableResults projections = hibQuery.scroll();
    projections.beforeFirst();
    Object[] projection = projections.get();
    assertNull( projection );

    projections.next();
    assertTrue( projections.isFirst() );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
    s.close();
View Full Code Here

    Query query = parser.parse( "dept:ITech" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 6 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    results.next();
    Object[] result = results.get();
    assertEquals( "incorrect entityInfo returned", 1000, result[0] );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
View Full Code Here

    Query query = parser.parse( "dept:ITech" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 3 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    results.next();
    Object[] result = results.get();
    assertEquals( "incorrect entityInfo returned", 1000, result[0] );
    results.scroll( 2 );
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1003, result[0] );
    // check cache addition
    results.next();
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1004, result[0] );

    results.scroll( -2 );
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1002, result[0] );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
View Full Code Here

    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 3 );
    hibQuery.setFirstResult( 1 );
    hibQuery.setMaxResults( 3 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    results.next();
    Object[] result = results.get();
    assertEquals( "incorrect entityInfo returned", 1002, result[0] );

    results.scroll( 2 );
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1004, result[0] );

    results.next();
    result = results.get();
    assertNull( result );

    results.scroll( -8 );
    result = results.get();
    assertNull( result );

    // And test a bad forward scroll.
    results.scroll( 10 );
    result = results.get();
    assertNull( result );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
View Full Code Here

    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 3 );
    hibQuery.setFirstResult( 1 );
    hibQuery.setMaxResults( 3 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    Object[] result = results.get();
    assertNull( "non-null entity infos returned", result );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
View Full Code Here

    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );



    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    results.next();
    assertTrue("beforeFirst() pointer incorrect", results.isFirst());

    results.afterLast();
    results.previous();
    assertTrue("afterLast() pointer incorrect", results.isLast());

    // Let's see if a bad reverse scroll screws things up
    results.scroll( -8 );
    results.next();
    assertTrue("large negative scroll() pointer incorrect", results.isFirst());

    // And test a bad forward scroll.
    results.scroll( 10 );
    results.previous();
    assertTrue("large positive scroll() pointer incorrect", results.isLast());

    // Finally, let's test a REAL screwup.
    hibQuery.setFirstResult( 3 );
    hibQuery.setMaxResults( 1 );

    results = hibQuery.scroll();
    results.first();
    Object[] result = results.get();
    assertEquals(1004, result[0]);

    results.last();
    result = results.get();
    assertEquals(1004, result[0]);

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
View Full Code Here

    assertNotNull( it.next() );
    assertFalse( it.hasNext() );

    query = parser.parse( "summary:Festina" );
    hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
    ScrollableResults sr = hibQuery.scroll();
    assertTrue( sr.first() );
    assertNotNull( sr.get() );
    assertFalse( sr.next() );
    sr.close();

    query = parser.parse( "summary:Festina OR brand:seiko" );
    hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
    hibQuery.setMaxResults( 2 );
    result = hibQuery.list();
View Full Code Here

    QueryParser parser = new QueryParser( "dept", new StandardAnalyzer() );

    Query query = parser.parse( "dept:XXX" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );

    ScrollableResults projections = hibQuery.scroll();
    projections.beforeFirst();
    projections.next();
    Object[] projection = projections.get();
    assertNull( projection );

    hibQuery = s.createFullTextQuery( query, Employee.class ).setFirstResult( 10 ).setMaxResults( 20 );

    projections = hibQuery.scroll();
    projections.beforeFirst();
    projections.next();
    projection = projections.get();
    assertNull( projection );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
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.