Package railo.runtime.db

Examples of railo.runtime.db.DataSourceManager


        else throw new DatabaseException("transaction has an invalid isolation level (attribute isolation, valid values are [read_uncommitted,read_committed,repeatable_read,serializable])",null,null,null);
    }

    @Override
    public int doStartTag() throws PageException {
      DataSourceManager manager = pageContext.getDataSourceManager();
        // first transaction
        if(manager.isAutoCommit()) {
            //if(!hasBody)throw new DatabaseException("transaction tag with no end Tag can only be used inside a transaction tag",null,null,null);
            manager.begin(isolation);
            return EVAL_BODY_INCLUDE;
        }
        // inside transaction
        innerTag=true;
        switch(action){
        /* nested transaction no longer throw a exception, they are simply ignored
        case ACTION_NONE:
          throw new DatabaseException("you can't have a nested transaction with no action defined",null,null,null);
        case ACTION_BEGIN:
            throw new DatabaseException("you can't start a transaction inside a transaction tag",null,null,null);
        */
        case ACTION_NONE:
        case ACTION_BEGIN:
            ignore=true;
            break;
       
        case ACTION_COMMIT:
          manager.commit();
        break;
        case ACTION_ROLLBACK:
          manager.rollback();
        break;
        case ACTION_SET_SAVEPOINT:
           ((DatasourceManagerImpl)manager).savepoint();
        break;
        }
View Full Code Here


   
    @Override
    public void doCatch(Throwable t) throws Throwable {
      if(innerTag || ignore) throw t;
       
      DataSourceManager manager = pageContext.getDataSourceManager();
        try {
            manager.rollback();
        } catch (DatabaseException e) {
          //print.printST(e);
        }
        throw t;
    }
View Full Code Here

    }
   
   
   
      Struct res=new StructImpl();
    DataSourceManager manager = pageContext.getDataSourceManager();
    DatasourceConnection dc = ds instanceof DataSource?
        manager.getConnection(pageContext,(DataSource)ds,username,password):
        manager.getConnection(pageContext,Caster.toString(ds),username,password);
   
    // create returnValue
    returnValue(dc);
   
    // create SQL
    StringBuilder sql=createSQL();
   

    // add returnValue to params
    if(returnValue!=null){
      params.add(0,returnValue);
    }
   
    SQLImpl _sql=new SQLImpl(sql.toString());
    CallableStatement callStat=null;
    try {
        callStat = dc.getConnection().prepareCall(sql.toString());
            //ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            //ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       
        if(blockfactor>0)callStat.setFetchSize(blockfactor);
        if(timeout>0)callStat.setQueryTimeout(timeout);
       
  // set IN register OUT
        Iterator<ProcParamBean> it = params.iterator();
      ProcParamBean param;
      int index=1;
        while(it.hasNext()) {
          param= it.next();
          param.setIndex(index);
          _sql.addItems(new SQLItemImpl(param.getValue()));
          if(param.getDirection()!=ProcParamBean.DIRECTION_OUT) {
            SQLCaster.setValue(pageContext.getTimeZone(),callStat, index, param);
          }
          if(param.getDirection()!=ProcParamBean.DIRECTION_IN) {
            registerOutParameter(callStat,param);
          }
          index++;
      }
       
  // cache
        boolean isFromCache=false;
        boolean hasCached=cachedbefore!=null || cachedafter!=null;
        Object cacheValue=null;
        String dsn = ds instanceof DataSource?((DataSource)ds).getName():Caster.toString(ds);
      if(clearCache) {
        hasCached=false;
        pageContext.getQueryCache().remove(pageContext,_sql,dsn,username,password);
      }
      else if(hasCached) {
        cacheValue = pageContext.getQueryCache().get(pageContext,_sql,dsn,username,password,cachedafter);
      }
      int count=0;
      if(cacheValue==null){
        // execute
        boolean isResult=callStat.execute();
       
          Struct cache=hasCached?new StructImpl():null;
 
          // resultsets
          ProcResultBean result;
         
          index=1;
        do {
            if(isResult){
              ResultSet rs=callStat.getResultSet();
              if(rs!=null) {
              try{
                result=(ProcResultBean) results.get(index++,null);
                if(result!=null) {
                  railo.runtime.type.Query q = new QueryImpl(rs,result.getMaxrows(),result.getName(),pageContext.getTimeZone())
                  count+=q.getRecordcount();
                  setVariable(result.getName(), q);
                  if(hasCached)cache.set(KeyImpl.getInstance(result.getName()), q);
                }
              }
              finally{
                IOUtil.closeEL(rs);
              }
            }
            }
          }
          while((isResult=callStat.getMoreResults()) || (callStat.getUpdateCount() != -1));

          // params
          it = params.iterator();
          while(it.hasNext()) {
            param= it.next();
            if(param.getDirection()!=ProcParamBean.DIRECTION_IN){
              Object value=null;
              if(!StringUtil.isEmpty(param.getVariable())){
                try{
                  value=SQLCaster.toCFType(callStat.getObject(param.getIndex()));
                }
                catch(Throwable t){}
                value=emptyIfNull(value);
               
                if(param==STATUS_CODE) res.set(STATUSCODE, value);
                else setVariable(param.getVariable(), value);
                if(hasCached)cache.set(KeyImpl.getInstance(param.getVariable()), value);
              }
            }
        }
          if(hasCached){
            cache.set(COUNT, Caster.toDouble(count));
            pageContext.getQueryCache().set(pageContext,_sql,dsn,username,password,cache,cachedbefore);
          }
         
      }
      else if(cacheValue instanceof Struct) {
        Struct sctCache = (Struct) cacheValue;
        count=Caster.toIntValue(sctCache.removeEL(COUNT),0);
       
        Iterator<Entry<Key, Object>> cit = sctCache.entryIterator();
        Entry<Key, Object> ce;
        while(cit.hasNext()){
          ce = cit.next();
          if(STATUS_CODE.getVariable().equals(ce.getKey().getString()))
            res.set(KEY_SC, ce.getValue());
          else setVariable(ce.getKey().getString(), ce.getValue());
        }
        isFromCache=true;
      }
     
        // result
        long exe;
       
        setVariable(this.result, res);
        res.set(KeyConstants._executionTime,Caster.toDouble(exe=(System.nanoTime()-startNS)));
        res.set(KeyConstants._cached,Caster.toBoolean(isFromCache));
       
        if(pageContext.getConfig().debug() && debug) {
          boolean logdb=((ConfigImpl)pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
        if(logdb)
          pageContext.getDebugger().addQuery(null,dsn,procedure,_sql,count,pageContext.getCurrentPageSource(),(int)exe);
      }
       
       
    }
    catch (SQLException e) {
        throw new DatabaseException(e,new SQLImpl(sql.toString()),dc);
    }
    finally {
        if(callStat!=null){
          try {
          callStat.close();
        } catch (SQLException e) {}
        }
        manager.releaseConnection(pageContext,dc);
    }
    return EVAL_PAGE;
  }
View Full Code Here

  public int doEndTag() throws PageException  {
    Object ds=getDatasource(pageContext,datasource);
   
   
   
    DataSourceManager manager = pageContext.getDataSourceManager();
      DatasourceConnection dc=ds instanceof DataSource?
          manager.getConnection(pageContext,(DataSource)ds,username,password):
          manager.getConnection(pageContext,Caster.toString(ds),username,password);
      try {
       
        Struct meta =null;
        try {
          meta=getMeta(dc,tablequalifier,tableowner,tablename);
        }
        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);
          boolean logdb=((ConfigImpl)pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
          if(logdb) {
            boolean debugUsage=DebuggerUtil.debugQueryUsage(pageContext,query);
            ((DebuggerPro)pageContext.getDebugger()).addQuery(debugUsage?query:null,dsn,"",sql,query.getRecordcount(),pageContext.getCurrentPageSource(),query.getExecutionTime());
          }
        }
      }
      return EVAL_PAGE;
      }
      finally {
        manager.releaseConnection(pageContext,dc);
      }
  }
View Full Code Here


  @Override
  public int doStartTag() throws PageException  {
    Object ds=getDatasource(pageContext, datasource);
    DataSourceManager manager = pageContext.getDataSourceManager();
    DatasourceConnection dc=ds instanceof DataSource?
          manager.getConnection(pageContext,(DataSource)ds,username,password):
          manager.getConnection(pageContext,Caster.toString(ds),username,password);
    try {
     
      if(type==TYPE_TABLE_COLUMNStypeColumns(dc.getConnection().getMetaData());
      else if(type==TYPE_DBNAMES)    typeDBNames(dc.getConnection().getMetaData());
      else if(type==TYPE_FOREIGNKEYStypeForeignKeys(dc.getConnection().getMetaData());
      else if(type==TYPE_INDEX)    typeIndex(dc.getConnection().getMetaData());
      else if(type==TYPE_PROCEDUREStypeProcedures(dc.getConnection().getMetaData());
      else if(type==TYPE_PROCEDURE_COLUMNS)typeProcedureColumns(dc.getConnection().getMetaData());
      else if(type==TYPE_TERMS)    typeTerms(dc.getConnection().getMetaData());
      else if(type==TYPE_TABLES)    typeTables(dc.getConnection().getMetaData());
      else if(type==TYPE_VERSION)    typeVersion(dc.getConnection().getMetaData());
      else if(type==TYPE_USERS)    typeUsers(dc.getConnection().getMetaData());
     
    }
    catch(SQLException sqle) {
      throw new DatabaseException(sqle,dc);
    }
    finally {
      manager.releaseConnection(pageContext,dc);
    }
   
   
               
      
View Full Code Here

  @Override
  public int doEndTag() throws PageException  {

    Object ds=Insert.getDatasource(pageContext,datasource);
   
    DataSourceManager manager = pageContext.getDataSourceManager();
      DatasourceConnection dc=ds instanceof DataSource?
          manager.getConnection(pageContext,(DataSource)ds,username,password):
          manager.getConnection(pageContext,Caster.toString(ds),username,password);
    try {
     
      Struct meta =null;
        try {
          meta=Insert.getMeta(dc,tablequalifier,tableowner,tablename);
        }
        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);
          boolean logdb=((ConfigImpl)pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
          if(logdb){
            boolean debugUsage=DebuggerUtil.debugQueryUsage(pageContext,query);
            ((DebuggerPro)pageContext.getDebugger()).addQuery(debugUsage?query:null,dsn,"",sql,query.getRecordcount(),pageContext.getCurrentPageSource(),query.getExecutionTime());
          }
        }
      }
      return EVAL_PAGE;
    }
    finally {
      manager.releaseConnection(pageContext,dc);
    }
  }
View Full Code Here

                throw new DatabaseException("class ["+clazz.getName()+"] is not a JDBC Driver","class must implement interface [java.sql.Driver]",null,null);
        getConnection(dsn, username, password);
    }

    private void _doVerifyDatasource(String name, String username, String password) throws PageException {
      DataSourceManager manager = pageContext.getDataSourceManager();
      manager.releaseConnection(pageContext,manager.getConnection(pageContext,name, username, password));
        //config.getConnection(name, username, password);
    }
View Full Code Here

  public boolean verifyDatasource(String name) throws SQLException, SecurityException {
    checkReadAccess();
    railo.runtime.db.DataSource d = _getDatasource(name);
    PageContext pc = pc();
    DataSourceManager manager = pc.getDataSourceManager();
      try {
      manager.releaseConnection(pc,manager.getConnection(pc,name, d.getUsername(), d.getPassword()));
      return true;
    } catch (PageException e) {
      return false;
    }
  }
View Full Code Here

TOP

Related Classes of railo.runtime.db.DataSourceManager

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.