Example #1
0
 public IResultIterator getSecondaryIterator(ScriptContext context, String subQueryName)
     throws DataException {
   try {
     Scriptable scope = null;
     if (context != null)
       scope =
           ((IDataScriptEngine) context.getScriptEngine(IDataScriptEngine.ENGINE_NAME))
               .getJSScope(context);
     return this.getSecondaryIterator(subQueryName, scope);
   } catch (BirtException e) {
     throw DataException.wrap(e);
   }
 }
Example #2
0
  /**
   * Evaluate the given value
   *
   * @param value
   * @param n
   * @return
   * @throws DataException
   */
  public boolean evaluate(ScriptContext cx, Scriptable scope, DataSetRuntime dataSet)
      throws DataException {
    if (filterPassController.getForceReset()) {
      doReset();
      filterPassController.setForceReset(false);
    }

    if (N == -1) {
      // Create a new evaluator
      // Evaluate N (which is operand1) at this time
      Object n_object = null;
      try {
        n_object = ExprEvaluateUtil.evaluateRawExpression2(n_expr, scope, cx, dataSet);
      } catch (BirtException e1) {
        throw DataException.wrap(e1);
      }

      double n_value = -1;
      try {
        n_value = DataTypeUtil.toDouble(n_object).doubleValue();
      } catch (BirtException e) {
        // conversion error
        throw new DataException(ResourceConstants.INVALID_TOP_BOTTOM_ARGUMENT, e);
      }

      // First time; calculate N based on updated row count
      if (n_percent) {
        if (n_value < 0 || n_value > 100)
          throw new DataException(ResourceConstants.INVALID_TOP_BOTTOM_PERCENT_ARGUMENT);
        N = (int) Math.round(n_value / 100 * filterPassController.getRowCount());
      } else {
        if (n_value < 0) throw new DataException(ResourceConstants.INVALID_TOP_BOTTOM_N_ARGUMENT);
        N = (int) n_value;
      }
    }

    // Evaluate operand expression
    Object value =
        ScriptEvalUtil.evalExpr(op_expr, cx.newContext(scope), ScriptExpression.defaultID, 0);

    if (filterPassController.getPassLevel() == FilterPassController.FIRST_PASS) {
      return doFirstPass(value);
    } else if (filterPassController.getPassLevel() == FilterPassController.SECOND_PASS) {
      return doSecondPass();
    }
    return false;
  }