Package org.hibernate

Examples of org.hibernate.ScrollableResults


    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


    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

    rs = s.createQuery( "select new Foo(fo.x) from Foo fo" ).iterate();
    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.createQuery( "select foo.long, foo.component.name, foo, foo.foo from Foo foo" ).list();
    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.createQuery( "from java.lang.Object" ).list().size()==0 );
    txn.commit();
    s.close();
View Full Code Here

    try {
      final Query q = session.createQuery(hql);
      for (int i = 0; i < param.length; i++)
        q.setParameter(i, param[i]);
      q.setReadOnly(true);
      final ScrollableResults rs = q.setCacheMode(CacheMode.IGNORE).scroll(
        ScrollMode.FORWARD_ONLY);
      int count = 0;
      while (rs.next()) {
        final T obj = (T) rs.get(0);
        action.execute(obj);
        if (++count % 20 == 0) {
          // flush a batch of updates and release memory:
          session.flush();
          session.clear();
View Full Code Here

          } else {
            hhStreams.add(importGen);
          }
        }
        query.setBoolean("isImport", isImport);
        ScrollableResults hhData = query.scroll();
        try {
          if (!hhData.next()) {
            continue;
          }
          int i = 0;
          long datumStartDate = hhData.getDate(0).getTime();
          double datumValue = hhData.getBigDecimal(1).doubleValue();
          for (long end = getFrom().getDate().getTime(); end <= getTo()
              .getDate().getTime(); end = HhStartDate.getNext(cal,
              end)) {
            if (datumStartDate == end) {
              for (List<Double> hhStream : hhStreams) {
                hhStream.set(i, hhStream.get(i) + datumValue);
              }
              if (hhData.next()) {
                datumStartDate = hhData.getDate(0).getTime();
                datumValue = hhData.getBigDecimal(1)
                    .doubleValue();
              }
            }
            i++;
          }
        } finally {
          hhData.close();
        }
      }
    }
    return map;
  }
View Full Code Here

  public void httpPost(Invocation inv) throws HttpException {
    Hiber.setReadWrite();
    if (inv.hasParameter("ignore")) {
      Date ignoreDate = inv.getDate("ignore");

      ScrollableResults snags = Hiber
          .session()
          .createQuery(
              "from SiteSnag snag where snag.finishDate < :ignoreDate")
          .setTimestamp(
              "ignoreDate", ignoreDate).scroll(
              ScrollMode.FORWARD_ONLY);
      while (snags.next()) {
        SiteSnag snag = (SiteSnag) snags.get(0);
        snag.setIsIgnored(true);
        Hiber.session().flush();
        Hiber.session().clear();
      }
      Hiber.commit();
View Full Code Here

          query.setTimestamp("to", finishDate.getDate());
        }
        if (targetChannel != null) {
          query.setEntity("targetChannel", targetChannel);
        }
        ScrollableResults hhData = query.scroll();
        HhStartDate groupStart = null;
        if (hhData.next()) {
          groupStart = (HhStartDate) hhData.get(0);
          if (targetChannel == null) {
            throw new UserException("There is no channel for the "
                + (isImport ? "import" : "export") + " "
                + (isKwh ? "kWh" : "kVArh")
                + " HH datum starting " + groupStart.toString()
                + " to move to in the generation starting "
                + startDate + ", finishing " + finishDate + ".");
          }
          Query channelUpdate = Hiber
              .session()
              .createSQLQuery(
                  "update hh_datum set channel_id = :targetChannelId from channel, supply_generation where hh_datum.start_date >= :startDate and channel.id = hh_datum.channel_id and supply_generation.id = channel.supply_generation_id and channel.is_import = :isImport and channel.is_kwh = :isKwh and supply_generation.supply_id = :supplyId"
                      + (finishDate == null ? ""
                          : " and hh_datum.start_date <= :finishDate"))
              .setLong("supplyId", supply.getId())
              .setBoolean("isImport", isImport)
              .setBoolean("isKwh", isKwh)
              .setLong("targetChannelId", targetChannel.getId())
              .setTimestamp("startDate", startDate.getDate());
          if (finishDate != null) {
            channelUpdate.setTimestamp("finishDate",
                finishDate.getDate());
          }
          channelUpdate.executeUpdate();
          HhStartDate groupFinish = groupStart;
          HhStartDate estStart = null;
          HhStartDate estFinish = null;

          hhData.beforeFirst();
          while (hhData.next()) {
            HhStartDate hhStartDate = (HhStartDate) hhData.get(0);
            if (groupFinish.getNext().before(hhStartDate)) {
              targetChannel.deleteSnag(ChannelSnag.SNAG_MISSING,
                  groupStart, groupFinish);
              groupStart = groupFinish = hhStartDate;
            } else {
              groupFinish = hhStartDate;
            }
            if (((BigDecimal) hhData.get(1)).doubleValue() < 0) {
              targetChannel.addSnag(ChannelSnag.SNAG_NEGATIVE,
                  hhStartDate, hhStartDate);
            }
            if ((Character) hhData.get(2) != HhDatum.ACTUAL) {
              if (estStart == null) {
                estStart = hhStartDate;
              }
              estFinish = hhStartDate;
            }

            if (estStart != null && !hhStartDate.equals(estFinish)) {
              targetChannel.addSnag(ChannelSnag.SNAG_ESTIMATED,
                  estStart, estFinish);
              estStart = null;
            }
          }
          targetChannel.deleteSnag(ChannelSnag.SNAG_MISSING,
              groupStart, groupFinish);
          if (estStart != null) {
            targetChannel.addSnag(ChannelSnag.SNAG_ESTIMATED,
                estStart, estFinish);
          }
          hhData.close();
        }
      }
    }
    Hiber.flush();
    for (Mpan mpan : mpans) {
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.