Package railo.runtime.db

Examples of railo.runtime.db.SQL


      comment.append( " (showing top " ).append( Caster.toString( top ) ).append( ")" );
    comment.append("\n");
    comment.append("Cached: ").append(query.isCached()?"Yes\n":"No\n");
    comment.append("Lazy: ").append(query instanceof SimpleQuery?"Yes\n":"No\n");
   
    SQL sql=query.getSql();
    if(sql!=null)
      comment.append("SQL: ").append("\n").append(StringUtil.suppressWhiteSpace(sql.toString().trim())).append("\n");
   
    //table.appendRow(1, new SimpleDumpData("Execution Time (ms)"), new SimpleDumpData(exeTime));
    //table.appendRow(1, new SimpleDumpData("recordcount"), new SimpleDumpData(getRecordcount()));
    //table.appendRow(1, new SimpleDumpData("cached"), new SimpleDumpData(isCached()?"Yes":"No"));
View Full Code Here


  @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)
    });
     
      PageContext pc = ThreadLocalPageContext.get();
   
    try {
      query = new QueryImpl(pc,dc,sqlSelect,-1,-1,-1,"query");
    }
      catch (DatabaseException de) {
        if(dc==null || !createTableIfNotExist) throw de;
        try {
          SQL sql = createSQL(dc,"text",strType);
          ScopeContext.info(log,sql.toString());
        new QueryImpl(pc,dc,sql,-1,-1,-1,"query");
        }
        catch (DatabaseException _de) {
          try {
            SQL sql = createSQL(dc,"memo",strType);
            ScopeContext.info(log,sql.toString());
          new QueryImpl(pc,dc,sql,-1,-1,-1,"query");
          }
          catch (DatabaseException __de) {
            SQL sql = createSQL(dc,"clob",strType);
            ScopeContext.info(log,sql.toString());
            new QueryImpl(pc,dc,sql,-1,-1,-1,"query");
          }
        }
        query = new QueryImpl(pc,dc,sqlSelect,-1,-1,-1,"query");
    }
View Full Code Here

  @Override
  public void clean(Config config, DatasourceConnection dc, int type,StorageScopeEngine engine,DatasourceStorageScopeCleaner cleaner,StorageScopeListener listener, Log log) throws PageException {
    String strType = VariableInterpreter.scopeInt2String(type);
    // select
      SQL sqlSelect=new SQLImpl("select cfid,name from "+PREFIX+"_"+strType+"_data where expires<=?"
            ,new SQLItem[]{
           new SQLItemImpl(System.currentTimeMillis(),Types.VARCHAR)
        });
      QueryImpl query;
      try{
View Full Code Here

        catch(SQLException se){
          meta=new StructImpl();
        }
       
       
        SQL sql=createSQL(meta);
      if(sql!=null) {
        railo.runtime.type.Query query = new QueryImpl(pageContext,dc,sql,-1,-1,-1,"query");
       
        if(pageContext.getConfig().debug()) {
          String dsn=ds instanceof DataSource?((DataSource)ds).getName():Caster.toString(ds);
View Full Code Here

        catch(SQLException se){
          meta=new StructImpl();
        }
     
        String[] pKeys=getPrimaryKeys(dc);
      SQL sql=createSQL(dc,pKeys,meta);
      if(sql!=null) {
        railo.runtime.type.Query query = new QueryImpl(pageContext,dc,sql,-1,-1,-1,"query");
       
        if(pageContext.getConfig().debug()) {
          String dsn=ds instanceof DataSource?((DataSource)ds).getName():Caster.toString(ds);
View Full Code Here

      throw new DatabaseException("no sql string defined, inside query tag",null,null,null);
    // cannot use attribute params and queryparam tag
    if(items.size()>0 && params!=null)
      throw new DatabaseException("you cannot use the attribute params and sub tags queryparam at the same time",null,null,null);
    // create SQL
    SQL sql;
    if(params!=null) {
      if(Decision.isArray(params))
        sql=QueryParamConverter.convert(strSQL, Caster.toArray(params));
      else if(Decision.isStruct(params))
        sql=QueryParamConverter.convert(strSQL, Caster.toStruct(params));
      else
        throw new DatabaseException("value of the attribute [params] has to be a struct or a array",null,null,null);
    }
    else sql=items.size()>0?new SQLImpl(strSQL,items.toArray(new SQLItem[items.size()])):new SQLImpl(strSQL);
   
    railo.runtime.type.Query query=null;
    long exe=0;
    boolean hasCached=cachedWithin!=null || cachedafter!=null;
   
   
    if(clearCache) {
      hasCached=false;
      pageContext.getQueryCache().remove(pageContext,sql,datasource!=null?datasource.getName():null,username,password);
    }
    else if(hasCached) {
      query=pageContext.getQueryCache().getQuery(pageContext,sql,datasource!=null?datasource.getName():null,username,password,cachedafter);
    }
   
   
    if(query==null) {
      if("query".equals(dbtype))     query=executeQoQ(sql);
      else if("orm".equals(dbtype) || "hql".equals(dbtype))   {
        long start=System.nanoTime();
        Object obj = executeORM(sql,returntype,ormoptions);
       
        if(obj instanceof railo.runtime.type.Query){
          query=(railo.runtime.type.Query) obj;
        }
        else {
          if(!StringUtil.isEmpty(name)) {
            pageContext.setVariable(name,obj);
          }
          if(result!=null){
            Struct sct=new StructImpl();
            sct.setEL(KeyConstants._cached, Boolean.FALSE);
            long time=System.nanoTime()-start;
            sct.setEL(KeyConstants._executionTime, Caster.toDouble(time/1000000));
            sct.setEL(KeyConstants._executionTimeNano, Caster.toDouble(time));
            sct.setEL(KeyConstants._SQL, sql.getSQLString());
            if(Decision.isArray(obj)){
             
            }
            else sct.setEL(KeyConstants._RECORDCOUNT, Caster.toDouble(1));
             
            pageContext.setVariable(result, sct);
          }
          else
            setExecutionTime((System.nanoTime()-start)/1000000);
          return EVAL_PAGE;
        }
      }
      else query=executeDatasoure(sql,result!=null,pageContext.getTimeZone());
      //query=(dbtype!=null && dbtype.equals("query"))?executeQoQ(sql):executeDatasoure(sql,result!=null);
     
      if(cachedWithin!=null) {
        DateTimeImpl cachedBefore = null;
        //if(cachedWithin!=null)
          cachedBefore=new DateTimeImpl(pageContext,System.currentTimeMillis()+cachedWithin.getMillis(),false);
                  pageContext.getQueryCache().set(pageContext,sql,datasource!=null?datasource.getName():null,username,password,query,cachedBefore);
               
               
      }
      exe=query.getExecutionTime();
    }
        else query.setCached(hasCached);
   
    if(pageContext.getConfig().debug() && debug) {
      boolean logdb=((ConfigImpl)pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
      if(logdb){
        boolean debugUsage=DebuggerUtil.debugQueryUsage(pageContext,query);
        ((DebuggerPro)pageContext.getDebugger()).addQuery(debugUsage?query:null,datasource!=null?datasource.getName():null,name,sql,query.getRecordcount(),pageContext.getCurrentPageSource(),exe);
      }
    }
   
    if(!query.isEmpty() && !StringUtil.isEmpty(name)) {
      pageContext.setVariable(name,query);
    }
   
    // Result
    if(result!=null) {
     
      Struct sct=new StructImpl();
      sct.setEL(KeyConstants._cached, Caster.toBoolean(query.isCached()));
      if(!query.isEmpty())sct.setEL(KeyConstants._COLUMNLIST, ListUtil.arrayToList(query.getColumnNamesAsString(),","));
      int rc=query.getRecordcount();
      if(rc==0)rc=query.getUpdateCount();
      sct.setEL(KeyConstants._RECORDCOUNT, Caster.toDouble(rc));
      sct.setEL(KeyConstants._executionTime, Caster.toDouble(query.getExecutionTime()/1000000));
      sct.setEL(KeyConstants._executionTimeNano, Caster.toDouble(query.getExecutionTime()));
     
      sct.setEL(KeyConstants._SQL, sql.getSQLString());
     
      // GENERATED KEYS
      railo.runtime.type.Query qi = Caster.toQuery(query,null);
      if(qi !=null){
        railo.runtime.type.Query qryKeys = qi.getGeneratedKeys();
        if(qryKeys!=null){
          StringBuilder generatedKey=new StringBuilder(),sb;
          Collection.Key[] columnNames = qryKeys.getColumnNames();
          QueryColumn column;
          for(int c=0;c<columnNames.length;c++){
            column = qryKeys.getColumn(columnNames[c]);
            sb=new StringBuilder();
            int size=column.size();
            for(int row=1;row<=size;row++) {
              if(row>1)sb.append(',');
              sb.append(Caster.toString(column.get(row,null)));
            }
            if(sb.length()>0){
              sct.setEL(columnNames[c], sb.toString());
              if(generatedKey.length()>0)generatedKey.append(',');
              generatedKey.append(sb);
            }
          }
          if(generatedKey.length()>0)
            sct.setEL(GENERATEDKEY, generatedKey.toString());
        }
      }
     
      // sqlparameters
      SQLItem[] params = sql.getItems();
      if(params!=null && params.length>0) {
        Array arr=new ArrayImpl();
        sct.setEL(SQL_PARAMETERS, arr);
        for(int i=0;i<params.length;i++) {
          arr.append(params[i].getValue());
View Full Code Here

  public static Query call(PageContext pc, String strSQL, Object params, String datasource) throws PageException {
   
    railo.runtime.tag.Query qry=new railo.runtime.tag.Query();
   
    if(params!=null) {
      SQL sql;
      if(Decision.isArray(params))
        sql=QueryParamConverter.convert(strSQL, Caster.toArray(params));
      else if(Decision.isStruct(params))
        sql=QueryParamConverter.convert(strSQL, Caster.toStruct(params));
      else
View Full Code Here

TOP

Related Classes of railo.runtime.db.SQL

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.