You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ik...@apache.org on 2019/08/25 17:10:36 UTC

[fineract-cn-postgresql] branch develop updated (a943bfc -> 669b386)

This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git.


    from a943bfc  Merge pull request #4 from ebenezergraham/FINCN-157
     new df172c6  EclipseLink Configuration extending JpaBaseConfiguration
     new ec31f9a  Removing start on deploy
     new 669b386  Merge pull request #5 from ebenezergraham/FINCN-2

The 12 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.


Summary of changes:
 build.gradle                                       |  38 +++--
 .../config/EclipseLinkJpaConfiguration.java        |  95 +++++++++++++
 .../config/PostgreSQLJavaConfiguration.java        | 156 ++++++++-------------
 .../cn/postgresql/util/PostgreSQLConstants.java    |   1 +
 4 files changed, 183 insertions(+), 107 deletions(-)
 create mode 100644 src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java


[fineract-cn-postgresql] 04/12: FINCN-148 build with travis-ci.com and upload artifacts to Artifactory

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit 49140c569ddd7d256c8e90caa5ec0972b9ac55bd
Author: Juhan Aasaru <Ju...@nortal.com>
AuthorDate: Thu Apr 25 11:24:49 2019 +0300

    FINCN-148 build with travis-ci.com and upload artifacts to Artifactory
---
 .travis.yml  | 30 +++++++++++++++++++++++++
 README.md    |  2 +-
 build.gradle | 20 ++++++++++++++++-
 travis.sh    | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 travis.yml   | 22 -------------------
 5 files changed, 121 insertions(+), 24 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..3e1044b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+language: java
+sudo: false
+jdk:
+- openjdk8
+install: true
+script: "./travis.sh"
+env:
+  global:
+    - BUILD_SNAPSHOTS_BRANCH=develop
+    - ARTIFACTORY_URL=https://mifos.jfrog.io/mifos
+    - ARTIFACTORY_USER=travis-ci
+    - secure: "mhGQ1cWlgaHNclvoxUupUMrslqdD5FXFsmXKUNRWbyHdRxos6rsxhNLJVOSf3Tv5QMQkOLFSbJd0uZcBCiY84TPdXLiIPrT3RkPwHrFG34L3W3oIs9+1XsCUGczD5qdLnYvDa1g+yk2cQB05vwnmtC6hx21pryvxrci68BoV9cVO9CqKhpjxy3gu4GdxtMfc6kU7PbNvLHoN738JZnngx8RUCL6pOUoe0UgbJMbd2goKmzY/eMAGGc+BPUOp8FUavuS4vT/eUoCL2dbLC8X50WRTbHACAHQY9l2ftRxE5d7HatN+1v4+yAvL25aafzV3WrwMTSzHMLWYPE5cCmGeZSswt1UNReHuLwz9R8KPfqAx3ML2Kt5TQivimS4SS2V4zutvysMO2iiPrCnQRM2iVGaHx1Rbjwmvexe9cLCg3QsIvLFxLB/sbb97WybM6DXiqBIO0NlcVEWFDIEgKFqf+yVH1LHpu [...]
diff --git a/README.md b/README.md
index 1692ac0..341a893 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Apache Fineract CN PostgreSQL
+# Apache Fineract CN PostgreSQL [![Build Status](https://api.travis-ci.com/apache/fineract-cn-postgresql.svg?branch=develop)](https://travis-ci.com/apache/fineract-cn-postgresql)
 
 ## Abstract
 Apache Fineract CN 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.
diff --git a/build.gradle b/build.gradle
index 64ac70f..d321842 100644
--- a/build.gradle
+++ b/build.gradle
@@ -24,6 +24,7 @@ buildscript {
 plugins {
     id 'com.github.hierynomus.license' version '0.13.1'
     id("org.nosphere.apache.rat") version "0.3.1"
+    id "com.jfrog.artifactory" version "4.9.5"
 }
 
 group 'org.apache.fineract.cn'
@@ -50,6 +51,7 @@ tasks.withType(JavaCompile) {
 repositories {
     jcenter()
     mavenLocal()
+    maven { url 'https://mifos.jfrog.io/mifos/libs-snapshot/' }
 }
 
 dependencies {
@@ -77,11 +79,27 @@ publishing {
             from components.java
             groupId project.group
             artifactId project.name
-            version project.version
+            version project.findProperty('externalVersion') ?: project.version
         }
     }
 }
 
+artifactory {
+    contextUrl = System.getenv("ARTIFACTORY_URL")
+    publish {
+        repository {
+            repoKey = project.findProperty('artifactoryRepoKey')
+            username = System.getenv("ARTIFACTORY_USER")
+            password = System.getenv("ARTIFACTORY_PASSWORD")
+        }
+
+        defaults {
+            publications ('postgresqlPublication')
+        }
+    }
+}
+artifactoryPublish.dependsOn('clean','publishToMavenLocal')
+
 license {
     header rootProject.file('HEADER')
     strictCheck true
diff --git a/travis.sh b/travis.sh
new file mode 100755
index 0000000..03a75ee
--- /dev/null
+++ b/travis.sh
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+# Documentation: https://cwiki.apache.org/confluence/display/FINERACT/Fineract-CN+Artifactory
+
+#Exit immediately if a command exits with a non-zero status.
+set -e
+EXIT_STATUS=0
+
+# Builds and Publishes a SNAPSHOT
+function build_snapshot() {
+  echo -e "Building and publishing a snapshot out of branch [$TRAVIS_BRANCH]"
+  ./gradlew -PartifactoryRepoKey=libs-snapshot-local -DbuildInfo.build.number=${TRAVIS_COMMIT::7} artifactoryPublish --stacktrace || EXIT_STATUS=$?
+}
+
+# Builds a Pull Request
+function build_pullrequest() {
+  echo -e "Building pull request #$TRAVIS_PULL_REQUEST of branch [$TRAVIS_BRANCH]. Won't publish anything to Artifactory."
+  ./gradlew publishToMavenLocal rat || EXIT_STATUS=$?
+}
+
+# For other branches we need to add branch name as prefix
+function build_otherbranch() {
+  echo -e "Building a snapshot out of branch [$TRAVIS_BRANCH] and publishing it with prefix '${TRAVIS_BRANCH}-SNAPSHOT'"
+  ./gradlew -PartifactoryRepoKey=libs-snapshot-local -DbuildInfo.build.number=${TRAVIS_COMMIT::7} -PexternalVersion=${TRAVIS_BRANCH}-SNAPSHOT artifactoryPublish --stacktrace || EXIT_STATUS=$?
+}
+
+# Builds and Publishes a Tag
+function build_tag() {
+  echo -e "Building tag [$TRAVIS_TAG] and publishing it as a release"
+  ./gradlew -PartifactoryRepoKey=libs-release-local -PexternalVersion=$TRAVIS_TAG artifactoryPublish --stacktrace || EXIT_STATUS=$?
+
+}
+
+echo -e "TRAVIS_BRANCH=$TRAVIS_BRANCH"
+echo -e "TRAVIS_TAG=$TRAVIS_TAG"
+echo -e "TRAVIS_COMMIT=${TRAVIS_COMMIT::7}"
+echo -e "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST"
+
+# Build Logic
+if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
+  build_pullrequest
+elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" != "$BUILD_SNAPSHOTS_BRANCH" ] && [ "$TRAVIS_TAG" == "" ]  ; then
+  build_otherbranch
+elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "$BUILD_SNAPSHOTS_BRANCH" ] && [ "$TRAVIS_TAG" == "" ] ; then
+  build_snapshot
+elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
+  build_tag
+else
+  echo -e "WARN: Unexpected env variable values => Branch [$TRAVIS_BRANCH], Tag [$TRAVIS_TAG], Pull Request [#$TRAVIS_PULL_REQUEST]"
+  ./gradlew clean build
+fi
+
+exit ${EXIT_STATUS}
diff --git a/travis.yml b/travis.yml
deleted file mode 100644
index 5cc5893..0000000
--- a/travis.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# 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.
-#
-
-language: java
-jdk:
- - oraclejdk8
\ No newline at end of file


[fineract-cn-postgresql] 12/12: Merge pull request #5 from ebenezergraham/FINCN-2

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit 669b3868248671a068def1fba2139e86b93926ca
Merge: a943bfc ec31f9a
Author: Isaac Kamga <ik...@apache.org>
AuthorDate: Sun Aug 25 18:10:31 2019 +0100

    Merge pull request #5 from ebenezergraham/FINCN-2
    
    Eclipselink Configuration Works

 build.gradle                                       |  38 +++--
 .../config/EclipseLinkJpaConfiguration.java        |  95 +++++++++++++
 .../config/PostgreSQLJavaConfiguration.java        | 156 ++++++++-------------
 .../cn/postgresql/util/PostgreSQLConstants.java    |   1 +
 4 files changed, 183 insertions(+), 107 deletions(-)


[fineract-cn-postgresql] 08/12: Adding rat report to After Failure procedure

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit a0ddbff091441de10bc69c681a98254ab5d5319a
Author: ebenezergraham <eg...@alustudent.com>
AuthorDate: Wed May 29 19:10:07 2019 +0400

    Adding rat report to After Failure procedure
---
 .travis.yml  | 3 +++
 build.gradle | 1 +
 2 files changed, 4 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 3e1044b..f14890c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -28,3 +28,6 @@ env:
     - ARTIFACTORY_URL=https://mifos.jfrog.io/mifos
     - ARTIFACTORY_USER=travis-ci
     - secure: "mhGQ1cWlgaHNclvoxUupUMrslqdD5FXFsmXKUNRWbyHdRxos6rsxhNLJVOSf3Tv5QMQkOLFSbJd0uZcBCiY84TPdXLiIPrT3RkPwHrFG34L3W3oIs9+1XsCUGczD5qdLnYvDa1g+yk2cQB05vwnmtC6hx21pryvxrci68BoV9cVO9CqKhpjxy3gu4GdxtMfc6kU7PbNvLHoN738JZnngx8RUCL6pOUoe0UgbJMbd2goKmzY/eMAGGc+BPUOp8FUavuS4vT/eUoCL2dbLC8X50WRTbHACAHQY9l2ftRxE5d7HatN+1v4+yAvL25aafzV3WrwMTSzHMLWYPE5cCmGeZSswt1UNReHuLwz9R8KPfqAx3ML2Kt5TQivimS4SS2V4zutvysMO2iiPrCnQRM2iVGaHx1Rbjwmvexe9cLCg3QsIvLFxLB/sbb97WybM6DXiqBIO0NlcVEWFDIEgKFqf+yVH1LHpu [...]
+after_failure:
+  - ./gradlew rat
+  - cat build/reports/rat/rat-report.txt
diff --git a/build.gradle b/build.gradle
index d321842..8a5cb92 100644
--- a/build.gradle
+++ b/build.gradle
@@ -119,4 +119,5 @@ rat {
             "gradlew.bat",
             "README.md"
     ]
+    plainOutput = true
 }


[fineract-cn-postgresql] 11/12: Removing start on deploy

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit ec31f9a69abd8eacbea7940459f44fe3859e7e2a
Author: Ebenezer Graham <eg...@alustudent.com>
AuthorDate: Sun Jul 21 22:22:05 2019 +0400

    Removing start on deploy
---
 .../fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java       | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java b/src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java
index 62ff39f..0ca5428 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java
@@ -90,7 +90,6 @@ public class EclipseLinkJpaConfiguration extends JpaBaseConfiguration {
 		properties.put(PersistenceUnitProperties.BATCH_WRITING, BatchWriting.JDBC);
 		properties.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.ALL_LABEL);// Todo: Reduce log level after test
 		properties.put(PersistenceUnitProperties.LOGGING_PARAMETERS, "true");
-		properties.put(PersistenceUnitProperties.DEPLOY_ON_STARTUP, "false");
 		return properties;
 	}
 }


[fineract-cn-postgresql] 03/12: Merge pull request #1 from Izakey/develop

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit 5f2cbfab9e770ab9172a8939772adc08413930ba
Merge: 3d72340 779aaa6
Author: Isaac Kamga <u2...@gmail.com>
AuthorDate: Sat Mar 23 02:43:02 2019 +0100

    Merge pull request #1 from Izakey/develop
    
    Revert to Hibernate ORM until migration to Postgres is complete

 build.gradle                                       |  3 +-
 .../config/PostgreSQLJavaConfiguration.java        |  8 ++-
 .../cn/postgresql/util/JdbcUrlBuilder.java         | 32 ++++------
 .../cn/postgresql/util/PostgreSQLConstants.java    |  4 +-
 .../cn/postgresql/util/JdbcUrlBuilderTest.java     | 68 ++++++----------------
 5 files changed, 36 insertions(+), 79 deletions(-)


[fineract-cn-postgresql] 06/12: Added password attribute to tenant domain transfer object

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit 643db751aa24205684946d5037273ee2bdbb1159
Author: Isaac Kamga <u2...@gmail.com>
AuthorDate: Thu May 2 02:45:13 2019 +0100

    Added password attribute to tenant domain transfer object
---
 .../fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java | 4 +++-
 src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java   | 5 +++++
 .../org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java   | 4 ++--
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java b/src/main/java/org/apache/fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java
index d3df26f..72b310a 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java
@@ -81,6 +81,7 @@ public final class ContextAwareRoutingDataSource extends AbstractRoutingDataSour
           .instanceName(tenant.getDatabaseName())
           .build());
       tenantDataSource.setUsername(tenant.getUser());
+      tenantDataSource.setPassword(tenant.getPassword());
 
       final BoneCPDataSource boneCpMetaDataSource = (BoneCPDataSource) this.metaDataSource;
       tenantDataSource.setIdleConnectionTestPeriodInMinutes(boneCpMetaDataSource.getIdleConnectionTestPeriodInMinutes());
@@ -99,7 +100,7 @@ public final class ContextAwareRoutingDataSource extends AbstractRoutingDataSour
   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 FROM seshat.tenants WHERE identifier = ?";
+    final String query = "SELECT driver_class, database_name, host, port, a_user, pwd FROM tenants WHERE identifier = ?";
     try (final Connection connection = this.metaDataSource.getConnection()) {
       try (final PreparedStatement preparedStatement = connection.prepareStatement(query)) {
         preparedStatement.setString(1, tenant.getIdentifier());
@@ -110,6 +111,7 @@ public final class ContextAwareRoutingDataSource extends AbstractRoutingDataSour
           tenant.setHost(resultSet.getString("host"));
           tenant.setPort(resultSet.getString("port"));
           tenant.setUser(resultSet.getString("a_user"));
+          tenant.setPassword(resultSet.getString("pwd"));
         }
       }
     } catch (SQLException ex) {
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java b/src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java
index 3bb7ef0..9b1d8d2 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java
@@ -27,6 +27,7 @@ public final class Tenant {
   private String host;
   private String port;
   private String user;
+  private String password;
 
   public Tenant(final String identifier) {
     super();
@@ -76,4 +77,8 @@ public final class Tenant {
   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/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java b/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
index c5ffe4b..242209b 100644
--- a/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
+++ b/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
@@ -47,7 +47,7 @@ public class JdbcUrlBuilderTest {
   }
 
   @Test
-  public void shouldCreateMysqlUrlNoInstance() {
+  public void shouldCreatePostgresqlUrlNoInstance() {
     final String expectedJdbcUrl = "jdbc:postgresql://localhost:5432";
 
     final String postgresqlJdbcUrl = JdbcUrlBuilder
@@ -59,7 +59,7 @@ public class JdbcUrlBuilderTest {
   }
 
   @Test
-  public void shouldCreateMysqlReplicationUrl() {
+  public void shouldCreatePostgresqlReplicationUrl() {
     final String expectedJdbcUrl = "jdbc:postgresql:replication://localhost:5432,anotherhost:5432/comp_test";
 
     final String mariaDbJdbcUrl = JdbcUrlBuilder


[fineract-cn-postgresql] 02/12: Revert to Hibernate ORM until migration to Postgres is complete

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit 779aaa65b2ad3d35fcc4f0ea177b378fc162130b
Author: Isaac Kamga <u2...@gmail.com>
AuthorDate: Fri Mar 22 23:34:31 2019 +0100

    Revert to Hibernate ORM until migration to Postgres is complete
---
 build.gradle                                       |  3 +-
 .../config/PostgreSQLJavaConfiguration.java        |  8 ++-
 .../cn/postgresql/util/JdbcUrlBuilder.java         | 32 ++++------
 .../cn/postgresql/util/PostgreSQLConstants.java    |  4 +-
 .../cn/postgresql/util/JdbcUrlBuilderTest.java     | 68 ++++++----------------
 5 files changed, 36 insertions(+), 79 deletions(-)

diff --git a/build.gradle b/build.gradle
index ac19102..64ac70f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -60,8 +60,7 @@ dependencies {
             [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'],
-            [group: 'org.postgresql', name: 'postgresql', version: '42.2.5'],
-            [group: 'org.apache.openjpa', name: 'openjpa', version: '3.0.0']
+            [group: 'org.postgresql', name: 'postgresql', version: '42.2.5']
     )
     testCompile(
             [group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.springboot]
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
index 9e114dd..09d7a9f 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
@@ -35,7 +35,7 @@ import org.springframework.dao.annotation.PersistenceExceptionTranslationPostPro
 import org.springframework.orm.jpa.JpaTransactionManager;
 import org.springframework.orm.jpa.JpaVendorAdapter;
 import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
-import org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
 import org.springframework.transaction.PlatformTransactionManager;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
@@ -70,7 +70,7 @@ public class PostgreSQLJavaConfiguration {
     em.setDataSource(dataSource);
     em.setPackagesToScan("org.apache.fineract.cn.**.repository");
 
-    final JpaVendorAdapter vendorAdapter = new OpenJpaVendorAdapter();
+    final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
     em.setJpaVendorAdapter(vendorAdapter);
     em.setJpaProperties(additionalProperties());
 
@@ -108,6 +108,8 @@ public class PostgreSQLJavaConfiguration {
             .build());
     boneCPDataSource.setUsername(
             this.env.getProperty(PostgreSQLConstants.POSTGRESQL_USER_PROP, PostgreSQLConstants.POSTGRESQL_USER_DEFAULT));
+    boneCPDataSource.setPassword(
+            this.env.getProperty(PostgreSQLConstants.POSTGRESQL_PASSWORD_PROP, PostgreSQLConstants.POSTGRESQL_PASSWORD_DEFAULT));
     boneCPDataSource.setIdleConnectionTestPeriodInMinutes(
             Long.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_PROP, PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_DEFAULT)));
     boneCPDataSource.setIdleMaxAgeInMinutes(
@@ -131,7 +133,7 @@ public class PostgreSQLJavaConfiguration {
 
   private Properties additionalProperties() {
     final Properties properties = new Properties();
-    properties.setProperty("openjpa.jdbc.DBDictionary", "org.apache.openjpa.jdbc.sql.PostgresDictionary");
+    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
     return properties;
   }
 }
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilder.java b/src/main/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilder.java
index d7b6d7b..78ebd0d 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilder.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilder.java
@@ -50,32 +50,20 @@ public final class JdbcUrlBuilder {
   }
 
   public String build() {
+    final String[] hostList = this.host.split(",");
     switch (this.type) {
       case POSTGRESQL:
-        final StringBuilder jdbcUrl = new StringBuilder(this.type.getSubProtocol());
-        if (this.host == null){
-          if (this.instanceName == null){
-            jdbcUrl.append("/");
+        final StringBuilder jdbcUrl = new StringBuilder();
+        final String jdbcProtocol = this.type.getSubProtocol() + (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(",");
           }
-          else
-            jdbcUrl.append(instanceName);
         }
-        else {
-          if (this.port == null){
-            if (this.instanceName == null){
-              jdbcUrl.append("//").append(this.host).append("/");
-            }
-            else
-              jdbcUrl.append("//").append(this.host).append("/").append(this.instanceName);
-          }
-          else {
-            if (this.instanceName == null){
-              jdbcUrl.append("//").append(this.host).append(":").append(this.port).append("/");
-            }
-            else {
-              jdbcUrl.append("//").append(this.host).append(":").append(this.port).append("/").append(instanceName);
-            }
-          }
+        if (this.instanceName != null) {
+          jdbcUrl.append("/").append(this.instanceName);
         }
         return jdbcUrl.toString();
       default:
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java b/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
index 5ed5aa0..824c03a 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
@@ -23,7 +23,7 @@ public interface PostgreSQLConstants {
   String LOGGER_NAME = "postgresql-logger";
 
   String POSTGRESQL_DRIVER_CLASS_PROP = "postgresql.driverClass";
-  String POSTGRESQL_DRIVER_CLASS_DEFAULT = "org.postgresql.jdbc.Driver";
+  String POSTGRESQL_DRIVER_CLASS_DEFAULT = "org.postgresql.Driver";
   String POSTGRESQL_DATABASE_NAME_PROP = "postgresql.database";
   String POSTGRESQL_DATABASE_NAME_DEFAULT = "seshat";
   String POSTGRESQL_HOST_PROP = "postgresql.host";
@@ -32,6 +32,8 @@ public interface PostgreSQLConstants {
   String POSTGRESQL_PORT_DEFAULT = "5432";
   String POSTGRESQL_USER_PROP = "postgresql.user";
   String POSTGRESQL_USER_DEFAULT = "postgres";
+  String POSTGRESQL_PASSWORD_PROP = "postgresql.password";
+  String POSTGRESQL_PASSWORD_DEFAULT = "postgres";
 
   String BONECP_IDLE_MAX_AGE_PROP = "bonecp.idleMaxAgeInMinutes";
   String BONECP_IDLE_MAX_AGE_DEFAULT = "240";
diff --git a/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java b/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
index b78a0b4..c5ffe4b 100644
--- a/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
+++ b/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
@@ -33,35 +33,13 @@ public class JdbcUrlBuilderTest {
   }
 
   @Test
-  public void shouldCreatePostgresqlUrlNeitherHostNorPort() {
-    final String expectedJdbcUrl = "jdbc:postgresql:comp_test";
-
-    final String postgresqlJdbcUrl = JdbcUrlBuilder
-            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
-            .instanceName("comp_test")
-            .build();
-
-    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
-  }
-
-  @Test
-  public void shouldCreatePostgresqlUrlNeitherHostNorInstance() {
-    final String expectedJdbcUrl = "jdbc:postgresql:/";
-
-    final String postgresqlJdbcUrl = JdbcUrlBuilder
-            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
-            .build();
-
-    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
-  }
-
-  @Test
-  public void shouldCreatePostgresqlUrlWithHostAndInstance() {
-    final String expectedJdbcUrl = "jdbc:postgresql://localhost/comp_test";
+  public void shouldCreatePostgresqlUrl() {
+    final String expectedJdbcUrl = "jdbc:postgresql://localhost:5432/comp_test";
 
     final String postgresqlJdbcUrl = JdbcUrlBuilder
         .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
         .host("localhost")
+        .port("5432")
         .instanceName("comp_test")
         .build();
 
@@ -69,40 +47,28 @@ public class JdbcUrlBuilderTest {
   }
 
   @Test
-  public void shouldCreatePostgresqlUrlNoPort() {
-    final String expectedJdbcUrl = "jdbc:postgresql://localhost/";
+  public void shouldCreateMysqlUrlNoInstance() {
+    final String expectedJdbcUrl = "jdbc:postgresql://localhost:5432";
 
     final String postgresqlJdbcUrl = JdbcUrlBuilder
-        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
-        .host("localhost")
-        .build();
-
-    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
-  }
-
-  @Test
-  public void shouldCreatePostgresqlUrl() {
-    final String expectedJdbcUrl = "jdbc:postgresql://localhost:5432/comp_test";
-
-    final String postgresqlJdbcUrl = JdbcUrlBuilder
-        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
-        .host("localhost")
-        .port("5432")
-        .instanceName("comp_test")
-        .build();
+            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+            .host("localhost")
+            .port("5432").build();
 
     Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
   }
 
   @Test
-  public void shouldCreatePostgresqlUrlNoInstance() {
-    final String expectedJdbcUrl = "jdbc:postgresql://localhost:5432/";
+  public void shouldCreateMysqlReplicationUrl() {
+    final String expectedJdbcUrl = "jdbc:postgresql:replication://localhost:5432,anotherhost:5432/comp_test";
 
-    final String postgresqlJdbcUrl = JdbcUrlBuilder
-        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
-        .host("localhost")
-        .port("5432").build();
+    final String mariaDbJdbcUrl = JdbcUrlBuilder
+            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+            .host("localhost, anotherhost")
+            .port("5432")
+            .instanceName("comp_test")
+            .build();
 
-    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
+    Assert.assertEquals(expectedJdbcUrl, mariaDbJdbcUrl);
   }
 }
\ No newline at end of file


[fineract-cn-postgresql] 07/12: Merge pull request #3 from Izakey/develop

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit e9b3ea6b8597f7b92b72b1884b068af4b89cc161
Merge: 9aac901 643db75
Author: Isaac Kamga <u2...@gmail.com>
AuthorDate: Thu May 2 02:52:43 2019 +0100

    Merge pull request #3 from Izakey/develop
    
    Added password attribute to tenant domain transfer object

 .../fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java | 4 +++-
 src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java   | 5 +++++
 .../org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java   | 4 ++--
 3 files changed, 10 insertions(+), 3 deletions(-)


[fineract-cn-postgresql] 01/12: Initial commit for fineract-cn-postgresql

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit 3d72340c322176dd1b2f7201364396c1ffd29a0c
Author: Isaac Kamga <u2...@gmail.com>
AuthorDate: Thu Nov 15 02:17:42 2018 +0100

    Initial commit for fineract-cn-postgresql
---
 .gitignore                                         |  15 ++
 HEADER                                             |  16 ++
 NOTICE.txt                                         |   5 +
 README.md                                          |  38 +++++
 build.gradle                                       | 105 +++++++++++++
 gradle/wrapper/gradle-wrapper.jar                  | Bin 0 -> 54212 bytes
 gradle/wrapper/gradle-wrapper.properties           |   6 +
 gradlew                                            | 172 +++++++++++++++++++++
 gradlew.bat                                        |  84 ++++++++++
 settings.gradle                                    |  18 +++
 .../cn/postgresql/config/EnablePostgreSQL.java     |  38 +++++
 .../postgresql/config/MetaDataSourceWrapper.java   |  36 +++++
 .../config/PostgreSQLJavaConfiguration.java        | 137 ++++++++++++++++
 .../PostgreSQLJavaConfigurationImportSelector.java |  50 ++++++
 .../PostgreSQLTenantBasedJavaConfiguration.java    |  45 ++++++
 .../PostgreSQLTenantFreeJavaConfiguration.java     |  37 +++++
 .../domain/ContextAwareRoutingDataSource.java      | 119 ++++++++++++++
 .../cn/postgresql/domain/FlywayFactoryBean.java    |  44 ++++++
 .../fineract/cn/postgresql/domain/Tenant.java      |  79 ++++++++++
 .../cn/postgresql/util/JdbcUrlBuilder.java         |  99 ++++++++++++
 .../cn/postgresql/util/LocalDateConverter.java     |  50 ++++++
 .../cn/postgresql/util/LocalDateTimeConverter.java |  52 +++++++
 .../cn/postgresql/util/PostgreSQLConstants.java    |  50 ++++++
 .../cn/postgresql/util/JdbcUrlBuilderTest.java     | 108 +++++++++++++
 .../cn/postgresql/util/LocalDateConverterTest.java |  45 ++++++
 travis.yml                                         |  22 +++
 26 files changed, 1470 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5a0e819
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,15 @@
+.gradle
+.idea
+build/
+target/
+out/
+
+# 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..60b675e
--- /dev/null
+++ b/HEADER
@@ -0,0 +1,16 @@
+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.
diff --git a/NOTICE.txt b/NOTICE.txt
new file mode 100644
index 0000000..447871d
--- /dev/null
+++ b/NOTICE.txt
@@ -0,0 +1,5 @@
+Apache Fineract CN PostgreSQL
+Copyright [2017-2018] The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1692ac0
--- /dev/null
+++ b/README.md
@@ -0,0 +1,38 @@
+# Apache Fineract CN PostgreSQL
+
+## Abstract
+Apache Fineract CN 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 PostgreSQL as described at 
+https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04.
+
+After installation you need to create the meta database:
+
+    sudo -i -u postgres psql
+    CREATE DATABASE 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..ac19102
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+
+buildscript {
+    repositories {
+        jcenter()
+    }
+}
+
+plugins {
+    id 'com.github.hierynomus.license' version '0.13.1'
+    id("org.nosphere.apache.rat") version "0.3.1"
+}
+
+group 'org.apache.fineract.cn'
+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: 'org.apache.fineract.cn', 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'],
+            [group: 'org.postgresql', name: 'postgresql', version: '42.2.5'],
+            [group: 'org.apache.openjpa', name: 'openjpa', version: '3.0.0']
+    )
+    testCompile(
+            [group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.springboot]
+    )
+}
+
+jar {
+    from sourceSets.main.allSource
+}
+
+publishing {
+    publications {
+        postgresqlPublication(MavenPublication) {
+            from components.java
+            groupId project.group
+            artifactId project.name
+            version project.version
+        }
+    }
+}
+
+license {
+    header rootProject.file('HEADER')
+    strictCheck true
+    mapping {
+        java = 'SLASHSTAR_STYLE'
+    }
+}
+
+rat {
+    // List of exclude directives, defaults to ['**/.gradle/**']
+    excludes = [
+            ".idea/**",
+            ".gradle/**",
+            "gradle/**",
+            "build/**",
+            "gradlew",
+            "gradlew.bat",
+            "README.md"
+    ]
+}
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..cea748d
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
+
+rootProject.name = 'postgresql'
\ No newline at end of file
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/EnablePostgreSQL.java b/src/main/java/org/apache/fineract/cn/postgresql/config/EnablePostgreSQL.java
new file mode 100644
index 0000000..b9f5de5
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/EnablePostgreSQL.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.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;
+
+@SuppressWarnings({"WeakerAccess", "unused"})
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@Import({PostgreSQLJavaConfigurationImportSelector.class})
+public @interface EnablePostgreSQL {
+  boolean forTenantContext() default true;
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/MetaDataSourceWrapper.java b/src/main/java/org/apache/fineract/cn/postgresql/config/MetaDataSourceWrapper.java
new file mode 100644
index 0000000..9c8752a
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/MetaDataSourceWrapper.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.config;
+
+import com.jolbox.bonecp.BoneCPDataSource;
+
+/**
+ * @author Isaac Kamga
+ */
+public class MetaDataSourceWrapper {
+  private final BoneCPDataSource metaDataSource;
+
+  public MetaDataSourceWrapper(final BoneCPDataSource metaDataSource) {
+    this.metaDataSource = metaDataSource;
+  }
+
+  BoneCPDataSource getMetaDataSource() {
+    return metaDataSource;
+  }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
new file mode 100644
index 0000000..9e114dd
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.config;
+
+import com.jolbox.bonecp.BoneCPDataSource;
+import org.apache.fineract.cn.postgresql.domain.FlywayFactoryBean;
+import org.apache.fineract.cn.postgresql.util.JdbcUrlBuilder;
+import org.apache.fineract.cn.lang.ApplicationName;
+import org.apache.fineract.cn.lang.config.EnableApplicationName;
+import org.apache.fineract.cn.postgresql.util.PostgreSQLConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+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.OpenJpaVendorAdapter;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.Properties;
+
+@SuppressWarnings("WeakerAccess")
+@Configuration
+@ConditionalOnProperty(prefix = "postgresql", name = "enabled", matchIfMissing = true)
+@EnableTransactionManagement
+@EnableApplicationName
+public class PostgreSQLJavaConfiguration {
+
+  private final Environment env;
+
+  @Autowired
+  public PostgreSQLJavaConfiguration(final Environment env) {
+    super();
+    this.env = env;
+  }
+
+  @Bean(name = PostgreSQLConstants.LOGGER_NAME)
+  public Logger logger() {
+    return LoggerFactory.getLogger(PostgreSQLConstants.LOGGER_NAME);
+  }
+
+  @Bean
+  public LocalContainerEntityManagerFactoryBean entityManagerFactory(final DataSource dataSource) {
+    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
+    em.setPersistenceUnitName("metaPU");
+    em.setDataSource(dataSource);
+    em.setPackagesToScan("org.apache.fineract.cn.**.repository");
+
+    final JpaVendorAdapter vendorAdapter = new OpenJpaVendorAdapter();
+    em.setJpaVendorAdapter(vendorAdapter);
+    em.setJpaProperties(additionalProperties());
+
+    return em;
+  }
+
+  @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);
+  }
+
+  @Bean
+  public MetaDataSourceWrapper metaDataSourceWrapper() {
+
+    final BoneCPDataSource boneCPDataSource = new BoneCPDataSource();
+    boneCPDataSource.setDriverClass(
+            this.env.getProperty(PostgreSQLConstants.POSTGRESQL_DRIVER_CLASS_PROP, PostgreSQLConstants.POSTGRESQL_DRIVER_CLASS_DEFAULT));
+    boneCPDataSource.setJdbcUrl(JdbcUrlBuilder
+            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+            .host(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_HOST_PROP, PostgreSQLConstants.POSTGRESQL_HOST_DEFAULT))
+            .port(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_PORT_PROP, PostgreSQLConstants.POSTGRESQL_PORT_DEFAULT))
+            .instanceName(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_PROP, PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_DEFAULT))
+            .build());
+    boneCPDataSource.setUsername(
+            this.env.getProperty(PostgreSQLConstants.POSTGRESQL_USER_PROP, PostgreSQLConstants.POSTGRESQL_USER_DEFAULT));
+    boneCPDataSource.setIdleConnectionTestPeriodInMinutes(
+            Long.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_PROP, PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_DEFAULT)));
+    boneCPDataSource.setIdleMaxAgeInMinutes(
+            Long.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_IDLE_MAX_AGE_PROP, PostgreSQLConstants.BONECP_IDLE_MAX_AGE_DEFAULT)));
+    boneCPDataSource.setMaxConnectionsPerPartition(
+            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_MAX_CONNECTION_PARTITION_PROP, PostgreSQLConstants.BONECP_MAX_CONNECTION_PARTITION_DEFAULT)));
+    boneCPDataSource.setMinConnectionsPerPartition(
+            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_MIN_CONNECTION_PARTITION_PROP, PostgreSQLConstants.BONECP_MIN_CONNECTION_PARTITION_DEFAULT)));
+    boneCPDataSource.setPartitionCount(
+            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_PARTITION_COUNT_PROP, PostgreSQLConstants.BONECP_PARTITION_COUNT_DEFAULT)));
+    boneCPDataSource.setAcquireIncrement(
+            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_ACQUIRE_INCREMENT_PROP, PostgreSQLConstants.BONECP_ACQUIRE_INCREMENT_DEFAULT)));
+    boneCPDataSource.setStatementsCacheSize(
+            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_STATEMENT_CACHE_PROP, PostgreSQLConstants.BONECP_STATEMENT_CACHE_DEFAULT)));
+
+    final Properties driverProperties = new Properties();
+    driverProperties.setProperty("useServerPrepStmts", "false");
+    boneCPDataSource.setDriverProperties(driverProperties);
+    return new MetaDataSourceWrapper(boneCPDataSource);
+  }
+
+  private Properties additionalProperties() {
+    final Properties properties = new Properties();
+    properties.setProperty("openjpa.jdbc.DBDictionary", "org.apache.openjpa.jdbc.sql.PostgresDictionary");
+    return properties;
+  }
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfigurationImportSelector.java b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfigurationImportSelector.java
new file mode 100644
index 0000000..557ba0c
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfigurationImportSelector.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.config;
+
+import org.springframework.context.annotation.ImportSelector;
+import org.springframework.core.type.AnnotationMetadata;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Isaac Kamga
+ */
+class PostgreSQLJavaConfigurationImportSelector implements ImportSelector {
+  @Override
+  public String[] selectImports(AnnotationMetadata importingClassMetadata) {
+    final boolean forTenantContext = (boolean)importingClassMetadata
+            .getAnnotationAttributes(EnablePostgreSQL.class.getTypeName())
+            .get("forTenantContext");
+
+    final Set<Class> classesToImport = new HashSet<>();
+    final String prop = System.getProperty("postgresql.enabled");
+    if (prop == null || "true".equals(prop)) {
+      classesToImport.add(PostgreSQLJavaConfiguration.class);
+      if (forTenantContext) {
+        classesToImport.add(PostgreSQLTenantBasedJavaConfiguration.class);
+      }
+      else {
+        classesToImport.add(PostgreSQLTenantFreeJavaConfiguration.class);
+      }
+    }
+    return classesToImport.stream().map(Class::getCanonicalName).toArray(String[]::new);
+  }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLTenantBasedJavaConfiguration.java b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLTenantBasedJavaConfiguration.java
new file mode 100644
index 0000000..a11cd35
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLTenantBasedJavaConfiguration.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.config;
+
+import org.apache.fineract.cn.postgresql.domain.ContextAwareRoutingDataSource;
+import org.apache.fineract.cn.postgresql.util.JdbcUrlBuilder;
+import org.apache.fineract.cn.postgresql.util.PostgreSQLConstants;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+
+@SuppressWarnings("WeakerAccess")
+@Configuration
+@ConditionalOnProperty(prefix = "postgresql", name = "enabled", matchIfMissing = true)
+public class PostgreSQLTenantBasedJavaConfiguration {
+  public DataSource dataSource(@Qualifier(PostgreSQLConstants.LOGGER_NAME) final Logger logger,
+                               final MetaDataSourceWrapper metaDataSource) {
+
+  final ContextAwareRoutingDataSource dataSources = new ContextAwareRoutingDataSource(logger, JdbcUrlBuilder.DatabaseType.POSTGRESQL);
+  dataSources.setMetaDataSource(metaDataSource.getMetaDataSource());
+  final HashMap<Object, Object> targetDataSources = new HashMap<>();
+  dataSources.setTargetDataSources(targetDataSources);
+  return dataSources;
+  }
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLTenantFreeJavaConfiguration.java b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLTenantFreeJavaConfiguration.java
new file mode 100644
index 0000000..a5310a5
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLTenantFreeJavaConfiguration.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.config;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import javax.sql.DataSource;
+
+/**
+ * @author Isaac Kamga
+ */
+@SuppressWarnings("WeakerAccess")
+@Configuration
+@ConditionalOnProperty(prefix = "postgresql", name = "enabled", matchIfMissing = true)
+public class PostgreSQLTenantFreeJavaConfiguration {
+  @Bean
+  public DataSource dataSource(final MetaDataSourceWrapper metaDataSource) {
+    return metaDataSource.getMetaDataSource();
+  }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java b/src/main/java/org/apache/fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java
new file mode 100644
index 0000000..d3df26f
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/domain/ContextAwareRoutingDataSource.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.domain;
+
+import com.jolbox.bonecp.BoneCPDataSource;
+import org.apache.fineract.cn.postgresql.util.JdbcUrlBuilder;
+import org.apache.fineract.cn.postgresql.util.PostgreSQLConstants;
+import org.apache.fineract.cn.lang.TenantContextHolder;
+import org.apache.fineract.cn.postgresql.util.JdbcUrlBuilder.DatabaseType;
+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 DatabaseType type;
+  private final ConcurrentHashMap<String, DataSource> dynamicDataSources;
+  private DataSource metaDataSource;
+
+  public ContextAwareRoutingDataSource(@Qualifier(PostgreSQLConstants.LOGGER_NAME) final Logger logger,
+                                       final 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 {}.", key);
+      final Tenant tenant = new Tenant(key);
+      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());
+
+      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 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"));
+        }
+      }
+    } catch (SQLException ex) {
+      throw new IllegalArgumentException("Could not fetch information for tenant '" + tenant.getIdentifier() + "'", ex);
+    }
+  }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/domain/FlywayFactoryBean.java b/src/main/java/org/apache/fineract/cn/postgresql/domain/FlywayFactoryBean.java
new file mode 100644
index 0000000..144961a
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/domain/FlywayFactoryBean.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.domain;
+
+import org.apache.fineract.cn.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/postgresql");
+    flyway.setTable(this.applicationName.getServiceName() + "_schema_version");
+    flyway.setBaselineOnMigrate(true);
+    flyway.setBaselineVersionAsString("0");
+    return flyway;
+  }
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java b/src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java
new file mode 100644
index 0000000..3bb7ef0
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/domain/Tenant.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.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;
+
+  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;
+  }
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilder.java b/src/main/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilder.java
new file mode 100644
index 0000000..d7b6d7b
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilder.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.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 POSTGRESQL:
+        final StringBuilder jdbcUrl = new StringBuilder(this.type.getSubProtocol());
+        if (this.host == null){
+          if (this.instanceName == null){
+            jdbcUrl.append("/");
+          }
+          else
+            jdbcUrl.append(instanceName);
+        }
+        else {
+          if (this.port == null){
+            if (this.instanceName == null){
+              jdbcUrl.append("//").append(this.host).append("/");
+            }
+            else
+              jdbcUrl.append("//").append(this.host).append("/").append(this.instanceName);
+          }
+          else {
+            if (this.instanceName == null){
+              jdbcUrl.append("//").append(this.host).append(":").append(this.port).append("/");
+            }
+            else {
+              jdbcUrl.append("//").append(this.host).append(":").append(this.port).append("/").append(instanceName);
+            }
+          }
+        }
+        return jdbcUrl.toString();
+      default:
+        throw new IllegalArgumentException("Unknown database type '" + this.type.name() + "'");
+    }
+  }
+
+  public enum DatabaseType {
+    POSTGRESQL("jdbc:postgresql:");
+
+    private final String subProtocol;
+
+    DatabaseType(final String subProtocol) {
+      this.subProtocol = subProtocol;
+    }
+
+    String getSubProtocol() {
+      return this.subProtocol;
+    }
+  }
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/util/LocalDateConverter.java b/src/main/java/org/apache/fineract/cn/postgresql/util/LocalDateConverter.java
new file mode 100644
index 0000000..29ea090
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/util/LocalDateConverter.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.util;
+
+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 Date.valueOf(attribute);
+    }
+  }
+
+  @Override
+  public LocalDate convertToEntityAttribute(final Date dbData) {
+    if (dbData == null) {
+      return null;
+    } else {
+      return dbData.toLocalDate();
+    }
+  }
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/util/LocalDateTimeConverter.java b/src/main/java/org/apache/fineract/cn/postgresql/util/LocalDateTimeConverter.java
new file mode 100644
index 0000000..47fb20e
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/util/LocalDateTimeConverter.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.util;
+
+
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+import org.apache.fineract.cn.lang.DateConverter;
+
+@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/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java b/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
new file mode 100644
index 0000000..5ed5aa0
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.util;
+
+public interface PostgreSQLConstants {
+
+  String LOGGER_NAME = "postgresql-logger";
+
+  String POSTGRESQL_DRIVER_CLASS_PROP = "postgresql.driverClass";
+  String POSTGRESQL_DRIVER_CLASS_DEFAULT = "org.postgresql.jdbc.Driver";
+  String POSTGRESQL_DATABASE_NAME_PROP = "postgresql.database";
+  String POSTGRESQL_DATABASE_NAME_DEFAULT = "seshat";
+  String POSTGRESQL_HOST_PROP = "postgresql.host";
+  String POSTGRESQL_HOST_DEFAULT = "localhost";
+  String POSTGRESQL_PORT_PROP = "postgresql.port";
+  String POSTGRESQL_PORT_DEFAULT = "5432";
+  String POSTGRESQL_USER_PROP = "postgresql.user";
+  String POSTGRESQL_USER_DEFAULT = "postgres";
+
+  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/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java b/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
new file mode 100644
index 0000000..b78a0b4
--- /dev/null
+++ b/src/test/java/org/apache/fineract/cn/postgresql/util/JdbcUrlBuilderTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/*
+ * PostgreSQL URL Formats
+ * https://jdbc.postgresql.org/documentation/head/connect.html
+ */
+
+public class JdbcUrlBuilderTest {
+
+  public JdbcUrlBuilderTest() {
+    super();
+  }
+
+  @Test
+  public void shouldCreatePostgresqlUrlNeitherHostNorPort() {
+    final String expectedJdbcUrl = "jdbc:postgresql:comp_test";
+
+    final String postgresqlJdbcUrl = JdbcUrlBuilder
+            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+            .instanceName("comp_test")
+            .build();
+
+    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
+  }
+
+  @Test
+  public void shouldCreatePostgresqlUrlNeitherHostNorInstance() {
+    final String expectedJdbcUrl = "jdbc:postgresql:/";
+
+    final String postgresqlJdbcUrl = JdbcUrlBuilder
+            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+            .build();
+
+    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
+  }
+
+  @Test
+  public void shouldCreatePostgresqlUrlWithHostAndInstance() {
+    final String expectedJdbcUrl = "jdbc:postgresql://localhost/comp_test";
+
+    final String postgresqlJdbcUrl = JdbcUrlBuilder
+        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+        .host("localhost")
+        .instanceName("comp_test")
+        .build();
+
+    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
+  }
+
+  @Test
+  public void shouldCreatePostgresqlUrlNoPort() {
+    final String expectedJdbcUrl = "jdbc:postgresql://localhost/";
+
+    final String postgresqlJdbcUrl = JdbcUrlBuilder
+        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+        .host("localhost")
+        .build();
+
+    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
+  }
+
+  @Test
+  public void shouldCreatePostgresqlUrl() {
+    final String expectedJdbcUrl = "jdbc:postgresql://localhost:5432/comp_test";
+
+    final String postgresqlJdbcUrl = JdbcUrlBuilder
+        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+        .host("localhost")
+        .port("5432")
+        .instanceName("comp_test")
+        .build();
+
+    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
+  }
+
+  @Test
+  public void shouldCreatePostgresqlUrlNoInstance() {
+    final String expectedJdbcUrl = "jdbc:postgresql://localhost:5432/";
+
+    final String postgresqlJdbcUrl = JdbcUrlBuilder
+        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+        .host("localhost")
+        .port("5432").build();
+
+    Assert.assertEquals(expectedJdbcUrl, postgresqlJdbcUrl);
+  }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/fineract/cn/postgresql/util/LocalDateConverterTest.java b/src/test/java/org/apache/fineract/cn/postgresql/util/LocalDateConverterTest.java
new file mode 100644
index 0000000..263ca57
--- /dev/null
+++ b/src/test/java/org/apache/fineract/cn/postgresql/util/LocalDateConverterTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.sql.Date;
+import java.time.LocalDate;
+
+public class LocalDateConverterTest {
+
+  public LocalDateConverterTest() {
+    super();
+  }
+
+  @Test
+  public void shouldConvertLocalDate() {
+    final LocalDateConverter converter = new LocalDateConverter();
+
+    final LocalDate expected = LocalDate.of(2017, 1, 1);
+
+    final Date dbDate = converter.convertToDatabaseColumn(expected);
+
+    final LocalDate result = converter.convertToEntityAttribute(dbDate);
+
+    Assert.assertEquals(expected, result);
+  }
+}
diff --git a/travis.yml b/travis.yml
new file mode 100644
index 0000000..5cc5893
--- /dev/null
+++ b/travis.yml
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+language: java
+jdk:
+ - oraclejdk8
\ No newline at end of file


[fineract-cn-postgresql] 05/12: Merge pull request #2 from aasaru/artifactory

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit 9aac901e68dbea007b03f5163d0cdad0a3e34ba9
Merge: 5f2cbfa 49140c5
Author: Awasum Yannick <aw...@apache.org>
AuthorDate: Tue Apr 30 09:14:55 2019 +0100

    Merge pull request #2 from aasaru/artifactory
    
    FINCN-148 build with travis-ci.com and upload artifacts to Artifactory

 .travis.yml  | 30 +++++++++++++++++++++++++
 README.md    |  2 +-
 build.gradle | 20 ++++++++++++++++-
 travis.sh    | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 travis.yml   | 22 -------------------
 5 files changed, 121 insertions(+), 24 deletions(-)


[fineract-cn-postgresql] 09/12: Merge pull request #4 from ebenezergraham/FINCN-157

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit a943bfc18e55abd31d062bca75bba4583681a7b2
Merge: e9b3ea6 a0ddbff
Author: Awasum Yannick <aw...@apache.org>
AuthorDate: Mon Jun 3 19:57:12 2019 +0100

    Merge pull request #4 from ebenezergraham/FINCN-157
    
    Adding rat report to After Failure procedure

 .travis.yml  | 3 +++
 build.gradle | 1 +
 2 files changed, 4 insertions(+)


[fineract-cn-postgresql] 10/12: EclipseLink Configuration extending JpaBaseConfiguration

Posted by ik...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-postgresql.git

commit df172c6601f4723d4319a20f8318719e439539ad
Author: Ebenezer Graham <eg...@alustudent.com>
AuthorDate: Sun Jul 21 21:36:44 2019 +0400

    EclipseLink Configuration extending JpaBaseConfiguration
    
    Using org.ecplise.persistence.jpa to avoid security exception
    
    The JpaConfiguration Class already contains an LEMFB.
---
 build.gradle                                       |  38 +++--
 .../config/EclipseLinkJpaConfiguration.java        |  96 +++++++++++++
 .../config/PostgreSQLJavaConfiguration.java        | 156 ++++++++-------------
 .../cn/postgresql/util/PostgreSQLConstants.java    |   1 +
 4 files changed, 184 insertions(+), 107 deletions(-)

diff --git a/build.gradle b/build.gradle
index 8a5cb92..20be6d6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -18,6 +18,12 @@
 buildscript {
     repositories {
         jcenter()
+        maven {
+            url "https://plugins.gradle.org/m2/"
+        }
+    }
+    dependencies {
+        classpath "gradle.plugin.org.jamgo:eclipselink-plugin:0.2.2"
     }
 }
 
@@ -25,16 +31,21 @@ plugins {
     id 'com.github.hierynomus.license' version '0.13.1'
     id("org.nosphere.apache.rat") version "0.3.1"
     id "com.jfrog.artifactory" version "4.9.5"
+ //   id "org.jamgo.eclipselink-plugin" version "0.2.2"
 }
 
 group 'org.apache.fineract.cn'
 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'
+        springcontext: '4.3.3.RELEASE',
+        springboot   : '1.4.1.RELEASE',
+        findbugs     : '3.0.1',
+        frameworklang: '0.1.0-BUILD-SNAPSHOT',
+        bonecp       : '0.8.0.RELEASE',
+        flyway       : '4.0.1',
+        postgresql   : '42.2.5',
+        eclipselink  : '2.7.4',
 ]
 
 apply plugin: 'java'
@@ -42,6 +53,7 @@ apply plugin: 'idea'
 apply plugin: 'maven'
 apply plugin: 'maven-publish'
 apply plugin: 'license'
+apply plugin: "org.jamgo.eclipselink-plugin"
 
 tasks.withType(JavaCompile) {
     sourceCompatibility = JavaVersion.VERSION_1_8
@@ -59,11 +71,16 @@ dependencies {
             [group: 'org.springframework', name: 'spring-context', version: versions.springcontext],
             [group: 'com.google.code.findbugs', name: 'jsr305', version: versions.findbugs],
             [group: 'org.apache.fineract.cn', 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'],
-            [group: 'org.postgresql', name: 'postgresql', version: '42.2.5']
+            [group: 'com.jolbox', name: 'bonecp', version: versions.bonecp],
+            [group: 'org.flywaydb', name: 'flyway-core', version: versions.flyway],
+            [group: 'org.postgresql', name: 'postgresql', version: versions.postgresql],
+            [group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.jpa', version: versions.eclipselink]
     )
+    compile(group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: versions.springboot)
+            {
+                exclude group: 'org.hibernate', module: 'hibernate-entitymanager'
+                exclude group: 'org.hibernate', module: 'hibernate-core'
+            }
     testCompile(
             [group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.springboot]
     )
@@ -94,11 +111,11 @@ artifactory {
         }
 
         defaults {
-            publications ('postgresqlPublication')
+            publications('postgresqlPublication')
         }
     }
 }
-artifactoryPublish.dependsOn('clean','publishToMavenLocal')
+artifactoryPublish.dependsOn('clean', 'publishToMavenLocal')
 
 license {
     header rootProject.file('HEADER')
@@ -121,3 +138,4 @@ rat {
     ]
     plainOutput = true
 }
+
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java b/src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java
new file mode 100644
index 0000000..62ff39f
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/EclipseLinkJpaConfiguration.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.postgresql.config;
+
+import org.eclipse.persistence.config.BatchWriting;
+import org.eclipse.persistence.config.PersistenceUnitProperties;
+import org.eclipse.persistence.config.TargetDatabase;
+import org.eclipse.persistence.logging.SessionLog;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
+import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
+import org.springframework.orm.jpa.vendor.Database;
+import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.transaction.jta.JtaTransactionManager;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Ebenezer Graham
+ */
+
+@Configuration
+@EnableTransactionManagement
+@EntityScan({
+		"org.apache.fineract.cn.**.repository",
+		"org.apache.fineract.cn.postgresql.util"
+})
+public class EclipseLinkJpaConfiguration extends JpaBaseConfiguration {
+	
+	
+	protected EclipseLinkJpaConfiguration(DataSource dataSource, JpaProperties properties, ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider) {
+		super(dataSource, properties, jtaTransactionManagerProvider);
+	}
+	
+	@Bean
+	public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
+		final JpaTransactionManager transactionManager = new JpaTransactionManager();
+		transactionManager.setEntityManagerFactory(emf);
+		return transactionManager;
+	}
+	
+	@Bean
+	public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
+		return new PersistenceExceptionTranslationPostProcessor();
+	}
+	
+	@Bean
+	protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
+		EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
+		vendorAdapter.setDatabasePlatform("org.eclipse.persistence.platform.database.PostgreSQLPlatform");
+		vendorAdapter.setShowSql(true); // Todo: remove sql log
+		vendorAdapter.setDatabase(Database.POSTGRESQL);
+		vendorAdapter.setGenerateDdl(false);
+		return vendorAdapter;
+	}
+	
+	@Bean
+	protected Map<String, Object> getVendorProperties() {
+		HashMap<String, Object> properties = new HashMap<>();
+		properties.put(PersistenceUnitProperties.WEAVING, "static");
+		properties.put(PersistenceUnitProperties.WEAVING_EAGER, "true");
+		properties.put(PersistenceUnitProperties.TARGET_DATABASE, TargetDatabase.PostgreSQL);
+		properties.put(PersistenceUnitProperties.BATCH_WRITING, BatchWriting.JDBC);
+		properties.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.ALL_LABEL);// Todo: Reduce log level after test
+		properties.put(PersistenceUnitProperties.LOGGING_PARAMETERS, "true");
+		properties.put(PersistenceUnitProperties.DEPLOY_ON_STARTUP, "false");
+		return properties;
+	}
+}
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
index 09d7a9f..7a92b0a 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/config/PostgreSQLJavaConfiguration.java
@@ -27,113 +27,75 @@ import org.apache.fineract.cn.postgresql.util.PostgreSQLConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
+import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
+import org.springframework.context.annotation.*;
 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 org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
 
-import javax.persistence.EntityManagerFactory;
 import javax.sql.DataSource;
 import java.util.Properties;
 
 @SuppressWarnings("WeakerAccess")
 @Configuration
 @ConditionalOnProperty(prefix = "postgresql", name = "enabled", matchIfMissing = true)
-@EnableTransactionManagement
 @EnableApplicationName
+@Import(EclipseLinkJpaConfiguration.class)
 public class PostgreSQLJavaConfiguration {
-
-  private final Environment env;
-
-  @Autowired
-  public PostgreSQLJavaConfiguration(final Environment env) {
-    super();
-    this.env = env;
-  }
-
-  @Bean(name = PostgreSQLConstants.LOGGER_NAME)
-  public Logger logger() {
-    return LoggerFactory.getLogger(PostgreSQLConstants.LOGGER_NAME);
-  }
-
-  @Bean
-  public LocalContainerEntityManagerFactoryBean entityManagerFactory(final DataSource dataSource) {
-    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
-    em.setPersistenceUnitName("metaPU");
-    em.setDataSource(dataSource);
-    em.setPackagesToScan("org.apache.fineract.cn.**.repository");
-
-    final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
-    em.setJpaVendorAdapter(vendorAdapter);
-    em.setJpaProperties(additionalProperties());
-
-    return em;
-  }
-
-  @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);
-  }
-
-  @Bean
-  public MetaDataSourceWrapper metaDataSourceWrapper() {
-
-    final BoneCPDataSource boneCPDataSource = new BoneCPDataSource();
-    boneCPDataSource.setDriverClass(
-            this.env.getProperty(PostgreSQLConstants.POSTGRESQL_DRIVER_CLASS_PROP, PostgreSQLConstants.POSTGRESQL_DRIVER_CLASS_DEFAULT));
-    boneCPDataSource.setJdbcUrl(JdbcUrlBuilder
-            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
-            .host(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_HOST_PROP, PostgreSQLConstants.POSTGRESQL_HOST_DEFAULT))
-            .port(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_PORT_PROP, PostgreSQLConstants.POSTGRESQL_PORT_DEFAULT))
-            .instanceName(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_PROP, PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_DEFAULT))
-            .build());
-    boneCPDataSource.setUsername(
-            this.env.getProperty(PostgreSQLConstants.POSTGRESQL_USER_PROP, PostgreSQLConstants.POSTGRESQL_USER_DEFAULT));
-    boneCPDataSource.setPassword(
-            this.env.getProperty(PostgreSQLConstants.POSTGRESQL_PASSWORD_PROP, PostgreSQLConstants.POSTGRESQL_PASSWORD_DEFAULT));
-    boneCPDataSource.setIdleConnectionTestPeriodInMinutes(
-            Long.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_PROP, PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_DEFAULT)));
-    boneCPDataSource.setIdleMaxAgeInMinutes(
-            Long.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_IDLE_MAX_AGE_PROP, PostgreSQLConstants.BONECP_IDLE_MAX_AGE_DEFAULT)));
-    boneCPDataSource.setMaxConnectionsPerPartition(
-            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_MAX_CONNECTION_PARTITION_PROP, PostgreSQLConstants.BONECP_MAX_CONNECTION_PARTITION_DEFAULT)));
-    boneCPDataSource.setMinConnectionsPerPartition(
-            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_MIN_CONNECTION_PARTITION_PROP, PostgreSQLConstants.BONECP_MIN_CONNECTION_PARTITION_DEFAULT)));
-    boneCPDataSource.setPartitionCount(
-            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_PARTITION_COUNT_PROP, PostgreSQLConstants.BONECP_PARTITION_COUNT_DEFAULT)));
-    boneCPDataSource.setAcquireIncrement(
-            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_ACQUIRE_INCREMENT_PROP, PostgreSQLConstants.BONECP_ACQUIRE_INCREMENT_DEFAULT)));
-    boneCPDataSource.setStatementsCacheSize(
-            Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_STATEMENT_CACHE_PROP, PostgreSQLConstants.BONECP_STATEMENT_CACHE_DEFAULT)));
-
-    final Properties driverProperties = new Properties();
-    driverProperties.setProperty("useServerPrepStmts", "false");
-    boneCPDataSource.setDriverProperties(driverProperties);
-    return new MetaDataSourceWrapper(boneCPDataSource);
-  }
-
-  private Properties additionalProperties() {
-    final Properties properties = new Properties();
-    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
-    return properties;
-  }
+	
+	private final Environment env;
+
+	@Autowired
+	protected PostgreSQLJavaConfiguration(Environment env) {
+		super();
+		this.env = env;
+	}
+	
+	@Bean(name = PostgreSQLConstants.LOGGER_NAME)
+	public Logger logger() {
+		return LoggerFactory.getLogger(PostgreSQLConstants.LOGGER_NAME);
+	}
+	
+	@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(PostgreSQLConstants.POSTGRESQL_DRIVER_CLASS_PROP, PostgreSQLConstants.POSTGRESQL_DRIVER_CLASS_DEFAULT));
+		boneCPDataSource.setJdbcUrl(JdbcUrlBuilder
+				.create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+				.host(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_HOST_PROP, PostgreSQLConstants.POSTGRESQL_HOST_DEFAULT))
+				.port(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_PORT_PROP, PostgreSQLConstants.POSTGRESQL_PORT_DEFAULT))
+				.instanceName(this.env.getProperty(PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_PROP, PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_DEFAULT))
+				.build());
+		boneCPDataSource.setUsername(
+				this.env.getProperty(PostgreSQLConstants.POSTGRESQL_USER_PROP, PostgreSQLConstants.POSTGRESQL_USER_DEFAULT));
+		boneCPDataSource.setPassword(
+				this.env.getProperty(PostgreSQLConstants.POSTGRESQL_PASSWORD_PROP, PostgreSQLConstants.POSTGRESQL_PASSWORD_DEFAULT));
+		boneCPDataSource.setIdleConnectionTestPeriodInMinutes(
+				Long.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_PROP, PostgreSQLConstants.BONECP_IDLE_CONNECTION_TEST_DEFAULT)));
+		boneCPDataSource.setIdleMaxAgeInMinutes(
+				Long.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_IDLE_MAX_AGE_PROP, PostgreSQLConstants.BONECP_IDLE_MAX_AGE_DEFAULT)));
+		boneCPDataSource.setMaxConnectionsPerPartition(
+				Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_MAX_CONNECTION_PARTITION_PROP, PostgreSQLConstants.BONECP_MAX_CONNECTION_PARTITION_DEFAULT)));
+		boneCPDataSource.setMinConnectionsPerPartition(
+				Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_MIN_CONNECTION_PARTITION_PROP, PostgreSQLConstants.BONECP_MIN_CONNECTION_PARTITION_DEFAULT)));
+		boneCPDataSource.setPartitionCount(
+				Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_PARTITION_COUNT_PROP, PostgreSQLConstants.BONECP_PARTITION_COUNT_DEFAULT)));
+		boneCPDataSource.setAcquireIncrement(
+				Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_ACQUIRE_INCREMENT_PROP, PostgreSQLConstants.BONECP_ACQUIRE_INCREMENT_DEFAULT)));
+		boneCPDataSource.setStatementsCacheSize(
+				Integer.valueOf(this.env.getProperty(PostgreSQLConstants.BONECP_STATEMENT_CACHE_PROP, PostgreSQLConstants.BONECP_STATEMENT_CACHE_DEFAULT)));
+		
+		final Properties driverProperties = new Properties();
+		driverProperties.setProperty("useServerPrepStmts", "false");
+		boneCPDataSource.setDriverProperties(driverProperties);
+		return new MetaDataSourceWrapper(boneCPDataSource);
+	}
 }
diff --git a/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java b/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
index 824c03a..e1af537 100644
--- a/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
+++ b/src/main/java/org/apache/fineract/cn/postgresql/util/PostgreSQLConstants.java
@@ -26,6 +26,7 @@ public interface PostgreSQLConstants {
   String POSTGRESQL_DRIVER_CLASS_DEFAULT = "org.postgresql.Driver";
   String POSTGRESQL_DATABASE_NAME_PROP = "postgresql.database";
   String POSTGRESQL_DATABASE_NAME_DEFAULT = "seshat";
+  String POSTGRESQL_DATABASE_NAME = "postgres";
   String POSTGRESQL_HOST_PROP = "postgresql.host";
   String POSTGRESQL_HOST_DEFAULT = "localhost";
   String POSTGRESQL_PORT_PROP = "postgresql.port";