Esempio n. 1
0
  /* (non-Javadoc)
   * @see org.fireflow.engine.IProcessInstance#setProcessInstanceVariable(java.lang.String, java.lang.Object)
   */
  public void setProcessInstanceVariable(String name, Object value) {
    IPersistenceService persistenceService = this.rtCtx.getPersistenceService();
    if (processInstanceVariables == null) {
      // 通过数据库查询进行初始化
      List<ProcessInstanceVar> allVars =
          persistenceService.findProcessInstanceVariable(this.getId());
      processInstanceVariables = new HashMap<String, Object>();
      if (allVars != null && allVars.size() != 0) {
        for (ProcessInstanceVar theVar : allVars) {
          processInstanceVariables.put(theVar.getVarPrimaryKey().getName(), theVar.getValue());
        }
      }
    }
    ProcessInstanceVar procInstVar = new ProcessInstanceVar();
    ProcessInstanceVarPk pk = new ProcessInstanceVarPk();
    pk.setProcessInstanceId(this.getId());
    pk.setName(name);
    procInstVar.setVarPrimaryKey(pk);
    procInstVar.setValue(value);
    procInstVar.setValueType(value.getClass().getName());

    if (processInstanceVariables.containsKey(name)) {
      persistenceService.updateProcessInstanceVariable(procInstVar);
    } else {
      persistenceService.saveProcessInstanceVariable(procInstVar);
    }
    processInstanceVariables.put(name, value);
  }
Esempio n. 2
0
 /* (non-Javadoc)
  * @see org.fireflow.engine.IProcessInstance#abort()
  */
 public void abort() throws EngineException {
   if (this.state.intValue() == IProcessInstance.COMPLETED
       || this.state.intValue() == IProcessInstance.CANCELED) {
     throw new EngineException(
         this,
         this.getWorkflowProcess(),
         "The process instance can not be aborted,the state of this process instance is "
             + this.getState());
   }
   IPersistenceService persistenceService = rtCtx.getPersistenceService();
   persistenceService.abortProcessInstance(this);
 }
Esempio n. 3
0
 /* (non-Javadoc)
  * @see org.fireflow.engine.IProcessInstance#suspend()
  */
 public void suspend() throws EngineException {
   if (this.state == IProcessInstance.COMPLETED || this.state == IProcessInstance.CANCELED) {
     throw new EngineException(
         this,
         this.getWorkflowProcess(),
         "The process instance can not be suspended,the state of this process instance is "
             + this.state);
   }
   if (this.isSuspended()) {
     return;
   }
   IPersistenceService persistenceService = this.rtCtx.getPersistenceService();
   persistenceService.suspendProcessInstance(this);
 }
Esempio n. 4
0
 /* (non-Javadoc)
  * @see org.fireflow.engine.IProcessInstance#getProcessInstanceVariable(java.lang.String)
  */
 public Object getProcessInstanceVariable(String name) {
   IPersistenceService persistenceService = this.rtCtx.getPersistenceService();
   if (processInstanceVariables == null) {
     // 通过数据库查询进行初始化
     List<ProcessInstanceVar> allVars =
         persistenceService.findProcessInstanceVariable(this.getId());
     processInstanceVariables = new HashMap<String, Object>();
     if (allVars != null && allVars.size() != 0) {
       for (ProcessInstanceVar theVar : allVars) {
         processInstanceVariables.put(theVar.getVarPrimaryKey().getName(), theVar.getValue());
       }
     }
   }
   return processInstanceVariables.get(name);
 }
Esempio n. 5
0
  /**
   * 生成joinPoint
   *
   * @param synchInst
   * @param token
   * @return
   * @throws EngineException
   */
  public IJoinPoint createJoinPoint(ISynchronizerInstance synchInst, IToken token)
      throws EngineException {

    int enterTransInstanceCount = synchInst.getEnteringTransitionInstances().size();
    if (enterTransInstanceCount == 0) { // 检查流程定义是否合法,同步器节点必须有输入边

      throw new EngineException(
          this.getId(),
          this.getWorkflowProcess(),
          synchInst.getSynchronizer().getId(),
          "The process definition ["
              + this.getName()
              + "] is invalid,the synchronizer["
              + synchInst.getSynchronizer()
              + "] has no entering transition");
    }
    IPersistenceService persistenceService = rtCtx.getPersistenceService();
    // 保存到数据库
    persistenceService.saveOrUpdateToken(token);

    IJoinPoint resultJoinPoint = null;
    resultJoinPoint = new JoinPoint();
    resultJoinPoint.setProcessInstance(this);
    resultJoinPoint.setSynchronizerId(synchInst.getSynchronizer().getId());
    if (enterTransInstanceCount == 1) {
      // 生成一个不存储到数据库中的JoinPoint
      resultJoinPoint.addValue(token.getValue());

      if (token.isAlive()) {
        resultJoinPoint.setAlive(true);
        resultJoinPoint.setFromActivityId(token.getFromActivityId());
      }
      resultJoinPoint.setStepNumber(token.getStepNumber() + 1);

      return resultJoinPoint;
    } else {

      int stepNumber = 0;

      List<IToken> tokensList_0 =
          persistenceService.findTokensForProcessInstance(
              this.getId(), synchInst.getSynchronizer().getId());
      Map<String, IToken> tokensMap = new HashMap<String, IToken>();
      for (int i = 0; i < tokensList_0.size(); i++) {
        IToken tmpToken = tokensList_0.get(i);
        String tmpFromActivityId = tmpToken.getFromActivityId();
        if (!tokensMap.containsKey(tmpFromActivityId)) {
          tokensMap.put(tmpFromActivityId, tmpToken);
        } else {
          // TODO  ====下面的代码有意义吗?===start===wmj2003
          IToken tmpToken2 = tokensMap.get(tmpFromActivityId);
          if (tmpToken2.getStepNumber() > tmpToken.getStepNumber()) {
            tokensMap.put(tmpFromActivityId, tmpToken2);
          }
          // TODO  ====下面的代码有意义吗?===end===wmj2003
        }
      }

      List<IToken> tokensList = new ArrayList<IToken>(tokensMap.values());

      for (int i = 0; i < tokensList.size(); i++) {
        IToken _token = tokensList.get(i);
        resultJoinPoint.addValue(_token.getValue());
        if (_token.isAlive()) { // 如果token的状态是alive
          resultJoinPoint.setAlive(true);
          String oldFromActivityId = resultJoinPoint.getFromActivityId();
          if (oldFromActivityId == null || oldFromActivityId.trim().equals("")) {
            resultJoinPoint.setFromActivityId(_token.getFromActivityId());
          } else {
            resultJoinPoint.setFromActivityId(
                oldFromActivityId + IToken.FROM_ACTIVITY_ID_SEPARATOR + _token.getFromActivityId());
          }
        }
        if (token.getStepNumber() > stepNumber) {
          stepNumber = token.getStepNumber();
        }
      }

      resultJoinPoint.setStepNumber(stepNumber + 1);

      return resultJoinPoint;
    }
  }