diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/configuration/DbConnectionBuilder.java b/li.strolch.agent/src/main/java/li/strolch/runtime/configuration/DbConnectionBuilder.java index 09f0c722e..c163e4df6 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/configuration/DbConnectionBuilder.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/configuration/DbConnectionBuilder.java @@ -32,12 +32,15 @@ import javax.sql.DataSource; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchRealm; import li.strolch.persistence.api.StrolchPersistenceException; +import li.strolch.runtime.StrolchConstants; /** * @author Robert von Burg */ public abstract class DbConnectionBuilder { + private static final String PROP_DB_POOL_PREFIX = "db.pool"; + private ComponentContainer container; private ComponentConfiguration configuration; @@ -69,7 +72,37 @@ public abstract class DbConnectionBuilder { String username = configuration.getString(dbUsernameKey, null); String password = configuration.getString(dbPasswordKey, null); - DataSource ds = build(realmName, dbUrl, username, password, null); + // find any pool configuration values + Set propertyKeys = configuration.getPropertyKeys(); + Properties props = new Properties(); + for (String key : propertyKeys) { + if (!key.startsWith(PROP_DB_POOL_PREFIX)) + continue; + + // TODO we should change how properties for realms are configured + // since defaultRealm does not have to be on the key, we need this hack: + String[] segments = key.split("\\."); + String poolKey; + String foundRealm; + if (segments.length == 4) { + // ends with realm + foundRealm = segments[3]; + } else if (segments.length == 3) { + // default realm + foundRealm = StrolchConstants.DEFAULT_REALM; + } else { + throw new IllegalArgumentException("Can't detect realm of this property: " + key); + } + // see if this is our realm + if (!foundRealm.equals(realmName)) + continue; + + poolKey = segments[2]; + String value = configuration.getString(key, null); + props.setProperty(poolKey, value); + } + + DataSource ds = build(realmName, dbUrl, username, password, props); dsMap.put(realmName, ds); } diff --git a/li.strolch.performancetest/src/runtime/config/StrolchConfiguration.xml b/li.strolch.performancetest/src/runtime/config/StrolchConfiguration.xml index 8eb073094..226558609 100644 --- a/li.strolch.performancetest/src/runtime/config/StrolchConfiguration.xml +++ b/li.strolch.performancetest/src/runtime/config/StrolchConfiguration.xml @@ -43,6 +43,7 @@ jdbc:postgresql://localhost/testdb testuser test + 1 diff --git a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlDbConnectionBuilder.java b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlDbConnectionBuilder.java index 7e3452b4b..94132bded 100644 --- a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlDbConnectionBuilder.java +++ b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlDbConnectionBuilder.java @@ -57,19 +57,15 @@ public final class PostgreSqlDbConnectionBuilder extends DbConnectionBuilder { public DataSource build(String realm, String url, String username, String password, Properties props) { HikariDataSource ds; - if (props != null) { - props.setProperty("dataSource.autoCommit", "false"); - HikariConfig config = new HikariConfig(props); - ds = new HikariDataSource(config); - } else { - ds = new HikariDataSource(); - ds.setAutoCommit(false); - } + HikariConfig config = new HikariConfig(props); + config.setAutoCommit(false); + config.setPoolName(realm); + config.setJdbcUrl(url); + config.setUsername(username); + config.setPassword(password); - ds.setPoolName(realm); - ds.setJdbcUrl(url); - ds.setUsername(username); - ds.setPassword(password); + ds = new HikariDataSource(config); + System.err.println(ds.getMaximumPoolSize()); return new StrolchPostgreDataSource(ds); } diff --git a/li.strolch.persistence.postgresql/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/li.strolch.persistence.postgresql/src/test/resources/cachedruntime/config/StrolchConfiguration.xml index fe782ba2d..a3d133f42 100644 --- a/li.strolch.persistence.postgresql/src/test/resources/cachedruntime/config/StrolchConfiguration.xml +++ b/li.strolch.persistence.postgresql/src/test/resources/cachedruntime/config/StrolchConfiguration.xml @@ -37,6 +37,7 @@ jdbc:postgresql://localhost/testdb testuser test + 1 diff --git a/li.strolch.persistence.postgresql/src/test/resources/realmtest/config/StrolchConfiguration.xml b/li.strolch.persistence.postgresql/src/test/resources/realmtest/config/StrolchConfiguration.xml index 010087cab..7ea084738 100644 --- a/li.strolch.persistence.postgresql/src/test/resources/realmtest/config/StrolchConfiguration.xml +++ b/li.strolch.persistence.postgresql/src/test/resources/realmtest/config/StrolchConfiguration.xml @@ -41,10 +41,12 @@ jdbc:postgresql://localhost/testdb1 testuser1 test + 1 jdbc:postgresql://localhost/testdb2 testuser2 test + 1 diff --git a/li.strolch.persistence.postgresql/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/li.strolch.persistence.postgresql/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml index 6f256379d..d931057e6 100644 --- a/li.strolch.persistence.postgresql/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml +++ b/li.strolch.persistence.postgresql/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml @@ -36,6 +36,7 @@ jdbc:postgresql://localhost/testdb testuser test + 1 diff --git a/li.strolch.service/src/test/resources/svctest/config/StrolchConfiguration.xml b/li.strolch.service/src/test/resources/svctest/config/StrolchConfiguration.xml index 9a070ccb8..8d97ea43d 100644 --- a/li.strolch.service/src/test/resources/svctest/config/StrolchConfiguration.xml +++ b/li.strolch.service/src/test/resources/svctest/config/StrolchConfiguration.xml @@ -52,10 +52,12 @@ jdbc:postgresql://localhost/cacheduserdb cacheduser test + 1 jdbc:postgresql://localhost/transactionaluserdb transactionaluser test + 1