Package railo.runtime.type

Examples of railo.runtime.type.Query


  public static Query getMemoryUsageAsQuery(int type) throws DatabaseException {
   
   
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();
    Query qry=new QueryImpl(new Collection.Key[]{
        KeyConstants._name,
        KeyConstants._type,
        KeyConstants._used,
        KeyConstants._max,
        KeyConstants._init
    },0,"memory");
   
    int row=0;
    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    while(it.hasNext()){
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if(type==MEMORY_TYPE_HEAP && _type!=MemoryType.HEAP)continue;
      if(type==MEMORY_TYPE_NON_HEAP && _type!=MemoryType.NON_HEAP)continue;
       
      row++;
      qry.addRow();
      qry.setAtEL(KeyConstants._name, row, bean.getName());
      qry.setAtEL(KeyConstants._type, row, _type.name());
      qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
      qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
      qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
     
    }
    return qry;
  }
View Full Code Here


   
  }


  public static railo.runtime.type.Query toQuery(PageContext pc,HibernateORMSession session, Object obj, String name) throws PageException {
    Query qry=null;
    // a single entity
    if(!CommonUtil.isArray(obj)){
      qry= toQuery(pc,session,HibernateCaster.toComponent(obj),name,null,1,1);
    }
   
View Full Code Here

                    }
                }
            catch (IOException e1) {}
           
            if(name!=null) {
                    Query qry = CSVParser.toQuery( str, delimiter, textqualifier, columns, firstrowasheaders  );
                    pageContext.setVariable(name,qry);
            }
        }
        // Binary
        else {
View Full Code Here

        Element[] elProviders = ConfigWebFactory.getChildren(parent,"resource-provider");
        Element[] elDefaultProviders = ConfigWebFactory.getChildren(parent,"default-resource-provider");
        ResourceProvider[] providers = config.getResourceProviders();
        ResourceProvider defaultProvider = config.getDefaultResourceProvider();
   
        Query qry=new QueryImpl(new String[]{"support","scheme","caseSensitive","default","class","arguments"},elProviders.length+elDefaultProviders.length,"resourceproviders");
        int row=1;
        for(int i=0;i<elDefaultProviders.length;i++) {
          getResourceProviders(new ResourceProvider[]{defaultProvider},qry,elDefaultProviders[i],row++,Boolean.TRUE);
        }
        for(int i=0;i<elProviders.length;i++) {
View Full Code Here

      if(hasMeta){
        names = new String[]{"name","size","type","dateLastModified","attributes","mode","directory","meta"};
        types=new String[]{"VARCHAR","DOUBLE","VARCHAR","DATE","VARCHAR","VARCHAR","VARCHAR","OBJECT"};
      }
      Array array=null;
      Query query=null;
      Object rtn;
      if(listInfo==LIST_INFO_QUERY_ALL || listInfo==LIST_INFO_QUERY_NAME){
        boolean listOnlyNames=listInfo==LIST_INFO_QUERY_NAME;
        rtn=query=new QueryImpl(
        listOnlyNames?new String[]{"name"}:names,
        listOnlyNames?new String[]{"VARCHAR"}:types,
        0,"query");
      }
      else
        rtn=array=new ArrayImpl();
     
      if(!directory.exists()){
        if(directory instanceof FileResource) return rtn;
      throw new ApplicationException("directory ["+directory.toString()+"] doesn't exist");
    }
    if(!directory.isDirectory()){
      if(directory instanceof FileResource) return rtn;
      throw new ApplicationException("file ["+directory.toString()+"] exists, but isn't a directory");
    }
    if(!directory.isReadable()){
      if(directory instanceof FileResource) return rtn;
      throw new ApplicationException("no access to read directory ["+directory.toString()+"]");
    }
   
    long startNS=System.nanoTime();
   
    try {
      // Query All
      if(listInfo==LIST_INFO_QUERY_ALL)
        _fillQueryAll(query,directory,filter,0,hasMeta,recurse);
     
      // Query Name
      else if(listInfo==LIST_INFO_QUERY_NAME) {
             if(recurse || type!=TYPE_ALL)_fillQueryNamesRec("",query, directory, filter, 0,recurse);
             else _fillQueryNames(query, directory, nameFilter, 0);
      }
     
      //Array Name/Path
      else if(listInfo==LIST_INFO_ARRAY_NAME || listInfo==LIST_INFO_ARRAY_PATH) {
        boolean onlyName=listInfo==LIST_INFO_ARRAY_NAME;
             if(!onlyName || recurse || type!=TYPE_ALL)_fillArrayPathOrName(array, directory, nameFilter, 0, recurse, onlyName);//QueryNamesRec("",query, directory, filter, 0,recurse);
             else _fillArrayName(array, directory, nameFilter, 0);
     
      
            
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
   
    // sort
    if(sort!=null && query!=null) {
      String[] arr=sort.toLowerCase().split(",");
      for(int i=arr.length-1;i>=0;i--) {
        try {
          String[] col=arr[i].trim().split("\\s+");
          if(col.length==1)query.sort(col[0].trim());
          else if(col.length==2) {
            String order=col[1].toLowerCase().trim();
            if(order.equals("asc"))
              query.sort(col[0],railo.runtime.type.Query.ORDER_ASC);
            else if(order.equals("desc"))
              query.sort(col[0],railo.runtime.type.Query.ORDER_DESC);
            else
              throw new ApplicationException("invalid order type ["+col[1]+"]");
          }
        }
        catch(Throwable t) {}
      }   
    }
    if(query!=null)query.setExecutionTime(System.nanoTime()-startNS);
    return rtn;
  }
View Full Code Here

   *
   * @param qry
   * @return
   */
  public static Key[] getColumnNames(Query qry) {
    Query qp = Caster.toQuery(qry,null);
   
    if(qp!=null) return qp.getColumnNames();
    String[] strNames = qry.getColumns();
    Key[] names=new Key[strNames.length];
    for(int i=0;i<names.length;i++){
      names[i]=KeyImpl.getInstance(strNames[i]);
    }
View Full Code Here

    Cache c = getCache(pc);
    Iterator it = c.entries().iterator();
      String key;
      CacheEntry entry;
      QueryCacheEntry ce;
      Query q;
      while(it.hasNext()){
      entry=(CacheEntry) it.next();
      if(!(entry.getValue() instanceof QueryCacheEntry)) continue;
      ce=(QueryCacheEntry) entry.getValue();
      if(!(ce.getValue() instanceof Query)) continue;
      q=(Query) ce.getValue();
      key=entry.getKey();
        if(filter.accept(q.getSql().toString())){
        c.remove(key);
        }
      }
  }
View Full Code Here

    DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
    DatasourceConnection dc=pool.getDatasourceConnection(pc,((PageContextImpl)pc).getDataSource(datasourceName),null,null);
    SQLExecutor executor=SQLExecutionFactory.getInstance(dc);
   
   
    Query query;
   
    try {
      if(!dc.getDatasource().isStorage())
        throw new ApplicationException("storage usage for this datasource is disabled, you can enable this in the railo administrator.");
      query = executor.select(pc.getConfig(),pc.getCFID(),pc.getApplicationContext().getName(), dc, type,log, true);
    }
    catch (SQLException se) {
      throw Caster.toPageException(se);
    }
      finally {
        if(dc!=null) pool.releaseDatasourceConnection(dc);
      }
     
      if(query!=null && pc.getConfig().debug()) {
        boolean debugUsage=DebuggerUtil.debugQueryUsage(pc,query);
        ((DebuggerPro)pc.getDebugger()).addQuery(debugUsage?query:null,datasourceName,"",query.getSql(),query.getRecordcount(),pc.getCurrentPageSource(),query.getExecutionTime());
      }
      boolean _isNew = query.getRecordcount()==0;
     
      if(_isNew) {
        ScopeContext.info(log,"create new "+strType+" scope for "+pc.getApplicationContext().getName()+"/"+pc.getCFID()+" in datasource ["+datasourceName+"]");
      return null;
      }
      String str=Caster.toString(query.get(KeyConstants._data));
      if(mxStyle) return null;
      Struct s = (Struct)pc.evaluate(str);
      ScopeContext.info(log,"load existing data from ["+datasourceName+"."+PREFIX+"_"+strType+"_data] to create "+strType+" scope for "+pc.getApplicationContext().getName()+"/"+pc.getCFID());
   
      return s;
View Full Code Here

  public static final String PREFIX = "cf";

  @Override
  public Query select(Config config,String cfid,String applicationName,DatasourceConnection dc, int type,Log log, boolean createTableIfNotExist) throws PageException {
    String strType = VariableInterpreter.scopeInt2String(type);
    Query query=null;
      SQL sqlSelect=new SQLImpl("select data from "+PREFIX+"_"+strType+"_data where cfid=? and name=? and expires > ?"
        ,new SQLItem[]{
       new SQLItemImpl(cfid,Types.VARCHAR),
      new SQLItemImpl(applicationName,Types.VARCHAR),
      new SQLItemImpl(now(config),Types.VARCHAR)
View Full Code Here

      railo.commons.net.http.Header[] headers = rsp.getAllHeaders();
      StringBuffer raw=new StringBuffer(rsp.getStatusLine()+" ");
      Struct responseHeader = new StructImpl();
      Struct cookie;
      Array setCookie = new ArrayImpl();
      Query cookies=new QueryImpl(new String[]{"name","value","path","domain","expires","secure","httpOnly"},0,"cookies");
     
          for(int i=0;i<headers.length;i++) {
            railo.commons.net.http.Header header=headers[i];
            //print.ln(header);
           
            raw.append(header.toString()+" ");
            if(header.getName().equalsIgnoreCase("Set-Cookie")) {
              setCookie.append(header.getValue());
              parseCookie(cookies,header.getValue());
            }
            else {
                //print.ln(header.getName()+"-"+header.getValue());
              Object value=responseHeader.get(KeyImpl.getInstance(header.getName()),null);
              if(value==null) responseHeader.set(KeyImpl.getInstance(header.getName()),header.getValue());
              else {
                  Array arr=null;
                  if(value instanceof Array) {
                      arr=(Array) value;
                  }
                  else {
                      arr=new ArrayImpl();
                      responseHeader.set(KeyImpl.getInstance(header.getName()),arr);
                      arr.appendEL(value);
                  }
                  arr.appendEL(header.getValue());
              }
            }
           
            // Content-Type
            if(header.getName().equalsIgnoreCase("Content-Type")) {
              mimetype=header.getValue();
              if(mimetype==null)mimetype=NO_MIMETYPE;
            }
           
            // Content-Encoding
            if(header.getName().equalsIgnoreCase("Content-Encoding")) {
              contentEncoding=header.getValue();
            }
           
          }
          cfhttp.set(RESPONSEHEADER,responseHeader);
          cfhttp.set(KeyConstants._cookies,cookies);
          responseHeader.set(STATUS_CODE,new Double(rsp.getStatusCode()));
          responseHeader.set(EXPLANATION,(rsp.getStatusText()));
          if(setCookie.size()>0)responseHeader.set(SET_COOKIE,setCookie);
         
      // is text
          boolean isText=
            mimetype == null || 
            mimetype == NO_MIMETYPE || HTTPUtil.isTextMimeType(mimetype);
           
        // is multipart
          boolean isMultipart= MultiPartResponseUtils.isMultipart(mimetype);       
        
          cfhttp.set(KeyConstants._text,Caster.toBoolean(isText));
         
      // mimetype charset
          //boolean responseProvideCharset=false;
          if(!StringUtil.isEmpty(mimetype,true)){
            if(isText) {
              String[] types=HTTPUtil.splitMimeTypeAndCharset(mimetype,null);
              if(types[0]!=null)cfhttp.set(KeyConstants._mimetype,types[0]);
              if(types[1]!=null)cfhttp.set(CHARSET,types[1]);
                 
            }
            else cfhttp.set(KeyConstants._mimetype,mimetype);
          }
          else cfhttp.set(KeyConstants._mimetype,NO_MIMETYPE);

      // File
          Resource file=null;
         
          if(strFile!=null && strPath!=null) {
              file=ResourceUtil.toResourceNotExisting(pageContext, strPath).getRealResource(strFile);
          }
          else if(strFile!=null) {
              file=ResourceUtil.toResourceNotExisting(pageContext, strFile);
          }
          else if(strPath!=null) {
              file=ResourceUtil.toResourceNotExisting(pageContext, strPath);
              //Resource dir = file.getParentResource();
              if(file.isDirectory()){
                file=file.getRealResource(req.getURI().getPath());// TODO was getName() ->http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/URI.html#getName()
              }
             
          }
          if(file!=null)pageContext.getConfig().getSecurityManager().checkFileLocation(file);
         
         
          // filecontent
          InputStream is=null;
        if(isText && getAsBinary!=GET_AS_BINARY_YES) {
          String str;
                try {
                 
                  // read content
                  if(method!=METHOD_HEAD) {
                    is = rsp.getContentAsStream();
                      if(is!=null &&isGzipEncoded(contentEncoding))
                        is = rsp.getStatusCode()!=200? new CachingGZIPInputStream(is):new GZIPInputStream(is);
                  }   
                    try {
                      try{
                      str = is==null?"":IOUtil.toString(is,responseCharset);
                      }
                      catch(EOFException eof){
                        if(is instanceof CachingGZIPInputStream) {
                          str = IOUtil.toString(is=((CachingGZIPInputStream)is).getRawData(),responseCharset);
                        }
                        else throw eof;
                      }
                    }
                    catch (UnsupportedEncodingException uee) {
                      str = IOUtil.toString(is,(Charset)null);
                    }
                }
                catch (IOException ioe) {
                  throw Caster.toPageException(ioe);
                }
                finally {
                  IOUtil.closeEL(is);
                }
                   
                if(str==null)str="";
            if(resolveurl){
              //if(e.redirectURL!=null)url=e.redirectURL.toExternalForm();
              str=new URLResolver().transform(str,e.response.getTargetURL(),false);
            }
            cfhttp.set(FILE_CONTENT,str);
            try {
              if(file!=null){
                IOUtil.write(file,str,pageContext.getConfig().getWebCharset(),false);
                    }
                }
            catch (IOException e1) {}

            if(name!=null) {
                    Query qry = CSVParser.toQuery( str, delimiter, textqualifier, columns, firstrowasheaders  );
                    pageContext.setVariable(name,qry);
            }
        }
        // Binary
        else {
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.