com.jolbox.bonecp.BoneCPConfig Java Examples
The following examples show how to use
com.jolbox.bonecp.BoneCPConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoneCPConnectionProviderFactory.java From qpid-broker-j with Apache License 2.0 | 6 votes |
public BoneCPConnectionProviderFactory() { Set<String> names = Arrays.stream(BoneCPConfig.class.getMethods()) .filter(m -> m.getName().startsWith("set") && m.getName().length() > 3 && Modifier.isPublic(m.getModifiers()) && m.getParameterCount() == 1 && (m.getParameterTypes()[0].isPrimitive() || m.getParameterTypes()[0] == String.class)) .map(m -> { String n = m.getName().substring(3); n = BONECP_SETTING_PREFIX + Character.toLowerCase(n.charAt(0)) + n.substring(1); return n; }).collect(Collectors.toSet()); _supportedAttributes = unmodifiableSet(names); }
Example #2
Source File: DatabaseConnections.java From StatsAgg with Apache License 2.0 | 6 votes |
public static void createConnectionPool() { BoneCPConfig config = new BoneCPConfig(); config.setMaxConnectionsPerPartition(DatabaseConfiguration.getCpMaxConnections()); config.setAcquireRetryAttempts(DatabaseConfiguration.getCpAcquireRetryAttempts()); config.setAcquireRetryDelayInMs(DatabaseConfiguration.getCpAcquireRetryDelay()); config.setConnectionTimeoutInMs(DatabaseConfiguration.getCpConnectionTimeout()); config.setStatisticsEnabled(DatabaseConfiguration.isCpEnableStatistics()); config.setDisableConnectionTracking(true); // set this to true to avoid bonecp closing connections erroniously config.setJdbcUrl(jdbc_); config.setUsername(DatabaseConfiguration.getUsername()); config.setPassword(DatabaseConfiguration.getPassword()); config.setDefaultAutoCommit(DatabaseConfiguration.getCpDefaultAutoCommit()); try { connectionPool_ = new BoneCP(config); } catch (Exception e) { connectionPool_ = null; logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e)); } }
Example #3
Source File: ConnectionPool.java From civcraft with GNU General Public License v2.0 | 6 votes |
public ConnectionPool(String dbcUrl, String user, String pass, int minConns, int maxConns, int partCount) throws ClassNotFoundException, SQLException { /* * Initialize our connection pool. * * We'll use a connection pool and reuse connections on a per-thread basis. */ /* setup the connection pool */ BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(dbcUrl); config.setUsername(user); config.setPassword(pass); config.setMinConnectionsPerPartition(minConns); config.setMaxConnectionsPerPartition(maxConns); config.setPartitionCount(partCount); // Enable only for debugging. //config.setCloseConnectionWatch(true); pool = new BoneCP(config); }
Example #4
Source File: BoneCPConnectionProvider.java From qpid-broker-j with Apache License 2.0 | 5 votes |
static BoneCPConfig createBoneCPConfig(final String connectionUrl, final String username, final String password, final Map<String, String> providerAttributes) { BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(connectionUrl); if (username != null) { config.setUsername(username); config.setPassword(password); } Map<String, String> attributes = new HashMap<>(providerAttributes); attributes.putIfAbsent(MIN_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MIN_CONNECTIONS_PER_PARTITION)); attributes.putIfAbsent(MAX_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MAX_CONNECTIONS_PER_PARTITION)); attributes.putIfAbsent(PARTITION_COUNT, String.valueOf(DEFAULT_PARTITION_COUNT)); Map<String, String> propertiesMap = attributes.entrySet() .stream() .collect(Collectors.toMap(p -> p.getKey().substring(JDBCSTORE_PREFIX.length()), Map.Entry::getValue)); Properties properties = new Properties(); properties.putAll(propertiesMap); try { config.setProperties(properties); } catch (Exception e) { throw new IllegalConfigurationException("Unexpected exception on applying BoneCP configuration", e); } return config; }
Example #5
Source File: BoneCPConnectionProviderTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void testCreateBoneCPConfig() { final Map<String, String> attributes = new HashMap<>(); attributes.put("qpid.jdbcstore.bonecp.idleMaxAgeInMinutes", "123"); attributes.put("qpid.jdbcstore.bonecp.connectionTimeoutInMs", "1234"); attributes.put("qpid.jdbcstore.bonecp.connectionTestStatement", "select 1"); attributes.put("qpid.jdbcstore.bonecp.logStatementsEnabled", "true"); attributes.put("qpid.jdbcstore.bonecp.partitionCount", "12"); String connectionUrl = "jdbc:mariadb://localhost:3306/test"; String username = "usr"; String password = "pwd"; BoneCPConfig config = BoneCPConnectionProvider.createBoneCPConfig(connectionUrl, username, password, attributes); assertEquals(connectionUrl, config.getJdbcUrl()); assertEquals(username, config.getUsername()); assertEquals(password, config.getPassword()); assertEquals("Unexpected idleMaxAgeInMinutes", 123, config.getIdleMaxAgeInMinutes()); assertEquals("Unexpected connectionTimeout", 1234, config.getConnectionTimeoutInMs()); assertEquals("Unexpected connectionTestStatement", "select 1", config.getConnectionTestStatement()); assertEquals("Unexpected logStatementsEnabled", true, config.isLogStatementsEnabled()); assertEquals("Unexpected maxConnectionsPerPartition", DEFAULT_MAX_CONNECTIONS_PER_PARTITION, config.getMaxConnectionsPerPartition()); assertEquals("Unexpected minConnectionsPerPartition", DEFAULT_MIN_CONNECTIONS_PER_PARTITION, config.getMinConnectionsPerPartition()); assertEquals("Unexpected partitionCount", 12, config.getPartitionCount()); }
Example #6
Source File: JDBCPoolConnection.java From dbpedia-live-mirror with GNU General Public License v3.0 | 5 votes |
/** * Initializes the pool from a property file * (need to move `Globals` out of here) */ private static void initConnection() { try { BoneCPConfig config = new BoneCPConfig(); Class.forName(Global.getOptions().get("Store.class")); config.setJdbcUrl(Global.getOptions().get("Store.dsn")); config.setUsername(Global.getOptions().get("Store.user")); config.setPassword(Global.getOptions().get("Store.pw")); connectionPool = new BoneCP(config); // setup the connection pool } catch (Exception e) { logger.error("Could not initialize Triple-Store connection! Exiting ...", e); System.exit(1); } }
Example #7
Source File: MysqlUtil.java From gameserver with Apache License 2.0 | 5 votes |
/** * Initialize the connection pool. */ public static final void init(String database, String username, String password, String server, int maxConn, int minConn, String jndi) { String dbUrl = StringUtil.concat("jdbc:mysql://", server, ":3306/", database, "?connectTimeout=", 10000, "&useUnicode=true&characterEncoding=utf8"); logger.info("Try to connect to Mysql with url: {}", dbUrl); // create a new configuration object BoneCPConfig config = new BoneCPConfig(); // set the JDBC url config.setJdbcUrl(dbUrl); config.setPartitionCount(2); config.setMaxConnectionsPerPartition(maxConn); config.setMinConnectionsPerPartition(minConn); config.setUsername(username); config.setPassword(password); // setup the connection pool try { BoneCPDataSource dataSource = new BoneCPDataSource(config); Context jndiContext = GameContext.getInstance().getJndiContext(); jndiContext.bind(jndi, dataSource); dataSourceMap.put(jndi, dataSource); dataSourceReadyMap.put(jndi, Boolean.TRUE); } catch (Exception e) { logger.warn("The connection to Mysql database is unavailable. Exception:{}", e.getMessage()); dataSourceReadyMap.put(jndi, Boolean.FALSE); } }
Example #8
Source File: DbTest.java From netcrusher-java with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { reactor = new NioReactor(); crusher = TcpCrusherBuilder.builder() .withReactor(reactor) .withBindAddress("127.0.0.1", CRUSHER_PORT) .withConnectAddress("127.0.0.1", DB_PORT) .buildAndOpen(); hsqlServer = new Server(); hsqlServer.setAddress("127.0.0.1"); hsqlServer.setPort(DB_PORT); hsqlServer.setDaemon(true); hsqlServer.setErrWriter(new PrintWriter(System.err)); hsqlServer.setLogWriter(new PrintWriter(System.out)); hsqlServer.setNoSystemExit(true); hsqlServer.setDatabasePath(0, "mem:testdb"); hsqlServer.setDatabaseName(0, "testdb"); hsqlServer.start(); Class.forName("org.hsqldb.jdbc.JDBCDriver"); BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(String.format("jdbc:hsqldb:hsql://127.0.0.1:%d/testdb", CRUSHER_PORT)); config.setUsername("sa"); config.setPassword(""); config.setInitSQL(SQL_CHECK); config.setConnectionTestStatement(SQL_CHECK); config.setAcquireIncrement(1); config.setAcquireRetryAttempts(1); config.setAcquireRetryDelayInMs(1000); config.setConnectionTimeoutInMs(1000); config.setQueryExecuteTimeLimitInMs(1000); config.setDefaultAutoCommit(false); config.setDefaultReadOnly(true); config.setDefaultTransactionIsolation("NONE"); config.setPartitionCount(1); config.setMinConnectionsPerPartition(1); config.setMaxConnectionsPerPartition(1); config.setLazyInit(true); config.setDetectUnclosedStatements(true); connectionPool = new BoneCP(config); }