Package railo.runtime.type

Examples of railo.runtime.type.QueryImpl


      }
      else if(value instanceof Array) {
        return ((java.sql.Array)value).getArray();
      }
      else if(value instanceof ResultSet) {
        return new QueryImpl((ResultSet)value,"query",null);
      }
      else
        return value;
      }
      catch(SQLException e) {
View Full Code Here


   * @throws ConverterException
   */
  private Object _deserializeQuery(Element recordset) throws ConverterException {
    try {
      // create Query Object
      Query query=new QueryImpl(
          railo.runtime.type.util.ListUtil.listToArray(
              recordset.getAttribute("fieldNames"),','
          )
        ,Caster.toIntValue(recordset.getAttribute("rowCount")),"query"
      );
View Full Code Here

      }
    }
    String[] headers = 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(QueryUtil.getValue(columns[i],row),QueryUtil.getValue(columns[i],row-1),true))
                        continue outer;
                }
                rtn.removeRow(row);
            }
           
        }
    // UNION // TODO support it
        ZExpression set = query.getSet();
View Full Code Here

  }
 
  public Query getOutputText() throws DatabaseException {
    DebugTextFragment[] fragments = outputLog.getFragments();
    int len = fragments==null?0:fragments.length;
    Query qryOutputLog=new QueryImpl(
                new Collection.Key[]{
                    KeyConstants._line
                    ,KeyConstants._template,
                    KeyConstants._text},
                len,"query");
   
   
        if(len>0) {
            for(int i=0;i<fragments.length;i++) {
              qryOutputLog.setAtEL(KeyConstants._line,i+1,fragments[i].line);
              qryOutputLog.setAtEL(KeyConstants._template,i+1,fragments[i].template);
              qryOutputLog.setAtEL(KeyConstants._text,i+1,fragments[i].text)
            }
        }
        return qryOutputLog;
       
  }
View Full Code Here

            for ( int i=0; i < numCols; i++ ) {
                arrays[ i ].append( row.get( i ) );
            }
        }

        return new QueryImpl( headers, arrays, "query" );
    }
View Full Code Here

    XMLBASE
  };
 
 
  public static Query toQuery(Struct data,boolean hasDC) throws DatabaseException {
    Query qry=new QueryImpl(hasDC?COLUMNS_WITH_DC:COLUMNS,0,"");
   
    String version=Caster.toString(data.get(VERSION,""),"");
    Array items=null;
    if(StringUtil.startsWithIgnoreCase(version,"rss") || StringUtil.startsWithIgnoreCase(version,"rdf"))  {
      items=Caster.toArray(data.get(ITEM, null),null);
View Full Code Here

   * @throws ConverterException
   */
  private Object _deserializeQuery(Element recordset) throws ConverterException {
    try {
      // create Query Object
      Query query=new QueryImpl(
          railo.runtime.type.util.ListUtil.listToArray(
              recordset.getAttribute("fieldNames"),','
          )
        ,Caster.toIntValue(recordset.getAttribute("rowCount")),"query"
      );
View Full Code Here

  public static  QueryImpl __execute(PageContext pc, SQL sql, int maxrows, int fetchsize, int timeout,Stopwatch stopwatch,Set<String> tables, boolean doSimpleTypes) throws PageException {
    ArrayList<String> usedTables=new ArrayList<String>();
    synchronized(lock) {
         
      QueryImpl nqr=null;
      ConfigImpl config = (ConfigImpl)pc.getConfig();
      DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
      DatasourceConnection dc=pool.getDatasourceConnection(pc,config.getDataSource(QOQ_DATASOURCE_NAME),"sa","");
        Connection conn = dc.getConnection();
        try {
          DBUtil.setAutoCommitEL(conn,false);

            //sql.setSQLString(HSQLUtil.sqlToZQL(sql.getSQLString(),false));
            try {
            Iterator<String> it = tables.iterator();
            //int len=tables.size();
                  while(it.hasNext()) {
              String tableName=it.next().toString();//tables.get(i).toString();
             
              String modTableName=tableName.replace('.','_');
                      String modSql=StringUtil.replace(sql.getSQLString(),tableName,modTableName,false);
              sql.setSQLString(modSql);
              addTable(conn,pc,modTableName,Caster.toQuery(pc.getVariable(tableName)),doSimpleTypes,usedTables);
            }
                  DBUtil.setReadOnlyEL(conn,true);
                  try {
                    nqr =new QueryImpl(pc,dc,sql,maxrows,fetchsize,timeout,"query",null,false,false);
                  }
                  finally {
            DBUtil.setReadOnlyEL(conn,false);
                    DBUtil.commitEL(conn);
                    DBUtil.setAutoCommitEL(conn,true);
                  }
           
        } 
              catch (SQLException e) {
                  DatabaseException de = new DatabaseException("there is a problem to execute sql statement on query",null,sql,null);
                  de.setDetail(e.getMessage());
                  throw de;
              }
 
        }
        finally {
          removeAll(conn,usedTables);
                DBUtil.setAutoCommitEL(conn,true);
          pool.releaseDatasourceConnection(dc);
         
          //manager.releaseConnection(dc);
        }
          nqr.setExecutionTime(stopwatch.time());
      return nqr;
    }
    }
View Full Code Here

    public static Query toQuery(Object o) throws PageException {
      if(o instanceof Query) return (Query)o;
      if(o instanceof ObjectWrap) {
            return toQuery(((ObjectWrap)o).getEmbededObject());
        }
        if(o instanceof ResultSet) return new QueryImpl((ResultSet)o,"query", ThreadLocalPageContext.getTimeZone());
        throw new CasterException(o,"query");
    }
View Full Code Here

    public static Query toQuery(Object o, boolean duplicate) throws PageException {
       
        if(o instanceof Query) {
            if(duplicate) {
                Query src = (Query)o;
                Query trg=new QueryImpl(src.getColumnNames(),src.getRowCount(),"query");

                Collection.Key[] keys=src.getColumnNames();
                QueryColumn[] columnsSrc=new QueryColumn[keys.length];
                for(int i=0;i<columnsSrc.length;i++) {
                    columnsSrc[i]=src.getColumn(keys[i]);
                }

                keys=trg.getColumnNames();
                QueryColumn[] columnsTrg=new QueryColumn[keys.length];
                for(int i=0;i<columnsTrg.length;i++) {
                    columnsTrg[i]=trg.getColumn(keys[i]);
                }
               
                int i;
                for(int row=trg.getRecordcount();row>0;row--) {
                    for(i=0;i<columnsTrg.length;i++) {
                        columnsTrg[i].set(row,columnsSrc[i].get(row,null));
                    }
                }
                return trg;
View Full Code Here

TOP

Related Classes of railo.runtime.type.QueryImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.