fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject [fineract-cn-postgresql] 02/22: Revert to Hibernate ORM until migration to Postgres is complete
Date Mon, 04 May 2020 06:36:33 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 779aaa65b2ad3d35fcc4f0ea177b378fc162130b
Author: Isaac Kamga <u2isaac@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


Mime
View raw message