You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by pt...@apache.org on 2021/02/16 22:59:33 UTC
[fineract] 01/01: Initial changes
This is an automated email from the ASF dual-hosted git repository.
ptuomola pushed a commit to branch FINERACT-849
in repository https://gitbox.apache.org/repos/asf/fineract.git
commit 808c2757086ab67254088dafcdb2d7e796527450
Author: Petri Tuomola <pe...@tuomola.org>
AuthorDate: Mon May 11 06:19:15 2020 +0300
Initial changes
---
fineract-provider/dependencies.gradle | 5 +-
.../core/domain/MySQLDictionaryCustom.java | 46 ------
.../infrastructure/openjpa/OpenJpaDialect.java | 159 ---------------------
.../openjpa/OpenJpaVendorAdapter.java | 122 ----------------
.../apache/fineract/spm/service/SpmService.java | 5 -
.../src/main/resources/META-INF/persistence.xml | 31 ++--
.../resources/META-INF/spring/infrastructure.xml | 2 +-
7 files changed, 19 insertions(+), 351 deletions(-)
diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle
index bfce3e5..d985a1c 100644
--- a/fineract-provider/dependencies.gradle
+++ b/fineract-provider/dependencies.gradle
@@ -69,6 +69,7 @@ dependencies {
'com.lowagie:itext',
'com.github.spullara.mustache.java:compiler',
'com.jayway.jsonpath:json-path',
+ 'org.eclipse.persistence:org.eclipse.persistence.jpa',
// JAX-B dependencies for JDK 9+
"jakarta.xml.bind:jakarta.xml.bind-api",
@@ -83,10 +84,6 @@ dependencies {
implementation ('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'org.hibernate'
}
- implementation ('org.apache.openjpa:openjpa') {
- exclude group: 'org.eclipse.persistence'
- exclude group: 'org.apache.geronimo.specs'
- }
implementation ('org.quartz-scheduler:quartz') {
exclude group: 'com.zaxxer', module: 'HikariCP-java7'
}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/MySQLDictionaryCustom.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/MySQLDictionaryCustom.java
deleted file mode 100644
index 973ca4f..0000000
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/MySQLDictionaryCustom.java
+++ /dev/null
@@ -1,46 +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.
- */
-package org.apache.fineract.infrastructure.core.domain;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import org.apache.openjpa.jdbc.sql.BooleanRepresentationFactory;
-import org.apache.openjpa.jdbc.sql.MySQLDictionary;
-
-@SuppressWarnings("unchecked")
-public class MySQLDictionaryCustom extends MySQLDictionary {
-
- public MySQLDictionaryCustom(){
- super();
- this.supportsSubselect = true;
- this.booleanRepresentation = BooleanRepresentationFactory.BOOLEAN;
- this.supportsGetGeneratedKeys = false ;
- this.allowsAliasInBulkClause = true ;
- this.useWildCardForCount = true ;
- }
-
- @Override
- public void connectedConfiguration(Connection conn) throws SQLException {
- super.connectedConfiguration(conn);
- this.supportsSubselect = true;
- this.supportsGetGeneratedKeys = false ;
- this.allowsAliasInBulkClause = true ;
- this.useWildCardForCount = true ;
- }
-}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/openjpa/OpenJpaDialect.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/openjpa/OpenJpaDialect.java
deleted file mode 100644
index 9a0d929..0000000
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/openjpa/OpenJpaDialect.java
+++ /dev/null
@@ -1,159 +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.
- */
-package org.apache.fineract.infrastructure.openjpa;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceException;
-import org.apache.commons.logging.LogFactory;
-import org.apache.openjpa.persistence.FetchPlan;
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
-import org.apache.openjpa.persistence.jdbc.IsolationLevel;
-import org.apache.openjpa.persistence.jdbc.JDBCFetchPlan;
-import org.springframework.jdbc.datasource.ConnectionHandle;
-import org.springframework.jdbc.datasource.ConnectionHolder;
-import org.springframework.jdbc.support.JdbcUtils;
-import org.springframework.orm.jpa.DefaultJpaDialect;
-import org.springframework.transaction.SavepointManager;
-import org.springframework.transaction.TransactionDefinition;
-import org.springframework.transaction.TransactionException;
-
-/**
- * {@link org.springframework.orm.jpa.JpaDialect} implementation for Apache OpenJPA.
- * Developed and tested against OpenJPA 2.2.
- *
- * @author Costin Leau
- * @author Juergen Hoeller
- * @since 2.0
- */
-public class OpenJpaDialect extends DefaultJpaDialect {
-
- @Override
- public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
- throws PersistenceException, SQLException, TransactionException {
-
- OpenJPAEntityManager openJpaEntityManager = getOpenJPAEntityManager(entityManager);
-
- if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
- // Pass custom isolation level on to OpenJPA's JDBCFetchPlan configuration
- FetchPlan fetchPlan = openJpaEntityManager.getFetchPlan();
- if (fetchPlan instanceof JDBCFetchPlan) {
- IsolationLevel isolation = IsolationLevel.fromConnectionConstant(definition.getIsolationLevel());
- ((JDBCFetchPlan) fetchPlan).setIsolation(isolation);
- }
- }
-
- entityManager.getTransaction().begin();
-
- if (!definition.isReadOnly()) {
- // Like with EclipseLink, make sure to start the logic transaction early so that other
- // participants using the connection (such as JdbcTemplate) run in a transaction.
- openJpaEntityManager.beginStore();
- }
-
- // Custom implementation for OpenJPA savepoint handling
- return new OpenJpaTransactionData(openJpaEntityManager);
- }
-
- @Override
- public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
- throws PersistenceException, SQLException {
-
- return new OpenJpaConnectionHandle(getOpenJPAEntityManager(entityManager));
- }
-
- /**
- * Return the OpenJPA-specific variant of {@code EntityManager}.
- * @param em the generic {@code EntityManager} instance
- * @return the OpenJPA-specific variant of {@code EntityManager}
- */
- protected OpenJPAEntityManager getOpenJPAEntityManager(EntityManager em) {
- return OpenJPAPersistence.cast(em);
- }
-
-
- /**
- * Transaction data Object exposed from {@code beginTransaction},
- * implementing the {@link SavepointManager} interface.
- */
- private static class OpenJpaTransactionData implements SavepointManager {
-
- private final OpenJPAEntityManager entityManager;
-
- private int savepointCounter = 0;
-
- public OpenJpaTransactionData(OpenJPAEntityManager entityManager) {
- this.entityManager = entityManager;
- }
-
- @Override
- public Object createSavepoint() throws TransactionException {
- this.savepointCounter++;
- String savepointName = ConnectionHolder.SAVEPOINT_NAME_PREFIX + this.savepointCounter;
- this.entityManager.setSavepoint(savepointName);
- return savepointName;
- }
-
- @Override
- public void rollbackToSavepoint(Object savepoint) throws TransactionException {
- this.entityManager.rollbackToSavepoint((String) savepoint);
- }
-
- @Override
- public void releaseSavepoint(Object savepoint) throws TransactionException {
- try {
- this.entityManager.releaseSavepoint((String) savepoint);
- }
- catch (Throwable ex) {
- LogFactory.getLog(OpenJpaTransactionData.class).debug(
- "Could not explicitly release OpenJPA savepoint", ex);
- }
- }
- }
-
-
- /**
- * {@link ConnectionHandle} implementation that fetches a new OpenJPA-provided
- * Connection for every {@code getConnection} call and closes the Connection on
- * {@code releaseConnection}. This is necessary because OpenJPA requires the
- * fetched Connection to be closed before continuing EntityManager work.
- * @see org.apache.openjpa.persistence.OpenJPAEntityManager#getConnection()
- */
- private static class OpenJpaConnectionHandle implements ConnectionHandle {
-
- private final OpenJPAEntityManager entityManager;
-
- public OpenJpaConnectionHandle(OpenJPAEntityManager entityManager) {
- this.entityManager = entityManager;
- }
-
- @Override
- public Connection getConnection() {
- return (Connection) this.entityManager.getConnection();
- }
-
- @Override
- public void releaseConnection(Connection con) {
- JdbcUtils.closeConnection(con);
- }
- }
-
-}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/openjpa/OpenJpaVendorAdapter.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/openjpa/OpenJpaVendorAdapter.java
deleted file mode 100644
index 015fc28..0000000
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/openjpa/OpenJpaVendorAdapter.java
+++ /dev/null
@@ -1,122 +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.
- */
-package org.apache.fineract.infrastructure.openjpa;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceProvider;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
-import org.apache.openjpa.persistence.PersistenceProviderImpl;
-import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
-import org.springframework.orm.jpa.vendor.Database;
-
-/**
- * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Apache OpenJPA.
- * Developed and tested against OpenJPA 2.2.
- *
- * <p>Exposes OpenJPA's persistence provider and EntityManager extension interface,
- * and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
- *
- * @author Costin Leau
- * @author Juergen Hoeller
- * @since 2.0
- * @see org.apache.openjpa.persistence.PersistenceProviderImpl
- * @see org.apache.openjpa.persistence.OpenJPAEntityManager
- */
-public class OpenJpaVendorAdapter extends AbstractJpaVendorAdapter {
-
- private final PersistenceProvider persistenceProvider = new PersistenceProviderImpl();
-
- private final OpenJpaDialect jpaDialect = new OpenJpaDialect();
-
-
- @Override
- public PersistenceProvider getPersistenceProvider() {
- return this.persistenceProvider;
- }
-
- @Override
- public String getPersistenceProviderRootPackage() {
- return "org.apache.openjpa";
- }
-
- @Override
- public Map<String, Object> getJpaPropertyMap() {
- Map<String, Object> jpaProperties = new HashMap<String, Object>();
-
- if (getDatabasePlatform() != null) {
- jpaProperties.put("openjpa.jdbc.DBDictionary", getDatabasePlatform());
- }
- else if (getDatabase() != null) {
- String databaseDictonary = determineDatabaseDictionary(getDatabase());
- if (databaseDictonary != null) {
- jpaProperties.put("openjpa.jdbc.DBDictionary", databaseDictonary);
- }
- }
-
- if (isGenerateDdl()) {
- jpaProperties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
- }
- if (isShowSql()) {
- // Taken from the OpenJPA 0.9.6 docs ("Standard OpenJPA Log Configuration + All SQL Statements")
- jpaProperties.put("openjpa.Log", "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE");
- }
-
- return jpaProperties;
- }
-
- /**
- * Determine the OpenJPA database dictionary name for the given database.
- * @param database the specified database
- * @return the OpenJPA database dictionary name, or {@code null} if none found
- */
- protected String determineDatabaseDictionary(Database database) {
- switch (database) {
- case DB2: return "db2";
- case DERBY: return "derby";
- case HSQL: return "hsql(SimulateLocking=true)";
- case INFORMIX: return "informix";
- case MYSQL: return "mysql";
- case ORACLE: return "oracle";
- case POSTGRESQL: return "postgres";
- case SQL_SERVER: return "sqlserver";
- case SYBASE: return "sybase";
- default: return null;
- }
- }
-
- @Override
- public OpenJpaDialect getJpaDialect() {
- return this.jpaDialect;
- }
-
- @Override
- public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface() {
- return OpenJPAEntityManagerFactorySPI.class;
- }
-
- @Override
- public Class<? extends EntityManager> getEntityManagerInterface() {
- return OpenJPAEntityManagerSPI.class;
- }
-
-}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
index 177034c..325a81a 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
@@ -29,7 +29,6 @@ import org.apache.fineract.spm.domain.Survey;
import org.apache.fineract.spm.domain.SurveyValidator;
import org.apache.fineract.spm.exception.SurveyNotFoundException;
import org.apache.fineract.spm.repository.SurveyRepository;
-import org.apache.openjpa.persistence.EntityExistsException;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
@@ -89,8 +88,6 @@ public class SpmService {
survey.setValidTo(cal.getTime());
try {
this.surveyRepository.saveAndFlush(survey);
- } catch (final EntityExistsException dve) {
- handleDataIntegrityIssues(dve, dve, survey.getKey());
} catch (final DataIntegrityViolationException dve) {
handleDataIntegrityIssues(dve.getMostSpecificCause(), dve, survey.getKey());
} catch (final JpaSystemException dve) {
@@ -105,8 +102,6 @@ public class SpmService {
try {
this.surveyValidator.validate(survey);
this.surveyRepository.saveAndFlush(survey);
- } catch (final EntityExistsException dve) {
- handleDataIntegrityIssues(dve, dve, survey.getKey());
} catch (final DataIntegrityViolationException dve) {
handleDataIntegrityIssues(dve.getMostSpecificCause(), dve, survey.getKey());
} catch (final JpaSystemException dve) {
diff --git a/fineract-provider/src/main/resources/META-INF/persistence.xml b/fineract-provider/src/main/resources/META-INF/persistence.xml
index 8b13301..128c9b2 100644
--- a/fineract-provider/src/main/resources/META-INF/persistence.xml
+++ b/fineract-provider/src/main/resources/META-INF/persistence.xml
@@ -22,17 +22,20 @@
<persistence version="2.0"
- xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
-
- <persistence-unit name="jpa-pu" transaction-type="RESOURCE_LOCAL">
- <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
- <properties>
- <property name="openjpa.Compatibility" value="QuotedNumbersInQueries=true"/>
- <property name="openjpa.jdbc.DBDictionary" value="org.apache.fineract.infrastructure.core.domain.MySQLDictionaryCustom"/>
- <!--<property name="openjpa.InverseManager" value="true(Action=warn)"/> -->
- <!-- <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"/>-->
- <property name="openjpa.jdbc.MappingDefaults" value="ForeignKeyDeleteAction=CASCADE"/>
- </properties>
- </persistence-unit>
-</persistence>
\ No newline at end of file
+xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+
+ <persistence-unit name="jpa-pu" transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ </persistence-unit>
+
+ <!-- Necessary to let EclipseLink/Weaver discover local classes without listing them in this file,
+ see http://www.eclipse.org/eclipselink/documentation/2.7/concepts/app_dev001.htm#BGBHFFAG-->
+ <exclude-unlisted-classes>false</exclude-unlisted-classes>
+
+ <properties>
+ <!-- Tell the application container that our classes are already woven,
+ see https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving-->
+ <property name="eclipselink.weaving" value="static" />
+ </properties>
+</persistence>
diff --git a/fineract-provider/src/main/resources/META-INF/spring/infrastructure.xml b/fineract-provider/src/main/resources/META-INF/spring/infrastructure.xml
index 0e09d89..040dea3 100644
--- a/fineract-provider/src/main/resources/META-INF/spring/infrastructure.xml
+++ b/fineract-provider/src/main/resources/META-INF/spring/infrastructure.xml
@@ -34,7 +34,7 @@
<property name="dataSource" ref="routingDataSource" />
<property name="persistenceUnitName" value="jpa-pu" />
<property name="jpaVendorAdapter">
- <bean class="org.apache.fineract.infrastructure.openjpa.OpenJpaVendorAdapter"/>
+ <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"/>
</property>
</bean>