fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nazeer1100...@apache.org
Subject incubator-fineract git commit: moving driver info to a property file
Date Tue, 16 Feb 2016 13:54:53 GMT
Repository: incubator-fineract
Updated Branches:
  refs/heads/develop 9c27413cf -> 1c0e5502e


moving driver info to a property file


Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/1c0e5502
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/1c0e5502
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/1c0e5502

Branch: refs/heads/develop
Commit: 1c0e5502e0832f56c09c34f1ad3e6d8616e825fd
Parents: 9c27413
Author: unknown <nazeer.shaik@confluxtechnologies.com>
Authored: Tue Feb 16 18:41:16 2016 +0530
Committer: unknown <nazeer.shaik@confluxtechnologies.com>
Committed: Tue Feb 16 18:41:33 2016 +0530

----------------------------------------------------------------------
 .../properties/basicauth/application.properties | 18 +++++
 .../properties/oauth/application.properties     | 18 +++++
 .../boot/AbstractApplicationConfiguration.java  |  2 +
 .../core/boot/JDBCDriverConfig.java             | 74 ++++++++++++++++++++
 .../core/boot/db/DataSourceConfiguration.java   |  9 ++-
 .../core/boot/db/DataSourceProperties.java      | 13 ++--
 .../FineractPlatformTenantConnection.java       |  6 +-
 .../service/TenantDatabaseUpgradeService.java   | 11 +--
 .../TomcatJdbcDataSourcePerTenantService.java   | 10 ++-
 .../resources/META-INF/spring/jdbc.properties   | 23 ++++++
 10 files changed, 164 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/properties/basicauth/application.properties
----------------------------------------------------------------------
diff --git a/fineract-provider/properties/basicauth/application.properties b/fineract-provider/properties/basicauth/application.properties
index adbef74..d1fad00 100644
--- a/fineract-provider/properties/basicauth/application.properties
+++ b/fineract-provider/properties/basicauth/application.properties
@@ -1,2 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
 
 spring.profiles.default=basicauth
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/properties/oauth/application.properties
----------------------------------------------------------------------
diff --git a/fineract-provider/properties/oauth/application.properties b/fineract-provider/properties/oauth/application.properties
index 05ef979..4d266fe 100644
--- a/fineract-provider/properties/oauth/application.properties
+++ b/fineract-provider/properties/oauth/application.properties
@@ -1,3 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
 
 spring.profiles.default=basicauth
 spring.profiles.active=oauth
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/AbstractApplicationConfiguration.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/AbstractApplicationConfiguration.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/AbstractApplicationConfiguration.java
index 282eb33..2d2e312 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/AbstractApplicationConfiguration.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/AbstractApplicationConfiguration.java
@@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 import org.springframework.context.annotation.ImportResource;
+import org.springframework.context.annotation.PropertySource;
 
 /**
  * Base Spring Configuration with what's common to all Configuration subclasses.
@@ -41,6 +42,7 @@ import org.springframework.context.annotation.ImportResource;
 @Configuration
 @Import({ WebXmlConfiguration.class, WebXmlOauthConfiguration.class, WebFrontEndConfiguration.class
})
 @ImportResource({ "classpath*:META-INF/spring/appContext.xml" })
+@PropertySource(value="classpath:META-INF/spring/jdbc.properties")
 @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
 		HibernateJpaAutoConfiguration.class,
 		DataSourceTransactionManagerAutoConfiguration.class,

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/JDBCDriverConfig.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/JDBCDriverConfig.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/JDBCDriverConfig.java
new file mode 100644
index 0000000..854f120
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/JDBCDriverConfig.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.core.boot;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Service;
+
+@Service
+public class JDBCDriverConfig {
+
+	private final static String DRIVER_CLASS_PROPERTYNAME = "DRIVERCLASS_NAME" ;
+	private final static String PROTOCOL_PROPERTYNAME = "PROTOCOL" ;
+	private final static String SUBPROTOCOL_PROPERTYNAME = "SUB_PROTOCOL" ;
+	private final static String PORT_PROPERTYNAME = "PORT" ;
+	
+	private String driverClassName ;
+	private String protocol ;
+	private String subProtocol ;
+	private Integer port ;
+	
+	@Autowired ApplicationContext context ;
+	
+	@PostConstruct
+	protected void init() {
+		Environment environment = context.getEnvironment() ;
+		driverClassName = (String)environment.getProperty(DRIVER_CLASS_PROPERTYNAME) ;
+		protocol = (String) environment.getProperty(PROTOCOL_PROPERTYNAME) ;
+		subProtocol = (String) environment.getProperty(SUBPROTOCOL_PROPERTYNAME) ;
+		port = Integer.parseInt((String) environment.getProperty(PORT_PROPERTYNAME)) ;
+	}
+	
+    public String getDriverClassName() {
+    	return this.driverClassName ;
+    }
+    
+    public String getProtocol() {
+    	return this.protocol ;
+    }
+
+    public String getSubProtocol() {
+    	return this.subProtocol ;
+    }
+    
+    public Integer getPort() {
+    	return this.port ;
+    }
+    
+    public String constructProtocol(String schemaServer, String schemaServerPort, String
schemaName) {
+    	final String url = new StringBuilder(protocol).append(":").append(subProtocol).append("://").append(schemaServer).append(':').append(schemaServerPort)
+                .append('/').append(schemaName).toString();
+        return url;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceConfiguration.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceConfiguration.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceConfiguration.java
index df8dac4..fe5f9bb 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceConfiguration.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceConfiguration.java
@@ -20,9 +20,11 @@ package org.apache.fineract.infrastructure.core.boot.db;
 
 import javax.sql.DataSource;
 
+import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
 import org.apache.tomcat.jdbc.pool.PoolConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -33,10 +35,12 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 public class DataSourceConfiguration {
 	private static final Logger logger = LoggerFactory.getLogger(DataSourceConfiguration.class);
-
+	
+	@Autowired JDBCDriverConfig config ;
+	
     @Bean
     public DataSourceProperties dataSourceProperties() {
-	return new DataSourceProperties();
+	return new DataSourceProperties(config.getDriverClassName(), config.getProtocol(), config.getSubProtocol(),
config.getPort());
     }
 
     @Bean
@@ -50,5 +54,4 @@ public class DataSourceConfiguration {
     protected DataSourceProperties getProperties() {
         return dataSourceProperties();
     }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceProperties.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceProperties.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceProperties.java
index 33800bd..24276f7 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceProperties.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/boot/db/DataSourceProperties.java
@@ -21,7 +21,6 @@ package org.apache.fineract.infrastructure.core.boot.db;
 import javax.validation.constraints.NotNull;
 
 import org.apache.tomcat.jdbc.pool.PoolProperties;
-import org.drizzle.jdbc.DrizzleDriver;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.StringUtils;
 
@@ -64,14 +63,12 @@ public class DataSourceProperties extends PoolProperties {
     @Value("${" + SUBPROTOCOL + ":mysql:thin}")
     private volatile @NotNull String jdbcSubprotocol;
 
-
-    public DataSourceProperties() {
+    public DataSourceProperties(String driverClassName, String protocol, String subProtocol,
Integer port) {
         super();
-
-        // default to save us from re-specifying this; note that it can still be
-        // overridden
-        setDriverClassName(DrizzleDriver.class.getName());
-
+        setDriverClassName(driverClassName);
+        this.jdbcProtocol = protocol ;
+        this.jdbcSubprotocol = subProtocol ;
+        this.port = port ;
         setDefaults();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/FineractPlatformTenantConnection.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/FineractPlatformTenantConnection.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/FineractPlatformTenantConnection.java
index 9e43f24..af5d493 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/FineractPlatformTenantConnection.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/FineractPlatformTenantConnection.java
@@ -77,11 +77,13 @@ public class FineractPlatformTenantConnection {
         this.testOnBorrow=tesOnBorrow;
     }
 
-    public String databaseURL() {
+    //The Connection Protocol should be built based on jdbc.properties. We can't hard code
this here and also, constructing protocol is not this class
+    //responsibility
+    /*public String databaseURL() {
         final String url = new StringBuilder("jdbc:mysql:thin://").append(this.schemaServer).append(':').append(this.schemaServerPort)
                 .append('/').append(this.schemaName).toString();
         return url;
-    }
+    }*/
     
     /**
      * @return the schemaServer

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
index 074ab18..8bf9199 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.sql.DataSource;
 
+import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
 import org.apache.fineract.infrastructure.core.boot.db.TenantDataSourcePortFixService;
 import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
 import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
@@ -42,11 +43,12 @@ import com.googlecode.flyway.core.util.jdbc.DriverDataSource;
 @Service
 public class TenantDatabaseUpgradeService {
 
-	private final String DRIVER_CLASS = "org.drizzle.jdbc.DrizzleDriver" ;
     private final TenantDetailsService tenantDetailsService;
     protected final DataSource tenantDataSource;
     protected final TenantDataSourcePortFixService tenantDataSourcePortFixService;
-
+    
+    @Autowired private JDBCDriverConfig driverConfig ;
+    
     @Autowired
     public TenantDatabaseUpgradeService(final TenantDetailsService detailsService,
             @Qualifier("tenantDataSourceJndi") final DataSource dataSource, TenantDataSourcePortFixService
tenantDataSourcePortFixService) {
@@ -63,14 +65,15 @@ public class TenantDatabaseUpgradeService {
             final FineractPlatformTenantConnection connection = tenant.getConnection();
             if (connection.isAutoUpdateEnabled()) {
                 final Flyway flyway = new Flyway();
-                DriverDataSource source = new DriverDataSource(DRIVER_CLASS, connection.databaseURL(),
connection.getSchemaUsername(), connection.getSchemaPassword()) ;
+                String connectionProtocol = driverConfig.constructProtocol(connection.getSchemaServer(),
connection.getSchemaServerPort(), connection.getSchemaName()) ;
+                DriverDataSource source = new DriverDataSource(driverConfig.getDriverClassName(),
connectionProtocol, connection.getSchemaUsername(), connection.getSchemaPassword()) ;
                 flyway.setDataSource(source);
                 flyway.setLocations("sql/migrations/core_db");
                 flyway.setOutOfOrder(true);
                 try {
                     flyway.migrate();
                 } catch (FlywayException e) {
-                    String betterMessage = e.getMessage() + "; for Tenant DB URL: " + connection.databaseURL()
+ ", username: "
+                    String betterMessage = e.getMessage() + "; for Tenant DB URL: " + connectionProtocol
+ ", username: "
                             + connection.getSchemaPassword();
                     throw new FlywayException(betterMessage, e.getCause());
                 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
index 4227bcc..34782a4 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import javax.sql.DataSource;
 
+import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
 import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
 import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
 import org.apache.tomcat.jdbc.pool.PoolConfiguration;
@@ -46,6 +47,9 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
     private final DataSource tenantDataSource;
 
     @Autowired
+    private JDBCDriverConfig driverConfig ;
+    
+    @Autowired
     public TomcatJdbcDataSourcePerTenantService(final @Qualifier("tenantDataSourceJndi")
DataSource tenantDataSource) {
         this.tenantDataSource = tenantDataSource;
     }
@@ -83,10 +87,10 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
         // http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency
 
         // see also org.apache.fineract.DataSourceProperties.setDefaults()
-
-        final String jdbcUrl = tenantConnectionObj.databaseURL();
+    	 String jdbcUrl = this.driverConfig.constructProtocol(tenantConnectionObj.getSchemaServer(),
tenantConnectionObj.getSchemaServerPort(), tenantConnectionObj.getSchemaName()) ;
+        //final String jdbcUrl = tenantConnectionObj.databaseURL();
         final PoolConfiguration poolConfiguration = new PoolProperties();
-        poolConfiguration.setDriverClassName("org.drizzle.jdbc.DrizzleDriver");
+        poolConfiguration.setDriverClassName(this.driverConfig.getDriverClassName());
         poolConfiguration.setName(tenantConnectionObj.getSchemaName() + "_pool");
         poolConfiguration.setUrl(jdbcUrl);
         poolConfiguration.setUsername(tenantConnectionObj.getSchemaUsername());

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/1c0e5502/fineract-provider/src/main/resources/META-INF/spring/jdbc.properties
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/resources/META-INF/spring/jdbc.properties b/fineract-provider/src/main/resources/META-INF/spring/jdbc.properties
new file mode 100644
index 0000000..8d64dc5
--- /dev/null
+++ b/fineract-provider/src/main/resources/META-INF/spring/jdbc.properties
@@ -0,0 +1,23 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+DRIVERCLASS_NAME:org.drizzle.jdbc.DrizzleDriver
+PROTOCOL:jdbc
+SUB_PROTOCOL:mysql:thin
+PORT:3306
\ No newline at end of file


Mime
View raw message