示例#1
0
  private void dispatchObject(Oop oop, ObjectVisitor visitor, boolean filterExists) {
    JSJavaObject jsObj = factory.newJSJavaObject(oop);
    Object[] args = new Object[] {jsObj};
    boolean b = true;

    try {
      if (filterExists) {
        Object res = call("filter", args);
        if (res instanceof Boolean) {
          b = ((Boolean) res).booleanValue();
        } else if (res instanceof Number) {
          b = ((Number) res).intValue() != 0;
        } else {
          b = (res != null);
        }
      }

      if (b) {
        Object select = call("result", args);
        visitor.visit(select);
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
示例#2
0
  private void executeQuery(SOQLQuery q, ObjectVisitor visitor) throws SOQLException {
    InstanceKlass kls = null;
    if (q.className != null) {
      kls = SystemDictionaryHelper.findInstanceKlass(q.className);
      if (kls == null) {
        throw new SOQLException(q.className + " is not found!");
      }
    }

    StringBuffer buf = new StringBuffer();
    buf.append("function result(");
    if (q.identifier != null) {
      buf.append(q.identifier);
    }
    buf.append(") { return ");
    buf.append(q.selectExpr.replace('\n', ' '));
    buf.append("; }");

    String selectCode = buf.toString();
    debugPrint(selectCode);
    String whereCode = null;
    if (q.whereExpr != null) {
      buf = new StringBuffer();
      buf.append("function filter(");
      buf.append(q.identifier);
      buf.append(") { return ");
      buf.append(q.whereExpr.replace('\n', ' '));
      buf.append("; }");
      whereCode = buf.toString();
      debugPrint(whereCode);
    } else {
      whereCode = "filter = null;";
    }

    beginQuery();
    // compile select expression and where condition
    evalString(selectCode, "", 1);
    evalString(whereCode, "", 1);

    // iterate thru heap, if needed
    if (q.className != null) {
      try {
        iterateOops(kls, visitor, q.isInstanceOf);
      } finally {
        endQuery();
      }
    } else {
      // simple "select <expr>" query
      try {
        Object select = call("result", new Object[] {});
        visitor.visit(select);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }