Package railo.runtime.type

Examples of railo.runtime.type.Query


    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

    // First Chance
        try {
          SelectParser parser=new SelectParser();
          selects = parser.parse(sql.getSQLString());
         
          Query q=qoq.execute(pc,sql,selects,maxrows);
          q.setExecutionTime(stopwatch.time());

          return q;
        }
        catch (SQLParserException spe) {
          //railo.print.printST(spe);
          //sp
          //railo.print.out("sql parser crash at:");
          //railo.print.out("--------------------------------");
          //railo.print.out(sql.getSQLString().trim());
          //railo.print.out("--------------------------------");
          //print.e("1:"+sql.getSQLString());
          prettySQL = SQLPrettyfier.prettyfie(sql.getSQLString());
          //print.e("2:"+prettySQL);
          try {
            Query query=executer.execute(pc,sql,prettySQL,maxrows);
            query.setExecutionTime(stopwatch.time());
            return query;
          } catch (PageException ex) {
            //railo.print.printST(ex);
            //railo.print.out("old executor/zql crash at:");
            //railo.print.out("--------------------------------");
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

  }
 
  @Override
  public final Query getCollectionsAsQuery() {
        final String v="VARCHAR";
        Query query=null;
        String[] cols = new String[]{"external","language","mapped","name","online","path","registered","lastmodified","categories","charset","created",
                       "size","doccount"};
        String[] types = new String[]{"BOOLEAN",v,"BOOLEAN",v,"BOOLEAN",v,v,"DATE","BOOLEAN",v,"OBJECT","DOUBLE","DOUBLE"};
        try {
            query=new QueryImpl(cols,types, collections.size(),"query");
        } catch (DatabaseException e) {
            query=new QueryImpl(cols, collections.size(),"query");
        }
       
        //Collection.Key[] keys = collections.keys();
      Iterator<Object> it = collections.valueIterator();
      int i=-1;
        while(it.hasNext()) {
          i++;
          try {
            SearchCollection coll = (SearchCollection) it.next();
                query.setAt(KeyConstants._external,i+1,Boolean.FALSE);
                query.setAt(KeyConstants._charset,i+1,"UTF-8");
                query.setAt(KeyConstants._created,i+1,coll.created());
               
                query.setAt("categories",i+1,Boolean.TRUE);
            query.setAt(KeyConstants._language,i+1,coll.getLanguage());
            query.setAt("mapped",i+1,Boolean.FALSE);
            query.setAt(KeyConstants._name,i+1,coll.getName());
            query.setAt(KeyConstants._online,i+1,Boolean.TRUE);
            query.setAt(KeyConstants._path,i+1,coll.getPath().getAbsolutePath());
            query.setAt("registered",i+1,"CF");
            query.setAt(KeyConstants._lastmodified,i+1,coll.getLastUpdate());
            query.setAt(KeyConstants._size,i+1,new Double(coll.getSize()));
            query.setAt("doccount",i+1,new Double(coll.getDocumentCount()));
          }
        catch(PageException pe) {}
      }
    return query;
  }
View Full Code Here

         
         
          //return StructUtil.copyToStruct((Map)value);
        }
        if(Decision.isQuery(value)) {
            Query q = Caster.toQuery(value);
            int recorcount=q.getRecordcount();
            String[] strColumns = q.getColumns();
           
            QueryColumn col;
            int row;
            for(int i=0;i<strColumns.length;i++) {
                col=q.getColumn(strColumns[i]);
                for(row=1;row<=recorcount;row++) {
                    col.set(row,toCFML(col.get(row,null)));
                }
            }
            return q;
View Full Code Here

            KeyConstants._datasource,
            KeyConstants._usage};
        String[] types = new String[]{"VARCHAR","DOUBLE","VARCHAR","VARCHAR","DOUBLE","VARCHAR","ANY"};
       
        //queries
        Query qryQueries=null;
        try {
            qryQueries = new QueryImpl(cols,types,queries.size(),"query");
        } catch (DatabaseException e) {
            qryQueries = new QueryImpl(cols,queries.size(),"query");
        }
    int row=0;
    try {
        while(qryIt.hasNext()) {
            row++;
            QueryEntryPro qe=(QueryEntryPro) qryIt.next();
        qryQueries.setAt(KeyConstants._name,row,qe.getName()==null?"":qe.getName());
            qryQueries.setAt(KeyConstants._time,row,Long.valueOf(qe.getExecutionTime()));
            qryQueries.setAt(KeyConstants._sql,row,qe.getSQL().toString());
        qryQueries.setAt(KeyConstants._src,row,qe.getSrc());
                qryQueries.setAt(KeyConstants._count,row,Integer.valueOf(qe.getRecordcount()));
                qryQueries.setAt(KeyConstants._datasource,row,qe.getDatasource());
               
                Struct usage = getUsage(qe);
                if(usage!=null) qryQueries.setAt(KeyConstants._usage,row,usage);

            Object o=qryExe.get(KeyImpl.init(qe.getSrc()),null);
            if(o==null) qryExe.setEL(KeyImpl.init(qe.getSrc()),Long.valueOf(qe.getExecutionTime()));
            else qryExe.setEL(KeyImpl.init(qe.getSrc()),Long.valueOf(((Long)o).longValue()+qe.getExecutionTime()));
        }
    }
    catch(PageException dbe) {}
   
      // Pages
      // src,load,app,query,total
      Struct debugging=new StructImpl();
      row=0;
        ArrayList<DebugEntryTemplate> arrPages = toArray();
    int len=arrPages.size();
        Query qryPage=new QueryImpl(
                new Collection.Key[]{
                    KeyConstants._id,
                    KeyConstants._count,
                    KeyConstants._min,
                    KeyConstants._max,
                    KeyConstants._avg
                    ,KeyConstants._app,
                    KeyConstants._load,
                    KeyConstants._query,
                    KeyConstants._total,
                    KeyConstants._src},
                len,"query");

    try {
            DebugEntryTemplate de;
            //PageSource ps;
        for(int i=0;i<len;i++) {
            row++;
            de=arrPages.get(i);
                //ps = de.getPageSource();
               
            qryPage.setAt(KeyConstants._id,row,de.getId());
            qryPage.setAt(KeyConstants._count,row,_toString(de.getCount()));
                qryPage.setAt(KeyConstants._min,row,_toString(de.getMin()));
                qryPage.setAt(KeyConstants._max,row,_toString(de.getMax()));
                qryPage.setAt(KeyConstants._avg,row,_toString(de.getExeTime()/de.getCount()));
                qryPage.setAt(KeyConstants._app,row,_toString(de.getExeTime()-de.getQueryTime()));
                qryPage.setAt(KeyConstants._load,row,_toString(de.getFileLoadTime()));
            qryPage.setAt(KeyConstants._query,row,_toString(de.getQueryTime()));
                qryPage.setAt(KeyConstants._total,row,_toString( de.getFileLoadTime() + de.getExeTime()));
            qryPage.setAt(KeyConstants._src,row,de.getSrc());   
      }
    }
    catch(PageException dbe) {}


      // Pages Parts
    List<DebugEntryTemplatePart> filteredPartEntries = null;
    boolean hasParts=partEntries!=null && !partEntries.isEmpty() && !arrPages.isEmpty();
    int qrySize=0;

    if(hasParts) {

      String slowestTemplate = arrPages.get( 0 ).getPath();

      filteredPartEntries = new ArrayList();

      java.util.Collection<DebugEntryTemplatePartImpl> col = partEntries.values();
      for ( DebugEntryTemplatePart detp : col ) {

        if ( detp.getPath().equals( slowestTemplate ) )
          filteredPartEntries.add( detp );
      }

      qrySize = Math.min( filteredPartEntries.size(), MAX_PARTS );
    }

    Query qryPart = new QueryImpl(
            new Collection.Key[]{
                 KeyConstants._id
                ,KeyConstants._count
                ,KeyConstants._min
                ,KeyConstants._max
                ,KeyConstants._avg
                ,KeyConstants._total
                ,KeyConstants._path
                ,KeyConstants._start
                ,KeyConstants._end
                ,KeyConstants._startLine
                ,KeyConstants._endLine
                ,KeyConstants._snippet
            }, qrySize, "query" );

    if(hasParts) {
      row=0;
          Collections.sort( filteredPartEntries, DEBUG_ENTRY_TEMPLATE_PART_COMPARATOR );

      DebugEntryTemplatePart[] parts = new DebugEntryTemplatePart[ qrySize ];

      if ( filteredPartEntries.size() > MAX_PARTS )
        parts = filteredPartEntries.subList(0, MAX_PARTS).toArray( parts );
      else
        parts = filteredPartEntries.toArray( parts );

      try {
              DebugEntryTemplatePart de;
              //PageSource ps;
          for(int i=0;i<parts.length;i++) {
              row++;
              de=parts[i];
                 
              qryPart.setAt(KeyConstants._id,row,de.getId());
              qryPart.setAt(KeyConstants._count,row,_toString(de.getCount()));
              qryPart.setAt(KeyConstants._min,row,_toString(de.getMin()));
              qryPart.setAt(KeyConstants._max,row,_toString(de.getMax()));
              qryPart.setAt(KeyConstants._avg,row,_toString(de.getExeTime()/de.getCount()));
              qryPart.setAt(KeyConstants._start,row,_toString(de.getStartPosition()));
              qryPart.setAt(KeyConstants._end,row,_toString(de.getEndPosition()));
              qryPart.setAt(KeyConstants._total,row,_toString(de.getExeTime()));
              qryPart.setAt(KeyConstants._path,row,de.getPath());

                    if ( de instanceof DebugEntryTemplatePartImpl ) {

                        qryPart.setAt( KeyConstants._startLine, row, _toString( ((DebugEntryTemplatePartImpl)de).getStartLine() ) );
                        qryPart.setAt( KeyConstants._endLine, row, _toString( ((DebugEntryTemplatePartImpl)de).getEndLine() ));
                        qryPart.setAt( KeyConstants._snippet, row, ((DebugEntryTemplatePartImpl)de).getSnippet() );
                    }
        }
      }
      catch(PageException dbe) {}
    }
   
   
   

    // exceptions
    len = exceptions==null?0:exceptions.size();
   
        Array arrExceptions=new ArrayImpl();
        if(len>0) {
            Iterator<CatchBlock> it = exceptions.iterator();
            row=0;
            while(it.hasNext()) {
              arrExceptions.appendEL(it.next())
            }
     
        }

    // output log
        //Query qryOutputLog=getOutputText();
       
       

    // timers
    len=timers==null?0:timers.size();
        Query qryTimers=new QueryImpl(
                new Collection.Key[]{KeyConstants._label,KeyConstants._time,KeyConstants._template},
                len,"timers");
        if(len>0) {
          try {
            Iterator<DebugTimerImpl> it = timers.iterator();
            DebugTimer timer;
            row=0;
            while(it.hasNext()) {
              timer=it.next();
              row++;
              qryTimers.setAt(KeyConstants._label,row,timer.getLabel());
              qryTimers.setAt(KeyConstants._template,row,timer.getTemplate());
              qryTimers.setAt(KeyConstants._time,row,Caster.toDouble(timer.getTime()));   
            }
      }
      catch(PageException dbe) {}
        }

    // traces
    len=traces==null?0:traces.size();
    if(!((ConfigImpl)pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_TRACING))len=0;
        Query qryTraces=new QueryImpl(
                new Collection.Key[]{
                    KeyConstants._type,
                    KeyConstants._category,
                    KeyConstants._text,
                    KeyConstants._template,
                    KeyConstants._line,
                    KeyConstants._action,
                    KeyConstants._varname,
                    KeyConstants._varvalue,
                    KeyConstants._time},
                len,"traces");
        if(len>0) {
          try {
            Iterator<DebugTraceImpl> it = traces.iterator();
            DebugTraceImpl trace;
            row=0;
            while(it.hasNext()) {
              trace= it.next();
              row++;
              qryTraces.setAt(KeyConstants._type,row,LogUtil.toStringType(trace.getType(), "INFO"))
              if(!StringUtil.isEmpty(trace.getCategory()))qryTraces.setAt(KeyConstants._category,row,trace.getCategory());
              if(!StringUtil.isEmpty(trace.getText()))qryTraces.setAt(KeyConstants._text,row,trace.getText());
              if(!StringUtil.isEmpty(trace.getTemplate()))qryTraces.setAt(KeyConstants._template,row,trace.getTemplate());
              if(trace.getLine()>0)qryTraces.setAt(KeyConstants._line,row,new Double(trace.getLine()));
              if(!StringUtil.isEmpty(trace.getAction()))qryTraces.setAt(KeyConstants._action,row,trace.getAction());
              if(!StringUtil.isEmpty(trace.getVarName()))qryTraces.setAt(KeyImpl.init("varname"),row,trace.getVarName());
              if(!StringUtil.isEmpty(trace.getVarValue()))qryTraces.setAt(KeyImpl.init("varvalue"),row,trace.getVarValue());
              qryTraces.setAt(KeyConstants._time,row,new Double(trace.getTime()));
            }
      }
      catch(PageException dbe) {}
        }
       


    // scope access
    len=implicitAccesses==null?0:implicitAccesses.size();
        Query qryImplicitAccesseses=new QueryImpl(
                new Collection.Key[]{
                    KeyConstants._template,
                    KeyConstants._line,
                    KeyConstants._scope,
                    KeyConstants._count,
                    KeyConstants._name},
                len,"implicitAccess");
        if(len>0) {
          try {
            Iterator<ImplicitAccessImpl> it = implicitAccesses.values().iterator();
            ImplicitAccessImpl das;
            row=0;
            while(it.hasNext()) {
              das= it.next();
              row++;
              qryImplicitAccesseses.setAt(KeyConstants._template,row,das.getTemplate());
              qryImplicitAccesseses.setAt(KeyConstants._line,row,new Double(das.getLine()));
              qryImplicitAccesseses.setAt(KeyConstants._scope,row,das.getScope());
              qryImplicitAccesseses.setAt(KeyConstants._count,row,new Double(das.getCount()));
              qryImplicitAccesseses.setAt(KeyConstants._name,row,das.getName())
             
            }
      }
      catch(PageException dbe) {}
        }
       
        Query history=new QueryImpl(new Collection.Key[]{},0,"history");
        try {
      history.addColumn(KeyConstants._id, historyId);
          history.addColumn(KeyConstants._level, historyLevel);
    } catch (PageException e) {
    }
   
    if(addAddionalInfo) {
      debugging.setEL(KeyConstants._cgi,pc.cgiScope());
View Full Code Here

   
    return debugging;
    }
   
  private static Struct getUsage(QueryEntry qe) throws PageException {
    Query qry = ((QueryEntryImpl)qe).getQry();
       
        QueryColumn c;
        DebugQueryColumn dqc;
        outer:if(qry!=null) {
          Struct usage=null;
          Collection.Key[] columnNames = qry.getColumnNames();
          Collection.Key columnName;
          for(int i=0;i<columnNames.length;i++){
            columnName=columnNames[i];
            c = qry.getColumn(columnName);
            if(!(c instanceof DebugQueryColumn)) break outer;
            dqc=(DebugQueryColumn) c;
            if(usage==null) usage=new StructImpl();
            usage.setEL(columnName, Caster.toBoolean(dqc.isUsed()));
          }
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

        }
        else if(type==SearchIndex.TYPE_URL) {
          ir=indexURL(si,new URL(key),recurse,timeout);
        }
        else if(type==SearchIndex.TYPE_CUSTOM) {
          Query qv;
          if(StringUtil.isEmpty(query)){
           
          // set columns
            railo.runtime.type.Array columns=new ArrayImpl();
              columns.append("key");
              columns.append("body");
              if(!StringUtil.isEmpty(title))columns.append("title");
              if(!StringUtil.isEmpty(urlpath))columns.append("urlpath");
              if(!StringUtil.isEmpty(custom1))columns.append("custom1");
              if(!StringUtil.isEmpty(custom2))columns.append("custom2");
              if(!StringUtil.isEmpty(custom3))columns.append("custom3");
              if(!StringUtil.isEmpty(custom4))columns.append("custom4");
             
            // populate query with a single row
                qv=new QueryImpl(columns,1,"query");
                // body
                qv.setAt(KeyConstants._key, 1, key);
                key="key";

                // body
                qv.setAt(KeyConstants._body, 1, body);
                body="body";

                // title
                if(!StringUtil.isEmpty(title)){
                  qv.setAt(KeyConstants._title, 1, title);
                  title="title";
                }

                // custom1
                if(!StringUtil.isEmpty(urlpath)){
                  qv.setAt("urlpath", 1, urlpath);
                  custom1="urlpath";
                }

                // custom1
                if(!StringUtil.isEmpty(custom1)){
                  qv.setAt(KeyConstants._custom1, 1, custom1);
                  custom1="custom1";
                }
                // custom2
                if(!StringUtil.isEmpty(custom2)){
                  qv.setAt(KeyConstants._custom2, 1, custom2);
                  custom2="custom2";
                }
                // custom3
                if(!StringUtil.isEmpty(custom3)){
                  qv.setAt(KeyConstants._custom3, 1, custom3);
                  custom3="custom3";
                }
                // custom4
                if(!StringUtil.isEmpty(custom4)){
                  qv.setAt(KeyConstants._custom4, 1, custom4);
                  custom4="custom4";
                }
            }
          else qv = Caster.toQuery(pc.getVariable(query));
           
          QueryColumn keyColumn=qv.getColumn(key);
           
            String[] strBodies=ListUtil.toStringArrayTrim(ListUtil.listToArrayRemoveEmpty(body,','));
            QueryColumn[] bodyColumns=new QueryColumn[strBodies.length];
            for(int i=0;i<bodyColumns.length;i++) {
                bodyColumns[i]=qv.getColumn(strBodies[i]);
            }
           
            ir= indexCustom(si,
                    getColumnEL(qv,title),
                    keyColumn,
View Full Code Here

TOP

Related Classes of railo.runtime.type.Query

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.