TODO: can the ExecutionManager.deleteChildExecution not be used?
489913
protected void deleteChildExecutions(ExecutionEntity parentExecution, boolean deleteExecution, CommandContext commandContext) {
    // Delete all child executions
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    Collection<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecution.getId());
    if (CollectionUtil.isNotEmpty(childExecutions)) {
      for (ExecutionEntity childExecution : childExecutions) {
        deleteChildExecutions(childExecution, true, commandContext);
      }
    }

    if (deleteExecution) {
      executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null, false);
    }
  }
150452
@Override
	public void listRemove(final T currentElement) throws FrameworkException {

		final T previousElement = listGetPrevious(currentElement);
		final T nextElement     = listGetNext(currentElement);

		if (currentElement != null) {

			if (previousElement != null) {
				unlinkNodes(getSiblingLinkType(), previousElement, currentElement);
			}

			if (nextElement != null) {
				unlinkNodes(getSiblingLinkType(), currentElement, nextElement);
			}
		}

		if (previousElement != null && nextElement != null) {

			Node previousNode = previousElement.getNode();
			Node nextNode     = nextElement.getNode();

			if (previousNode != null && nextNode != null) {

				linkNodes(getSiblingLinkType(), previousElement, nextElement);
			}

		}
	}
854319
@Override
   protected void leaving(NodeData node, int level) throws RepositoryException
   {
      try
      {
         if (exportChildVersionHistory && node.getPrimaryTypeName().equals(Constants.NT_VERSIONEDCHILD))
         {
            try
            {
               PropertyData childVersionHistory =
                  ((PropertyData)dataManager.getItemData(node, new QPathEntry(Constants.JCR_CHILDVERSIONHISTORY, 1),
                     ItemType.PROPERTY));
               String childVersionHistoryId =
                  getValueAsStringForExport(childVersionHistory.getValues().get(0), childVersionHistory.getType());

               //check does this child version history was already exported
               if (!exportedVersionHistories.contains(childVersionHistoryId))
               {

                  writer.writeStartElement(Constants.NS_SV_PREFIX, Constants.SV_VERSION_HISTORY, getSvNamespaceUri());
                  writer.writeAttribute(Constants.NS_SV_PREFIX, getSvNamespaceUri(), Constants.SV_NAME,
                     childVersionHistoryId);

                  NodeData versionStorage = (NodeData)dataManager.getItemData(Constants.VERSIONSTORAGE_UUID);
                  NodeData childVersionNodeData =
                     (NodeData)dataManager.getItemData(versionStorage, new QPathEntry("", childVersionHistoryId, 1),
                        ItemType.NODE);
                  childVersionNodeData.accept(this);

                  writer.writeEndElement();
                  exportedVersionHistories.add(childVersionHistoryId);
               }
            }
            catch (IOException e)
            {
               throw new RepositoryException("Can't export versioned child version history: " + e.getMessage(), e);
            }
         }

         writer.writeEndElement();
      }
      catch (XMLStreamException e)
      {
         throw new RepositoryException(e);
      }

   }
574575
@Override
  public CompletedExecutionInstruction executionComplete(
      JobExecutionContext context, JobExecutionException result) {

    if (result != null && result.refireImmediately()) {
      return CompletedExecutionInstruction.RE_EXECUTE_JOB;
    }

    if (result != null && result.unscheduleFiringTrigger()) {
      return CompletedExecutionInstruction.SET_TRIGGER_COMPLETE;
    }

    if (result != null && result.unscheduleAllTriggers()) {
      return CompletedExecutionInstruction.SET_ALL_JOB_TRIGGERS_COMPLETE;
    }

    if (!mayFireAgain()) {
      return CompletedExecutionInstruction.DELETE_TRIGGER;
    }

    return CompletedExecutionInstruction.NOOP;
  }
335382
private void _delActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__delActionPerformed
        int[] i = _oList.getSelectedRows();
        String[] o = new String[i.length];
        for (int j = 0; j < i.length; j++) {
            o[j] = (String) _oList.getValueAt(i[j], 0);
        }
        if (R != null) {
            try {
                R.rm(o);
            } catch (Rsession.RException ex) {
                ex.printStackTrace();
            }
        }
        update();
    }
228135
void handleRemove(SimpleTest test, Conjunction selector,
                    MatchTarget object, InternTable subExpr, OrdinalPosition parentId) throws MatchingException
  {
    if (tc.isEntryEnabled())
	    tc.entry(this,cclass, "handleRemove","test: "+test+ ",selector: "+selector+", object: "+object);
	    	
    if (test.getKind() == SimpleTest.ID)
      trueChild = trueChild.remove(selector, object, subExpr, ordinalPosition);
    else if (test.getKind() == SimpleTest.NOTID)
      falseChild = falseChild.remove(selector, object, subExpr, ordinalPosition);
    else
      throw new IllegalStateException();

    if (tc.isEntryEnabled())
	    tc.exit(this,cclass, "handleRemove");      
  }
840129
public void removeChild(HierarchicalFormModel child) {
		Assert.notNull(child, "child");
		child.removeParent();
		children.remove(child);
		child.removePropertyChangeListener(DIRTY_PROPERTY, childStateChangeHandler);
		child.removePropertyChangeListener(COMMITTABLE_PROPERTY, childStateChangeHandler);
		// when dynamically adding/removing childModels take care of
		// dirtymessages:
		// removing child that was dirty: remove from dirty map and update dirty
		// state
		if (dirtyValueAndFormModels.remove(child))
			dirtyUpdated();
	}
1046321
Observable<ComapiResult<MessagesQueryResponse>> processOrphanedEvents(ComapiResult<MessagesQueryResponse> result, final ChatController.OrphanedEventsToRemoveListener removeListener) {

        if (result.isSuccessful() && result.getResult() != null) {

            final MessagesQueryResponse response = result.getResult();

            final List<MessageReceived> messages = response.getMessages();
            final String[] ids = new String[messages.size()];

            if (!messages.isEmpty()) {
                for (int i = 0; i < messages.size(); i++) {
                    ids[i] = messages.get(i).getMessageId();
                }
            }

            return db.save(response.getOrphanedEvents())
                    .flatMap(count -> db.queryOrphanedEvents(ids))
                    .flatMap(toDelete -> Observable.create(emitter ->
                            storeFactory.execute(new StoreTransaction<ChatStore>() {

                                @Override
                                protected void execute(ChatStore store) {

                                    if (!toDelete.isEmpty()) {

                                        storeFactory.execute(new StoreTransaction<ChatStore>() {
                                            @Override
                                            protected void execute(ChatStore store) {

                                                List<ChatMessageStatus> statuses = modelAdapter.adaptEvents(toDelete);

                                                store.beginTransaction();

                                                if (!statuses.isEmpty()) {
                                                    for (ChatMessageStatus status : statuses) {
                                                        store.update(status);
                                                    }
                                                }

                                                String[] ids = new String[toDelete.size()];
                                                for (int i = 0; i < toDelete.size(); i++) {
                                                    ids[i] = toDelete.get(i).id();
                                                }
                                                removeListener.remove(ids);

                                                store.endTransaction();

                                                emitter.onNext(result);
                                                emitter.onCompleted();
                                            }
                                        });
                                    } else {
                                        emitter.onNext(result);
                                        emitter.onCompleted();
                                    }
                                }
                            }), Emitter.BackpressureMode.BUFFER));
        } else {
            return Observable.fromCallable(() -> result);
        }
    }
477355
public void leave(DelegateExecution execution) {

    boolean zeroNrOfInstances = false;
    if (resolveNrOfInstances(execution) == 0) {
      // Empty collection, just leave.
      zeroNrOfInstances = true;
      removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
      super.leave(execution); // Plan the default leave
      execution.setMultiInstanceRoot(false);
    }

    int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable());
    int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
    int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
    int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES) - 1;

    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution, null);
    callActivityEndListeners(execution);

    if (zeroNrOfInstances) {
      return;
    }

    DelegateExecution miRootExecution = getMultiInstanceRootExecution(execution);
    if (miRootExecution != null) { // will be null in case of empty collection
      setLoopVariable(miRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
      setLoopVariable(miRootExecution, NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);
    }

    //executeCompensationBoundaryEvents(execution.getCurrentFlowElement(), execution);

    logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);

    ExecutionEntity executionEntity = (ExecutionEntity) execution;

    if (executionEntity.getParent() != null) {

      executionEntity.inactivate();
      lockFirstParentScope(executionEntity);

      if (nrOfCompletedInstances >= nrOfInstances || completionConditionSatisfied(execution.getParent())) {

        ExecutionEntity executionToUse = null;
        if (nrOfInstances > 0) {
          executionToUse = executionEntity.getParent();
        } else {
          executionToUse = executionEntity;
        }

        boolean hasCompensation = false;
        Activity activity = (Activity) execution.getCurrentFlowElement();
        if (activity instanceof Transaction) {
          hasCompensation = true;
        } else if (activity instanceof SubProcess) {
          SubProcess subProcess = (SubProcess) activity;
          for (FlowElement subElement : subProcess.getFlowElements()) {
            if (subElement instanceof Activity) {
              Activity subActivity = (Activity) subElement;
              if (CollectionUtil.isNotEmpty(subActivity.getBoundaryEvents())) {
                for (BoundaryEvent boundaryEvent : subActivity.getBoundaryEvents()) {
                  if (CollectionUtil.isNotEmpty(boundaryEvent.getEventDefinitions()) &&
                      boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {

                    hasCompensation = true;
                    break;
                  }
                }
              }
            }
          }
        }

        if (hasCompensation) {
          ScopeUtil.createCopyOfSubProcessExecutionForCompensation(executionToUse);
        }

        if (activity instanceof CallActivity) {
          ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
          if (executionToUse != null) {
            List<String> callActivityExecutionIds = new ArrayList<String>();

            // Find all execution entities that are at the call activity
            List<ExecutionEntity> childExecutions = executionEntityManager.collectChildren(executionToUse);
            if (childExecutions != null) {
              for (ExecutionEntity childExecution : childExecutions) {
                if (activity.getId().equals(childExecution.getCurrentActivityId())) {
                  callActivityExecutionIds.add(childExecution.getId());
                }
              }

              // Now all call activity executions have been collected, loop again and check which should be removed
              for (int i=childExecutions.size()-1; i>=0; i--) {
                ExecutionEntity childExecution = childExecutions.get(i);
                if (StringUtils.isNotEmpty(childExecution.getSuperExecutionId())
                    && callActivityExecutionIds.contains(childExecution.getSuperExecutionId())) {

                  executionEntityManager.deleteProcessInstanceExecutionEntity(childExecution.getId(), activity.getId(),
                      "call activity completion condition met", true, false);
                }
              }

            }
          }
        }

        deleteChildExecutions(executionToUse, false, Context.getCommandContext());
        removeLocalLoopVariable(executionToUse, getCollectionElementIndexVariable());
        executionToUse.setScope(false);
        executionToUse.setMultiInstanceRoot(false);
        Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionToUse, true);
      }

    } else {
      removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
      execution.setMultiInstanceRoot(false);
      super.leave(execution);
    }
  }
137764
public void handleChildCompletion(CmmnActivityExecution execution, CmmnActivityExecution child) {
    fireForceUpdate(execution);

    if (execution.isActive()) {
      checkAndCompleteCaseExecution(execution);
    }
  }
1014590
public static <T extends MutableTreeNode<T>> void removeChild(T parent, T child) {
        checkArgNotNull(parent, "parent");
        int index = parent.getChildren().indexOf(child);
        checkElementIndex(index, parent.getChildren().size());
        parent.removeChild(index);
    }
880101
public void removeChildAt(int index) throws IndexOutOfBoundsException {
        Node<T> child = children.get(index);
        child.parent = null;
        children.remove(index);
    }
578100
public static Fix deleteExceptions(
      MethodTree tree, final VisitorState state, List<ExpressionTree> toDelete) {
    List<? extends ExpressionTree> trees = tree.getThrows();
    if (toDelete.size() == trees.size()) {
      return SuggestedFix.replace(
          getThrowsPosition(tree, state) - 1, state.getEndPosition(getLast(trees)), "");
    }
    String replacement =
        FluentIterable.from(tree.getThrows())
            .filter(Predicates.not(Predicates.in(toDelete)))
            .transform(
                new Function<ExpressionTree, String>() {
                  @Override
                  @Nullable
                  public String apply(ExpressionTree input) {
                    return state.getSourceForNode(input);
                  }
                })
            .join(Joiner.on(", "));
    return SuggestedFix.replace(
        ((JCTree) tree.getThrows().get(0)).getStartPosition(),
        state.getEndPosition(getLast(tree.getThrows())),
        replacement);
  }
127677
private void removeChildrenItems(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException, IllegalNameException,
      IllegalStateException, UnsupportedOperationException, InvalidItemStateException, RepositoryException
   {
      String parentId = resultSet.getString(DBConstants.COLUMN_ID);
      String selectStatement = "select * from " + iTable + " where I_CLASS = 1 and PARENT_ID = '" + parentId + "'";
      String deleteStatement = "delete from " + iTable + " where I_CLASS = 1 and PARENT_ID = '" + parentId + "'";

      // traversing down to the bottom of the tree
      PreparedStatement statement = conn.getJdbcConnection().prepareStatement(selectStatement);
      ResultSet selResult = statement.executeQuery();
      try
      {
         while (selResult.next())
         {
            removeChildrenItems(conn, selResult);
         }
      }
      finally
      {
         JDBCUtils.freeResources(selResult, statement, null);
      }
      
      // remove properties
      NodeData node = createNodeData(resultSet);
      for (PropertyData prop : conn.getChildPropertiesData(node))
      {
         conn.delete(prop, new SimpleChangedSizeHandler());
      }

      // remove nodes
      statement = conn.getJdbcConnection().prepareStatement(deleteStatement);
      try
      {
         statement.execute();
      }
      finally
      {
         JDBCUtils.freeResources(null, statement, null);
      }
   }
1036945
private void handleChildMethod(ExecutableElement methodElement) {
    String methodIdentifier = stitchMethodIdentifier(methodElement);
    MethodReferenceNode node = (MethodReferenceNode) elementReferenceMap.get(methodIdentifier);
    if (node == null) {
      node = new MethodReferenceNode(methodElement);
    }
    node.invoked = true;
    elementReferenceMap.put(methodIdentifier, node);
    addToOverrideMap(methodElement);
  }
561661
@Override
  protected void runChild(FrameworkMethod method, RunNotifier notifier) {

    Description description = describeChild(method);
    if (method.getAnnotation(Ignore.class) != null) {
      notifier.fireTestIgnored(description);
      return;
    }

    notifier.fireTestStarted(description);
    String testClassName = getTestClass().getJavaClass().getName();
    String testName = description.getDisplayName();

    try {
      Document result = mClient.runAtServer(mContainerUrl, testClassName, testName);
      mClient.processResults(result);
    } catch (Throwable e) {
      notifier.fireTestFailure(new Failure(description, e));
    } finally {
      notifier.fireTestFinished(description);
    }
  }
79893
public void setExecution(ExecutionEntity execution) {
    executionId = execution.getId();
    processInstanceId = execution.getProcessInstanceId();
    processDefinitionId = execution.getProcessDefinitionId();
  }