Examples of ERXFetchSpecificationBatchIterator


Examples of er.extensions.eof.ERXFetchSpecificationBatchIterator

     
      // For demo purposes we will use batches and EC recycling, which would be common for processing huge data sets
      ERXFetchSpecification<ResultItem> fs = taskInfo.fetchSpecificationForResultItems();
     
      // Batch iterator
      ERXFetchSpecificationBatchIterator fsIterator = new ERXFetchSpecificationBatchIterator(fs, ec);

      // Loop for a period of time
      while (fsIterator.hasNext() && !_isStopped) {
        @SuppressWarnings("unchecked")
        NSArray<ResultItem> batch = fsIterator.nextBatch();
       
        for (ResultItem resultItem : batch) {
          resultItem.setWorkflowState(ResultItem.WORKFLOW_CHECKING_FACTORIAL);
          performFactorialProcessing(resultItem);
          resultItem.setWorkflowState(ResultItem.WORKFLOW_PROCESSING_COMPLETE);

          ec.saveChanges();
         
         
          _elapsedTime = System.currentTimeMillis() - startTime;
         
          // Update progress variables
          _countCompleted++;
          _percentComplete = (double)(_countCompleted) / (double)_totalCount;
          _status = wholeNumberFormatter.format(_countCompleted) + " numbers checked for factorial proximity";
         
          if (_isStopped) {
            break;
          }

        }
       
        // Swap in a fresh EC for the next batch to help with memory management
        EOEditingContext freshEC = newEditingContext();
        ec.unlock();
        ec = freshEC;
        freshEC.lock();
       
        fsIterator.setEditingContext(ec);
       
        // We need to refault taskInfo into the new EC after swapping
        taskInfo = (TaskInfo) ec.faultForGlobalID(_taskInfoGID, ec);
       
      }
View Full Code Here

Examples of er.extensions.eof.ERXFetchSpecificationBatchIterator

            int treshhold = 10;
            EOEditingContext ec = ERXEC.newEditingContext();
            ec.lock();
            try {
                EOFetchSpecification fs = new EOFetchSpecification(entity.name(), null, null);
                ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator(fs);
                iterator.setEditingContext(ec);
                while(iterator.hasNextBatch()) {
                    NSArray objects = iterator.nextBatch();
                    if(iterator.currentBatchIndex() % treshhold == 0) {
                        ec.unlock();
                        // ec.dispose();
                        ec = ERXEC.newEditingContext();
                        ec.lock();
                        iterator.setEditingContext(ec);
                    }
                    for(Enumeration i = incides.objectEnumerator(); i.hasMoreElements(); ) {
                        ERIndex index = (ERIndex) i.nextElement();
                        index.addObjectsToIndex(ec, objects);
                    }
View Full Code Here

Examples of er.extensions.eof.ERXFetchSpecificationBatchIterator

            int treshhold = 10;
            EOEditingContext ec = ERXEC.newEditingContext();
            ec.lock();
            try {
                EOFetchSpecification fs = new EOFetchSpecification(entityName, null, null);
                ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator(fs);
                iterator.setEditingContext(ec);
                while (iterator.hasNextBatch()) {
                    NSArray objects = iterator.nextBatch();
                    if (iterator.currentBatchIndex() % treshhold == 0) {
                        ec.unlock();
                        // ec.dispose();
                        ec = ERXEC.newEditingContext();
                        ec.lock();
                        iterator.setEditingContext(ec);
                    }
                    NSArray<Document> documents = addedDocumentsForObjects(objects);
                    Transaction transaction = new Transaction(ec);
                    handler().addObjectsToIndex(transaction, objects);
                }
View Full Code Here

Examples of er.extensions.eof.ERXFetchSpecificationBatchIterator

    if (range == null) {
      objects = editingContext.objectsWithFetchSpecification(fetchSpec);
      results = new Results<T>(objects, 0, -1, objects.count());
    }
    else {
      ERXFetchSpecificationBatchIterator batchIterator = new ERXFetchSpecificationBatchIterator(fetchSpec, editingContext, range.length());
      objects = batchIterator.batchWithRange(range);
      results = new Results<T>(objects, range.location(), range.length(), batchIterator.count());
    }
    return results;
  }
View Full Code Here

Examples of er.extensions.eof.ERXFetchSpecificationBatchIterator

         * @return batch iterator for messages to be sent
         */
        public ERXFetchSpecificationBatchIterator batchIteratorForUnsentMessages() {
            EOFetchSpecification fetchSpec = EOFetchSpecification.fetchSpecificationNamed("messagesToBeSent",
                                                                                          "ERCMailMessage");
            return new ERXFetchSpecificationBatchIterator(fetchSpec);
        }
View Full Code Here

Examples of er.extensions.eof.ERXFetchSpecificationBatchIterator

     * messages.
     */
    public void processOutgoingMail() {
        if (log.isDebugEnabled())
            log.debug("Starting outgoing mail processing.");
        ERXFetchSpecificationBatchIterator iterator = ERCMailMessage.mailMessageClazz().batchIteratorForUnsentMessages();

        EOEditingContext ec = ERXEC.newEditingContext();
        iterator.setEditingContext(ec);
        ec.lock();
        try {
            iterator.batchCount();
        } finally {
            ec.unlock();
        }
        ec.dispose();
        while (iterator.hasNextBatch()) {
            EOEditingContext temp = ERXEC.newEditingContext();
            temp.lock();
            try {
                iterator.setEditingContext(temp);
                sendMailMessages(iterator.nextBatch());
            } finally {
                temp.unlock();
            }
            temp.dispose();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.