From d079442e0ec322fe01b08906da2521475380b9bb Mon Sep 17 00:00:00 2001 From: Channa Gayan Date: Sat, 15 Mar 2014 22:42:21 +0530 Subject: [PATCH] Changes to issue: MIFOSX-949 --- ...fospltaform-tenants-first-time-install.sql | 7 +++ .../core/domain/MifosPlatformTenant.java | 47 ++++++++++++++++++- .../TomcatJdbcDataSourcePerTenantService.java | 14 +++--- .../BasicAuthTenantDetailsServiceJdbc.java | 12 ++++- .../service/JdbcTenantDetailsService.java | 12 ++++- 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/mifosng-db/mifospltaform-tenants-first-time-install.sql b/mifosng-db/mifospltaform-tenants-first-time-install.sql index 4e188cffd..ee3ef9078 100644 --- a/mifosng-db/mifospltaform-tenants-first-time-install.sql +++ b/mifosng-db/mifospltaform-tenants-first-time-install.sql @@ -73,6 +73,13 @@ CREATE TABLE `tenants` ( `schema_username` varchar(100) NOT NULL DEFAULT 'root', `schema_password` varchar(100) NOT NULL DEFAULT 'mysql', `auto_update` tinyint(1) NOT NULL DEFAULT '1', + `initial_size` int(5) DEFAULT NULL, + `validation_interval` int(60) DEFAULT NULL, + `remove_abandoned` varchar(10) DEFAULT NULL, + `remove_abandoned_timeout` int(10) DEFAULT NULL, + `log_abandoned` varchar(10) DEFAULT NULL, + `abondoned_when_percentage_full` int(10) DEFAULT NULL, + `test_on_borrow` varchar(10) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/domain/MifosPlatformTenant.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/domain/MifosPlatformTenant.java index 46d56749d..279b41493 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/domain/MifosPlatformTenant.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/domain/MifosPlatformTenant.java @@ -17,10 +17,18 @@ public class MifosPlatformTenant { private final String schemaPassword; private final String timezoneId; private final boolean autoUpdateEnabled; + private final int initialSize; + private final boolean testOnBorrow; + private final long validationInterval; + private final boolean removeAbandoned; + private final int removeAbandonedTimeout; + private final boolean logAbandoned; + private final int abandonWhenPercentageFull; public MifosPlatformTenant(final Long id, final String tenantIdentifier, final String name, final String schemaName, - final String schemaServer, final String schemaServerPort, final String schemaUsername, final String schemaPassword, - final String timezoneId, final boolean autoUpdateEnabled) { + final String schemaServer, final String schemaServerPort, final String schemaUsername, final String schemaPassword, + final String timezoneId, final boolean autoUpdateEnabled,final int initialSize,final boolean testOnBorrow,final long validationInterval, + final boolean removeAbandoned,final int removeAbandonedTimeout,final boolean logAbandoned,final int abandonWhenPercentageFull) { this.id = id; this.tenantIdentifier = tenantIdentifier; this.name = name; @@ -31,6 +39,13 @@ public class MifosPlatformTenant { this.schemaPassword = schemaPassword; this.timezoneId = timezoneId; this.autoUpdateEnabled = autoUpdateEnabled; + this.initialSize = initialSize; + this.testOnBorrow = testOnBorrow; + this.validationInterval = validationInterval; + this.removeAbandoned = removeAbandoned; + this.removeAbandonedTimeout = removeAbandonedTimeout; + this.logAbandoned = logAbandoned; + this.abandonWhenPercentageFull = abandonWhenPercentageFull; } public String databaseURL() { @@ -39,6 +54,34 @@ public class MifosPlatformTenant { return url; } + public int getInitialSize() { + return initialSize; + } + + public boolean isTestOnBorrow() { + return testOnBorrow; + } + + public long getValidationInterval() { + return validationInterval; + } + + public boolean isRemoveAbandoned() { + return removeAbandoned; + } + + public int getRemoveAbandonedTimeout() { + return removeAbandonedTimeout; + } + + public boolean isLogAbandoned() { + return logAbandoned; + } + + public int getAbandonWhenPercentageFull() { + return abandonWhenPercentageFull; + } + public Long getId() { return this.id; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java index 996aafb69..41a299d84 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java @@ -73,7 +73,7 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe poolConfiguration.setUsername(tenant.getSchemaUsername()); poolConfiguration.setPassword(tenant.getSchemaPassword()); - poolConfiguration.setInitialSize(5); + poolConfiguration.setInitialSize(tenant.getInitialSize()); // poolConfiguration.setMaxActive(5); // poolConfiguration.setMinIdle(1); // poolConfiguration.setMaxIdle(4); @@ -82,14 +82,14 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe // poolConfiguration.setTimeBetweenEvictionRunsMillis(30000); // poolConfiguration.setMinEvictableIdleTimeMillis(60000); - poolConfiguration.setTestOnBorrow(true); + poolConfiguration.setTestOnBorrow(tenant.isTestOnBorrow()); poolConfiguration.setValidationQuery("SELECT 1"); - poolConfiguration.setValidationInterval(30000); + poolConfiguration.setValidationInterval(tenant.getValidationInterval()); - poolConfiguration.setRemoveAbandoned(true); - poolConfiguration.setRemoveAbandonedTimeout(60); - poolConfiguration.setLogAbandoned(true); - poolConfiguration.setAbandonWhenPercentageFull(50); + poolConfiguration.setRemoveAbandoned(tenant.isRemoveAbandoned()); + poolConfiguration.setRemoveAbandonedTimeout(tenant.getRemoveAbandonedTimeout()); + poolConfiguration.setLogAbandoned(tenant.isLogAbandoned()); + poolConfiguration.setAbandonWhenPercentageFull(tenant.getAbandonWhenPercentageFull()); poolConfiguration.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport"); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/BasicAuthTenantDetailsServiceJdbc.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/BasicAuthTenantDetailsServiceJdbc.java index 7515686af..9296ba2c0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/BasicAuthTenantDetailsServiceJdbc.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/BasicAuthTenantDetailsServiceJdbc.java @@ -38,7 +38,7 @@ public class BasicAuthTenantDetailsServiceJdbc implements BasicAuthTenantDetails private final StringBuilder sqlBuilder = new StringBuilder( "id, name,identifier, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, auto_update as autoUpdate, ")// - .append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ")// + .append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ,initial_size as initialSize,validation_interval as validationInterval,remove_abandoned as removeAbandoned,remove_abandoned_timeout as removeAbandonedTimeout,log_abandoned as logAbandoned,abondoned_when_percentage_full as abondonedWhenPercentageFull,test_on_borrow as testOnBorrow ")// .append(" from tenants t");// public String schema() { @@ -58,9 +58,17 @@ public class BasicAuthTenantDetailsServiceJdbc implements BasicAuthTenantDetails final String schemaPassword = rs.getString("schemaPassword"); final String timezoneId = rs.getString("timezoneId"); final boolean autoUpdateEnabled = rs.getBoolean("autoUpdate"); + final int initialSize = rs.getInt("initialSize"); + final boolean testOnBorrow = rs.getBoolean("testOnBorrow"); + final long validationInterval = rs.getLong("validationInterval"); + final boolean removeAbandoned = rs.getBoolean("removeAbandoned"); + final int removeAbandonedTimeout = rs.getInt("removeAbandonedTimeout"); + final boolean logAbandoned = rs.getBoolean("logAbandoned"); + final int abandonWhenPercentageFull = rs.getInt("abondonedWhenPercentageFull"); return new MifosPlatformTenant(id, tenantIdentifier, name, schemaName, schemaServer, schemaServerPort, schemaUsername, - schemaPassword, timezoneId, autoUpdateEnabled); + schemaPassword, timezoneId, autoUpdateEnabled,initialSize,testOnBorrow,validationInterval,removeAbandoned,removeAbandonedTimeout + ,logAbandoned,abandonWhenPercentageFull); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java index 9396bb23d..0da3c11d6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java @@ -39,7 +39,7 @@ public class JdbcTenantDetailsService implements TenantDetailsService { private final StringBuilder sqlBuilder = new StringBuilder( "id, name,identifier, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, auto_update as autoUpdate, ")// - .append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ")// + .append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ,initial_size as initialSize,validation_interval as validationInterval,remove_abandoned as removeAbandoned,remove_abandoned_timeout as removeAbandonedTimeout,log_abandoned as logAbandoned,abondoned_when_percentage_full as abondonedWhenPercentageFull,test_on_borrow as testOnBorrow ")// .append(" from tenants t");// public String schema() { @@ -59,9 +59,17 @@ public class JdbcTenantDetailsService implements TenantDetailsService { final String schemaPassword = rs.getString("schemaPassword"); final String timezoneId = rs.getString("timezoneId"); final boolean autoUpdateEnabled = rs.getBoolean("autoUpdate"); + final int initialSize = rs.getInt("initialSize"); + final boolean testOnBorrow = rs.getBoolean("testOnBorrow"); + final long validationInterval = rs.getLong("validationInterval"); + final boolean removeAbandoned = rs.getBoolean("removeAbandoned"); + final int removeAbandonedTimeout = rs.getInt("removeAbandonedTimeout"); + final boolean logAbandoned = rs.getBoolean("logAbandoned"); + final int abandonWhenPercentageFull = rs.getInt("abondonedWhenPercentageFull"); return new MifosPlatformTenant(id, tenantIdentifier, name, schemaName, schemaServer, schemaServerPort, schemaUsername, - schemaPassword, timezoneId, autoUpdateEnabled); + schemaPassword, timezoneId, autoUpdateEnabled,initialSize,testOnBorrow,validationInterval,removeAbandoned,removeAbandonedTimeout + ,logAbandoned,abandonWhenPercentageFull); } }