예제 #1
0
  public void create(String oql) throws QueryException {

    _fieldNum = 0;
    _expr = null;
    _spCall = null;

    // Separate parser for CALL-type queries (using stored procedured)
    if (oql.startsWith("CALL ")) {
      createCall(oql);
      return;
    }

    Lexer lexer = new Lexer(oql);
    Parser parser = new Parser(lexer);
    ParseTreeNode parseTree = parser.getParseTree();

    _dbEngine = _dbImpl.getPersistenceEngine();
    if (_dbEngine == null) throw new QueryException("Could not get a persistence engine");

    ParseTreeWalker walker = new ParseTreeWalker(_dbEngine, parseTree, _dbImpl.getClassLoader());

    _objClass = walker.getObjClass();
    _clsDesc = walker.getClassDescriptor();
    _expr = walker.getQueryExpression();
    _paramInfo = walker.getParamInfo();
    _projectionType = walker.getProjectionType();
    _pathInfo = walker.getPathInfo();

    // port param info types back to the format of old bind types.
    // first get the maximum SQL param.
    int max = 0;
    for (Enumeration e = _paramInfo.elements(); e.hasMoreElements(); ) {
      ParamInfo info = (ParamInfo) e.nextElement();
      for (Enumeration f = info.getParamMap().elements(); f.hasMoreElements(); ) {
        int paramIndex = ((Integer) f.nextElement()).intValue();
        if (paramIndex > max) max = paramIndex;
      }
    }

    // then create the types array and fill it
    _bindTypes = new Class[max];
    for (Enumeration e = _paramInfo.elements(); e.hasMoreElements(); ) {
      ParamInfo info = (ParamInfo) e.nextElement();
      for (Enumeration f = info.getParamMap().elements(); f.hasMoreElements(); ) {
        int paramIndex = ((Integer) f.nextElement()).intValue();
        _bindTypes[paramIndex - 1] = f.getClass();
      }
    }
  }