From f07b241ddc18f9debab1dbb96e6c5de32e2f5ea1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 8 May 2015 18:07:30 +0200 Subject: [PATCH] [New] Added feature to ignore a realm on DB init This can be very handy to not start the connection pool for realms which you know won't connect to the DB (but is not transient) - weird isn't it? =)) The property is: db.ignore.realm. The actual use case is the following: - You have a realm which use is used normally and is not transient so you have a configuration for it - you have another StrolchComponent which opens its own transactions to the DB but you only require a subset of the realms so you then use the ignore property to ignore the other realms. --- ch.eitchnet.utils | 2 +- .../runtime/configuration/DbConnectionBuilder.java | 8 ++++++++ .../postgresql/PostgreSqlDbConnectionBuilder.java | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ch.eitchnet.utils b/ch.eitchnet.utils index dd1489772..1689ff69a 160000 --- a/ch.eitchnet.utils +++ b/ch.eitchnet.utils @@ -1 +1 @@ -Subproject commit dd1489772d243af5429201c5ac45a450d8635809 +Subproject commit 1689ff69a93f7fcf491400e36b941c905d368018 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 d77de4a67..ba8fd0180 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 @@ -15,6 +15,7 @@ */ package li.strolch.runtime.configuration; +import static ch.eitchnet.db.DbConstants.PROP_DB_IGNORE_REALM; import static ch.eitchnet.db.DbConstants.PROP_DB_PASSWORD; import static ch.eitchnet.db.DbConstants.PROP_DB_URL; import static ch.eitchnet.db.DbConstants.PROP_DB_USERNAME; @@ -69,10 +70,17 @@ public abstract class DbConnectionBuilder { if (realm.getMode().isTransient()) continue; + String dbIgnoreRealmKey = makeRealmKey(realmName, PROP_DB_IGNORE_REALM); String dbUrlKey = makeRealmKey(realmName, PROP_DB_URL); String dbUsernameKey = makeRealmKey(realmName, PROP_DB_USERNAME); String dbPasswordKey = makeRealmKey(realmName, PROP_DB_PASSWORD); + boolean dbIgnoreRealm = configuration.getBoolean(dbIgnoreRealmKey, Boolean.FALSE); + if (dbIgnoreRealm) { + logger.info("Ignoring any DB configuration for Realm " + realmName); + continue; + } + String dbUrl = configuration.getString(dbUrlKey, null); String username = configuration.getString(dbUsernameKey, null); String password = configuration.getString(dbPasswordKey, null); 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 f7cc748b2..ad2f99b8d 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 @@ -65,8 +65,8 @@ public final class PostgreSqlDbConnectionBuilder extends DbConnectionBuilder { config.setPassword(password); ds = new HikariDataSource(config); - logger.info("[" + realm + "] PostgreSQL Connection pool has a maximum pool size of " + ds.getMaximumPoolSize() - + " connections"); + logger.info("[" + realm + "] PostgreSQL Connection pool to " + url + " has a maximum pool size of " + + ds.getMaximumPoolSize() + " connections"); return new StrolchPostgreDataSource(ds); }