Package org.apache.commons.dbcp

Examples of org.apache.commons.dbcp.PoolingDataSource


    // factory to this.  (So despite how it may appear, all of the objects
    // declared in this method are incorporated into the returned result.)
    //
    new PoolableConnectionFactory(
        connectionFactory, connectionPool, null, null, false, true);
    return new PoolingDataSource(connectionPool);
  }
View Full Code Here


    objectPool.setTestWhileIdle(true);
    objectPool.setTimeBetweenEvictionRunsMillis(60 * 1000L);
    PoolableObjectFactory factory = new PoolableConnectionFactory(connectionFactory, objectPool, null,
        "SELECT 1", false, false);
    objectPool.setFactory(factory);
    delegate = new PoolingDataSource(objectPool);
  }
View Full Code Here

           
            ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, user, password);
           
            dsConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
           
            dataSource = new PoolingDataSource(connectionPool);           
           
            log.info("DBCPCDatasourceComponent successfuly started!");
        }
        catch (Throwable e)
        {
View Full Code Here

      else
      {
        whenExhaustedActionType = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
      }

      final PoolingDataSource poolingDataSource = new PoolingDataSource();
      final Driver driver = ObjectUtilities.loadAndInstantiate(driverClass, PooledDatasourceHelper.class, Driver.class);

      // As the name says, this is a generic pool; it returns  basic Object-class objects.
      final GenericObjectPool pool = new GenericObjectPool(null);
      pool.setWhenExhaustedAction(whenExhaustedActionType);

      // Tuning the connection pool
      pool.setMaxActive(maxActiveConnection);
      pool.setMaxIdle(maxIdleConnection);
      pool.setMaxWait(waitTime);
      pool.setMinIdle(minIdleConnection);
      pool.setTestWhileIdle(testWhileIdle);
      pool.setTestOnReturn(testOnReturn);
      pool.setTestOnBorrow(testOnBorrow);
      pool.setTestWhileIdle(testWhileIdle);
      /*
      ConnectionFactory creates connections on behalf of the pool.
      Here, we use the DriverManagerConnectionFactory because that essentially
      uses DriverManager as the source of connections.
      */
      final Properties properties = new Properties();
      properties.setProperty("user", databaseConnection.getUsername());
      properties.setProperty("password", databaseConnection.getPassword());
      final ConnectionFactory factory = new DriverConnectionFactory(driver, url, properties);

      /*
      Puts pool-specific wrappers on factory connections.  For clarification:
      "[PoolableConnection]Factory," not "Poolable[ConnectionFactory]."
      */
      // This declaration is used implicitly.
      //noinspection UnusedDeclaration
      final PoolableConnectionFactory pcf = new PoolableConnectionFactory(factory, // ConnectionFactory
          pool, // ObjectPool
          null, // KeyedObjectPoolFactory
          validQuery, // String (validation query)
          false, // boolean (default to read-only?)
          true // boolean (default to auto-commit statements?)
      );

      /*
      initialize the pool to X connections
      */
      logger.debug("Pool defaults to " + maxActiveConnection + " max active/" + maxIdleConnection + "max idle" + "with " + waitTime + "wait time"//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
          + " idle connections."); //$NON-NLS-1$

      for (int i = 0; i < maxIdleConnection; ++i)
      {
        pool.addObject();
      }
      logger.debug("Pool now has " + pool.getNumActive() + " active/" + pool.getNumIdle() + " idle connections."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      /*
      All of this is wrapped in a DataSource, which client code should
      already know how to handle (since it's the same class of object
      they'd fetch via the container's JNDI tree
      */
      poolingDataSource.setPool(pool);

      // store the pool, so we can get to it later
      cacheManager.getDataSourceCache().put(databaseConnection.getName(), poolingDataSource);
      return (poolingDataSource);
    }
View Full Code Here

    final HashMap<String, String> attrs = new HashMap<String, String>();
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.hsqldb.jdbcDriver");
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:hsqldb:mem:SampleData");
    con.setAttributes(attrs);

    final PoolingDataSource poolingDataSource = PooledDatasourceHelper.setupPooledDataSource(con);
    final Connection connection = poolingDataSource.getConnection();
    connection.close();

  }
View Full Code Here

    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);

    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

    return dataSource;
  }
View Full Code Here

        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                jdbcUrl, user, pass);
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
                connectionFactory, connectionPool, null, null, false, true);

        dataSource = new PoolingDataSource(connectionPool);
    }
View Full Code Here

        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                jdbcUrl, user, pass);
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
                connectionFactory, connectionPool, null, null, false, true);

        dataSource = new PoolingDataSource(connectionPool);
        quoteFields = Boolean
                .getBoolean("org.apache.oodt.cas.workflow.instanceRep.datasource.quoteFields");
        pageSize = Integer.getInteger(
                "org.apache.oodt.cas.workflow.instanceRep.pageSize", 20)
                .intValue();
View Full Code Here

          url, username, password)
      GenericObjectPool connectionPool = new GenericObjectPool();
      KeyedObjectPoolFactory stmtPool = new GenericKeyedObjectPoolFactory(null);
      new PoolableConnectionFactory(
          connectionFactory, connectionPool, stmtPool, null, false, true);
      DataSource dataSource = new PoolingDataSource(connectionPool);

      //test the connection (this will throw an exception if the connection is faulty)
      dataSource.getConnection();

      //return that data source.
      return dataSource;
    } catch (ClassNotFoundException e) {
      throw new DatabaseCreationException(
View Full Code Here

            final PoolableConnectionFactory cloudPoolableConnectionFactory = new PoolableConnectionFactory(cloudConnectionFactory, cloudConnectionPool, poolableObjFactory,
                    cloudValidationQuery, false, false, isolationLevel);

            // Default Data Source for CloudStack
            s_ds = new PoolingDataSource(cloudPoolableConnectionFactory.getPool());

            // Configure the usage db
            final int usageMaxActive = Integer.parseInt(dbProps.getProperty("db.usage.maxActive"));
            final int usageMaxIdle = Integer.parseInt(dbProps.getProperty("db.usage.maxIdle"));
            final long usageMaxWait = Long.parseLong(dbProps.getProperty("db.usage.maxWait"));
            final String usageUsername = dbProps.getProperty("db.usage.username");
            final String usagePassword = dbProps.getProperty("db.usage.password");
            final String usageHost = dbProps.getProperty("db.usage.host");
            final int usagePort = Integer.parseInt(dbProps.getProperty("db.usage.port"));
            final String usageDbName = dbProps.getProperty("db.usage.name");
            final boolean usageAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.usage.autoReconnect"));
            final String usageUrl = dbProps.getProperty("db.usage.url.params");

            final GenericObjectPool usageConnectionPool = new GenericObjectPool(null, usageMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                    usageMaxWait, usageMaxIdle);

            final ConnectionFactory usageConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + usageHost + ":" + usagePort + "/" + usageDbName +
                    "?autoReconnect=" + usageAutoReconnect + (usageUrl != null ? "&" + usageUrl : ""), usageUsername, usagePassword);

            final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory(usageConnectionFactory, usageConnectionPool,
                    new StackKeyedObjectPoolFactory(), null, false, false);

            // Data Source for usage server
            s_usageDS = new PoolingDataSource(usagePoolableConnectionFactory.getPool());

            // Configure awsapi db
            final String awsapiDbName = dbProps.getProperty("db.awsapi.name");
            final GenericObjectPool awsapiConnectionPool = new GenericObjectPool(null, usageMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                    usageMaxWait, usageMaxIdle);
            final ConnectionFactory awsapiConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + cloudHost + ":" + cloudPort + "/" + awsapiDbName +
                    "?autoReconnect=" + usageAutoReconnect, cloudUsername, cloudPassword);
            final PoolableConnectionFactory awsapiPoolableConnectionFactory = new PoolableConnectionFactory(awsapiConnectionFactory, awsapiConnectionPool,
                    new StackKeyedObjectPoolFactory(), null, false, false);

            // Data Source for awsapi
            s_awsapiDS = new PoolingDataSource(awsapiPoolableConnectionFactory.getPool());

            try {
                // Configure the simulator db
                final int simulatorMaxActive = Integer.parseInt(dbProps.getProperty("db.simulator.maxActive"));
                final int simulatorMaxIdle = Integer.parseInt(dbProps.getProperty("db.simulator.maxIdle"));
                final long simulatorMaxWait = Long.parseLong(dbProps.getProperty("db.simulator.maxWait"));
                final String simulatorUsername = dbProps.getProperty("db.simulator.username");
                final String simulatorPassword = dbProps.getProperty("db.simulator.password");
                final String simulatorHost = dbProps.getProperty("db.simulator.host");
                final int simulatorPort = Integer.parseInt(dbProps.getProperty("db.simulator.port"));
                final String simulatorDbName = dbProps.getProperty("db.simulator.name");
                final boolean simulatorAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.simulator.autoReconnect"));

                final GenericObjectPool simulatorConnectionPool = new GenericObjectPool(null, simulatorMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                        simulatorMaxWait, simulatorMaxIdle);

                final ConnectionFactory simulatorConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + simulatorHost + ":" + simulatorPort + "/" + simulatorDbName +
                        "?autoReconnect=" + simulatorAutoReconnect, simulatorUsername, simulatorPassword);

                final PoolableConnectionFactory simulatorPoolableConnectionFactory = new PoolableConnectionFactory(simulatorConnectionFactory, simulatorConnectionPool,
                        new StackKeyedObjectPoolFactory(), null, false, false);
                s_simulatorDS = new PoolingDataSource(simulatorPoolableConnectionFactory.getPool());
            } catch (Exception e) {
                s_logger.debug("Simulator DB properties are not available. Not initializing simulator DS");
            }
        } catch (final Exception e) {
            s_ds = getDefaultDataSource("cloud");
View Full Code Here

TOP

Related Classes of org.apache.commons.dbcp.PoolingDataSource

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.