use of org.datanucleus.store.rdbms.datasource.dbcp2.ConnectionFactory in project Openfire by igniterealtime.
the class EmbeddedConnectionProvider method start.
@Override
public void start() {
File databaseDir = new File(JiveGlobals.getHomeDirectory(), File.separator + "embedded-db");
// If the database doesn't exist, create it.
if (!databaseDir.exists()) {
databaseDir.mkdirs();
}
try {
serverURL = "jdbc:hsqldb:" + databaseDir.getCanonicalPath() + File.separator + "openfire";
} catch (IOException ioe) {
Log.error("EmbeddedConnectionProvider: Error starting connection pool: ", ioe);
}
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(serverURL, "sa", "");
final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
poolableConnectionFactory.setMaxConnLifetimeMillis((long) (0.5 * JiveConstants.DAY));
final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMinIdle(3);
poolConfig.setMaxTotal(25);
final GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, poolConfig);
poolableConnectionFactory.setPool(connectionPool);
dataSource = new PoolingDataSource<>(connectionPool);
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.ConnectionFactory in project druid by druid-io.
the class BasicDataSourceExtTest method testCreateConnectionFactory.
@Test
public void testCreateConnectionFactory() throws Exception {
MetadataStorageConnectorConfig connectorConfig = new MetadataStorageConnectorConfig() {
private final List<String> passwords = Lists.newArrayList("pwd1", "pwd2");
@Override
public String getUser() {
return "testuser";
}
@Override
public String getPassword() {
return passwords.remove(0);
}
};
BasicDataSourceExt basicDataSourceExt = new BasicDataSourceExt(connectorConfig);
basicDataSourceExt.setConnectionProperties("p1=v1");
basicDataSourceExt.addConnectionProperty("p2", "v2");
Driver driver = EasyMock.mock(Driver.class);
Capture<String> uriArg = Capture.newInstance();
Capture<Properties> propsArg = Capture.newInstance();
EasyMock.expect(driver.connect(EasyMock.capture(uriArg), EasyMock.capture(propsArg))).andReturn(null).times(2);
EasyMock.replay(driver);
basicDataSourceExt.setDriver(driver);
ConnectionFactory connectionFactory = basicDataSourceExt.createConnectionFactory();
Properties expectedProps = new Properties();
expectedProps.put("p1", "v1");
expectedProps.put("p2", "v2");
expectedProps.put("user", connectorConfig.getUser());
Assert.assertNull(connectionFactory.createConnection());
Assert.assertEquals(connectorConfig.getConnectURI(), uriArg.getValue());
expectedProps.put("password", "pwd1");
Assert.assertEquals(expectedProps, propsArg.getValue());
Assert.assertNull(connectionFactory.createConnection());
Assert.assertEquals(connectorConfig.getConnectURI(), uriArg.getValue());
expectedProps.put("password", "pwd2");
Assert.assertEquals(expectedProps, propsArg.getValue());
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.ConnectionFactory in project cloudstack by apache.
the class TransactionLegacy method getDefaultDataSource.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static DataSource getDefaultDataSource(final String database) {
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
final GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
return new PoolingDataSource(connectionPool);
}
Aggregations