Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions fineract-provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ configurations {
driver
}
dependencies {
driver 'mysql:mysql-connector-java:5.1.16'
driver 'org.drizzle.jdbc:drizzle-jdbc:1.3'
}

URLClassLoader loader = GroovyObject.class.classLoader
Expand All @@ -211,17 +211,17 @@ configurations.driver.each {File file ->

task createDB<<{
description= "Creates the Database. Needs database name to be passed (like: -PdbName=someDBname)"
sql = Sql.newInstance( 'jdbc:mysql://localhost:3306/', mysqlUser, mysqlPassword, 'com.mysql.jdbc.Driver' )
sql = Sql.newInstance( 'jdbc:mysql:thin://localhost:3306/', mysqlUser, mysqlPassword, 'org.drizzle.jdbc.DrizzleDriver' )
sql.execute( 'create database '+"`$dbName`" )
}

task dropDB<<{
description= "Drops the specified database. The database name has to be passed (like: -PdbName=someDBname)"
sql = Sql.newInstance( 'jdbc:mysql://localhost:3306/', mysqlUser, mysqlPassword, 'com.mysql.jdbc.Driver' )
sql = Sql.newInstance( 'jdbc:mysql:thin://localhost:3306/', mysqlUser, mysqlPassword, 'org.drizzle.jdbc.DrizzleDriver' )
sql.execute( 'DROP DATABASE '+"`$dbName`")
}
task setBlankPassword<<{
sql = Sql.newInstance( 'jdbc:mysql://localhost:3306/', mysqlUser, mysqlPassword, 'com.mysql.jdbc.Driver' )
sql = Sql.newInstance( 'jdbc:mysql:thin://localhost:3306/', mysqlUser, mysqlPassword, 'org.drizzle.jdbc.DrizzleDriver' )
sql.execute('USE `mifosplatform-tenants`')
sql.execute('UPDATE mifosplatform-tenants.tenants SET schema_server = \'localhost\', schema_server_port = \'3306\', schema_username = \'mifos\', schema_password = \'mysql\' WHERE id=1;')
}
Expand All @@ -235,13 +235,13 @@ buildscript {

dependencies {
classpath "org.flywaydb:flyway-gradle-plugin:3.0" // version upgraded during Spring Boot & MariaDB4j work, as prev. used v0.2 didn't work well after *.sql moved from fineract-db to fineract-provider/src/main/resources (new version also has clearer errors, e.g. in case of missing DB)
classpath 'mysql:mysql-connector-java:5.1.22'
classpath 'org.drizzle.jdbc:drizzle-jdbc:1.3'
}
}


flyway {
url = "jdbc:mysql://localhost:3306/mifostenant-default"
url = "jdbc:mysql:thin://localhost:3306/mifostenant-default"
user = mysqlUser
password = mysqlPassword
}
Expand All @@ -255,7 +255,7 @@ task migrateTenantDB<<{
tenantDbName = rootProject.getProperty("dbName")
}

flyway.url= "jdbc:mysql://localhost:3306/$tenantDbName"
flyway.url= "jdbc:mysql:thin://localhost:3306/$tenantDbName"
flyway.locations= [filePath]
/**We use ${ as the prefix for strecthy reporting, do not want them to be interpreted by Flyway**/
flyway.placeholderPrefix = "\$\${"
Expand All @@ -271,7 +271,7 @@ task showTenantDBInfo<<{
tenantDbName = rootProject.getProperty("dbName")
}

flyway.url= "jdbc:mysql://localhost:3306/$tenantDbName"
flyway.url= "jdbc:mysql:thin://localhost:3306/$tenantDbName"
flyway.locations= [filePath]
flywayInfo.execute()
}
Expand All @@ -286,7 +286,7 @@ task migrateTenantListDB<<{
tenantsDbName = rootProject.getProperty("dbName")
}

flyway.url= "jdbc:mysql://localhost:3306/$tenantsDbName"
flyway.url= "jdbc:mysql:thin://localhost:3306/$tenantsDbName"
flyway.locations= [filePath]

flywayMigrate.execute()
Expand All @@ -301,7 +301,7 @@ task showTenantListDBInfo<<{
tenantsDbName = rootProject.getProperty("dbName")
}

flyway.url= "jdbc:mysql://localhost:3306/$tenantsDbName"
flyway.url= "jdbc:mysql:thin://localhost:3306/$tenantsDbName"
flyway.locations= [filePath]
flywayInfo.execute()
}
Expand All @@ -315,7 +315,7 @@ task repairTenantDB<<{
tenantsDbName = rootProject.getProperty("dbName")
}

flyway.url= "jdbc:mysql://localhost:3306/$tenantsDbName"
flyway.url= "jdbc:mysql:thin://localhost:3306/$tenantsDbName"
flyway.locations= [filePath]
flywayRepair.execute()
}
Expand Down
5 changes: 3 additions & 2 deletions fineract-provider/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ dependencies {
[group: 'com.google.guava', name: 'guava', version: '15.0'],

[group: 'joda-time', name: 'joda-time', version: '2.4'],
[group: 'net.sourceforge.javacsv', name: 'javacsv', version: '2.0'],
//[group: 'net.sourceforge.javacsv', name: 'javacsv', version: '2.0'],
[group: 'org.apache.commons', name: 'commons-email', version: '1.3.3'],
[group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'],

// no slf4j & logback here (anymore), as spring-boot-starter-logging already brings this now, better assembled (log4j-over-slf4j was originally forgotten here)

[group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'],
//[group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'],
[group: 'org.drizzle.jdbc', name: 'drizzle-jdbc', version: '1.3'],
// [group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: tomcatVersion],


Expand Down
5 changes: 3 additions & 2 deletions fineract-provider/dev-dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ dependencies {
[group: 'com.google.guava', name: 'guava', version: '15.0'],

[group: 'joda-time', name: 'joda-time', version: '2.4'],
[group: 'net.sourceforge.javacsv', name: 'javacsv', version: '2.0'],
//[group: 'net.sourceforge.javacsv', name: 'javacsv', version: '2.0'],
[group: 'org.apache.commons', name: 'commons-email', version: '1.3.3'],
[group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'],

// no slf4j & logback here (anymore), as spring-boot-starter-logging already brings this now, better assembled (log4j-over-slf4j was originally forgotten here)

[group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'],
//[group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'],
[group: 'org.drizzle.jdbc', name: 'drizzle-jdbc', version: '1.3'],
[group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: tomcatVersion],


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -141,16 +142,16 @@ private void updateOrganizationRunningBalance(Date entityDate) {

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

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);
Expand All @@ -168,10 +169,10 @@ private void updateOrganizationRunningBalance(Date entityDate) {
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());
Expand All @@ -183,18 +184,18 @@ private void updateOrganizationRunningBalance(Date entityDate) {
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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;

Expand Down Expand Up @@ -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;


Expand All @@ -69,7 +70,7 @@ public DataSourceProperties() {

// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public FineractPlatformTenantConnection(final Long connectionId,final String sch
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
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> {

Expand All @@ -45,12 +44,13 @@ public void onApplicationEvent(@SuppressWarnings("unused") ContextClosedEvent ev
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

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
Expand All @@ -41,6 +42,7 @@
@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;
Expand All @@ -61,7 +63,8 @@ public void upgradeAllTenants() {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private DataSource createNewDataSourceFor(final FineractPlatformTenantConnection

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -333,8 +334,8 @@ private String constructUpdateStatement(final Long loanId, BigDecimal principalO

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");
Expand Down
19 changes: 19 additions & 0 deletions fineract-provider/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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`;
Expand Down
2 changes: 1 addition & 1 deletion fineract-provider/src/test/resources/META-INF/context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>