Package com.webobjects.eocontrol

Examples of com.webobjects.eocontrol.EOEditingContext


    Format wholeNumberFormatter = new DecimalFormat("#,##0");
   
    long startTime = System.currentTimeMillis();
   
    // Create an EC and lock/try/finally/unlock.
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      // Create the new TaskInfo
      TaskInfo taskInfo = ERXEOControlUtilities.createAndInsertObject(ec, TaskInfo.class);
     
      // Task start time
      taskInfo.setStartTime(new NSTimestamp(startTime));
     
      taskInfo.setStartNumber(_numberToCheck);
      taskInfo.setDuration(DURATION);
     
      // Loop for a period of time
      while (_elapsedTime < DURATION && !_isStopped) {
        ResultItem resultItem = ERXEOControlUtilities.createAndInsertObject(ec, ResultItem.class);
        resultItem.setTaskInfo(taskInfo);
       
        resultItem.setNumberToCheck(_numberToCheck);

        if (Utilities.isPrime(_numberToCheck)) {
          log.info("==>> " + _numberToCheck + " is a PRIME number.");
          resultItem.setIsPrime(Boolean.TRUE);
        } else {
          log.debug(_numberToCheck + " is not a prime number but is a COMPOSITE number.");
          resultItem.setIsPrime(Boolean.FALSE);
        }
       
        ec.saveChanges();
       
       
        _elapsedTime = System.currentTimeMillis() - startTime;
       
        // Update progress variables
        _count++;
        _percentComplete = (double)(_elapsedTime) / (double)DURATION;
        _status = wholeNumberFormatter.format(_count) + " numbers checked for prime qualification";

        _numberToCheck++;
      }
     
      // Complete the stats
      taskInfo.setEndNumber(_numberToCheck - 1);
      taskInfo.setEndTime(new NSTimestamp());
      taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PRIME_CHECKED);
     
      ec.saveChanges();
     
      _resultGid = ec.globalIDForObject(taskInfo);
     
    } finally {
      ec.unlock();
    }
   
    return _resultGid;
  }
View Full Code Here


       whether we are refreshing and on the snapshot's age and the fetchTimestamp of the EC doing the fetching.
      */   
    try {
       // Again with the object rape.  EODatabaseChannel.currentEditingContext() is private and the underlying instance variable
       // is protected.  We need the ec, so we do what we have to...
       EOEditingContext ec = (EOEditingContext) currentEditingContext.invoke(dbChannel, new Object[] {});
      
       // Get the snapshot if it has not expired.  cachedSnapshot will be null if it has expired
       // If not null, it should be the same as the existingSnapshot parameter
       NSDictionary cachedSnapshot = dbCtxt.database().snapshotForGlobalID(gid, ec.fetchTimestamp());
   
       // If we are refreshing or the snapshot in the cache has timed out, but the fetched row
       // matches the cached snapshot, reset the time stamp by recording the existing snapshot again.
       if (existingSnapshot.equals(fetchedRow) && (dbChannel.isRefreshingObjects() || cachedSnapshot == null)) {
         dbCtxt.database().recordSnapshotForGlobalID(existingSnapshot, gid);
View Full Code Here

    }

    @Override
    public WOComponent backAction() {
        if(_masterObject != null) {
            EOEditingContext ec = _masterObject.editingContext();
            ec.lock();
            try {
                _masterObject.takeValueForKey(singleSelection() ? selectedObjects().lastObject() : selectedObjects(), _relationshipKey);
                ec.saveChanges();
            } finally {
                ec.unlock();
            }
        }
        return super.backAction();
    }
View Full Code Here

    public static void receiveNotification(NSNotification n) {
        log.info("Received: " + n);
    }
   
    private void testIndexing() {
        EOEditingContext ec = ERXEC.newEditingContext();
        ec.lock();
        try {
            Tag tag = Tag.clazz.allObjects(ec).lastObject();
            Asset asset = Asset.clazz.allObjects(ec).lastObject();
            AssetGroup assetGroup = AssetGroup.clazz.allObjects(ec).lastObject();
            // new DataCreator().createDummyData();
            ERIndex eofStore = ERIndex.indexNamed("AssetInEOFStore");
            ERIndex fileStore = ERIndex.indexNamed("AssetInFileStore");
            EOQualifier tagQualifier = new EOKeyValueQualifier("tags.name", EOQualifier.QualifierOperatorEqual, tag.name());
            EOQualifier groupQualifier = new EOKeyValueQualifier("assetGroup.name", EOQualifier.QualifierOperatorEqual, tag.name());
            log.info("fileStore: " + fileStore.findGlobalIDs(tagQualifier).count());
            log.info("eofStore: " + eofStore.findGlobalIDs(tagQualifier).count());
            log.info("fileStore: " + fileStore.findGlobalIDs(groupQualifier).count());
            log.info("eofStore: " + eofStore.findGlobalIDs(groupQualifier).count());
           
            String newName = "cooltest";
            tagQualifier = new EOKeyValueQualifier("tags.name", com.webobjects.eocontrol.EOQualifier.QualifierOperatorEqual, newName);
            tag.setName(newName + " " + System.currentTimeMillis());
            ec.saveChanges();
           
            assetGroup.setName(newName + "  " + System.currentTimeMillis());
            ec.saveChanges();
            log.info("fileStore 1: " + fileStore.findGlobalIDs(tagQualifier).count());
            log.info("eofStore 1: " + eofStore.findGlobalIDs(tagQualifier).count());
            try {
                if(true) {
                    Thread.sleep(2000);
                }
                log.info("fileStore 2: " + fileStore.findGlobalIDs(tagQualifier).count());
                log.info("eofStore 2: " + eofStore.findGlobalIDs(tagQualifier).count());
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } finally {
            ec.unlock();
        }
    }
View Full Code Here

    public String selectionWidgetName() {
        return singleSelection() ? "WORadioButton" : "WOCheckBox";
    }
   
    public void setMasterObjectAndRelationshipKey(EOEnterpriseObject eo, String relationshipName) {
        EOEditingContext ec = ERXEC.newEditingContext(eo.editingContext(), false);
        setEditingContext(ec);
        _masterObject = EOUtilities.localInstanceOfObject(ec, eo);
        _relationshipKey = relationshipName;
        setObject(_masterObject);
        _singleSelection = _masterObject.classDescription().toManyRelationshipKeys().containsObject(_relationshipKey) ? Boolean.FALSE : Boolean.TRUE;
View Full Code Here

    _elapsedTime = 0;
    Format wholeNumberFormatter = new DecimalFormat("#,##0");
   
    long startTime = System.currentTimeMillis();
   
    EOEditingContext ec = newEditingContext();
    ec.lock();
    try {
      // Array for monitoring completed tasks to ensure normal completion
      NSMutableArray<Future<?>> childFutures = new NSMutableArray<Future<?>>();
      // Create the new TaskInfo
      TaskInfo taskInfo = ERXEOControlUtilities.createAndInsertObject(ec, TaskInfo.class);
     
      // Task start time
      taskInfo.setStartTime(new NSTimestamp(startTime));
     
      taskInfo.setStartNumber(_startNumber);
      taskInfo.setDuration(_taskDuration);
     
      ec.saveChanges();
      _resultGid = ec.globalIDForObject(taskInfo);
      _parentTaskPrimaryKey = (Integer) taskInfo.rawPrimaryKey();
     
      // Initialize loop variables
      long childTaskStartNumber = _startNumber;
      int incrementQuantity = _childBatchBaseQuantity + Utilities.sharedRandom().nextInt(_childBatchBaseQuantity);
      long childTaskEndNumber =  childTaskStartNumber + incrementQuantity;
     
     
      // Loop for a period of time
      while (_elapsedTime < _taskDuration && !_isStopped) {
        ChildPrimeTask childTask = new ChildPrimeTask(_nextChildIDValue, _resultGid, childTaskStartNumber, childTaskEndNumber);
        _nextChildIDValue++;
       
        boolean isRejected = true;
        while (isRejected && !ChildTaskPool.EXECUTOR_SERVICE.isShutdown() && !_isStopped) {
          try {
            Future<?> future = ChildTaskPool.EXECUTOR_SERVICE.submit(childTask);
           
            if (log.isInfoEnabled())
              log.info("Submitted task corresponding to " + future);
            isRejected = false;
            childFutures.add(future);
           
            // For the sake of demo, we assume all child tasks complete their work.
            _endNumber = childTaskEndNumber;
          } catch (RejectedExecutionException e) {
            try {
              Thread.sleep(2000);
              removeCompletedFutures(childFutures);
            } catch (InterruptedException e1) {
              stop();
            }
          }
        }
       
        childTaskStartNumber = childTaskEndNumber + 1;
        incrementQuantity = _childBatchBaseQuantity + Utilities.sharedRandom().nextInt(_childBatchBaseQuantity * 2);
        childTaskEndNumber =  childTaskStartNumber + incrementQuantity;

        _elapsedTime = System.currentTimeMillis() - startTime;
       
        // Update progress variables
        _percentComplete = (double)(_elapsedTime) / (double)_taskDuration;
        _status = wholeNumberFormatter.format(_count) + " numbers checked for prime qualification";

      }
     
      if (_isStopped) {
        _status = "Stopped";
      }
     
      // Wait for all child tasks to finish
      while (childFutures.count() > 0) {
        removeCompletedFutures(childFutures);
        Thread.sleep(1000);
      }
     
      // Complete the stats
      // Refresh it since the object has been already updated (its relationship) and saved on ChildThreads
      ERXEOControlUtilities.refreshObject(taskInfo);
      taskInfo.setEndNumber(_endNumber);
      taskInfo.setEndTime(new NSTimestamp());
      taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PRIME_CHECKED);
      ec.saveChanges();
     
      _resultGid = ec.globalIDForObject(taskInfo);
     
    } finally {
      ec.unlock();
    }
   
    return _resultGid;
  }
View Full Code Here

      return "Checking " + _childCurrentNumber + " in range " + _childFromNumber + " - " + _childToNumber;
    }

    @Override
    public void _run() {
      EOEditingContext ec = newEditingContext();
      ec.lock();
      try {
        log.info("Started child in " + Thread.currentThread().getName() + " with OSC " + ec.parentObjectStore());
       
        TaskInfo taskInfo = (TaskInfo) ec.faultForGlobalID(_childTaskInfoGID, ec);
       
        while (_childCurrentNumber <= _childToNumber) {
          ResultItem resultItem = ERXEOControlUtilities.createAndInsertObject(ec, ResultItem.class);
          resultItem.setTaskInfo(taskInfo);
         
          resultItem.setNumberToCheck(_childCurrentNumber);

          if (Utilities.isPrime(_childCurrentNumber)) {
            log.info("==>> " + _childCurrentNumber + " is a PRIME number.");
            resultItem.setIsPrime(Boolean.TRUE);
          } else {
            log.debug(_childCurrentNumber + " is not a prime number but is a COMPOSITE number.");
            resultItem.setIsPrime(Boolean.FALSE);
          }
         
          // We could save changes once per child task, but let's do this to keep EOF busy for the demo.
          ec.saveChanges();
         
          // Update our number to check
          _childCurrentNumber++;
         
          // Update parent task count statistic
          _count++;
        }
      } finally {
        ec.unlock();
      }
    }
View Full Code Here

    Format wholeNumberFormatter = new DecimalFormat("#,##0");
   
    long startTime = System.currentTimeMillis();
   
    // Create an EC and lock/try/finally/unlock.
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      //
      TaskInfo taskInfo = (TaskInfo)ERXEOGlobalIDUtilities.fetchObjectWithGlobalID(ec, taskGID);

      // Loop for a period of time
      while (_elapsedTime < DURATION && !_isStopped) {
        ResultItem resultItem = ERXEOControlUtilities.createAndInsertObject(taskInfo.editingContext(), ResultItem.class);
        resultItem.setTaskInfo(taskInfo);  

        resultItem.setNumberToCheck(_numberToCheck);

        if (Utilities.isPrime(_numberToCheck)) {
          log.info("==>> " + _numberToCheck + " is a PRIME number.");
          resultItem.setIsPrime(Boolean.TRUE);
        } else {
          log.debug(_numberToCheck + " is not a prime number but is a COMPOSITE number.");
          resultItem.setIsPrime(Boolean.FALSE);
        }
       
        ec.saveChanges();
       
        _elapsedTime = System.currentTimeMillis() - startTime;
       
        // Update progress variables
        _count++;
        _percentComplete = (double)(_elapsedTime) / (double)DURATION;
        _status = wholeNumberFormatter.format(_count) + " numbers checked for prime qualification";

        _numberToCheck++;
      }
     
      // Complete the stats
      taskInfo.setEndNumber(_numberToCheck - 1);
      taskInfo.setEndTime(new NSTimestamp());
      taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PRIME_CHECKED);
     
      ec.saveChanges();
     
      _resultGid = ec.globalIDForObject(taskInfo);
     
    } finally {
      ec.unlock();
    }
   
    return _resultGid;
  }
View Full Code Here

      erpi.setMasterObjectAndRelationshipKey(masterObject, relationshipKey);
      erpi.setNextPage(previousPageFromRequest());
    }

    protected void prepareListPage(D2WContext context, ListPageInterface lpi, String entityName) {
        EOEditingContext ec = session().defaultEditingContext();
        //ak: this check could be better...but anyway, as we edit, we should get a peer context
        if(lpi instanceof ERD2WEditableListPage) {
            ec = ERXEC.newEditingContext(session().defaultEditingContext().parentObjectStore());
        }
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
View Full Code Here

    }

    if (!_isStopped) {
      // We create an ec just for the sake of the constructor API on
      // T06EOFFactorialUpdateTask
      EOEditingContext ec = newEditingContext();
      ec.lock();
      try {
        TaskInfo taskInfo = (TaskInfo) ec.faultForGlobalID(_taskInfoGID, ec);
        _task2 = new T06EOFFactorialUpdateTask(taskInfo);
      } finally {
        ec.unlock();
      }
     
      // Sometimes it ise useful to share the parent OSC with a subtask to avoid data out of sync issues
      _task2.setParentObjectStore(parentObjectStore());
     
      // Here we show how the second task can be executed in yet another thread while this
      // thread waits for the result
     
     
      Future<EOGlobalID> future = ERXExecutorService.executorService().submit(_task2);
      // This next statement blocks until the task, running in another thread, is complete.
      _taskInfoGID = future.get();
     
      // Finally, overwrite the startTime and Duration to reflect this combo task
      // rather than the last task.
      ec = newEditingContext();
      ec.lock();
      try {
        TaskInfo taskInfo = (TaskInfo) ec.faultForGlobalID(_taskInfoGID, ec);
        taskInfo.setStartTime(new NSTimestamp(startTime));
        taskInfo.setDuration(Long.valueOf(taskInfo.endTime().getTime() - startTime));
        ec.saveChanges();
      } finally {
        ec.unlock();
      }
    }

    return _taskInfoGID;
  }
View Full Code Here

TOP

Related Classes of com.webobjects.eocontrol.EOEditingContext

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.