[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.<realmName>

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.
This commit is contained in:
Robert von Burg 2015-05-08 18:07:30 +02:00
parent 1da65c1131
commit f07b241ddc
3 changed files with 11 additions and 3 deletions

@ -1 +1 @@
Subproject commit dd1489772d243af5429201c5ac45a450d8635809
Subproject commit 1689ff69a93f7fcf491400e36b941c905d368018

View File

@ -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);

View File

@ -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);
}