Package org.apache.commons.dbcp

Examples of org.apache.commons.dbcp.PoolableConnectionFactory


                        LOG_CHANNEL,
                        Logger.INFO);

                    DriverManagerConnectionFactory connectionFactory =
                        new DriverManagerConnectionFactory(url, user, password);
                    new PoolableConnectionFactory(
                        connectionFactory,
                        connectionPool,
                        // TODO switching on pooling of prepared statements causes problems with closing of connections
                        // switched off for now
//                  new StackKeyedObjectPoolFactory(),
View Full Code Here


      //create a new data source based on the database connection info provided.
      ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
          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();
View Full Code Here

            pool.setMinIdle(minSize);
            pool.setMaxWait(120000);


            // create the pool object factory
            PoolableConnectionFactory factory = new PoolableConnectionFactory(xacf, pool, null, null, true, true);
            factory.setValidationQuery("select example_type_id from example_type limit 1");
            factory.setDefaultReadOnly(false);

            String transIso = jotmJdbcElement.getAttribute("isolation-level");
            if (transIso != null && transIso.length() > 0) {
                if ("Serializable".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
                } else if ("RepeatableRead".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
                } else if ("ReadUncommitted".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
                } else if ("ReadCommitted".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                } else if ("None".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
                }
            }
            pool.setFactory(factory);

            mds = new ManagedDataSource(pool, xacf.getTransactionRegistry());
View Full Code Here

            final ConnectionFactory cloudConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + cloudHost + ":" + cloudPort + "/" + cloudDbName +
                    "?autoReconnect=" + cloudAutoReconnect + (url != null ? "&" + url : "") + (useSSL ? "&useSSL=true" : ""), cloudUsername, cloudPassword);

            final KeyedObjectPoolFactory poolableObjFactory = (cloudPoolPreparedStatements ? new StackKeyedObjectPoolFactory() : null);

            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

    private static DataSource getDefaultDataSource(final String database) {
        final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
        final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
           "jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
        final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
           connectionFactory, connectionPool, null, null, false, true);
        return new PoolingDataSource(
           /* connectionPool */poolableConnectionFactory.getPool());
    }
View Full Code Here

    connectionPool.setMaxActive(repoContext.getMaximumConnections());

    statementPool = new GenericKeyedObjectPoolFactory(null);

    // creating the factor automatically wires the connection pool
    new PoolableConnectionFactory(connFactory, connectionPool, statementPool,
        handler.validationQuery(), false, false,
        repoContext.getTransactionIsolation().getCode());

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

        Properties jdbcProps = repoContext.getConnectionProperties();

        ConnectionFactory connFactory =
            new DriverManagerConnectionFactory(connectUrl, jdbcProps);

        new PoolableConnectionFactory(connFactory, connectionPool, statementPool,
                handler.validationQuery(), false, false,
                repoContext.getTransactionIsolation().getCode());
      } catch (IllegalStateException ex) {
        // failed to reconfigure connection factory
        LOG.warn("Repository connection cannot be reconfigured currently. " +
View Full Code Here

        }

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

        ds = new PoolingDataSource(connectionPool);

        return ds;
View Full Code Here

      abandonedConfig.setRemoveAbandoned(Boolean.parseBoolean(removeAbandoned));
    }

    String validationQuery = config.getProperty(RDBMS.VALIDATION_QUERY);
    boolean hasValQuery = validationQuery != null && validationQuery.trim().length() > 0;
    PoolableConnectionFactory factory = new PoolableConnectionFactory(connectionFactory,
        this.pool, null, hasValQuery ? validationQuery : null, false, true,
        defaultTransactionIsolation, abandonedConfig);

    this.pool.setFactory(factory);
    PoolingDataSource dataSource;
View Full Code Here

                uri, properties);

        // Create the PoolableConnectionFactory, which wraps the "real"
        // Connections created by the ConnectionFactory with
        // the classes that implement the pooling functionality.
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
                connectionFactory, result, null, null, false, false);

        // To remove warnings
        poolableConnectionFactory.getPool();

        return result;
    }
View Full Code Here

TOP

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

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.