@Override public DataSource create(Configuration hdpConfig) throws SQLException { LOG.debug("Creating BoneCP connection pool for the MetaStore"); String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig); String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig); String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig); int maxPoolSize = MetastoreConf.getIntVar(hdpConfig, MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS); Properties properties = DataSourceProvider.getPrefixedProperties(hdpConfig, BONECP); long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L); String partitionCount = properties.getProperty(PARTITION_COUNT_PROPERTY, "1"); BoneCPConfig config = null; try { config = new BoneCPConfig(properties); } catch (Exception e) { throw new SQLException("Cannot create BoneCP configuration: ", e); } config.setJdbcUrl(driverUrl); // if we are waiting for connection for a long time, something is really wrong // better raise an error than hang forever // see DefaultConnectionStrategy.getConnectionInternal() config.setConnectionTimeoutInMs(connectionTimeout); config.setMaxConnectionsPerPartition(maxPoolSize); config.setPartitionCount(Integer.parseInt(partitionCount)); config.setUser(user); config.setPassword(passwd); return initMetrics(new BoneCPDataSource(config)); }
BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl("jdbc:hsqldb:mem:test_common;shutDown=false"); config.setUsername("sa"); config.setPassword(""); JdbcTemplate dataSource = new BoneCPDataSource(config); jdbcTemplate = new JdbcTemplate(dataSource); //If you are using named queries NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); //create necessary tables etc here. setupDb(jdbcTemplate); SomeBean anotherBean = new SomeBean(); YourDAO dao = new YourDAOImpl(); dao.setNamedJdbcTemplate(namedParameterJdbcTemplate); dao.setSomeOtherBean(anotherBean); //Mimic spring container if you implement InitialzingBean dao.afterPropertiesSet();
object ConnectionPool { Class.forName("[ENTER DRIVER]") private val connstring = [ENTER YOUR STRING] private var cp : BoneCP = _ createConnectionPool() //upon init create the cp /** * Create a new connection pool */ def createConnectionPool() = { if(cp == null) { try { val config = new BoneCPConfig() config.setJdbcUrl(connstring) config.setMaxConnectionsPerPartition(3) config.setMinConnectionsPerPartition(1) config.setPartitionCount(1) cp = new BoneCP(config) } catch { case e: SQLException => e.printStackTrace() } } } def getConnection () = { cp.getConnection }
Properties props = new Properties(); props.setProperty("characterEncoding", "UTF-8"); props.setProperty("useUnicode", "true"); BoneCPConfig config = new BoneCPConfig(props); config.setJdbcUrl("jdbc:mysql://" + MYSQL_HOST_NAME + "/" + MYSQL_BASE_NAME);
/** * Initialize a new {@link com.jolbox.bonecp.BoneCPDataSource} instance with given configuration * properties * * @see AbstractDataSourceFactory#callConstructor(Class, java.util.Properties) */ @Override protected DataSource callConstructor(Class clazz, Properties configProperties) throws Exception { BoneCPConfig config = new BoneCPConfig(configProperties); BoneCPDataSource dataSource = (BoneCPDataSource) clazz.getConstructor(BoneCPConfig.class).newInstance(config); dataSource.setDriverClass(configProperties.getProperty("driverClass")); return dataSource; } }
BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl("jdbc:mysql://" + MYSQL_HOST_NAME + "/" + MYSQL_BASE_NAME + "?user=" + MYSQL_LOGIN + "&password=" + MYSQL_PASSWORD + "&characterEncoding=utf-8");
public JDBCConnectionPool(final String jdbcString, final int numberOfConnection) throws SQLException { super(); this.numberOfConnection = numberOfConnection; this.jdbcString = jdbcString; BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(jdbcString); this.connectionPool = new BoneCP(config); this.connectionSession = new HashMap<String, Connection>(); }
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(jdbcConfig, "JdbcConfig must not be NULL."); BoneCPConfig config = new BoneCPConfig(); Field[] fields = BoneCPConfig.class.getDeclaredFields(); Iterator<Object> itor = jdbcConfig.keySet().iterator(); while (itor.hasNext()){ String name = (String)itor.next(); Object value = jdbcConfig.get(name); for (Field field: fields){ if (field.getName().equalsIgnoreCase(name)){ try { field.setAccessible(true); field.set(config, value); } catch (Exception e) { // should never happen } } } } dataSource = new BoneCPDataSource(config); }
public Object getObjectInstance(Object object, Name name, Context context, Hashtable<?, ?> table) throws Exception { Reference ref = (Reference) object; Enumeration<RefAddr> addrs = ref.getAll(); Properties props = new Properties(); while (addrs.hasMoreElements()) { RefAddr addr = addrs.nextElement(); if (addr.getType().equals("driverClassName")){ Class.forName((String) addr.getContent()); } else { props.put(addr.getType(), addr.getContent()); } } BoneCPConfig config = new BoneCPConfig(props); return new BoneCPDataSource(config); }
/** * {@inheritDoc} * */ @Override public Object getObjectInstance(Object object, Name name, Context context, Hashtable<?, ?> table) throws Exception { final Reference ref = (Reference) object; final Enumeration<RefAddr> addrs = ref.getAll(); final Properties props = new Properties(); while (addrs.hasMoreElements()) { final RefAddr addr = addrs.nextElement(); if (addr.getType().equals("driverClassName")) { Class.forName((String) addr.getContent()); } else { props.put(addr.getType(), addr.getContent()); } } final BoneCPConfig config = new BoneCPConfig(props); return new BoneCPDataSource(config); }
public DataSource dataSource() throws SQLException, PropertyVetoException { BoneCPConfig config = new BoneCPConfig(); config.setUsername(""); config.setPassword(""); config.setJdbcUrl("jdbc:derby:C:\\Users\\Kevin\\Desktop\\DerbyDB"); BoneCPDataSource dataSource = new BoneCPDataSource(config); dataSource.setDriverClass("org.apache.derby.jdbc.EmbeddedDriver"); return dataSource; }
@Override public DataSource getDataSource(JsonObject config) throws SQLException { BoneCPConfig boneCPConfig = new BoneCPConfig(); mergeConfig(boneCPConfig, config); // we now need to change the default class loader mostly for the cases where // we do not use fat jars. In that case other connection pools will fail // loading the drivers boneCPConfig.setClassLoader(getClassLoader()); return new BoneCPDataSource(boneCPConfig); }
public JDBCManager(String driver, String connectionUri, int nConnectionsPool, String userName, String password) throws SQLException, ClassNotFoundException { Class.forName(driver); BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(connectionUri); config.setMinConnectionsPerPartition(nConnectionsPool); config.setMaxConnectionsPerPartition(nConnectionsPool); config.setUsername(userName); config.setPassword(password); config.setPartitionCount(1); config.setDefaultAutoCommit(false); connectionPool = new BoneCP(config); // setup the connection pool }
public JDBCManager(String driver, String connectionUri, int nConnectionsPool, String userName, String password) throws SQLException, ClassNotFoundException { Class.forName(driver); BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(connectionUri); config.setMinConnectionsPerPartition(nConnectionsPool); config.setMaxConnectionsPerPartition(nConnectionsPool); config.setUsername(userName); config.setPassword(password); config.setPartitionCount(1); config.setDefaultAutoCommit(false); connectionPool = new BoneCP(config); // setup the connection pool }
@Override public DataSource create(Configuration hdpConfig) throws SQLException { LOG.debug("Creating BoneCP connection pool for the MetaStore"); String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig); String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig); String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig); int maxPoolSize = MetastoreConf.getIntVar(hdpConfig, MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS); Properties properties = DataSourceProvider.getPrefixedProperties(hdpConfig, BONECP); long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L); String partitionCount = properties.getProperty(PARTITION_COUNT_PROPERTY, "1"); BoneCPConfig config = null; try { config = new BoneCPConfig(properties); } catch (Exception e) { throw new SQLException("Cannot create BoneCP configuration: ", e); } config.setJdbcUrl(driverUrl); //if we are waiting for connection for a long time, something is really wrong //better raise an error than hang forever //see DefaultConnectionStrategy.getConnectionInternal() config.setConnectionTimeoutInMs(connectionTimeout); config.setMaxConnectionsPerPartition(maxPoolSize); config.setPartitionCount(Integer.parseInt(partitionCount)); config.setUser(user); config.setPassword(passwd); return new BoneCPDataSource(config); }
BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(driverUrl); config.setMaxConnectionsPerPartition(10);
BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(driverUrl); config.setMaxConnectionsPerPartition(10);
private BoneCPDataSource createBoneCPDataSource(Properties props) throws Exception { BoneCPDataSource dataSource = null; if (props == null) { dataSource = new BoneCPDataSource(); dataSource.setMaxConnectionsPerPartition(maxActive); dataSource.setMinConnectionsPerPartition(minIdle); } else { BoneCPConfig config = new BoneCPConfig(props); dataSource = new BoneCPDataSource(config); } dataSource.setJdbcUrl(jdbcUrl); dataSource.setDriverClass(jdbcDriver); dataSource.setUsername(username); dataSource.setPassword(password); return dataSource; }
private DataSource getBoneCPDatSource() { final BoneCPConfig dbConfig = new BoneCPConfig(); dbConfig.setJdbcUrl(config.getJdbcUrl()); dbConfig.setUsername(config.getUsername()); dbConfig.setPassword(config.getPassword()); dbConfig.setMinConnectionsPerPartition(config.getMinIdle()); dbConfig.setMaxConnectionsPerPartition(config.getMaxActive()); dbConfig.setConnectionTimeout(config.getConnectionTimeout().getPeriod(), config.getConnectionTimeout().getUnit()); /* dbConfig.setIdleMaxAge(config.getIdleMaxAge().getPeriod(), config.getIdleMaxAge().getUnit()); dbConfig.setMaxConnectionAge(config.getMaxConnectionAge().getPeriod(), config.getMaxConnectionAge().getUnit()); dbConfig.setIdleConnectionTestPeriod(config.getIdleConnectionTestPeriod().getPeriod(), config.getIdleConnectionTestPeriod().getUnit()); */ dbConfig.setPartitionCount(1); dbConfig.setDisableJMX(false); return new BoneCPDataSource(dbConfig); }
@Override public DBI get() { final BoneCPConfig dbConfig = new BoneCPConfig(); dbConfig.setJdbcUrl(config.getJdbcUrl()); dbConfig.setUsername(config.getUsername());