Connector changes from mysql to drizzle
This commit is contained in:
+16
-15
@@ -21,6 +21,7 @@ package org.apache.fineract.accounting.journalentry.service;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -141,7 +142,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
|
||||
|
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList(organizationRunningBalanceSql, entityDate, entityDate);
|
||||
for (Map<String, Object> entries : list) {
|
||||
Long accountId = (Long) entries.get("accountId");
|
||||
Long accountId = Long.parseLong(entries.get("accountId").toString()); //Drizzle is returning Big Integer where as MySQL returns Long.
|
||||
if (!runningBalanceMap.containsKey(accountId)) {
|
||||
runningBalanceMap.put(accountId, (BigDecimal) entries.get("runningBalance"));
|
||||
}
|
||||
@@ -149,8 +150,8 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
|
||||
|
||||
List<Map<String, Object>> officesRunningBalanceList = jdbcTemplate.queryForList(officesRunningBalanceSql, entityDate, entityDate);
|
||||
for (Map<String, Object> entries : officesRunningBalanceList) {
|
||||
Long accountId = (Long) entries.get("accountId");
|
||||
Long officeId = (Long) entries.get("officeId");
|
||||
Long accountId = Long.parseLong(entries.get("accountId").toString());
|
||||
Long officeId = Long.parseLong(entries.get("officeId").toString());
|
||||
Map<Long, BigDecimal> runningBalance = null;
|
||||
if (officesRunningBalance.containsKey(officeId)) {
|
||||
runningBalance = officesRunningBalance.get(officeId);
|
||||
@@ -168,10 +169,10 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
|
||||
if (entryDatas.size() > 0) {
|
||||
// run a batch update of 1000 SQL statements at a time
|
||||
final Integer batchUpdateSize = 1000;
|
||||
final Integer batchUpdateSizeMinusOne = batchUpdateSize - 1;
|
||||
String[] updateSql = new String[batchUpdateSize];
|
||||
int i = 0;
|
||||
for (JournalEntryData entryData : entryDatas) {
|
||||
ArrayList<String> updateSql = new ArrayList<>();
|
||||
int batchIndex = 0;
|
||||
for (int index = 0 ; index < entryDatas.size() ; index++) {
|
||||
JournalEntryData entryData = entryDatas.get(index) ;
|
||||
Map<Long, BigDecimal> officeRunningBalanceMap = null;
|
||||
if (officesRunningBalance.containsKey(entryData.getOfficeId())) {
|
||||
officeRunningBalanceMap = officesRunningBalance.get(entryData.getOfficeId());
|
||||
@@ -183,18 +184,18 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
|
||||
BigDecimal runningBalance = calculateRunningBalance(entryData, runningBalanceMap);
|
||||
String sql = "UPDATE acc_gl_journal_entry je SET je.is_running_balance_calculated=1, je.organization_running_balance="
|
||||
+ runningBalance + ",je.office_running_balance=" + officeRunningBalance + " WHERE je.id=" + entryData.getId();
|
||||
updateSql[i++] = sql;
|
||||
|
||||
if (i == batchUpdateSizeMinusOne) {
|
||||
updateSql.add(sql) ;
|
||||
batchIndex++ ;
|
||||
if (batchIndex == batchUpdateSize || index == entryDatas.size()-1) {
|
||||
// run a batch update of the 1000 update SQL statements
|
||||
this.jdbcTemplate.batchUpdate(updateSql);
|
||||
|
||||
String[] batch = new String[updateSql.size()] ;
|
||||
updateSql.toArray(batch) ;
|
||||
this.jdbcTemplate.batchUpdate(batch);
|
||||
// reset counter and string array
|
||||
i = 0;
|
||||
updateSql = new String[batchUpdateSize];
|
||||
batchIndex = 0;
|
||||
updateSql.clear();
|
||||
}
|
||||
}
|
||||
this.jdbcTemplate.batchUpdate(updateSql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@ 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;
|
||||
|
||||
@@ -60,7 +61,7 @@ public class DataSourceProperties extends PoolProperties {
|
||||
@Value("${" + PROTOCOL + ":jdbc}")
|
||||
private volatile @NotNull String jdbcProtocol;
|
||||
|
||||
@Value("${" + SUBPROTOCOL + ":mysql}")
|
||||
@Value("${" + SUBPROTOCOL + ":mysql:thin}")
|
||||
private volatile @NotNull String jdbcSubprotocol;
|
||||
|
||||
|
||||
@@ -69,7 +70,7 @@ public class DataSourceProperties extends PoolProperties {
|
||||
|
||||
// default to save us from re-specifying this; note that it can still be
|
||||
// overridden
|
||||
setDriverClassName(com.mysql.jdbc.Driver.class.getName());
|
||||
setDriverClassName(DrizzleDriver.class.getName());
|
||||
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class FineractPlatformTenantConnection {
|
||||
}
|
||||
|
||||
public String databaseURL() {
|
||||
final String url = new StringBuilder("jdbc:mysql://").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();
|
||||
return url;
|
||||
}
|
||||
|
||||
+6
-6
@@ -22,14 +22,13 @@ import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobRegisterServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.mysql.jdbc.AbandonedConnectionCleanupThread;
|
||||
|
||||
@Service
|
||||
public class AbandonedConnectionCleanupShutdownListener implements ApplicationListener<ContextClosedEvent> {
|
||||
|
||||
@@ -45,12 +44,13 @@ public class AbandonedConnectionCleanupShutdownListener implements ApplicationLi
|
||||
}
|
||||
|
||||
private void shutDowncleanUpThreadAndDeregisterJDBCDriver() {
|
||||
try {
|
||||
AbandonedConnectionCleanupThread.shutdown();
|
||||
logger.info("Shut-down of AbandonedConnectionCleanupThread successful");
|
||||
/*try {
|
||||
|
||||
AbandonedConnectionCleanupThread.shutdown(); tomcat memoroy leak with mysql connector. With Drizzle not required
|
||||
logger.info("Shut-down of AbandonedConnectionCleanupThread successful");
|
||||
} catch (Throwable t) {
|
||||
logger.error("Exception occurred while shut-down of AbandonedConnectionCleanupThread", t);
|
||||
}
|
||||
}*/
|
||||
|
||||
// This manually deregisters JDBC driver, which prevents Tomcat 7 from
|
||||
// complaining about memory leaks
|
||||
|
||||
+4
-1
@@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import com.googlecode.flyway.core.Flyway;
|
||||
import com.googlecode.flyway.core.api.FlywayException;
|
||||
import com.googlecode.flyway.core.util.jdbc.DriverDataSource;
|
||||
|
||||
/**
|
||||
* A service that picks up on tenants that are configured to auto-update their
|
||||
@@ -41,6 +42,7 @@ import com.googlecode.flyway.core.api.FlywayException;
|
||||
@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;
|
||||
@@ -61,7 +63,8 @@ public class TenantDatabaseUpgradeService {
|
||||
final FineractPlatformTenantConnection connection = tenant.getConnection();
|
||||
if (connection.isAutoUpdateEnabled()) {
|
||||
final Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(connection.databaseURL(), connection.getSchemaUsername(), connection.getSchemaPassword());
|
||||
DriverDataSource source = new DriverDataSource(DRIVER_CLASS, connection.databaseURL(), connection.getSchemaUsername(), connection.getSchemaPassword()) ;
|
||||
flyway.setDataSource(source);
|
||||
flyway.setLocations("sql/migrations/core_db");
|
||||
flyway.setOutOfOrder(true);
|
||||
try {
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
|
||||
|
||||
final String jdbcUrl = tenantConnectionObj.databaseURL();
|
||||
final PoolConfiguration poolConfiguration = new PoolProperties();
|
||||
poolConfiguration.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
poolConfiguration.setDriverClassName("org.drizzle.jdbc.DrizzleDriver");
|
||||
poolConfiguration.setName(tenantConnectionObj.getSchemaName() + "_pool");
|
||||
poolConfiguration.setUrl(jdbcUrl);
|
||||
poolConfiguration.setUsername(tenantConnectionObj.getSchemaUsername());
|
||||
|
||||
+3
-2
@@ -19,6 +19,7 @@
|
||||
package org.apache.fineract.portfolio.loanaccount.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@@ -333,8 +334,8 @@ public class LoanArrearsAgingServiceImpl implements LoanArrearsAgingService, Bus
|
||||
|
||||
private void updateSchheduleWithPaidDetail(Map<Long, List<LoanSchedulePeriodData>> scheduleDate, List<Map<String, Object>> loanSummary) {
|
||||
for (Map<String, Object> transactionMap : loanSummary) {
|
||||
Long loanId = (Long) transactionMap.get("loanId");
|
||||
|
||||
String longValue = transactionMap.get("loanId").toString() ; //From JDBC Template API, we are getting BigInteger but in other call, we are getting Long
|
||||
Long loanId = Long.parseLong(longValue) ;
|
||||
BigDecimal principalAmtPaid = (BigDecimal) transactionMap.get("principalAmtPaid");
|
||||
BigDecimal principalAmtWrittenoff = (BigDecimal) transactionMap.get("principalAmtWrittenoff");
|
||||
BigDecimal interestAmtPaid = (BigDecimal) transactionMap.get("interestAmtPaid");
|
||||
|
||||
@@ -1,2 +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
|
||||
+4
-3
@@ -31,7 +31,7 @@ ALTER TABLE `m_client`
|
||||
ADD CONSTRAINT `FK_m_client_m_image` FOREIGN KEY (`image_id`) REFERENCES `m_image` (`id`);
|
||||
|
||||
/*Move existing image locations to new table*/
|
||||
drop procedure if exists migrate_customer_image_data;
|
||||
/*drop procedure if exists migrate_customer_image_data;
|
||||
|
||||
delimiter #
|
||||
create procedure migrate_customer_image_data()
|
||||
@@ -64,9 +64,10 @@ end#
|
||||
|
||||
delimiter ;
|
||||
call migrate_customer_image_data();
|
||||
|
||||
*/
|
||||
|
||||
/*Now drop the procedure*/
|
||||
drop procedure if exists migrate_customer_image_data;
|
||||
/*drop procedure if exists migrate_customer_image_data; */
|
||||
|
||||
/*Delete image key from client*/
|
||||
ALTER TABLE `m_client` DROP COLUMN `image_key`;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
<Context>
|
||||
<Resource type="javax.sql.DataSource" name="jdbc/mifosplatform-tenants"
|
||||
driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/mifosplatform-tenants"
|
||||
driverClassName="org.drizzle.jdbc.DrizzleDriver" url="jdbc:mysql:thin://localhost:3306/mifosplatform-tenants"
|
||||
username="root" password="mysql" validationQuery="select 1" maxActive="10"
|
||||
maxIdle="4" />
|
||||
</Context>
|
||||
Reference in New Issue
Block a user