You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by my...@apache.org on 2018/01/22 15:11:49 UTC
[fineract-cn-mariadb] branch develop created (now a42774c)
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git.
at a42774c Merge pull request #6 from myrle-krantz/develop
This branch includes the following new commits:
new 6f0c108 Open sourcing core.mariadb.
new d2ba260 added workaround for weird mariadb behaviour
new ef671ec Merge pull request #1 from mgeiss/develop
new 96fcf48 removed suggested fix b/c it's not working
new 289d5b1 Merge pull request #2 from mgeiss/develop
new 642a6d9 disabled use of server side generated prepared statements
new dc774a6 Merge pull request #3 from mgeiss/develop
new edbd5b2 added replication capability to mariadb jdbc url
new c9f017c Merge pull request #4 from mgeiss/develop
new 3868342 Local vs bound variable. Minor fix.
new bc9ccf9 Merge pull request #5 from myrle-krantz/develop
new 154667e Added configuration parameter to @Enable annotation to make it possible to run db connection in a tenant-agnostic manner while still taking advantage of connection pooling/configuration code. This could be further improved to sandbox by app in the tenant-agnostic manner.
new 51b6844 Merge branch 'develop' of https://github.com/mifosio/mariadb into develop
new a42774c Merge pull request #6 from myrle-krantz/develop
The 14 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 11/14: Merge pull request #5 from
myrle-krantz/develop
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit bc9ccf90e8fd4095aea7839e0ffbb86ef65eee72
Merge: c9f017c 3868342
Author: Myrle Krantz <my...@apache.org>
AuthorDate: Mon May 15 17:19:39 2017 +0200
Merge pull request #5 from myrle-krantz/develop
Local vs bound variable. Minor fix.
.../io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 03/14: Merge pull request #1 from
mgeiss/develop
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit ef671ec6f03ed4ba76a1b3a674aac173e3f45eba
Merge: 6f0c108 d2ba260
Author: Markus Geiß <ma...@apache.org>
AuthorDate: Thu Apr 20 20:12:59 2017 +0200
Merge pull request #1 from mgeiss/develop
added workaround for weird mariadb behaviour
src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 08/14: added replication capability to
mariadb jdbc url
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit edbd5b2f2cf2612a922d0c24d7353be42cf2b716
Author: mgeiss <mg...@mifos.org>
AuthorDate: Tue Apr 25 16:24:12 2017 +0200
added replication capability to mariadb jdbc url
---
.../io/mifos/core/mariadb/util/JdbcUrlBuilder.java | 20 ++++++++++----
.../core/mariadb/util/JdbcUrlBuilderTest.java | 32 ++++++++++++++++++++--
2 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
index 3c2576d..dc376c0 100644
--- a/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
+++ b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
@@ -47,19 +47,29 @@ public final class JdbcUrlBuilder {
}
public String build() {
+ final String[] hostList = this.host.split(",");
switch (this.type) {
case MARIADB:
- return this.type.prefix()
- + this.host + ":"
- + this.port
- + (this.instanceName != null ? "/" + this.instanceName : "");
+ final StringBuilder jdbcUrl = new StringBuilder();
+ final String jdbcProtocol = this.type.prefix() + (hostList.length > 1 ? "replication://" : "//");
+ jdbcUrl.append(jdbcProtocol);
+ for (int i = 0; i < hostList.length; i++) {
+ jdbcUrl.append(hostList[i].trim()).append(":").append(this.port);
+ if ((i + 1) < hostList.length) {
+ jdbcUrl.append(",");
+ }
+ }
+ if (this.instanceName != null) {
+ jdbcUrl.append("/").append(this.instanceName);
+ }
+ return jdbcUrl.toString();
default:
throw new IllegalArgumentException("Unknown database type '" + this.type.name() + "'");
}
}
public enum DatabaseType {
- MARIADB("jdbc:mariadb://");
+ MARIADB("jdbc:mariadb:");
private final String prefix;
diff --git a/src/test/java/io/mifos/core/mariadb/util/JdbcUrlBuilderTest.java b/src/test/java/io/mifos/core/mariadb/util/JdbcUrlBuilderTest.java
index 550e5bc..ca8848c 100644
--- a/src/test/java/io/mifos/core/mariadb/util/JdbcUrlBuilderTest.java
+++ b/src/test/java/io/mifos/core/mariadb/util/JdbcUrlBuilderTest.java
@@ -20,21 +20,47 @@ import org.junit.Test;
public class JdbcUrlBuilderTest {
- private final static String MARIADB_JDBC_URL = "jdbc:mariadb://localhost:3306/comp_test";
-
public JdbcUrlBuilderTest() {
super();
}
@Test
public void shouldCreateMysqlUrl() {
+ final String expectedJdbcUrl = "jdbc:mariadb://localhost:3306/comp_test";
+
+ final String mariaDbJdbcUrl = JdbcUrlBuilder
+ .create(JdbcUrlBuilder.DatabaseType.MARIADB)
+ .host("localhost")
+ .port("3306")
+ .instanceName("comp_test")
+ .build();
+
+ Assert.assertEquals(expectedJdbcUrl, mariaDbJdbcUrl);
+ }
+
+ @Test
+ public void shouldCreateMysqlUrlNoInstance() {
+ final String expectedJdbcUrl = "jdbc:mariadb://localhost:3306";
+
final String mariaDbJdbcUrl = JdbcUrlBuilder
.create(JdbcUrlBuilder.DatabaseType.MARIADB)
.host("localhost")
+ .port("3306").build();
+
+ Assert.assertEquals(expectedJdbcUrl, mariaDbJdbcUrl);
+ }
+
+ @Test
+ public void shouldCreateMysqlReplicationUrl() {
+ final String expectedJdbcUrl = "jdbc:mariadb:replication://localhost:3306,anotherhost:3306/comp_test";
+
+ final String mariaDbJdbcUrl = JdbcUrlBuilder
+ .create(JdbcUrlBuilder.DatabaseType.MARIADB)
+ .host("localhost, anotherhost")
.port("3306")
.instanceName("comp_test")
.build();
- Assert.assertEquals(MARIADB_JDBC_URL, mariaDbJdbcUrl);
+ Assert.assertEquals(expectedJdbcUrl, mariaDbJdbcUrl);
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 13/14: Merge branch 'develop' of
https://github.com/mifosio/mariadb into develop
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit 51b68442022b765323e952deb5aaa39ec11baa79
Merge: 154667e bc9ccf9
Author: myrle-krantz <mk...@mifos.org>
AuthorDate: Wed May 17 16:44:54 2017 +0200
Merge branch 'develop' of https://github.com/mifosio/mariadb into develop
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 07/14: Merge pull request #3 from
mgeiss/develop
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit dc774a6beb6669b50343f957c30900786a0052a4
Merge: 289d5b1 642a6d9
Author: Markus Geiß <ma...@apache.org>
AuthorDate: Fri Apr 21 12:51:33 2017 +0200
Merge pull request #3 from mgeiss/develop
disabled use of server side generated prepared statements
.../java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java | 4 ++++
1 file changed, 4 insertions(+)
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 06/14: disabled use of server side generated
prepared statements
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit 642a6d9ee00baa043a3d4ef20a466bf5f344a003
Author: mgeiss <mg...@mifos.org>
AuthorDate: Fri Apr 21 12:32:34 2017 +0200
disabled use of server side generated prepared statements
---
.../java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
index 2e5be65..ded27a0 100644
--- a/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
+++ b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
@@ -107,6 +107,10 @@ public class MariaDBJavaConfiguration {
boneCPDataSource.setStatementsCacheSize(
Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_STATEMENT_CACHE_PROP, MariaDBConstants.BONECP_STATEMENT_CACHE_DEFAULT)));
+ final Properties driverProperties = new Properties();
+ driverProperties.setProperty("useServerPrepStmts", "false");
+ boneCPDataSource.setDriverProperties(driverProperties);
+
final ContextAwareRoutingDataSource dataSource = new ContextAwareRoutingDataSource(logger, JdbcUrlBuilder.DatabaseType.MARIADB);
dataSource.setMetaDataSource(boneCPDataSource);
final HashMap<Object, Object> targetDataSources = new HashMap<>();
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 09/14: Merge pull request #4 from
mgeiss/develop
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit c9f017c16787a8438666753e2ae48269a45ca92b
Merge: dc774a6 edbd5b2
Author: Markus Geiß <ma...@apache.org>
AuthorDate: Tue Apr 25 16:24:55 2017 +0200
Merge pull request #4 from mgeiss/develop
added replication capability to mariadb jdbc url
.../io/mifos/core/mariadb/util/JdbcUrlBuilder.java | 20 ++++++++++----
.../core/mariadb/util/JdbcUrlBuilderTest.java | 32 ++++++++++++++++++++--
2 files changed, 44 insertions(+), 8 deletions(-)
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 01/14: Open sourcing core.mariadb.
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit 6f0c108d092310cdc026362a6e06e148d3952275
Author: myrle-krantz <mk...@mifos.org>
AuthorDate: Tue Mar 14 10:42:19 2017 +0100
Open sourcing core.mariadb.
---
.gitignore | 14 ++
HEADER | 13 ++
README.md | 41 +++++
build.gradle | 81 ++++++++++
gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54212 bytes
gradle/wrapper/gradle-wrapper.properties | 6 +
gradlew | 172 +++++++++++++++++++++
gradlew.bat | 84 ++++++++++
settings.gradle | 1 +
.../mifos/core/mariadb/config/EnableMariaDB.java | 34 ++++
.../mariadb/config/MariaDBJavaConfiguration.java | 139 +++++++++++++++++
.../domain/ContextAwareRoutingDataSource.java | 116 ++++++++++++++
.../core/mariadb/domain/FlywayFactoryBean.java | 41 +++++
.../java/io/mifos/core/mariadb/domain/Tenant.java | 85 ++++++++++
.../io/mifos/core/mariadb/util/JdbcUrlBuilder.java | 74 +++++++++
.../core/mariadb/util/LocalDateConverter.java | 49 ++++++
.../core/mariadb/util/LocalDateTimeConverter.java | 49 ++++++
.../mifos/core/mariadb/util/MariaDBConstants.java | 49 ++++++
.../core/mariadb/util/JdbcUrlBuilderTest.java | 40 +++++
19 files changed, 1088 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..97a9529
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,14 @@
+.gradle
+.idea
+build/
+target/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+*.iml
+
+*.log
\ No newline at end of file
diff --git a/HEADER b/HEADER
new file mode 100644
index 0000000..d47a70e
--- /dev/null
+++ b/HEADER
@@ -0,0 +1,13 @@
+Copyright ${year} ${name}.
+
+Licensed 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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..90a94a9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,41 @@
+# Mifos I/O Core MariaDB
+
+[](https://gitter.im/mifos-initiative/mifos.io?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+
+This project is an umbrella for all Mifos I/O Core components.
+
+## Abstract
+Mifos I/O is an application framework for digital financial services, a system to support nationwide and cross-national financial transactions and help to level and speed the creation of an inclusive, interconnected digital economy for every nation in the world.
+
+## Prerequisites
+### Runtime
+Install Java 8 as described at https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html.
+
+### Installation
+Install MariaDB as described at https://mariadb.com/kb/en/mariadb/binary-packages/.
+
+After installation you need to create the meta database:
+
+ mysql -u root -pmysql
+ CREATE DATABASE IF NOT EXISTS system_console;
+
+## Multi-tenancy
+Multi-tenancy is reached by providing separate data storage on a per tenant basis.
+
+For every tenant a new database instance is created internally. A tenant aware component provides transparent access to these resources.
+
+## Versioning
+The version numbers follow the [Semantic Versioning](http://semver.org/) scheme.
+
+In addition to MAJOR.MINOR.PATCH the following postfixes are used to indicate the development state.
+
+* BUILD-SNAPSHOT - A release currently in development.
+* RELEASE - _General availability_ indicates that this release is the best available version and is recommended for all usage.
+
+The versioning layout is {MAJOR}.{MINOR}.{PATCH}-{INDICATOR}[.{PATCH}]. Only milestones and release candidates can have patch versions. Some examples:
+
+1.2.3-BUILD-SNAPSHOT
+1.3.5-RELEASE
+
+## License
+See [LICENSE](LICENSE) file.
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..152c6e5
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,81 @@
+buildscript {
+ repositories {
+ jcenter();
+ }
+}
+
+plugins {
+ id 'com.github.hierynomus.license' version '0.13.1'
+}
+
+group 'io.mifos.core'
+version '0.1.0-BUILD-SNAPSHOT'
+
+ext.versions = [
+ springcontext : '4.3.3.RELEASE',
+ springboot : '1.4.1.RELEASE',
+ findbugs : '3.0.1',
+ frameworklang : '0.1.0-BUILD-SNAPSHOT'
+]
+
+apply plugin: 'java'
+apply plugin: 'idea'
+apply plugin: 'maven'
+apply plugin: 'maven-publish'
+apply plugin: 'license'
+
+tasks.withType(JavaCompile) {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+}
+
+repositories {
+ jcenter()
+ mavenLocal()
+}
+
+dependencies {
+ compile(
+ [group: 'org.springframework', name: 'spring-context', version: versions.springcontext],
+ [group: 'com.google.code.findbugs', name: 'jsr305', version: versions.findbugs],
+ [group: 'io.mifos.core', name: 'lang', version: versions.frameworklang],
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: versions.springboot],
+ [group: 'com.jolbox', name: 'bonecp', version: '0.8.0.RELEASE'],
+ [group: 'org.flywaydb', name: 'flyway-core', version: '4.0.1']
+ )
+
+ //Workaround for bug described here: https://discuss.gradle.org/t/build-failure-when-4-1-0-of-net-java-dev-jna-jna-is-selected-in-place-of-3-3-0-due-to-change-in-artifacts-with-classifiers/9377/3
+ //These two compiled of jna and the exclude under mariadb-java-client may be removable once
+ //the bug is fixed in gradle.
+ compile('org.mariadb.jdbc:mariadb-java-client:1.4.3') {
+ exclude group: 'net.java.dev.jna'
+ }
+
+ compile 'net.java.dev.jna:jna:4.1.0'
+ compile 'net.java.dev.jna:jna-platform:4.1.0'
+
+ testCompile(
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.springboot]
+ )
+}
+
+publishing {
+ publications {
+ mariadbPublication(MavenPublication) {
+ from components.java
+ groupId project.group
+ artifactId project.name
+ version project.version
+ }
+ }
+}
+
+license {
+ header rootProject.file('HEADER')
+ strictCheck true
+ mapping {
+ java = 'SLASHSTAR_STYLE'
+ }
+ ext.year = Calendar.getInstance().get(Calendar.YEAR)
+ ext.name = 'The Mifos Initiative'
+}
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..a84e6fd
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..ab59e12
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue Mar 14 10:20:00 CET 2017
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..4453cce
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save ( ) {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..e95643d
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..4a2128f
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'mariadb'
\ No newline at end of file
diff --git a/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java b/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
new file mode 100644
index 0000000..b756123
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.config;
+
+import org.springframework.context.annotation.Import;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@Import({MariaDBJavaConfiguration.class})
+public @interface EnableMariaDB {
+
+}
diff --git a/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
new file mode 100644
index 0000000..2e5be65
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.config;
+
+import com.jolbox.bonecp.BoneCPDataSource;
+import io.mifos.core.lang.ApplicationName;
+import io.mifos.core.lang.config.EnableApplicationName;
+import io.mifos.core.mariadb.domain.ContextAwareRoutingDataSource;
+import io.mifos.core.mariadb.domain.FlywayFactoryBean;
+import io.mifos.core.mariadb.util.JdbcUrlBuilder;
+import io.mifos.core.mariadb.util.MariaDBConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.JpaVendorAdapter;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Properties;
+
+@SuppressWarnings("WeakerAccess")
+@Configuration
+@ConditionalOnProperty(prefix = "mariadb", name = "enabled", matchIfMissing = true)
+@EnableTransactionManagement
+@EnableApplicationName
+public class MariaDBJavaConfiguration {
+
+ private final Environment env;
+
+ @Autowired
+ public MariaDBJavaConfiguration(final Environment env) {
+ super();
+ this.env = env;
+ }
+
+ @Bean(name = MariaDBConstants.LOGGER_NAME)
+ public Logger logger() {
+ return LoggerFactory.getLogger(MariaDBConstants.LOGGER_NAME);
+ }
+
+ @Bean
+ public LocalContainerEntityManagerFactoryBean entityManagerFactory(final DataSource dataSource) {
+ final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
+ em.setPersistenceUnitName("metaPU");
+ em.setDataSource(dataSource);
+ em.setPackagesToScan("io.mifos.**.repository");
+
+ final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
+ em.setJpaVendorAdapter(vendorAdapter);
+ em.setJpaProperties(additionalProperties());
+
+ return em;
+ }
+
+ @Bean
+ public DataSource dataSource(@Qualifier(MariaDBConstants.LOGGER_NAME) final Logger logger) {
+ final BoneCPDataSource boneCPDataSource = new BoneCPDataSource();
+ boneCPDataSource.setDriverClass(
+ this.env.getProperty(MariaDBConstants.MARIADB_DRIVER_CLASS_PROP, MariaDBConstants.MARIADB_DRIVER_CLASS_DEFAULT));
+ boneCPDataSource.setJdbcUrl(JdbcUrlBuilder
+ .create(JdbcUrlBuilder.DatabaseType.MARIADB)
+ .host(this.env.getProperty(MariaDBConstants.MARIADB_HOST_PROP, MariaDBConstants.MARIADB_HOST_DEFAULT))
+ .port(this.env.getProperty(MariaDBConstants.MARIADB_PORT_PROP, MariaDBConstants.MARIADB_PORT_DEFAULT))
+ .instanceName(this.env.getProperty(MariaDBConstants.MARIADB_DATABASE_NAME_PROP, MariaDBConstants.MARIADB_DATABASE_NAME_DEFAULT))
+ .build());
+ boneCPDataSource.setUsername(
+ this.env.getProperty(MariaDBConstants.MARIADB_USER_PROP, MariaDBConstants.MARIADB_USER_DEFAULT));
+ boneCPDataSource.setPassword(
+ this.env.getProperty(MariaDBConstants.MARIADB_PASSWORD_PROP, MariaDBConstants.MARIADB_PASSWORD_DEFAULT));
+ boneCPDataSource.setIdleConnectionTestPeriodInMinutes(
+ Long.valueOf(this.env.getProperty(MariaDBConstants.BONECP_IDLE_CONNECTION_TEST_PROP, MariaDBConstants.BONECP_IDLE_CONNECTION_TEST_DEFAULT)));
+ boneCPDataSource.setIdleMaxAgeInMinutes(
+ Long.valueOf(this.env.getProperty(MariaDBConstants.BONECP_IDLE_MAX_AGE_PROP, MariaDBConstants.BONECP_IDLE_MAX_AGE_DEFAULT)));
+ boneCPDataSource.setMaxConnectionsPerPartition(
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_MAX_CONNECTION_PARTITION_PROP, MariaDBConstants.BONECP_MAX_CONNECTION_PARTITION_DEFAULT)));
+ boneCPDataSource.setMinConnectionsPerPartition(
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_MIN_CONNECTION_PARTITION_PROP, MariaDBConstants.BONECP_MIN_CONNECTION_PARTITION_DEFAULT)));
+ boneCPDataSource.setPartitionCount(
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_PARTITION_COUNT_PROP, MariaDBConstants.BONECP_PARTITION_COUNT_DEFAULT)));
+ boneCPDataSource.setAcquireIncrement(
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_ACQUIRE_INCREMENT_PROP, MariaDBConstants.BONECP_ACQUIRE_INCREMENT_DEFAULT)));
+ boneCPDataSource.setStatementsCacheSize(
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_STATEMENT_CACHE_PROP, MariaDBConstants.BONECP_STATEMENT_CACHE_DEFAULT)));
+
+ final ContextAwareRoutingDataSource dataSource = new ContextAwareRoutingDataSource(logger, JdbcUrlBuilder.DatabaseType.MARIADB);
+ dataSource.setMetaDataSource(boneCPDataSource);
+ final HashMap<Object, Object> targetDataSources = new HashMap<>();
+ dataSource.setTargetDataSources(targetDataSources);
+ return dataSource;
+ }
+
+ @Bean
+ public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
+ final JpaTransactionManager transactionManager = new JpaTransactionManager();
+ transactionManager.setEntityManagerFactory(emf);
+ return transactionManager;
+ }
+
+ @Bean
+ public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
+ return new PersistenceExceptionTranslationPostProcessor();
+ }
+
+ @Bean
+ public FlywayFactoryBean flywayFactoryBean(final ApplicationName applicationName) {
+ return new FlywayFactoryBean(applicationName);
+ }
+
+ private Properties additionalProperties() {
+ final Properties properties = new Properties();
+ properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
+ return properties;
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java b/src/main/java/io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java
new file mode 100644
index 0000000..4614d1a
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.domain;
+
+import com.jolbox.bonecp.BoneCPDataSource;
+import io.mifos.core.lang.TenantContextHolder;
+import io.mifos.core.mariadb.util.JdbcUrlBuilder;
+import io.mifos.core.mariadb.util.MariaDBConstants;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.concurrent.ConcurrentHashMap;
+
+public final class ContextAwareRoutingDataSource extends AbstractRoutingDataSource {
+
+ private final Logger logger;
+ private final JdbcUrlBuilder.DatabaseType type;
+ private final ConcurrentHashMap<String, DataSource> dynamicDataSources;
+ private DataSource metaDataSource;
+
+ public ContextAwareRoutingDataSource(@Qualifier(MariaDBConstants.LOGGER_NAME) final Logger logger,
+ final JdbcUrlBuilder.DatabaseType type) {
+ super();
+ this.logger = logger;
+ this.type = type;
+ this.dynamicDataSources = new ConcurrentHashMap<>();
+ }
+
+ public void setMetaDataSource(final DataSource metaDataSource) {
+ this.metaDataSource = metaDataSource;
+ super.setDefaultTargetDataSource(metaDataSource);
+ }
+
+ @Override
+ protected Object determineCurrentLookupKey() {
+ return TenantContextHolder.checkedGetIdentifier();
+ }
+
+ @Override
+ protected DataSource determineTargetDataSource() {
+ if (!TenantContextHolder.identifier().isPresent()) {
+ this.logger.warn("Tenant context not available.");
+ return super.determineTargetDataSource();
+ }
+
+ final String currentLookupKey = this.determineCurrentLookupKey().toString();
+
+ this.dynamicDataSources.computeIfAbsent(currentLookupKey, (key) -> {
+ this.logger.info("Creating new dynamic data source for {}.", currentLookupKey);
+ final Tenant tenant = new Tenant(currentLookupKey);
+ this.readAdditionalTenantInformation(tenant);
+ final BoneCPDataSource tenantDataSource = new BoneCPDataSource();
+ tenantDataSource.setDriverClass(tenant.getDriverClass());
+ tenantDataSource.setJdbcUrl(JdbcUrlBuilder
+ .create(this.type)
+ .host(tenant.getHost())
+ .port(tenant.getPort())
+ .instanceName(tenant.getDatabaseName())
+ .build());
+ tenantDataSource.setUsername(tenant.getUser());
+ tenantDataSource.setPassword(tenant.getPassword());
+
+ final BoneCPDataSource boneCpMetaDataSource = (BoneCPDataSource) this.metaDataSource;
+ tenantDataSource.setIdleConnectionTestPeriodInMinutes(boneCpMetaDataSource.getIdleConnectionTestPeriodInMinutes());
+ tenantDataSource.setIdleMaxAgeInMinutes(boneCpMetaDataSource.getIdleMaxAgeInMinutes());
+ tenantDataSource.setMaxConnectionsPerPartition(boneCpMetaDataSource.getMaxConnectionsPerPartition());
+ tenantDataSource.setMinConnectionsPerPartition(boneCpMetaDataSource.getMinConnectionsPerPartition());
+ tenantDataSource.setPartitionCount(boneCpMetaDataSource.getPartitionCount());
+ tenantDataSource.setAcquireIncrement(boneCpMetaDataSource.getAcquireIncrement());
+ tenantDataSource.setStatementsCacheSize(boneCpMetaDataSource.getStatementsCacheSize());
+ return tenantDataSource;
+ });
+
+ return this.dynamicDataSources.get(currentLookupKey);
+ }
+
+ private void readAdditionalTenantInformation(final Tenant tenant) {
+ this.logger.info("Reading additional information for {}.", tenant.getIdentifier());
+ @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) final String query = "SELECT driver_class, database_name, host, port, a_user, pwd FROM seshat.tenants WHERE identifier = ?";
+ try (final Connection connection = this.metaDataSource.getConnection()) {
+ try (final PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ preparedStatement.setString(1, tenant.getIdentifier());
+ final ResultSet resultSet = preparedStatement.executeQuery();
+ if (resultSet.next()) {
+ tenant.setDriverClass(resultSet.getString("driver_class"));
+ tenant.setDatabaseName(resultSet.getString("database_name"));
+ tenant.setHost(resultSet.getString("host"));
+ tenant.setPort(resultSet.getString("port"));
+ tenant.setUser(resultSet.getString("a_user"));
+ tenant.setPassword(resultSet.getString("pwd"));
+ }
+ }
+ } catch (SQLException ex) {
+ throw new IllegalArgumentException("Could not fetch information for tenant '" + tenant.getIdentifier() + "'", ex);
+ }
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/domain/FlywayFactoryBean.java b/src/main/java/io/mifos/core/mariadb/domain/FlywayFactoryBean.java
new file mode 100644
index 0000000..a01ee7b
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/domain/FlywayFactoryBean.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.domain;
+
+import io.mifos.core.lang.ApplicationName;
+import org.flywaydb.core.Flyway;
+
+import javax.sql.DataSource;
+
+public class FlywayFactoryBean {
+
+ private final ApplicationName applicationName;
+
+ public FlywayFactoryBean(final ApplicationName applicationName) {
+ super();
+ this.applicationName = applicationName;
+ }
+
+ public Flyway create(final DataSource dataSource) {
+ final Flyway flyway = new Flyway();
+ flyway.setDataSource(dataSource);
+ flyway.setLocations("db/migrations/mariadb");
+ flyway.setTable(this.applicationName.getServiceName() + "_schema_version");
+ flyway.setBaselineOnMigrate(true);
+ flyway.setBaselineVersionAsString("0");
+ return flyway;
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/domain/Tenant.java b/src/main/java/io/mifos/core/mariadb/domain/Tenant.java
new file mode 100644
index 0000000..7997cce
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/domain/Tenant.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.domain;
+
+@SuppressWarnings("WeakerAccess")
+public final class Tenant {
+
+ private final String identifier;
+ private String driverClass;
+ private String databaseName;
+ private String host;
+ private String port;
+ private String user;
+ private String password;
+
+ public Tenant(final String identifier) {
+ super();
+ this.identifier = identifier;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public String getDriverClass() {
+ return driverClass;
+ }
+
+ public void setDriverClass(String driverClass) {
+ this.driverClass = driverClass;
+ }
+
+ public String getDatabaseName() {
+ return databaseName;
+ }
+
+ public void setDatabaseName(String databaseName) {
+ this.databaseName = databaseName;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getPort() {
+ return port;
+ }
+
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
new file mode 100644
index 0000000..3c2576d
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.util;
+
+public final class JdbcUrlBuilder {
+
+ private final DatabaseType type;
+ private String host;
+ private String port;
+ private String instanceName;
+
+ private JdbcUrlBuilder(final DatabaseType type) {
+ super();
+ this.type = type;
+ }
+
+ public static JdbcUrlBuilder create(final DatabaseType type) {
+ return new JdbcUrlBuilder(type);
+ }
+
+ public JdbcUrlBuilder host(final String host) {
+ this.host = host;
+ return this;
+ }
+
+ public JdbcUrlBuilder port(final String port) {
+ this.port = port;
+ return this;
+ }
+
+ public JdbcUrlBuilder instanceName(final String instanceName) {
+ this.instanceName = instanceName;
+ return this;
+ }
+
+ public String build() {
+ switch (this.type) {
+ case MARIADB:
+ return this.type.prefix()
+ + this.host + ":"
+ + this.port
+ + (this.instanceName != null ? "/" + this.instanceName : "");
+ default:
+ throw new IllegalArgumentException("Unknown database type '" + this.type.name() + "'");
+ }
+ }
+
+ public enum DatabaseType {
+ MARIADB("jdbc:mariadb://");
+
+ private final String prefix;
+
+ DatabaseType(final String prefix) {
+ this.prefix = prefix;
+ }
+
+ String prefix() {
+ return this.prefix;
+ }
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/util/LocalDateConverter.java b/src/main/java/io/mifos/core/mariadb/util/LocalDateConverter.java
new file mode 100644
index 0000000..73b4f0b
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/util/LocalDateConverter.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.util;
+
+import io.mifos.core.lang.DateConverter;
+
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+import java.sql.Date;
+import java.time.LocalDate;
+
+@Converter
+public class LocalDateConverter implements AttributeConverter<LocalDate, Date> {
+
+ public LocalDateConverter() {
+ super();
+ }
+
+ @Override
+ public Date convertToDatabaseColumn(final LocalDate attribute) {
+ if (attribute == null) {
+ return null;
+ } else {
+ return new Date(DateConverter.toEpochDay(attribute));
+ }
+ }
+
+ @Override
+ public LocalDate convertToEntityAttribute(final Date dbData) {
+ if (dbData == null) {
+ return null;
+ } else {
+ return DateConverter.toLocalDate(DateConverter.fromEpochMillis(dbData.getTime()));
+ }
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/util/LocalDateTimeConverter.java b/src/main/java/io/mifos/core/mariadb/util/LocalDateTimeConverter.java
new file mode 100644
index 0000000..f78fa94
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/util/LocalDateTimeConverter.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.util;
+
+import io.mifos.core.lang.DateConverter;
+
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+
+@Converter
+public class LocalDateTimeConverter implements AttributeConverter<LocalDateTime, Timestamp> {
+
+ public LocalDateTimeConverter() {
+ super();
+ }
+
+ @Override
+ public Timestamp convertToDatabaseColumn(final LocalDateTime attribute) {
+ if (attribute == null) {
+ return null;
+ } else {
+ return new Timestamp(DateConverter.toEpochMillis(attribute));
+ }
+ }
+
+ @Override
+ public LocalDateTime convertToEntityAttribute(final Timestamp dbData) {
+ if (dbData == null) {
+ return null;
+ } else {
+ return DateConverter.fromEpochMillis(dbData.getTime());
+ }
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/util/MariaDBConstants.java b/src/main/java/io/mifos/core/mariadb/util/MariaDBConstants.java
new file mode 100644
index 0000000..fb626c0
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/util/MariaDBConstants.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.util;
+
+public interface MariaDBConstants {
+
+ String LOGGER_NAME = "maridb-logger";
+
+ String MARIADB_DRIVER_CLASS_PROP = "mariadb.driverClass";
+ String MARIADB_DRIVER_CLASS_DEFAULT = "org.mariadb.jdbc.Driver";
+ String MARIADB_DATABASE_NAME_PROP = "mariadb.database";
+ String MARIADB_DATABASE_NAME_DEFAULT = "seshat";
+ String MARIADB_HOST_PROP = "mariadb.host";
+ String MARIADB_HOST_DEFAULT = "localhost";
+ String MARIADB_PORT_PROP = "mariadb.port";
+ String MARIADB_PORT_DEFAULT = "3306";
+ String MARIADB_USER_PROP = "mariadb.user";
+ String MARIADB_USER_DEFAULT = "root";
+ String MARIADB_PASSWORD_PROP = "mariadb.password";
+ String MARIADB_PASSWORD_DEFAULT = "mysql";
+
+ String BONECP_IDLE_MAX_AGE_PROP = "bonecp.idleMaxAgeInMinutes";
+ String BONECP_IDLE_MAX_AGE_DEFAULT = "240";
+ String BONECP_IDLE_CONNECTION_TEST_PROP = "bonecp.idleConnectionTestPeriodInMinutes";
+ String BONECP_IDLE_CONNECTION_TEST_DEFAULT = "60";
+ String BONECP_MAX_CONNECTION_PARTITION_PROP = "bonecp.maxConnectionsPerPartition";
+ String BONECP_MAX_CONNECTION_PARTITION_DEFAULT = "16";
+ String BONECP_MIN_CONNECTION_PARTITION_PROP = "bonecp.minConnectionsPerPartition";
+ String BONECP_MIN_CONNECTION_PARTITION_DEFAULT = "4";
+ String BONECP_PARTITION_COUNT_PROP = "bonecp.partitionCount";
+ String BONECP_PARTITION_COUNT_DEFAULT = "2";
+ String BONECP_ACQUIRE_INCREMENT_PROP = "bonecp.acquireIncrement";
+ String BONECP_ACQUIRE_INCREMENT_DEFAULT = "4";
+ String BONECP_STATEMENT_CACHE_PROP = "bonecp.statementsCacheSize";
+ String BONECP_STATEMENT_CACHE_DEFAULT = "128";
+}
diff --git a/src/test/java/io/mifos/core/mariadb/util/JdbcUrlBuilderTest.java b/src/test/java/io/mifos/core/mariadb/util/JdbcUrlBuilderTest.java
new file mode 100644
index 0000000..550e5bc
--- /dev/null
+++ b/src/test/java/io/mifos/core/mariadb/util/JdbcUrlBuilderTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JdbcUrlBuilderTest {
+
+ private final static String MARIADB_JDBC_URL = "jdbc:mariadb://localhost:3306/comp_test";
+
+ public JdbcUrlBuilderTest() {
+ super();
+ }
+
+ @Test
+ public void shouldCreateMysqlUrl() {
+ final String mariaDbJdbcUrl = JdbcUrlBuilder
+ .create(JdbcUrlBuilder.DatabaseType.MARIADB)
+ .host("localhost")
+ .port("3306")
+ .instanceName("comp_test")
+ .build();
+
+ Assert.assertEquals(MARIADB_JDBC_URL, mariaDbJdbcUrl);
+ }
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 04/14: removed suggested fix b/c it's not
working
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit 96fcf48d31932e89459d76d9e43cd6d824955799
Author: mgeiss <mg...@mifos.org>
AuthorDate: Thu Apr 20 20:46:51 2017 +0200
removed suggested fix b/c it's not working
---
src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
index dbddabd..3c2576d 100644
--- a/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
+++ b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
@@ -52,8 +52,7 @@ public final class JdbcUrlBuilder {
return this.type.prefix()
+ this.host + ":"
+ this.port
- + (this.instanceName != null ? "/" + this.instanceName : "")
- + "?useServerPrepStmts=false";
+ + (this.instanceName != null ? "/" + this.instanceName : "");
default:
throw new IllegalArgumentException("Unknown database type '" + this.type.name() + "'");
}
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 02/14: added workaround for weird mariadb
behaviour
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit d2ba26084aad094658ce30ac10fd039bb496c096
Author: mgeiss <mg...@mifos.org>
AuthorDate: Thu Apr 20 20:11:18 2017 +0200
added workaround for weird mariadb behaviour
---
src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
index 3c2576d..dbddabd 100644
--- a/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
+++ b/src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java
@@ -52,7 +52,8 @@ public final class JdbcUrlBuilder {
return this.type.prefix()
+ this.host + ":"
+ this.port
- + (this.instanceName != null ? "/" + this.instanceName : "");
+ + (this.instanceName != null ? "/" + this.instanceName : "")
+ + "?useServerPrepStmts=false";
default:
throw new IllegalArgumentException("Unknown database type '" + this.type.name() + "'");
}
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 12/14: Added configuration parameter to
@Enable annotation to make it possible to run db connection in a
tenant-agnostic manner while still taking advantage of connection
pooling/configuration code. This could be further improved to sandbox by
app in the tenant-agnostic manner.
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit 154667e2c225cbba95983fb11a94fd55631f1855
Author: myrle-krantz <mk...@mifos.org>
AuthorDate: Wed May 17 16:44:38 2017 +0200
Added configuration parameter to @Enable annotation to make it possible to run db connection in a tenant-agnostic manner while still taking advantage of connection pooling/configuration code. This could be further improved to sandbox by app in the tenant-agnostic manner.
---
build.gradle | 4 ++
.../mifos/core/mariadb/config/EnableMariaDB.java | 5 +-
.../mariadb/config/MariaDBJavaConfiguration.java | 78 ++++++++++------------
.../MariaDBJavaConfigurationImportSelector.java | 47 +++++++++++++
.../MariaDBTenantBasedJavaConfiguration.java | 44 ++++++++++++
...ava => MariaDBTenantFreeJavaConfiguration.java} | 28 ++++----
...ableMariaDB.java => MetaDataSourceWrapper.java} | 27 ++++----
7 files changed, 162 insertions(+), 71 deletions(-)
diff --git a/build.gradle b/build.gradle
index 152c6e5..666b501 100644
--- a/build.gradle
+++ b/build.gradle
@@ -59,6 +59,10 @@ dependencies {
)
}
+jar {
+ from sourceSets.main.allSource
+}
+
publishing {
publications {
mariadbPublication(MavenPublication) {
diff --git a/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java b/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
index b756123..51d003a 100644
--- a/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
+++ b/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
@@ -24,11 +24,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+@SuppressWarnings({"WeakerAccess", "unused"})
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
-@Import({MariaDBJavaConfiguration.class})
+@Import({MariaDBJavaConfigurationImportSelector.class})
public @interface EnableMariaDB {
-
+ boolean forTenantContext() default true;
}
diff --git a/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
index ded27a0..5603d97 100644
--- a/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
+++ b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfiguration.java
@@ -15,17 +15,16 @@
*/
package io.mifos.core.mariadb.config;
+
import com.jolbox.bonecp.BoneCPDataSource;
import io.mifos.core.lang.ApplicationName;
import io.mifos.core.lang.config.EnableApplicationName;
-import io.mifos.core.mariadb.domain.ContextAwareRoutingDataSource;
import io.mifos.core.mariadb.domain.FlywayFactoryBean;
import io.mifos.core.mariadb.util.JdbcUrlBuilder;
import io.mifos.core.mariadb.util.MariaDBConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -40,7 +39,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
-import java.util.HashMap;
import java.util.Properties;
@SuppressWarnings("WeakerAccess")
@@ -78,61 +76,57 @@ public class MariaDBJavaConfiguration {
}
@Bean
- public DataSource dataSource(@Qualifier(MariaDBConstants.LOGGER_NAME) final Logger logger) {
+ public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
+ final JpaTransactionManager transactionManager = new JpaTransactionManager();
+ transactionManager.setEntityManagerFactory(emf);
+ return transactionManager;
+ }
+
+ @Bean
+ public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
+ return new PersistenceExceptionTranslationPostProcessor();
+ }
+
+ @Bean
+ public FlywayFactoryBean flywayFactoryBean(final ApplicationName applicationName) {
+ return new FlywayFactoryBean(applicationName);
+ }
+
+ @Bean
+ public MetaDataSourceWrapper metaDataSourceWrapper() {
+
final BoneCPDataSource boneCPDataSource = new BoneCPDataSource();
boneCPDataSource.setDriverClass(
- this.env.getProperty(MariaDBConstants.MARIADB_DRIVER_CLASS_PROP, MariaDBConstants.MARIADB_DRIVER_CLASS_DEFAULT));
+ this.env.getProperty(MariaDBConstants.MARIADB_DRIVER_CLASS_PROP, MariaDBConstants.MARIADB_DRIVER_CLASS_DEFAULT));
boneCPDataSource.setJdbcUrl(JdbcUrlBuilder
- .create(JdbcUrlBuilder.DatabaseType.MARIADB)
- .host(this.env.getProperty(MariaDBConstants.MARIADB_HOST_PROP, MariaDBConstants.MARIADB_HOST_DEFAULT))
- .port(this.env.getProperty(MariaDBConstants.MARIADB_PORT_PROP, MariaDBConstants.MARIADB_PORT_DEFAULT))
- .instanceName(this.env.getProperty(MariaDBConstants.MARIADB_DATABASE_NAME_PROP, MariaDBConstants.MARIADB_DATABASE_NAME_DEFAULT))
- .build());
+ .create(JdbcUrlBuilder.DatabaseType.MARIADB)
+ .host(this.env.getProperty(MariaDBConstants.MARIADB_HOST_PROP, MariaDBConstants.MARIADB_HOST_DEFAULT))
+ .port(this.env.getProperty(MariaDBConstants.MARIADB_PORT_PROP, MariaDBConstants.MARIADB_PORT_DEFAULT))
+ .instanceName(this.env.getProperty(MariaDBConstants.MARIADB_DATABASE_NAME_PROP, MariaDBConstants.MARIADB_DATABASE_NAME_DEFAULT))
+ .build());
boneCPDataSource.setUsername(
- this.env.getProperty(MariaDBConstants.MARIADB_USER_PROP, MariaDBConstants.MARIADB_USER_DEFAULT));
+ this.env.getProperty(MariaDBConstants.MARIADB_USER_PROP, MariaDBConstants.MARIADB_USER_DEFAULT));
boneCPDataSource.setPassword(
- this.env.getProperty(MariaDBConstants.MARIADB_PASSWORD_PROP, MariaDBConstants.MARIADB_PASSWORD_DEFAULT));
+ this.env.getProperty(MariaDBConstants.MARIADB_PASSWORD_PROP, MariaDBConstants.MARIADB_PASSWORD_DEFAULT));
boneCPDataSource.setIdleConnectionTestPeriodInMinutes(
- Long.valueOf(this.env.getProperty(MariaDBConstants.BONECP_IDLE_CONNECTION_TEST_PROP, MariaDBConstants.BONECP_IDLE_CONNECTION_TEST_DEFAULT)));
+ Long.valueOf(this.env.getProperty(MariaDBConstants.BONECP_IDLE_CONNECTION_TEST_PROP, MariaDBConstants.BONECP_IDLE_CONNECTION_TEST_DEFAULT)));
boneCPDataSource.setIdleMaxAgeInMinutes(
- Long.valueOf(this.env.getProperty(MariaDBConstants.BONECP_IDLE_MAX_AGE_PROP, MariaDBConstants.BONECP_IDLE_MAX_AGE_DEFAULT)));
+ Long.valueOf(this.env.getProperty(MariaDBConstants.BONECP_IDLE_MAX_AGE_PROP, MariaDBConstants.BONECP_IDLE_MAX_AGE_DEFAULT)));
boneCPDataSource.setMaxConnectionsPerPartition(
- Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_MAX_CONNECTION_PARTITION_PROP, MariaDBConstants.BONECP_MAX_CONNECTION_PARTITION_DEFAULT)));
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_MAX_CONNECTION_PARTITION_PROP, MariaDBConstants.BONECP_MAX_CONNECTION_PARTITION_DEFAULT)));
boneCPDataSource.setMinConnectionsPerPartition(
- Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_MIN_CONNECTION_PARTITION_PROP, MariaDBConstants.BONECP_MIN_CONNECTION_PARTITION_DEFAULT)));
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_MIN_CONNECTION_PARTITION_PROP, MariaDBConstants.BONECP_MIN_CONNECTION_PARTITION_DEFAULT)));
boneCPDataSource.setPartitionCount(
- Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_PARTITION_COUNT_PROP, MariaDBConstants.BONECP_PARTITION_COUNT_DEFAULT)));
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_PARTITION_COUNT_PROP, MariaDBConstants.BONECP_PARTITION_COUNT_DEFAULT)));
boneCPDataSource.setAcquireIncrement(
- Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_ACQUIRE_INCREMENT_PROP, MariaDBConstants.BONECP_ACQUIRE_INCREMENT_DEFAULT)));
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_ACQUIRE_INCREMENT_PROP, MariaDBConstants.BONECP_ACQUIRE_INCREMENT_DEFAULT)));
boneCPDataSource.setStatementsCacheSize(
- Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_STATEMENT_CACHE_PROP, MariaDBConstants.BONECP_STATEMENT_CACHE_DEFAULT)));
+ Integer.valueOf(this.env.getProperty(MariaDBConstants.BONECP_STATEMENT_CACHE_PROP, MariaDBConstants.BONECP_STATEMENT_CACHE_DEFAULT)));
final Properties driverProperties = new Properties();
driverProperties.setProperty("useServerPrepStmts", "false");
boneCPDataSource.setDriverProperties(driverProperties);
-
- final ContextAwareRoutingDataSource dataSource = new ContextAwareRoutingDataSource(logger, JdbcUrlBuilder.DatabaseType.MARIADB);
- dataSource.setMetaDataSource(boneCPDataSource);
- final HashMap<Object, Object> targetDataSources = new HashMap<>();
- dataSource.setTargetDataSources(targetDataSources);
- return dataSource;
- }
-
- @Bean
- public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
- final JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(emf);
- return transactionManager;
- }
-
- @Bean
- public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
- return new PersistenceExceptionTranslationPostProcessor();
- }
-
- @Bean
- public FlywayFactoryBean flywayFactoryBean(final ApplicationName applicationName) {
- return new FlywayFactoryBean(applicationName);
+ return new MetaDataSourceWrapper(boneCPDataSource);
}
private Properties additionalProperties() {
diff --git a/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfigurationImportSelector.java b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfigurationImportSelector.java
new file mode 100644
index 0000000..b1dc720
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/config/MariaDBJavaConfigurationImportSelector.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.config;
+
+import org.springframework.context.annotation.ImportSelector;
+import org.springframework.core.type.AnnotationMetadata;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Myrle Krantz
+ */
+class MariaDBJavaConfigurationImportSelector implements ImportSelector {
+ @Override
+ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
+ final boolean forTenantContext = (boolean)importingClassMetadata
+ .getAnnotationAttributes(EnableMariaDB.class.getTypeName())
+ .get("forTenantContext");
+
+ final Set<Class> classesToImport = new HashSet<>();
+ final String prop = System.getProperty("mariadb.enabled");
+ if (prop == null || "true".equals(prop)) {
+ classesToImport.add(MariaDBJavaConfiguration.class);
+ if (forTenantContext) {
+ classesToImport.add(MariaDBTenantBasedJavaConfiguration.class);
+ }
+ else {
+ classesToImport.add(MariaDBTenantFreeJavaConfiguration.class);
+ }
+ }
+ return classesToImport.stream().map(Class::getCanonicalName).toArray(String[]::new);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/mifos/core/mariadb/config/MariaDBTenantBasedJavaConfiguration.java b/src/main/java/io/mifos/core/mariadb/config/MariaDBTenantBasedJavaConfiguration.java
new file mode 100644
index 0000000..7506cfb
--- /dev/null
+++ b/src/main/java/io/mifos/core/mariadb/config/MariaDBTenantBasedJavaConfiguration.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.mariadb.config;
+
+import io.mifos.core.mariadb.domain.ContextAwareRoutingDataSource;
+import io.mifos.core.mariadb.util.JdbcUrlBuilder;
+import io.mifos.core.mariadb.util.MariaDBConstants;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+
+@SuppressWarnings("WeakerAccess")
+@Configuration
+@ConditionalOnProperty(prefix = "mariadb", name = "enabled", matchIfMissing = true)
+public class MariaDBTenantBasedJavaConfiguration {
+ @Bean
+ public DataSource dataSource(@Qualifier(MariaDBConstants.LOGGER_NAME) final Logger logger,
+ final MetaDataSourceWrapper metaDataSource) {
+
+ final ContextAwareRoutingDataSource dataSource = new ContextAwareRoutingDataSource(logger, JdbcUrlBuilder.DatabaseType.MARIADB);
+ dataSource.setMetaDataSource(metaDataSource.getMetaDataSource());
+ final HashMap<Object, Object> targetDataSources = new HashMap<>();
+ dataSource.setTargetDataSources(targetDataSources);
+ return dataSource;
+ }
+}
diff --git a/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java b/src/main/java/io/mifos/core/mariadb/config/MariaDBTenantFreeJavaConfiguration.java
similarity index 53%
copy from src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
copy to src/main/java/io/mifos/core/mariadb/config/MariaDBTenantFreeJavaConfiguration.java
index b756123..cf6e7fe 100644
--- a/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
+++ b/src/main/java/io/mifos/core/mariadb/config/MariaDBTenantFreeJavaConfiguration.java
@@ -15,20 +15,22 @@
*/
package io.mifos.core.mariadb.config;
-import org.springframework.context.annotation.Import;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Inherited
-@Import({MariaDBJavaConfiguration.class})
-public @interface EnableMariaDB {
+import javax.sql.DataSource;
+/**
+ * @author Myrle Krantz
+ */
+@SuppressWarnings("WeakerAccess")
+@Configuration
+@ConditionalOnProperty(prefix = "mariadb", name = "enabled", matchIfMissing = true)
+public class MariaDBTenantFreeJavaConfiguration {
+ @Bean
+ public DataSource dataSource(final MetaDataSourceWrapper metaDataSource) {
+ return metaDataSource.getMetaDataSource();
+ }
}
diff --git a/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java b/src/main/java/io/mifos/core/mariadb/config/MetaDataSourceWrapper.java
similarity index 58%
copy from src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
copy to src/main/java/io/mifos/core/mariadb/config/MetaDataSourceWrapper.java
index b756123..43b497c 100644
--- a/src/main/java/io/mifos/core/mariadb/config/EnableMariaDB.java
+++ b/src/main/java/io/mifos/core/mariadb/config/MetaDataSourceWrapper.java
@@ -15,20 +15,19 @@
*/
package io.mifos.core.mariadb.config;
-import org.springframework.context.annotation.Import;
+import com.jolbox.bonecp.BoneCPDataSource;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+/**
+ * @author Myrle Krantz
+ */
+public class MetaDataSourceWrapper {
+ private final BoneCPDataSource metaDataSource;
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Inherited
-@Import({MariaDBJavaConfiguration.class})
-public @interface EnableMariaDB {
+ public MetaDataSourceWrapper(final BoneCPDataSource metaDataSource) {
+ this.metaDataSource = metaDataSource;
+ }
-}
+ BoneCPDataSource getMetaDataSource() {
+ return metaDataSource;
+ }
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 10/14: Local vs bound variable. Minor fix.
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit 38683427520702d65c30ee232a4587a95a54e9d7
Author: myrle-krantz <mk...@mifos.org>
AuthorDate: Mon May 15 17:18:45 2017 +0200
Local vs bound variable. Minor fix.
---
.../io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java b/src/main/java/io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java
index 4614d1a..f70457a 100644
--- a/src/main/java/io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java
+++ b/src/main/java/io/mifos/core/mariadb/domain/ContextAwareRoutingDataSource.java
@@ -65,8 +65,8 @@ public final class ContextAwareRoutingDataSource extends AbstractRoutingDataSour
final String currentLookupKey = this.determineCurrentLookupKey().toString();
this.dynamicDataSources.computeIfAbsent(currentLookupKey, (key) -> {
- this.logger.info("Creating new dynamic data source for {}.", currentLookupKey);
- final Tenant tenant = new Tenant(currentLookupKey);
+ this.logger.info("Creating new dynamic data source for {}.", key);
+ final Tenant tenant = new Tenant(key);
this.readAdditionalTenantInformation(tenant);
final BoneCPDataSource tenantDataSource = new BoneCPDataSource();
tenantDataSource.setDriverClass(tenant.getDriverClass());
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 05/14: Merge pull request #2 from
mgeiss/develop
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit 289d5b1e3a2c5e84d5758b6e2049d407ec8a0d70
Merge: ef671ec 96fcf48
Author: Markus Geiß <ma...@apache.org>
AuthorDate: Thu Apr 20 20:47:33 2017 +0200
Merge pull request #2 from mgeiss/develop
removed suggested fix b/c it's not working
src/main/java/io/mifos/core/mariadb/util/JdbcUrlBuilder.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.
[fineract-cn-mariadb] 14/14: Merge pull request #6 from
myrle-krantz/develop
Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git
commit a42774cf26bb0abbe76fc5deeccd843eb89d6a45
Merge: bc9ccf9 51b6844
Author: Myrle Krantz <my...@apache.org>
AuthorDate: Wed May 17 16:48:47 2017 +0200
Merge pull request #6 from myrle-krantz/develop
1st pass: cross-tenant db
build.gradle | 4 ++
.../mifos/core/mariadb/config/EnableMariaDB.java | 5 +-
.../mariadb/config/MariaDBJavaConfiguration.java | 78 ++++++++++------------
.../MariaDBJavaConfigurationImportSelector.java | 47 +++++++++++++
.../MariaDBTenantBasedJavaConfiguration.java | 44 ++++++++++++
...ava => MariaDBTenantFreeJavaConfiguration.java} | 28 ++++----
...ableMariaDB.java => MetaDataSourceWrapper.java} | 27 ++++----
7 files changed, 162 insertions(+), 71 deletions(-)
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.