예제 #1
0
  private static Struct checkTableFill(DatabaseMetaData md, String dbName, String tableName)
      throws SQLException, PageException {
    Struct rows = new CastableStruct(tableName, Struct.TYPE_LINKED);
    ResultSet columns = md.getColumns(dbName, null, tableName, null);
    // print.o(new QueryImpl(columns,""));
    try {
      String name;
      Object nullable;
      while (columns.next()) {
        name = columns.getString("COLUMN_NAME");

        nullable = columns.getObject("IS_NULLABLE");
        rows.setEL(
            KeyImpl.init(name),
            new ColumnInfo(
                name,
                columns.getInt("DATA_TYPE"),
                columns.getString("TYPE_NAME"),
                columns.getInt("COLUMN_SIZE"),
                Caster.toBooleanValue(nullable)));
      }
    } finally {
      DBUtil.closeEL(columns);
    } // Table susid defined for cfc susid does not exist.

    return rows;
  }
예제 #2
0
 @Override
 public boolean onApplicationStart(PageContext pc) throws PageException {
   ComponentAccess app = apps.get(pc.getApplicationContext().getName());
   if (app != null && app.contains(pc, ON_APPLICATION_START)) {
     Object rtn = call(app, pc, ON_APPLICATION_START, ArrayUtil.OBJECT_EMPTY, true);
     return Caster.toBooleanValue(rtn, true);
   }
   return true;
 }
예제 #3
0
 public boolean getXmlStandalone() {
   // dynamic load to support jre 1.4 and 1.5
   try {
     Method m = doc.getClass().getMethod("getXmlStandalone", new Class[] {});
     return Caster.toBooleanValue(m.invoke(doc, ArrayUtil.OBJECT_EMPTY));
   } catch (Exception e) {
     throw new PageRuntimeException(Caster.toPageException(e));
   }
 }
예제 #4
0
 public static void checkRestriction() {
   PageContext pc = ThreadLocalPageContext.get();
   boolean enable = false;
   try {
     enable = Caster.toBooleanValue(pc.serverScope().get("enableGateway", Boolean.FALSE), false);
   } catch (PageException e) {
   }
   // enable=false;
   if (!enable) throw new PageRuntimeException(new FunctionNotSupported("SendGatewayMessage"));
 }
예제 #5
0
  public static Object call(PageContext pc, Object[] objArr) throws PageException {
    if (objArr.length < 3)
      throw new ExpressionException("invalid call of a CFML Based built in function");

    // translate arguments
    String filename = Caster.toString((((FunctionValue) objArr[0]).getValue()));
    Collection.Key name = KeyImpl.toKey((((FunctionValue) objArr[1]).getValue()));
    boolean isweb = Caster.toBooleanValue((((FunctionValue) objArr[2]).getValue()));

    UDF udf = loadUDF(pc, filename, name, isweb);
    Struct meta = udf.getMetaData(pc);
    boolean caller =
        meta == null ? false : Caster.toBooleanValue(meta.get(CALLER, Boolean.FALSE), false);

    Struct namedArguments = null;
    Object[] arguments = null;
    if (objArr.length <= 3) arguments = ArrayUtil.OBJECT_EMPTY;
    else if (objArr[3] instanceof FunctionValue) {
      FunctionValue fv;
      namedArguments = new StructImpl();
      if (caller) namedArguments.setEL(CALLER, pc.undefinedScope().duplicate(false));
      for (int i = 3; i < objArr.length; i++) {
        fv = toFunctionValue(name, objArr[i]);
        namedArguments.set(fv.getName(), fv.getValue());
      }
    } else {
      int offset = (caller ? 2 : 3);
      arguments = new Object[objArr.length - offset];
      if (caller) arguments[0] = pc.undefinedScope().duplicate(false);
      for (int i = 3; i < objArr.length; i++) {
        arguments[i - offset] = toObject(name, objArr[i]);
      }
    }

    // load UDF

    // execute UDF
    if (namedArguments == null) {
      return udf.call(pc, arguments, false);
    }

    return udf.callWithNamedValues(pc, namedArguments, false);
  }
예제 #6
0
파일: Executer.java 프로젝트: ringgi/railo
  /**
   * execute a and operation
   *
   * @param sql
   * @param qr QueryResult to execute on it
   * @param expression
   * @param row row of resultset to execute
   * @return result
   * @throws PageException
   */
  private Object executeOr(PageContext pc, SQL sql, Query qr, ZExpression expression, int row)
      throws PageException {
    int len = expression.nbOperands();

    // boolean rtn=Caster.toBooleanValue(executeExp(pc,sql,qr,expression.getOperand(0),row));
    for (int i = 0; i < len; i++) {
      if (Caster.toBooleanValue(executeExp(pc, sql, qr, expression.getOperand(i), row)))
        return Boolean.TRUE;
      // if(rtn)break;
      // rtn=rtn || Caster.toBooleanValue(executeExp(pc,sql,qr,expression.getOperand(i),row));
    }
    return Boolean.FALSE;
  }
예제 #7
0
파일: Executer.java 프로젝트: ringgi/railo
  private Query testExecute(PageContext pc, SQL sql, Query qr, ZQuery query, int maxrows)
      throws PageException {

    int recCount = qr.getRecordcount();
    Vector vSelects = query.getSelect();
    int selCount = vSelects.size();

    Map selects = new HashTable();
    boolean isSMS = false;
    // headers
    for (int i = 0; i < selCount; i++) {
      ZSelectItem select = (ZSelectItem) vSelects.get(i);

      if (select.isWildcard()
          || (isSMS = select.getColumn().equals(SQLPrettyfier.PLACEHOLDER_ASTERIX))) {

        if (!isSMS && !select.getColumn().equals("*"))
          throw new DatabaseException(
              "can't execute this type of query at the moment", null, sql, null);
        String[] keys = qr.keysAsString();
        for (int y = 0; y < keys.length; y++) {
          selects.put(keys[y], keys[y]);
        }
        isSMS = false;
      } else {
        // if(SQLPrettyfier.PLACEHOLDER_COUNT.equals(select.getAlias())) select.setAlias("count");
        // if(SQLPrettyfier.PLACEHOLDER_COUNT.equals(select.getColumn())) select.setExpression(new
        // ZConstant("count",ZConstant.COLUMNNAME));

        String alias = select.getAlias();
        String column = select.getColumn();
        if (alias == null) alias = column;
        alias = alias.toLowerCase();

        selects.put(alias, select);
      }
    }
    String[] headers = (String[]) selects.keySet().toArray(new String[selects.size()]);

    // aHeaders.toArray(new String[aHeaders.size()]);
    QueryImpl rtn = new QueryImpl(headers, 0, "query");
    rtn.setSql(sql);

    // loop records
    Vector orders = query.getOrderBy();
    ZExp where = query.getWhere();
    // print.out(headers);
    // int newRecCount=0;
    boolean hasMaxrow = maxrows > -1 && (orders == null || orders.size() == 0);
    for (int row = 1; row <= recCount; row++) {
      sql.setPosition(0);
      if (hasMaxrow && maxrows <= rtn.getRecordcount()) break;
      boolean useRow = where == null || Caster.toBooleanValue(executeExp(pc, sql, qr, where, row));
      if (useRow) {

        rtn.addRow(1);
        for (int cell = 0; cell < headers.length; cell++) {
          Object value = selects.get(headers[cell]);

          rtn.setAt(
              headers[cell], rtn.getRecordcount(), getValue(pc, sql, qr, row, headers[cell], value)
              // executeExp(qr, selects[cell].getExpression(),row)
              );
        }
      }
    }

    // Group By
    if (query.getGroupBy() != null)
      throw new DatabaseException("group by are not supported at the moment", null, sql, null);

    // Order By
    if (orders != null && orders.size() > 0) {

      int len = orders.size();
      for (int i = len - 1; i >= 0; i--) {
        ZOrderBy order = (ZOrderBy) orders.get(i);
        ZConstant name = (ZConstant) order.getExpression();
        rtn.sort(
            name.getValue().toLowerCase(),
            order.getAscOrder() ? Query.ORDER_ASC : Query.ORDER_DESC);
      }
      if (maxrows > -1) {
        rtn.cutRowsTo(maxrows);
      }
    }
    // Distinct
    if (query.isDistinct()) {
      String[] keys = rtn.getColumns();
      QueryColumn[] columns = new QueryColumn[keys.length];
      for (int i = 0; i < columns.length; i++) {
        columns[i] = rtn.getColumn(keys[i]);
      }

      int i;
      outer:
      for (int row = rtn.getRecordcount(); row > 1; row--) {
        for (i = 0; i < columns.length; i++) {
          if (!Operator.equals(columns[i].get(row), columns[i].get(row - 1), true)) continue outer;
        }
        rtn.removeRow(row);
      }
    }
    // UNION // TODO support it
    ZExpression set = query.getSet();
    if (set != null) {
      ZExp op = set.getOperand(0);
      if (op instanceof ZQuery)
        throw new DatabaseException("union is not supported at the moment", null, sql, null);
      // getInvokedTables((ZQuery)op, tablesNames);
    }

    return rtn;
  }
예제 #8
0
  protected void _onRequest(
      PageContext pc, PageSource requestedPage, PageSource appPS, RequestListener rl)
      throws PageException {
    PageContextImpl pci = (PageContextImpl) pc;
    if (appPS != null) {
      String callPath = appPS.getComponentName();

      ComponentAccess app = ComponentLoader.loadComponent(pci, null, appPS, callPath, false, false);

      // init
      initApplicationContext(pci, app);

      apps.put(pc.getApplicationContext().getName(), app);

      if (!pci.initApplicationContext()) return;

      if (rl != null) {
        requestedPage = rl.execute(pc, requestedPage);
        if (requestedPage == null) return;
      }

      String targetPage = requestedPage.getFullRealpath();
      boolean doOnRequestEnd = true;

      // onRequestStart
      if (app.contains(pc, ON_REQUEST_START)) {
        Object rtn = call(app, pci, ON_REQUEST_START, new Object[] {targetPage}, true);
        if (!Caster.toBooleanValue(rtn, true)) return;
      }

      // onRequest
      boolean isCFC =
          ResourceUtil.getExtension(targetPage, "")
              .equalsIgnoreCase(pc.getConfig().getCFCExtension());
      Object method;
      if (isCFC
          && app.contains(pc, ON_CFCREQUEST)
          && (method = pc.urlFormScope().get(ComponentPage.METHOD, null)) != null) {

        Struct url = (Struct) Duplicator.duplicate(pc.urlFormScope(), true);

        url.removeEL(KeyConstants._fieldnames);
        url.removeEL(ComponentPage.METHOD);
        Object args = url.get(KeyConstants._argumentCollection, null);
        Object returnFormat = url.removeEL(KeyConstants._returnFormat);
        Object queryFormat = url.removeEL(KeyConstants._queryFormat);

        if (args == null) {
          args = pc.getHttpServletRequest().getAttribute("argumentCollection");
        }

        if (args instanceof String) {
          args = new JSONExpressionInterpreter().interpret(pc, (String) args);
        }

        if (args != null) {
          if (Decision.isCastableToStruct(args)) {
            Struct sct = Caster.toStruct(args, false);
            // Key[] keys = url.keys();
            Iterator<Entry<Key, Object>> it = url.entryIterator();
            Entry<Key, Object> e;
            while (it.hasNext()) {
              e = it.next();
              sct.setEL(e.getKey(), e.getValue());
            }
            args = sct;
          } else if (Decision.isCastableToArray(args)) {
            args = Caster.toArray(args);
          } else {
            Array arr = new ArrayImpl();
            arr.appendEL(args);
            args = arr;
          }
        } else args = url;

        Object rtn =
            call(
                app,
                pci,
                ON_CFCREQUEST,
                new Object[] {requestedPage.getComponentName(), method, args},
                true);

        if (rtn != null) {
          if (pc.getHttpServletRequest().getHeader("AMF-Forward") != null) {
            pc.variablesScope().setEL("AMF-Forward", rtn);
            // ThreadLocalWDDXResult.set(rtn);
          } else {
            try {
              pc.forceWrite(
                  ComponentPage.convertResult(
                      pc, app, method.toString(), returnFormat, queryFormat, rtn));
            } catch (Exception e) {
              throw Caster.toPageException(e);
            }
          }
        }

      }
      // else if(!isCFC && app.contains(pc,ON_REQUEST)) {}
      else {
        // TODO impl die nicht so generisch ist
        try {

          if (!isCFC && app.contains(pc, ON_REQUEST))
            call(app, pci, ON_REQUEST, new Object[] {targetPage}, false);
          else pci.doInclude(requestedPage);
        } catch (PageException pe) {
          if (!Abort.isSilentAbort(pe)) {
            if (pe instanceof MissingIncludeException) {
              if (((MissingIncludeException) pe).getPageSource().equals(requestedPage)) {
                if (app.contains(pc, ON_MISSING_TEMPLATE)) {
                  if (!Caster.toBooleanValue(
                      call(app, pci, ON_MISSING_TEMPLATE, new Object[] {targetPage}, true), true))
                    throw pe;
                } else throw pe;
              } else throw pe;
            } else throw pe;
          } else {
            doOnRequestEnd = false;
            if (app.contains(pc, ON_ABORT)) {
              call(app, pci, ON_ABORT, new Object[] {targetPage}, true);
            }
          }
        }
      }

      // onRequestEnd
      if (doOnRequestEnd && app.contains(pc, ON_REQUEST_END)) {
        call(app, pci, ON_REQUEST_END, new Object[] {targetPage}, true);
      }
    } else {
      apps.put(pc.getApplicationContext().getName(), null);
      pc.doInclude(requestedPage);
    }
  }