Package org.hibernate

Examples of org.hibernate.ScrollableResults


        if (i.intValue() >= 0)
        {
          pstmt.setTimeout(i.intValue());
        }
      }
      final ScrollableResults res = pstmt.scroll(ScrollMode.FORWARD_ONLY);
      return generateDefaultTableModel(res, pstmt.getReturnAliases());
    }
    catch (Exception e)
    {
      throw new ReportDataFactoryException("Failed at query: " + query, e);
View Full Code Here


    }

    public int getRowCountByExample(User exampleUser, String... ignoreProperty) {

        Criteria crit = prepareExampleCriteria(exampleUser, null, false, ignoreProperty);
        ScrollableResults cursor = crit.scroll();
        cursor.last();
        int count = cursor.getRowNumber() + 1;
        cursor.close();
        return count;
    }
View Full Code Here

            String query = "select o from " + entityClass.getName() + " o fetch all properties";
            if (WikiNode.class.isAssignableFrom(entityClass)) {
                // If it's a WikiNode, fetch the associated User instances, avoiding N+1 selects
                query = "select o from " + entityClass.getName() + " o inner join fetch o.createdBy left join fetch o.lastModifiedBy fetch all properties";
            }
            ScrollableResults cursor = ftSession.createQuery(query).scroll();

            cursor.last();
            int count = cursor.getRowNumber() + 1;
            log.debug("total documents in database: " + count);

            if (count > 0) {
                cursor.first(); // Reset to first result row
                int i = 0;
                while (true) {
                    i++;
                    Object o = cursor.get(0);
                    log.debug("indexing instance " + i + ": " + o);
                    ftSession.index(o);
                    if (i % batchSize == 0) {
                        log.debug("ending batch, beginning new batch");
                        ftSession.clear(); // Clear persistence context for each batch
                    }
                    progress.setPercentComplete( new Double(100d/count*i).intValue() );
                    log.debug(progress);

                    if (cursor.isLast())
                        break;
                    else
                        cursor.next();
                }
            }
            cursor.close();
            //userTx.commit();

            progress.setStatus(Progress.COMPLETE);
            log.debug("indexing complete of entity class: " + entityClass);

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

    crit.addOrder(Order.asc("reihenfolge"));
    crit.createCriteria("prozess", "proz");
    crit.add(Restrictions.eq("proz.istTemplate", Boolean.FALSE));
    crit.add(Restrictions.eq("proz.projekt", inProject));

    ScrollableResults list = crit.setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);

    while (list.next()) {
      Schritt step = (Schritt) list.get(0);
      String shorttitle = (step.getTitel().length() > 60 ? step.getTitel().substring(0, 60) + "..." : step.getTitel());

      IProjectTask pt = null;
      for (IProjectTask task : myTaskList) {
        if (task.getTitle().equals(shorttitle)) {
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

   @Override
   public void clear() {
      EntityManager emStream = emf.createEntityManager();
      try {
         ScrollableResults results = null;
         ArrayList<Object> batch = new ArrayList<Object>((int) configuration.batchSize());
         EntityTransaction txStream = emStream.getTransaction();
         txStream.begin();
         try {
            log.trace("Clearing JPA Store");
            Session session = emStream.unwrap(Session.class);
            Criteria criteria = session.createCriteria(configuration.entityClass()).setReadOnly(true)
                  .setProjection(Projections.id());
            if (setFetchSizeMinInteger) {
               criteria.setFetchSize(Integer.MIN_VALUE);
            }
            results = criteria.scroll(ScrollMode.FORWARD_ONLY);

            while (results.next()) {
               Object o = results.get(0);
               batch.add(o);
               if (batch.size() == configuration.batchSize()) {
                  session.clear();
                  removeBatch(batch);
               }
            }
            if (configuration.storeMetadata()) {
               /* We have to close the stream before executing further request */
               results.close();
               results = null;
               String metadataTable = emStream.getMetamodel().entity(MetadataEntity.class).getName();
               Query clearMetadata = emStream.createQuery("DELETE FROM " + metadataTable);
               clearMetadata.executeUpdate();
            }
            txStream.commit();
         } finally {
            removeBatch(batch);
            if (results != null) {
               results.close();
            }
            if (txStream != null && txStream.isActive()) {
               txStream.rollback();
            }
         }
View Full Code Here

      ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor);
      final TaskContextImpl taskContext = new TaskContextImpl();
      EntityManager emStream = emf.createEntityManager();
      try {
         EntityTransaction txStream = emStream.getTransaction();
         ScrollableResults keys = null;
         txStream.begin();
         try {
            Session session = emStream.unwrap(Session.class);
            Criteria criteria = session.createCriteria(configuration.entityClass()).setReadOnly(true)
                  .setProjection(Projections.id());
            if (setFetchSizeMinInteger) {
               criteria.setFetchSize(Integer.MIN_VALUE);
            }

            keys = criteria.scroll(ScrollMode.FORWARD_ONLY);
            while (keys.next()) {
               if (taskContext.isStopped())
                  break;
               final Object key = keys.get(0);
               if (filter != null && !filter.accept(key)) {
                  if (trace) log.trace("Key " + key + " filtered");
                  continue;
               }

               Object tempEntity = null;
               InternalMetadata tempMetadata = null;
               boolean loaded = false;

               /* We need second entity manager because with MySQL we can't do streaming in parallel with other queries
                  using single connection */
               EntityManager emExec = emf.createEntityManager();
               try {
                  EntityTransaction txExec = emExec.getTransaction();
                  txExec.begin();
                  try {
                     do {
                        try {
                           tempEntity = fetchValue ? findEntity(emExec, key) : null;
                           tempMetadata = fetchMetadata ? getMetadata(emExec, key) : null;
                        } finally {
                           try {
                              txExec.commit();
                              loaded = true;
                           } catch (Exception e) {
                              log.trace("Failed to load once", e);
                           }
                        }
                     } while (!loaded);
                  } finally {
                     if (txExec != null && txExec.isActive()) {
                        txExec.rollback();
                     }

                  }
               } finally {
                  if (emExec != null) {
                     emExec.close();
                  }
               }
               final Object entity = tempEntity;
               final InternalMetadata metadata = tempMetadata;
               if (trace) log.trace("Processing " + key + " -> " + entity + "(" + metadata + ")");

               if (metadata != null && metadata.isExpired(timeService.wallClockTime())) continue;
               eacs.submit(new Callable<Void>() {
                  @Override
                  public Void call() throws Exception {
                     try {
                        final MarshalledEntry marshalledEntry = marshallerEntryFactory.newMarshalledEntry(key, entity, metadata);
                        if (marshalledEntry != null) {
                           task.processEntry(marshalledEntry, taskContext);
                        }
                        return null;
                     } catch (Exception e) {
                        log.errorExecutingParallelStoreTask(e);
                        throw e;
                     }
                  }
               });
            }
            txStream.commit();
         } finally {
            if (keys != null) keys.close();
            if (txStream != null && txStream.isActive()) {
               txStream.rollback();
            }
         }
      } finally {
View Full Code Here

   public void purge(Executor threadPool, final PurgeListener listener) {
      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

   @Override
   public void clear() {
      EntityManager emStream = emf.createEntityManager();
      try {
         ScrollableResults results = null;
         ArrayList<Object> batch = new ArrayList<Object>((int) configuration.batchSize());
         EntityTransaction txStream = emStream.getTransaction();
         txStream.begin();
         try {
            log.trace("Clearing JPA Store");
            Session session = emStream.unwrap(Session.class);
            Criteria criteria = session.createCriteria(configuration.entityClass()).setReadOnly(true)
                  .setProjection(Projections.id());
            if (setFetchSizeMinInteger) {
               criteria.setFetchSize(Integer.MIN_VALUE);
            }
            results = criteria.scroll(ScrollMode.FORWARD_ONLY);

            while (results.next()) {
               Object o = results.get(0);
               batch.add(o);
               if (batch.size() == configuration.batchSize()) {
                  session.clear();
                  removeBatch(batch);
               }
            }
            if (configuration.storeMetadata()) {
               /* We have to close the stream before executing further request */
               results.close();
               results = null;
               String metadataTable = emStream.getMetamodel().entity(MetadataEntity.class).getName();
               Query clearMetadata = emStream.createQuery("DELETE FROM " + metadataTable);
               clearMetadata.executeUpdate();
            }
            txStream.commit();
         } finally {
            removeBatch(batch);
            if (results != null) {
               results.close();
            }
            if (txStream != null && txStream.isActive()) {
               txStream.rollback();
            }
         }
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.