Package org.apache.avalon.excalibur.datasource

Examples of org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource


            String maxPool = getPoolMax();
            perThreadPoolSet = Collections.synchronizedSet(new HashSet<ResourceLimitingJdbcDataSource>());
            if (maxPool.equals("0")){ // i.e. if we want per thread pooling
                variables.putObject(poolName, new DataSourceComponentImpl()); // pool will be created later
            } else {
                ResourceLimitingJdbcDataSource src=initPool(maxPool);
                synchronized(this){
                    excaliburSource = src;
                    variables.putObject(poolName, new DataSourceComponentImpl(excaliburSource));
                }
            }
View Full Code Here


    /*
     * Set up the DataSource - maxPool is a parameter, so the same code can
     * also be used for setting up the per-thread pools.
    */
    private ResourceLimitingJdbcDataSource initPool(String maxPool) {
        ResourceLimitingJdbcDataSource source = null;
        source = new ResourceLimitingJdbcDataSource();
        DefaultConfiguration config = new DefaultConfiguration("rl-jdbc"); // $NON-NLS-1$

        if (log.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder(40);
            sb.append("MaxPool: ");
            sb.append(maxPool);
            sb.append(" Timeout: ");
            sb.append(getTimeout());
            sb.append(" TrimInt: ");
            sb.append(getTrimInterval());
            sb.append(" Auto-Commit: ");
            sb.append(isAutocommit());
            log.debug(sb.toString());
        }
        DefaultConfiguration poolController = new DefaultConfiguration("pool-controller"); // $NON-NLS-1$
        poolController.setAttribute("max", maxPool); // $NON-NLS-1$
        poolController.setAttribute("max-strict", "true"); // $NON-NLS-1$ $NON-NLS-2$
        poolController.setAttribute("blocking", "true"); // $NON-NLS-1$ $NON-NLS-2$
        poolController.setAttribute("timeout", getTimeout()); // $NON-NLS-1$
        poolController.setAttribute("trim-interval", getTrimInterval()); // $NON-NLS-1$
        config.addChild(poolController);

        DefaultConfiguration autoCommit = new DefaultConfiguration("auto-commit"); // $NON-NLS-1$
        autoCommit.setValue(String.valueOf(isAutocommit()));
        config.addChild(autoCommit);

        if (log.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder(40);
            sb.append("KeepAlive: ");
            sb.append(isKeepAlive());
            sb.append(" Age: ");
            sb.append(getConnectionAge());
            sb.append(" CheckQuery: ");
            sb.append(getCheckQuery());
            log.debug(sb.toString());
        }
        DefaultConfiguration cfgKeepAlive = new DefaultConfiguration("keep-alive"); // $NON-NLS-1$
        cfgKeepAlive.setAttribute("disable", String.valueOf(!isKeepAlive())); // $NON-NLS-1$
        cfgKeepAlive.setAttribute("age", getConnectionAge()); // $NON-NLS-1$
        cfgKeepAlive.setValue(getCheckQuery());
        poolController.addChild(cfgKeepAlive);

        String _username = getUsername();
        if (log.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder(40);
            sb.append("Driver: ");
            sb.append(getDriver());
            sb.append(" DbUrl: ");
            sb.append(getDbUrl());
            sb.append(" User: ");
            sb.append(_username);
            log.debug(sb.toString());
        }
        DefaultConfiguration cfgDriver = new DefaultConfiguration("driver"); // $NON-NLS-1$
        cfgDriver.setValue(getDriver());
        config.addChild(cfgDriver);
        DefaultConfiguration cfgDbUrl = new DefaultConfiguration("dburl"); // $NON-NLS-1$
        cfgDbUrl.setValue(getDbUrl());
        config.addChild(cfgDbUrl);

        if (_username.length() > 0){
            DefaultConfiguration cfgUsername = new DefaultConfiguration("user"); // $NON-NLS-1$
            cfgUsername.setValue(_username);
            config.addChild(cfgUsername);
            DefaultConfiguration cfgPassword = new DefaultConfiguration("password"); // $NON-NLS-1$
            cfgPassword.setValue(getPassword());
            config.addChild(cfgPassword);
        }

        // log is required to ensure errors are available
        source.enableLogging(new LogKitLogger(log));
        try {
            source.configure(config);
            source.setInstrumentableName(getDataSource());
        } catch (ConfigurationException e) {
            log.error("Could not configure datasource for pool: "+getDataSource(),e);
        }
        return source;
    }
View Full Code Here

        }

        @Override
        public Connection getConnection() throws SQLException {
            Connection conn = null;
            ResourceLimitingJdbcDataSource dsc = null;
            if (sharedDSC != null){ // i.e. shared pool
                dsc = sharedDSC;
            } else {
                Map<String, ResourceLimitingJdbcDataSource> poolMap = perThreadPoolMap.get();
                dsc = poolMap.get(getDataSource());
                if (dsc == null){
                    dsc = initPool("1");
                    poolMap.put(getDataSource(),dsc);
                    log.debug("Storing pool: "+dsc.getInstrumentableName()+" @"+System.identityHashCode(dsc));
                    perThreadPoolSet.add(dsc);
                }
            }
            if (dsc != null) {
                conn=dsc.getConnection();
                int transactionIsolation = DataSourceElementBeanInfo.getTransactionIsolationMode(getTransactionIsolation());
                if (transactionIsolation >= 0 && conn.getTransactionIsolation() != transactionIsolation) {
                    try {
                        // make sure setting the new isolation mode is done in an auto committed transaction
                        conn.setTransactionIsolation(transactionIsolation);
View Full Code Here

        excaliburSource = null;
    }
    if (perThreadPoolSet != null) {// in case
      Iterator it = perThreadPoolSet.iterator();
      while(it.hasNext()){
        ResourceLimitingJdbcDataSource dsc = (ResourceLimitingJdbcDataSource)it.next();
        log.debug("Disposing pool: "+dsc.getInstrumentableName()+" @"+System.identityHashCode(dsc));
        dsc.dispose();
      }
      perThreadPoolSet.clear();
    }
  }
View Full Code Here

    } else {
      String maxPool = getPoolMax();
      if (maxPool.equals("0")){ // i.e. if we want per thread pooling
        variables.putObject(poolName, new DataSourceComponentImpl()); // pool will be created later
      } else {
        ResourceLimitingJdbcDataSource src=initPool(maxPool);
        synchronized(this){
          excaliburSource = src;
            variables.putObject(poolName, new DataSourceComponentImpl(excaliburSource));
        }
      }
View Full Code Here

  /*
   * Set up the DataSource - maxPool is a parameter, so the same code can
   * also be used for setting up the per-thread pools.
  */
  private ResourceLimitingJdbcDataSource initPool(String maxPool) {
    ResourceLimitingJdbcDataSource source = null;
    source = new ResourceLimitingJdbcDataSource();
    DefaultConfiguration config = new DefaultConfiguration("rl-jdbc"); // $NON-NLS-1$

    if (log.isDebugEnabled()) {
      StringBuffer sb = new StringBuffer(40);
      sb.append("MaxPool: ");
      sb.append(maxPool);
      sb.append(" Timeout: ");
      sb.append(getTimeout());
      sb.append(" TrimInt: ");
      sb.append(getTrimInterval());
      sb.append(" Auto-Commit: ");
      sb.append(isAutocommit());
      log.debug(sb.toString());
    }
    DefaultConfiguration poolController = new DefaultConfiguration("pool-controller"); // $NON-NLS-1$
    poolController.setAttribute("max", maxPool); // $NON-NLS-1$
    poolController.setAttribute("max-strict", "true"); // $NON-NLS-1$ $NON-NLS-2$
    poolController.setAttribute("blocking", "true"); // $NON-NLS-1$ $NON-NLS-2$
    poolController.setAttribute("timeout", getTimeout()); // $NON-NLS-1$
    poolController.setAttribute("trim-interval", getTrimInterval()); // $NON-NLS-1$
    config.addChild(poolController);

    DefaultConfiguration autoCommit = new DefaultConfiguration("auto-commit"); // $NON-NLS-1$
    autoCommit.setValue(String.valueOf(isAutocommit()));
    config.addChild(autoCommit);
   
    if (log.isDebugEnabled()) {
      StringBuffer sb = new StringBuffer(40);
      sb.append("KeepAlive: ");
      sb.append(isKeepAlive());
      sb.append(" Age: ");
      sb.append(getConnectionAge());
      sb.append(" CheckQuery: ");
      sb.append(getCheckQuery());
      log.debug(sb.toString());
    }
    DefaultConfiguration cfgKeepAlive = new DefaultConfiguration("keep-alive"); // $NON-NLS-1$
    cfgKeepAlive.setAttribute("disable", String.valueOf(!isKeepAlive())); // $NON-NLS-1$
    cfgKeepAlive.setAttribute("age", getConnectionAge()); // $NON-NLS-1$
    cfgKeepAlive.setValue(getCheckQuery());
    poolController.addChild(cfgKeepAlive);

    String _username = getUsername();
    if (log.isDebugEnabled()) {
      StringBuffer sb = new StringBuffer(40);
      sb.append("Driver: ");
      sb.append(getDriver());
      sb.append(" DbUrl: ");
      sb.append(getDbUrl());
      sb.append(" User: ");
      sb.append(_username);
      log.debug(sb.toString());
    }
    DefaultConfiguration cfgDriver = new DefaultConfiguration("driver"); // $NON-NLS-1$
    cfgDriver.setValue(getDriver());
    config.addChild(cfgDriver);
    DefaultConfiguration cfgDbUrl = new DefaultConfiguration("dburl"); // $NON-NLS-1$
    cfgDbUrl.setValue(getDbUrl());
    config.addChild(cfgDbUrl);

    if (_username.length() > 0){
      DefaultConfiguration cfgUsername = new DefaultConfiguration("user"); // $NON-NLS-1$
      cfgUsername.setValue(_username);
      config.addChild(cfgUsername);
      DefaultConfiguration cfgPassword = new DefaultConfiguration("password"); // $NON-NLS-1$
      cfgPassword.setValue(getPassword());
      config.addChild(cfgPassword);
    }

    // log is required to ensure errors are available
    source.enableLogging(new LogKitLogger(log));
    try {
      source.configure(config);
      source.setInstrumentableName(getDataSource());
    } catch (ConfigurationException e) {
      log.error("Could not configure datasource for pool: "+getDataSource(),e);
    }
    return source;
  }
View Full Code Here

      sharedDSC=p_dsc;
    }

    public Connection getConnection() throws SQLException {
      Connection conn = null;
      ResourceLimitingJdbcDataSource dsc = null;
      if (sharedDSC != null){ // i.e. shared pool
        dsc = sharedDSC;
      } else {
        Map poolMap = (Map) perThreadPoolMap.get();
        dsc = (ResourceLimitingJdbcDataSource) poolMap.get(getDataSource());
        if (dsc == null){
          dsc = initPool("1");
          poolMap.put(getDataSource(),dsc);
          log.debug("Storing pool: "+dsc.getInstrumentableName()+" @"+System.identityHashCode(dsc));
          perThreadPoolSet.add(dsc);
        }
      }
      if (dsc != null) {
          conn=dsc.getConnection();
      }
      return conn;
    }
View Full Code Here

    el.started = started;
    return el;
  }

  private void initPool() throws Exception {
    excaliburSource = new ResourceLimitingJdbcDataSource();
    DefaultConfiguration config = new DefaultConfiguration("rl-jdbc");

    if (log.isDebugEnabled()) {
      StringBuffer sb = new StringBuffer(40);
      sb.append("MaxPool: ");
View Full Code Here

            String maxPool = getPoolMax();
            perThreadPoolSet = Collections.synchronizedSet(new HashSet<ResourceLimitingJdbcDataSource>());
            if (maxPool.equals("0")){ // i.e. if we want per thread pooling
                variables.putObject(poolName, new DataSourceComponentImpl()); // pool will be created later
            } else {
                ResourceLimitingJdbcDataSource src=initPool(maxPool);
                synchronized(this){
                    excaliburSource = src;
                    variables.putObject(poolName, new DataSourceComponentImpl(excaliburSource));
                }
            }
View Full Code Here

    /*
     * Set up the DataSource - maxPool is a parameter, so the same code can
     * also be used for setting up the per-thread pools.
    */
    private ResourceLimitingJdbcDataSource initPool(String maxPool) {
        ResourceLimitingJdbcDataSource source = null;
        source = new ResourceLimitingJdbcDataSource();
        DefaultConfiguration config = new DefaultConfiguration("rl-jdbc"); // $NON-NLS-1$

        if (log.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder(40);
            sb.append("MaxPool: ");
            sb.append(maxPool);
            sb.append(" Timeout: ");
            sb.append(getTimeout());
            sb.append(" TrimInt: ");
            sb.append(getTrimInterval());
            sb.append(" Auto-Commit: ");
            sb.append(isAutocommit());
            log.debug(sb.toString());
        }
        DefaultConfiguration poolController = new DefaultConfiguration("pool-controller"); // $NON-NLS-1$
        poolController.setAttribute("max", maxPool); // $NON-NLS-1$
        poolController.setAttribute("max-strict", "true"); // $NON-NLS-1$ $NON-NLS-2$
        poolController.setAttribute("blocking", "true"); // $NON-NLS-1$ $NON-NLS-2$
        poolController.setAttribute("timeout", getTimeout()); // $NON-NLS-1$
        poolController.setAttribute("trim-interval", getTrimInterval()); // $NON-NLS-1$
        config.addChild(poolController);

        DefaultConfiguration autoCommit = new DefaultConfiguration("auto-commit"); // $NON-NLS-1$
        autoCommit.setValue(String.valueOf(isAutocommit()));
        config.addChild(autoCommit);

        if (log.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder(40);
            sb.append("KeepAlive: ");
            sb.append(isKeepAlive());
            sb.append(" Age: ");
            sb.append(getConnectionAge());
            sb.append(" CheckQuery: ");
            sb.append(getCheckQuery());
            log.debug(sb.toString());
        }
        DefaultConfiguration cfgKeepAlive = new DefaultConfiguration("keep-alive"); // $NON-NLS-1$
        cfgKeepAlive.setAttribute("disable", String.valueOf(!isKeepAlive())); // $NON-NLS-1$
        cfgKeepAlive.setAttribute("age", getConnectionAge()); // $NON-NLS-1$
        cfgKeepAlive.setValue(getCheckQuery());
        poolController.addChild(cfgKeepAlive);

        String _username = getUsername();
        if (log.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder(40);
            sb.append("Driver: ");
            sb.append(getDriver());
            sb.append(" DbUrl: ");
            sb.append(getDbUrl());
            sb.append(" User: ");
            sb.append(_username);
            log.debug(sb.toString());
        }
        DefaultConfiguration cfgDriver = new DefaultConfiguration("driver"); // $NON-NLS-1$
        cfgDriver.setValue(getDriver());
        config.addChild(cfgDriver);
        DefaultConfiguration cfgDbUrl = new DefaultConfiguration("dburl"); // $NON-NLS-1$
        cfgDbUrl.setValue(getDbUrl());
        config.addChild(cfgDbUrl);

        if (_username.length() > 0){
            DefaultConfiguration cfgUsername = new DefaultConfiguration("user"); // $NON-NLS-1$
            cfgUsername.setValue(_username);
            config.addChild(cfgUsername);
            DefaultConfiguration cfgPassword = new DefaultConfiguration("password"); // $NON-NLS-1$
            cfgPassword.setValue(getPassword());
            config.addChild(cfgPassword);
        }

        // log is required to ensure errors are available
        source.enableLogging(new LogKitLogger(log));
        try {
            source.configure(config);
            source.setInstrumentableName(getDataSource());
        } catch (ConfigurationException e) {
            log.error("Could not configure datasource for pool: "+getDataSource(),e);
        }
        return source;
    }
View Full Code Here

TOP

Related Classes of org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource

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.