Package org.hibernate

Examples of org.hibernate.ScrollableResults


      ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor);
      TaskContextImpl taskContext = new TaskContextImpl();
      EntityManager emStream = emf.createEntityManager();
      try {
         EntityTransaction txStream = emStream.getTransaction();
         ScrollableResults results = null;
         txStream.begin();
         try {
            Session session = emStream.unwrap(Session.class);
            Criteria criteria = strategy.getCriteria(session).setReadOnly(true);
            if (setFetchSizeMinInteger) {
               criteria.setFetchSize(Integer.MIN_VALUE);
            }
            results = criteria.scroll(ScrollMode.FORWARD_ONLY);
            try {
               while (results.next()) {
                  if (taskContext.isStopped())
                     break;
                  Object result = results.get(0);
                  Object key = strategy.getKey(result);
                  if (filter != null && !filter.accept(key)) {
                     if (trace) log.trace("Key " + key + " filtered");
                     continue;
                  }
                  eacs.submit(strategy.getTask(task, taskContext, result, key));
               }
            } finally {
               if (results != null) results.close();
            }
            txStream.commit();
         } finally {
            if (txStream != null && txStream.isActive()) {
               txStream.rollback();
View Full Code Here


      }
      ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(threadPool);
      EntityManager emStream = emf.createEntityManager();
      try {
         EntityTransaction txStream = emStream.getTransaction();
         ScrollableResults metadataKeys = null;
         txStream.begin();
         try {
            long currentTime = timeService.wallClockTime();
            Session session = emStream.unwrap(Session.class);
            Criteria criteria = session.createCriteria(MetadataEntity.class).setReadOnly(true)
                  .add(Restrictions.le(MetadataEntity.EXPIRATION, currentTime)).setProjection(Projections.id());
            if (setFetchSizeMinInteger) {
               criteria.setFetchSize(Integer.MIN_VALUE);
            }

            metadataKeys = criteria.scroll(ScrollMode.FORWARD_ONLY);
            ArrayList<MetadataEntityKey> batch = new ArrayList<MetadataEntityKey>((int) configuration.batchSize());
            while (metadataKeys.next()) {
               MetadataEntityKey mKey = (MetadataEntityKey) metadataKeys.get(0);
               batch.add(mKey);
               if (batch.size() == configuration.batchSize()) {
                  purgeBatch(batch, listener, eacs, currentTime);
                  batch.clear();
               }
            }
            purgeBatch(batch, listener, eacs, currentTime);
            txStream.commit();
         } finally {
            if (metadataKeys != null) metadataKeys.close();
            if (txStream != null && txStream.isActive()) {
               txStream.rollback();
            }
         }
      } finally {
View Full Code Here

      return;
    }
    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

  public void testScrollOrderParentDesc() {
    try {
      insertTestData();
      Session s = openSession();
      ScrollableResults results = s.createQuery( QUERY + " order by p.name desc" ).scroll();
      List list = new ArrayList();
      while ( results.next() ) {
        list.add( results.get( 0 ) );
      }
      assertResultFromAllUsers( list );
      s.close();
    }
    finally {
View Full Code Here

  public void testScrollOrderParentAscChildrenAsc() {
    try {
      insertTestData();
      Session s = openSession();
      ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name asc" ).scroll();
      List list = new ArrayList();
      while ( results.next() ) {
        list.add( results.get( 0 ) );
      }
      assertResultFromAllUsers( list );
      s.close();
    }
    finally {
View Full Code Here

  public void testScrollOrderParentAscChildrenDesc() {
    try {
      insertTestData();
      Session s = openSession();
      ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name desc" ).scroll();
      List list = new ArrayList();
      while ( results.next() ) {
        list.add( results.get( 0 ) );
      }
      assertResultFromAllUsers( list );
      s.close();
    }
    finally {
View Full Code Here

      .createCriteria( indexedType )
      .setProjection( Projections.id() )
      .setCacheable( false )
      .setFetchSize( idFetchSize );

    ScrollableResults results = criteria.scroll( ScrollMode.FORWARD_ONLY );
    ArrayList<Serializable> destinationList = new ArrayList<Serializable>( batchSize );
    long counter = 0;
    try {
      while ( results.next() ) {
        Serializable id = (Serializable) results.get( 0 );
        destinationList.add( id );
        if ( destinationList.size() == batchSize ) {
          enqueueList( destinationList );
          destinationList = new ArrayList<Serializable>( batchSize );
        }
        counter++;
        if ( counter == totalCount ) {
          break;
        }
      }
    }
    finally {
      results.close();
    }
    enqueueList( destinationList );
  }
View Full Code Here

    assertTrue( "Incorrect result size", iter.hasNext() );
    obj = iter.next();
    assertTrue( "Incorrect return type", obj instanceof Map );
    assertEquals( "Incorrect return type", ( (Map) obj ).size(), 2 );

    ScrollableResults sr = session.createQuery( "select new map(an.description, an.bodyWeight) from Animal an" ).scroll();
    assertTrue( "Incorrect result size", sr.next() );
    obj = sr.get(0);
    assertTrue( "Incorrect return type", obj instanceof Map );
    assertEquals( "Incorrect return type", ( (Map) obj ).size(), 2 );
    sr.close();

    sr = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" ).scroll();
    assertTrue( "Incorrect result size", sr.next() );
    assertTrue( "Incorrect return type", sr.get(0) instanceof Animal );
    sr.close();

    // caching...
    QueryStatistics stats = getSessions().getStatistics().getQueryStatistics( "select new Animal(an.description, an.bodyWeight) from Animal an" );
    results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" )
        .setCacheable( true )
View Full Code Here

    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

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.