public <T> T execute(Context context, Command<T> command) {

    ExecutionResultImpl results = null;
    if (context != null) {
      results = (ExecutionResultImpl) ((KnowledgeCommandContext) context).getExecutionResults();
    }

    if (results == null) {
      results = new ExecutionResultImpl();
    }

    if (!(command instanceof BatchExecutionCommandImpl)) {
      return (T)
          ((GenericCommand) command)
              .execute(new FixedKnowledgeCommandContext(context, null, this.kbase, this, results));
    }

    try {
      session.startBatchExecution(results);
      ((GenericCommand) command)
          .execute(new FixedKnowledgeCommandContext(context, null, this.kbase, this, results));
      ExecutionResults result = session.getExecutionResult();
      return (T) result;
    } finally {
      session.endBatchExecution();
    }
  }