moving driver info to a property file
This commit is contained in:
@@ -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
|
spring.profiles.default=basicauth
|
||||||
@@ -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.default=basicauth
|
||||||
spring.profiles.active=oauth
|
spring.profiles.active=oauth
|
||||||
+2
@@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.ImportResource;
|
import org.springframework.context.annotation.ImportResource;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base Spring Configuration with what's common to all Configuration subclasses.
|
* Base Spring Configuration with what's common to all Configuration subclasses.
|
||||||
@@ -41,6 +42,7 @@ import org.springframework.context.annotation.ImportResource;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@Import({ WebXmlConfiguration.class, WebXmlOauthConfiguration.class, WebFrontEndConfiguration.class })
|
@Import({ WebXmlConfiguration.class, WebXmlOauthConfiguration.class, WebFrontEndConfiguration.class })
|
||||||
@ImportResource({ "classpath*:META-INF/spring/appContext.xml" })
|
@ImportResource({ "classpath*:META-INF/spring/appContext.xml" })
|
||||||
|
@PropertySource(value="classpath:META-INF/spring/jdbc.properties")
|
||||||
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
|
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
|
||||||
HibernateJpaAutoConfiguration.class,
|
HibernateJpaAutoConfiguration.class,
|
||||||
DataSourceTransactionManagerAutoConfiguration.class,
|
DataSourceTransactionManagerAutoConfiguration.class,
|
||||||
|
|||||||
+74
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+6
-3
@@ -20,9 +20,11 @@ package org.apache.fineract.infrastructure.core.boot.db;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
|
||||||
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
|
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -33,10 +35,12 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class DataSourceConfiguration {
|
public class DataSourceConfiguration {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DataSourceConfiguration.class);
|
private static final Logger logger = LoggerFactory.getLogger(DataSourceConfiguration.class);
|
||||||
|
|
||||||
|
@Autowired JDBCDriverConfig config ;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DataSourceProperties dataSourceProperties() {
|
public DataSourceProperties dataSourceProperties() {
|
||||||
return new DataSourceProperties();
|
return new DataSourceProperties(config.getDriverClassName(), config.getProtocol(), config.getSubProtocol(), config.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -50,5 +54,4 @@ public class DataSourceConfiguration {
|
|||||||
protected DataSourceProperties getProperties() {
|
protected DataSourceProperties getProperties() {
|
||||||
return dataSourceProperties();
|
return dataSourceProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+5
-8
@@ -21,7 +21,6 @@ package org.apache.fineract.infrastructure.core.boot.db;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
import org.drizzle.jdbc.DrizzleDriver;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@@ -64,14 +63,12 @@ public class DataSourceProperties extends PoolProperties {
|
|||||||
@Value("${" + SUBPROTOCOL + ":mysql:thin}")
|
@Value("${" + SUBPROTOCOL + ":mysql:thin}")
|
||||||
private volatile @NotNull String jdbcSubprotocol;
|
private volatile @NotNull String jdbcSubprotocol;
|
||||||
|
|
||||||
|
public DataSourceProperties(String driverClassName, String protocol, String subProtocol, Integer port) {
|
||||||
public DataSourceProperties() {
|
|
||||||
super();
|
super();
|
||||||
|
setDriverClassName(driverClassName);
|
||||||
// default to save us from re-specifying this; note that it can still be
|
this.jdbcProtocol = protocol ;
|
||||||
// overridden
|
this.jdbcSubprotocol = subProtocol ;
|
||||||
setDriverClassName(DrizzleDriver.class.getName());
|
this.port = port ;
|
||||||
|
|
||||||
setDefaults();
|
setDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -77,11 +77,13 @@ public class FineractPlatformTenantConnection {
|
|||||||
this.testOnBorrow=tesOnBorrow;
|
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)
|
final String url = new StringBuilder("jdbc:mysql:thin://").append(this.schemaServer).append(':').append(this.schemaServerPort)
|
||||||
.append('/').append(this.schemaName).toString();
|
.append('/').append(this.schemaName).toString();
|
||||||
return url;
|
return url;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the schemaServer
|
* @return the schemaServer
|
||||||
|
|||||||
+7
-4
@@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.sql.DataSource;
|
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.boot.db.TenantDataSourcePortFixService;
|
||||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
|
||||||
@@ -42,11 +43,12 @@ import com.googlecode.flyway.core.util.jdbc.DriverDataSource;
|
|||||||
@Service
|
@Service
|
||||||
public class TenantDatabaseUpgradeService {
|
public class TenantDatabaseUpgradeService {
|
||||||
|
|
||||||
private final String DRIVER_CLASS = "org.drizzle.jdbc.DrizzleDriver" ;
|
|
||||||
private final TenantDetailsService tenantDetailsService;
|
private final TenantDetailsService tenantDetailsService;
|
||||||
protected final DataSource tenantDataSource;
|
protected final DataSource tenantDataSource;
|
||||||
protected final TenantDataSourcePortFixService tenantDataSourcePortFixService;
|
protected final TenantDataSourcePortFixService tenantDataSourcePortFixService;
|
||||||
|
|
||||||
|
@Autowired private JDBCDriverConfig driverConfig ;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TenantDatabaseUpgradeService(final TenantDetailsService detailsService,
|
public TenantDatabaseUpgradeService(final TenantDetailsService detailsService,
|
||||||
@Qualifier("tenantDataSourceJndi") final DataSource dataSource, TenantDataSourcePortFixService tenantDataSourcePortFixService) {
|
@Qualifier("tenantDataSourceJndi") final DataSource dataSource, TenantDataSourcePortFixService tenantDataSourcePortFixService) {
|
||||||
@@ -63,14 +65,15 @@ public class TenantDatabaseUpgradeService {
|
|||||||
final FineractPlatformTenantConnection connection = tenant.getConnection();
|
final FineractPlatformTenantConnection connection = tenant.getConnection();
|
||||||
if (connection.isAutoUpdateEnabled()) {
|
if (connection.isAutoUpdateEnabled()) {
|
||||||
final Flyway flyway = new Flyway();
|
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.setDataSource(source);
|
||||||
flyway.setLocations("sql/migrations/core_db");
|
flyway.setLocations("sql/migrations/core_db");
|
||||||
flyway.setOutOfOrder(true);
|
flyway.setOutOfOrder(true);
|
||||||
try {
|
try {
|
||||||
flyway.migrate();
|
flyway.migrate();
|
||||||
} catch (FlywayException e) {
|
} 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();
|
+ connection.getSchemaPassword();
|
||||||
throw new FlywayException(betterMessage, e.getCause());
|
throw new FlywayException(betterMessage, e.getCause());
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -23,6 +23,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
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.FineractPlatformTenant;
|
||||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
|
||||||
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
|
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
|
||||||
@@ -45,6 +46,9 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
|
|||||||
private final Map<Long, DataSource> tenantToDataSourceMap = new HashMap<>(1);
|
private final Map<Long, DataSource> tenantToDataSourceMap = new HashMap<>(1);
|
||||||
private final DataSource tenantDataSource;
|
private final DataSource tenantDataSource;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JDBCDriverConfig driverConfig ;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TomcatJdbcDataSourcePerTenantService(final @Qualifier("tenantDataSourceJndi") DataSource tenantDataSource) {
|
public TomcatJdbcDataSourcePerTenantService(final @Qualifier("tenantDataSourceJndi") DataSource tenantDataSource) {
|
||||||
this.tenantDataSource = 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
|
// http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency
|
||||||
|
|
||||||
// see also org.apache.fineract.DataSourceProperties.setDefaults()
|
// see also org.apache.fineract.DataSourceProperties.setDefaults()
|
||||||
|
String jdbcUrl = this.driverConfig.constructProtocol(tenantConnectionObj.getSchemaServer(), tenantConnectionObj.getSchemaServerPort(), tenantConnectionObj.getSchemaName()) ;
|
||||||
final String jdbcUrl = tenantConnectionObj.databaseURL();
|
//final String jdbcUrl = tenantConnectionObj.databaseURL();
|
||||||
final PoolConfiguration poolConfiguration = new PoolProperties();
|
final PoolConfiguration poolConfiguration = new PoolProperties();
|
||||||
poolConfiguration.setDriverClassName("org.drizzle.jdbc.DrizzleDriver");
|
poolConfiguration.setDriverClassName(this.driverConfig.getDriverClassName());
|
||||||
poolConfiguration.setName(tenantConnectionObj.getSchemaName() + "_pool");
|
poolConfiguration.setName(tenantConnectionObj.getSchemaName() + "_pool");
|
||||||
poolConfiguration.setUrl(jdbcUrl);
|
poolConfiguration.setUrl(jdbcUrl);
|
||||||
poolConfiguration.setUsername(tenantConnectionObj.getSchemaUsername());
|
poolConfiguration.setUsername(tenantConnectionObj.getSchemaUsername());
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user