@Override public PooledConnectionFactoryConfigurationBuilder<S> read(PooledConnectionFactoryConfiguration template) { this.propertyFile = template.propertyFile(); this.connectionUrl = template.connectionUrl(); this.driverClass = template.driverClass(); this.username = template.username(); this.password = template.password(); return this; }
@Override public PooledConnectionFactoryConfiguration create() { return new PooledConnectionFactoryConfiguration(propertyFile, connectionUrl, driverClass, username, password); }
JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0); assert store.connectionFactory() instanceof PooledConnectionFactoryConfiguration; assert ((PooledConnectionFactoryConfiguration)store.connectionFactory()).connectionUrl().equals(JDBC_URL); assert store.table().tableNamePrefix().equals("STRINGS_"); assert store.table().idColumnName().equals("id"); JdbcStringBasedStoreConfiguration store2 = (JdbcStringBasedStoreConfiguration) configuration2.persistence().stores().get(0); assert store2.connectionFactory() instanceof PooledConnectionFactoryConfiguration; assert ((PooledConnectionFactoryConfiguration)store2.connectionFactory()).connectionUrl().equals(JDBC_URL); assert store2.table().tableNamePrefix().equals("STRINGS_"); assert store2.table().idColumnName().equals("id");
private void logWarnMessages(PooledConnectionFactoryConfiguration poolConfig) { log.warn("The c3p0 connection factory has been deprecated and will be removed in future releases"); if (poolConfig.propertyFile() != null) { log.warn(String.format("Ignoring properties file '%s'. In order to configure additional c3p0 properies, " + "you must place a '%s' or '%s' file on the classpath.", poolConfig.propertyFile(), C3P0_CONFIG, C3P0_PROPERTIES)); } }
private Properties loadPropertiesFile(ClassLoader classLoader, PooledConnectionFactoryConfiguration poolConfig) { if (classLoader == null) return new Properties(); FileLookup fileLookup = FileLookupFactory.newInstance(); String propertyPath = poolConfig.propertyFile(); InputStream is = null; try { if (propertyPath != null) { is = fileLookup.lookupFileStrict(propertyPath, classLoader); } else if (classLoader.getResource(HIKARI_PROPERTIES) != null) { is = fileLookup.lookupFileStrict(HIKARI_PROPERTIES, classLoader); } if (is != null) { Properties properties = new Properties(); properties.load(is); return properties; } } catch (IOException e) { log.errorLoadingHikariCPProperties(PooledConnectionFactoryConfiguration.class.getName()); } return new Properties(); }
public Builder<?> read(PooledConnectionFactoryConfiguration template) { this.connectionUrl = template.connectionUrl(); this.driverClass = template.driverClass(); this.username = template.username(); this.password = template.password(); return this; }
public HikariConnectionPool(ClassLoader classLoader, PooledConnectionFactoryConfiguration poolConfig) { try { Properties properties = loadPropertiesFile(classLoader, poolConfig); if (poolConfig.connectionUrl() != null) properties.setProperty("jdbcUrl", poolConfig.connectionUrl()); if (poolConfig.driverClass() != null) properties.setProperty("driverClassName", poolConfig.driverClass()); if (poolConfig.username() != null) properties.setProperty("dataSource.user", poolConfig.username()); if (poolConfig.password() != null) properties.setProperty("dataSource.password", poolConfig.password()); HikariConfig hikariConfig = new HikariConfig(properties); hikariConfig.setRegisterMbeans(true); hikari = new HikariDataSource(hikariConfig); } catch (Exception e) { log.errorCreatingHikariCP(e); throw new PersistenceException("Error creating HikariCP instance: ", e); } }
private void writeJDBCStoreConnection(XMLExtendedStreamWriter writer, PooledConnectionFactoryConfiguration configuration) throws XMLStreamException { writer.writeStartElement(Element.CONNECTION_POOL); writeOptional(writer, Attribute.CONNECTION_URL, configuration.connectionUrl()); writeOptional(writer, Attribute.DRIVER_CLASS, configuration.driverClass()); writeOptional(writer, Attribute.USERNAME, configuration.username()); writeOptional(writer, Attribute.PASSWORD, configuration.password()); writer.writeEndElement(); }
public C3P0ConnectionPool(ClassLoader classLoader, PooledConnectionFactoryConfiguration poolConfig) { logWarnMessages(poolConfig); logFileOverride(classLoader); c3p0.setProperties(new Properties()); try { /* Since c3p0 does not throw an exception when it fails to load a driver we attempt to do so here * Also, c3p0 does not allow specifying a custom classloader, so use c3p0's */ Class.forName(poolConfig.driverClass(), true, ComboPooledDataSource.class.getClassLoader()); c3p0.setDriverClass(poolConfig.driverClass()); //loads the jdbc driver } catch (Exception e) { log.errorInstantiatingJdbcDriver(poolConfig.driverClass(), e); throw new PersistenceException(String.format( "Error while instatianting JDBC driver: '%s'", poolConfig.driverClass()), e); } c3p0.setJdbcUrl(poolConfig.connectionUrl()); c3p0.setUser(poolConfig.username()); c3p0.setPassword(poolConfig.password()); }
assertEquals(DatabaseType.H2, store.dialect()); PooledConnectionFactoryConfiguration connectionFactory = (PooledConnectionFactoryConfiguration) store.connectionFactory(); assertEquals("jdbc:h2:mem:infinispan;DB_CLOSE_DELAY=-1", connectionFactory.connectionUrl()); assertEquals("org.h2.Driver", connectionFactory.driverClass()); assertEquals("dbuser", connectionFactory.username()); assertEquals("dbpass", connectionFactory.password()); assertTrue(store.ignoreModifications()); assertTrue(store.fetchPersistentState());