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

coheigea pushed a commit to branch coheigea/jpa
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git

commit b89578cb8bb1f7293d1e1e86e24c99d63ad0ba6b
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Wed May 13 15:53:05 2026 +0100

    Copy JPA classes form Syncope into the project
---
 services/idp-core/pom.xml                          |  36 ++---
 .../orm/jpa/vendor/OpenJpaDialect.java             | 159 +++++++++++++++++++++
 .../orm/jpa/vendor/OpenJpaVendorAdapter.java       | 131 +++++++++++++++++
 3 files changed, 302 insertions(+), 24 deletions(-)

diff --git a/services/idp-core/pom.xml b/services/idp-core/pom.xml
index 58f598d8..e86724c0 100644
--- a/services/idp-core/pom.xml
+++ b/services/idp-core/pom.xml
@@ -208,30 +208,6 @@
                     </execution>
                 </executions>
             </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-dependency-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>org.apache.syncope.core</groupId>
-                                    
<artifactId>syncope-core-persistence-jpa</artifactId>
-                                    <version>2.1.6</version>
-                                    <destFileName>fediz-oidc.war</destFileName>
-                                    
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
-                                    
<includes>org/springframework/orm/jpa/vendor/*.class</includes> 
-                                </artifactItem>
-                            </artifactItems>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-source-plugin</artifactId>
@@ -245,6 +221,18 @@
                    </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>validate</id>
+                        <configuration>
+                            
<excludes>**/org/springframework/orm/jpa/vendor/**/*.java</excludes>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
 
         </plugins>
     </build>
diff --git 
a/services/idp-core/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaDialect.java
 
b/services/idp-core/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaDialect.java
new file mode 100644
index 00000000..aec657c3
--- /dev/null
+++ 
b/services/idp-core/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaDialect.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.orm.jpa.vendor;
+
+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 Juergen Hoeller
+ * @author Costin Leau
+ * @since 2.0
+ */
+public class OpenJpaDialect extends DefaultJpaDialect {
+
+    private static final long serialVersionUID = 2099118508988476959L;
+
+    @Override
+    public Object beginTransaction(final EntityManager entityManager, final 
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(final EntityManager 
entityManager, final 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(final 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;
+
+        OpenJpaTransactionData(final 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(final Object savepoint) throws 
TransactionException {
+            this.entityManager.rollbackToSavepoint((String) savepoint);
+        }
+
+        @Override
+        public void releaseSavepoint(final 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;
+
+        OpenJpaConnectionHandle(final OpenJPAEntityManager entityManager) {
+            this.entityManager = entityManager;
+        }
+
+        @Override
+        public Connection getConnection() {
+            return (Connection) this.entityManager.getConnection();
+        }
+
+        @Override
+        public void releaseConnection(final Connection con) {
+            JdbcUtils.closeConnection(con);
+        }
+    }
+
+}
diff --git 
a/services/idp-core/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaVendorAdapter.java
 
b/services/idp-core/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaVendorAdapter.java
new file mode 100644
index 00000000..a8016377
--- /dev/null
+++ 
b/services/idp-core/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaVendorAdapter.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.orm.jpa.vendor;
+
+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;
+
+/**
+ * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for 
Apache OpenJPA.
+ * Developed and tested against OpenJPA 3.0.
+ *
+ * Exposes OpenJPA's persistence provider and EntityManager extension 
interface,
+ * and adapts {@link AbstractJpaVendorAdapter}'s common configuration settings.
+ * No support for the detection of annotated packages (through
+ * {@link 
org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo#getManagedPackages()})
+ * since OpenJPA doesn't use package-level metadata.
+ *
+ * @author Juergen Hoeller
+ * @author Costin Leau
+ * @since 2.0
+ * @see OpenJpaDialect
+ * @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<>();
+
+        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(final 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;
+    }
+
+}

Reply via email to