Package com.jolbox.bonecp

Examples of com.jolbox.bonecp.BoneCPDataSource


public class BonecpDataSourceBuilder extends DataSourceBuilderBase {
  private static final Logger log = LoggerFactory.getLogger(BonecpDataSourceBuilder.class);

  @Override
  public DataSource buildDataSource(String key, JdbcConfiguration jdbcConfig) {
    BoneCPDataSource pooledDataSource = new BoneCPDataSource();

    if (jdbcConfig.driverClassName != null) {
      try {
        Class.forName(jdbcConfig.driverClassName);
      } catch (ClassNotFoundException e) {
        log.warn("Ignoring error loading DB driver", e);
      }
    }

    // pooledDataSource.setDriverClassName(getProperty(keyPrefix + "driverClassName"));
    pooledDataSource.setJdbcUrl(jdbcConfig.jdbcUrl);
    pooledDataSource.setUsername(jdbcConfig.username);
    pooledDataSource.setPassword(jdbcConfig.password);

    String sqlDebug = null;

    if (jdbcConfig.extraProperties != null) {
      sqlDebug = jdbcConfig.extraProperties.get("sql.debug");
    }

    Properties jdbcProperties = buildDbProperties(jdbcConfig);

    if (!jdbcProperties.isEmpty()) {
      try {
        pooledDataSource.setDriverProperties(jdbcProperties);
      } catch (Exception e) {
        throw new IllegalStateException("Unable to set JDBC properties", e);
      }
    }

    if (!Strings.isNullOrEmpty(sqlDebug)) {
      pooledDataSource.setLogStatementsEnabled(Boolean.parseBoolean(sqlDebug));
    }

    pooledDataSource.setPartitionCount(1);
    pooledDataSource.setMinConnectionsPerPartition(1);

    // Don't auto-acquire new connections
    // TODO: This is broken!!!
    pooledDataSource.setPoolAvailabilityThreshold(0);

    // Enable statement caching
    pooledDataSource.setStatementsCacheSize(32);

    // Track statistics
    pooledDataSource.setStatisticsEnabled(true);

    pooledDataSource.setConnectionHook(new BoneCPConnectionHook(key));

    databaseStatistics.register(key, pooledDataSource,
        new BoneCpMetricsReporter(databaseStatistics.getMetricKey(key), pooledDataSource));

    log.warn("Building data source for " + jdbcConfig.jdbcUrl);
View Full Code Here


    @Resource
    private Environment environment;

    @Bean
    public DataSource dataSource() {
        BoneCPDataSource dataSource = new BoneCPDataSource();

        dataSource.setDriverClass(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
        dataSource.setJdbcUrl(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
        dataSource.setUsername(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
        dataSource.setPassword(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));

        return dataSource;
    }
View Full Code Here

    config.setIdleMaxAgeInSeconds(getIdleMaxAgeInSeconds());
    config.setIdleConnectionTestPeriodInSeconds(getIdleConnectionTestPeriodInSeconds());
    config.setReleaseHelperThreads(getReleaseHelperThreads());
    config.setStatementsCacheSize(getStatementsCacheSize());
   
    BoneCPDataSource bonecp = new BoneCPDataSource(config);
    log.info("BoneCP连接池创建完成!");
    return bonecp;
  }
View Full Code Here

    public CommonDataSource pool(final String name, final String driver, final Properties properties) {
        // bonecp already have a kind of ObjectRecipe so simply giving it the values
        final Properties props = new Properties();
        props.put("properties", prefixedProps(properties));

        final BoneCPDataSource ds = build(BoneCPDataSource.class, props);
        if (ds.getDriverClass() == null || ds.getDriverClass().isEmpty()) {
            ds.setDriverClass(driver);
        }
        if (ds.getPoolName() == null || ds.getPoolName().isEmpty()) {
            ds.setPoolName(name);
        }

        final String xa = String.class.cast(properties.remove("XaDataSource"));
        if (xa != null) {
            cleanProperty(ds, "xadatasource");

            final XADataSource xaDs = XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa);
            ds.setDatasourceBean(new ManagedXADataSource(xaDs, OpenEJB.getTransactionManager()));
        }

        return ds;
    }
View Full Code Here

  }
 
    public static void main(String args[]) throws ClassNotFoundException, ParserConfigurationException, SAXException, IOException, SQLException, ParseException {
        long time;
        BoneCPConfig configuration;
        BoneCPDataSource dataSource;
        InputStream stream;
        InputSource inputSource;
        SequentialOrdersImporter importer;
       
        if (args.length != 4) {
            System.out.println("Usage: java " + SequentialOrdersImporter.class.getName() + " URL USER PASSWORD FILE");
            return;
        }
        time = System.currentTimeMillis();
        dataSource = null;
        stream = null;
        try {
          Class.forName("com.mysql.jdbc.Driver");
          configuration = new BoneCPConfig();
          configuration.setJdbcUrl(args[0]);
          configuration.setUsername(args[1]);
          configuration.setPassword(args[2]);
          dataSource = new BoneCPDataSource(configuration);
            stream = new FileInputStream(args[3]);
            inputSource = new InputSource(stream);
            importer = new SequentialOrdersImporter();
            importer.importOrders(dataSource, inputSource);
        } finally {
View Full Code Here

        }
       
        public static void main(String args[]) throws ClassNotFoundException, SQLException, ParserConfigurationException, SAXException, IOException, InterruptedException, VerticesProcessingException {
          long time;
          BoneCPConfig configuration;
          BoneCPDataSource dataSource;
          InputStream stream;
          InputSource inputSource;
          OrdersImporter importer;
         
          if (args.length != 4) {
              System.out.println("Usage: java " + OrdersImporter.class.getName() + " URL USER PASSWORD FILE");
              return;
          }
          time = System.currentTimeMillis();
          dataSource = null;
          stream = null;
          try {
          Class.forName("com.mysql.jdbc.Driver");
          configuration = new BoneCPConfig();
          configuration.setJdbcUrl(args[0]);
          configuration.setUsername(args[1]);
          configuration.setPassword(args[2]);
          dataSource = new BoneCPDataSource(configuration);
            stream = new FileInputStream(args[3]);
            inputSource = new InputSource(stream);
            importer = new OrdersImporter();
            importer.importOrders(dataSource, inputSource);
          } finally {
View Full Code Here

   
    if(applicationContext.containsBean("custom_dataSource")){
      return (DataSource)applicationContext.getBean("custom_dataSource");
    }
   
    BoneCPDataSource dataSource = new BoneCPDataSource();
    dataSource.setDriverClass(env.getProperty("database.driverClass"));
    dataSource.setJdbcUrl(env.getProperty("database.url"));
    dataSource.setUsername(env.getProperty("database.username"));
    dataSource.setPassword(env.getProperty("database.password"));
   
    dataSource.setIdleConnectionTestPeriodInMinutes(env.getProperty("dataSource.idleConnectionTestPeriod", Long.class, 240L));
    dataSource.setIdleMaxAgeInMinutes(env.getProperty("dataSource.idleMaxAge", Long.class, 60L));
    dataSource.setMaxConnectionsPerPartition(env.getProperty("dataSource.maxConnectionsPerPartition", Integer.class));
    dataSource.setMinConnectionsPerPartition(env.getProperty("dataSource.minConnectionsPerPartition", Integer.class));
    dataSource.setPartitionCount(env.getProperty("dataSource.partitionCount", Integer.class));
    dataSource.setAcquireIncrement(env.getProperty("dataSource.acquireIncrement", Integer.class));
//    dataSource.setStatementCacheSize(env.getProperty("dataSource.statementsCacheSize", Integer.class));
    dataSource.setReleaseHelperThreads(env.getProperty("dataSource.releaseHelperThreads", Integer.class));
    return dataSource;
  }
View Full Code Here

  }

  @Bean
  @Override
  public DataSource dataSource() {
    BoneCPDataSource ds = new BoneCPDataSource();
    ds.setDriverClass("oracle.jdbc.OracleDriver");
    final String host = System.getProperty("oracle.hostname", "localhost");
    final String service = System.getProperty("oracle.sid", "orcl");
    final String url = " jdbc:oracle:thin:@//" + host + ":" + ORACLE_PORT + "/" + service;
    ds.setJdbcUrl(url);
    ds.setUsername(System.getProperty("oracle.username"));
    ds.setPassword(System.getProperty("oracle.password"));
    return ds;
  }
View Full Code Here

        @Override
        protected BoneCPDataSource setupDataSourcePool( DataSourceConfigurationValue config )
                throws Exception
        {
            BoneCPDataSource pool = new BoneCPDataSource();

            Class.forName( config.driver().get() );
            pool.setDriverClass( config.driver().get() );
            pool.setJdbcUrl( config.url().get() );

            if ( !config.username().get().equals( "" ) ) {
                pool.setUsername( config.username().get() );
                pool.setPassword( config.password().get() );
            }
           
            if ( config.minPoolSize().get() != null ) {
                pool.setMinConnectionsPerPartition( config.minPoolSize().get() );
            }
            if ( config.maxPoolSize().get() != null ) {
                pool.setMaxConnectionsPerPartition( config.maxPoolSize().get() );
            }
            if ( config.loginTimeoutSeconds().get() != null ) {
                pool.setLoginTimeout( config.loginTimeoutSeconds().get() );
            }
            if ( config.maxConnectionAgeSeconds().get() != null ) {
                pool.setMaxConnectionAgeInSeconds( config.maxConnectionAgeSeconds().get() );
            }
            if ( config.validationQuery().get() != null ) {
                pool.setConnectionTestStatement( config.validationQuery().get() );
            }

            String props = config.properties().get();
            String[] properties = props.split( "," );
            Properties poolProperties = new Properties();
            for ( String property : properties ) {
                if ( property.trim().length() > 0 ) {
                    String[] keyvalue = property.trim().split( "=" );
                    poolProperties.setProperty( keyvalue[0], keyvalue[1] );
                }
            }
            pool.setProperties( poolProperties );

            return pool;
        }
View Full Code Here

    public CommonDataSource pool(final String name, final String driver, final Properties properties) {
        // bonecp already have a kind of ObjectRecipe so simply giving it the values
        final Properties props = new Properties();
        props.put("properties", prefixedProps(properties));

        final BoneCPDataSource ds = build(BoneCPDataSource.class, props);
        if (ds.getDriverClass() == null || ds.getDriverClass().isEmpty()) {
            ds.setDriverClass(driver);
        }
        if (ds.getPoolName() == null || ds.getPoolName().isEmpty()) {
            ds.setPoolName(name);
        }

        final String xa = String.class.cast(properties.remove("XaDataSource"));
        if (xa != null) {
            cleanProperty(ds, "xadatasource");

            final XADataSource xaDs = XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa);
            ds.setDatasourceBean(new ManagedXADataSource(xaDs, OpenEJB.getTransactionManager()));
        }

        return ds;
    }
View Full Code Here

TOP

Related Classes of com.jolbox.bonecp.BoneCPDataSource

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.