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

pcristof pushed a commit to branch OPENJPA-2940
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit 569e3f0972dc12989fc8b1215357b00a61379774
Author: Paulo Cristovão de Araújo Silva Filho <pcris...@gmail.com>
AuthorDate: Tue Aug 12 20:57:56 2025 -0300

    [OPENJPA-2940][WIP] Fixing 
createEntityManagerFactory(PersistenceConfiguration) method
---
 .../TestEntityManagerFactoryLoading.java           |  2 +-
 .../simple/TestEntityManagerFactory.java           |  2 +-
 .../persistence/util/TestPersistenceUnitUtil.java  |  2 +-
 .../persistence/PersistenceProductDerivation.java  | 12 +++++++++--
 .../persistence/PersistenceProviderImpl.java       | 11 +---------
 .../persistence/PersistenceUnitInfoImpl.java       | 25 ++++++++++++++++++++++
 6 files changed, 39 insertions(+), 15 deletions(-)

diff --git 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestEntityManagerFactoryLoading.java
 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestEntityManagerFactoryLoading.java
index 5f1ee1960..34ef982fe 100644
--- 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestEntityManagerFactoryLoading.java
+++ 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestEntityManagerFactoryLoading.java
@@ -51,7 +51,7 @@ public class TestEntityManagerFactoryLoading {
        
        @Before
        public void beforeEach() {
-               PersistenceConfiguration conf = new 
PersistenceConfiguration("test");
+               PersistenceConfiguration conf = new 
PersistenceConfiguration("dynamicaly-created-pu");
                
conf.property(PersistenceConfiguration.SCHEMAGEN_DATABASE_ACTION, 
"drop-and-create");
                conf.managedClass(FGManager.class);
                conf.managedClass(FGDepartment.class);
diff --git 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerFactory.java
 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerFactory.java
index 49c452cb4..8af389132 100644
--- 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerFactory.java
+++ 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerFactory.java
@@ -37,7 +37,7 @@ public class TestEntityManagerFactory extends TestCase {
     }
        
        public void testEMFCreation() {
-               PersistenceConfiguration conf = new 
PersistenceConfiguration("non-existent-PU");
+               PersistenceConfiguration conf = new 
PersistenceConfiguration("dynamicaly-created-pu");
                conf.managedClass(AllFieldTypes.class);
                
conf.property(PersistenceConfiguration.SCHEMAGEN_DATABASE_ACTION, 
"drop-and-create");
                
diff --git 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestPersistenceUnitUtil.java
 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestPersistenceUnitUtil.java
index 167446ad4..93872e351 100644
--- 
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestPersistenceUnitUtil.java
+++ 
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestPersistenceUnitUtil.java
@@ -59,7 +59,7 @@ public class TestPersistenceUnitUtil {
        
        @BeforeClass
        public static void beforeAll() {
-               PersistenceConfiguration conf = new 
PersistenceConfiguration("test");
+               PersistenceConfiguration conf = new 
PersistenceConfiguration("dynamicaly-created-pu");
                
conf.property(PersistenceConfiguration.SCHEMAGEN_DATABASE_ACTION, 
"drop-and-create");
                Stream.of(EagerEntity.class, LazyEmbed.class,
                                LazyEntity.class, EagerEmbed.class, 
RelEntity.class, EagerEmbedRel.class,
diff --git 
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
 
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
index a5fa09946..330f3acec 100644
--- 
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
+++ 
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
@@ -34,6 +34,7 @@ import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.Set;
 
+import jakarta.persistence.PersistenceConfiguration;
 import jakarta.persistence.SharedCacheMode;
 import jakarta.persistence.ValidationMode;
 import jakarta.persistence.spi.PersistenceUnitInfo;
@@ -296,7 +297,7 @@ public class PersistenceProductDerivation
         }
         return true;
     }
-
+    
     /**
      * Load configuration from the given persistence unit with the specified
      * user properties.
@@ -321,6 +322,13 @@ public class PersistenceProductDerivation
         return cp;
     }
 
+    public ConfigurationProvider load(PersistenceConfiguration config, Map 
props) throws IOException {
+       ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
+       // convert config into pinfo
+       PersistenceUnitInfoImpl pinfo = PersistenceUnitInfoImpl.convert(config);
+       return load((PersistenceUnitInfo) pinfo, props);
+    }
+    
     /**
      * Load configuration from the given resource and unit names, which may
      * be null.
@@ -654,7 +662,7 @@ public class PersistenceProductDerivation
             _puNameCollisions.put(puName, new PUNameCollision(puName, file1, 
file2));
         }
     }
-
+    
     /**
      * Custom configuration provider.
      */
diff --git 
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
 
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
index 55f64a01a..6e917a226 100644
--- 
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
+++ 
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
@@ -166,16 +166,7 @@ public class PersistenceProviderImpl
 
        @Override
        public EntityManagerFactory 
createEntityManagerFactory(PersistenceConfiguration config) {
-               List<Class<?>> managedClasses = config.managedClasses();
-               if (managedClasses != null && !managedClasses.isEmpty()) {
-                       String managedClassesList = 
managedClasses.stream().map(Class::getName).collect(Collectors.joining(";"));
-                       String old = 
config.properties().containsKey("openjpa.MetaDataFactory")
-                                       ? "," + 
config.properties().get("openjpa.MetaDataFactory").toString()
-                                       : "";
-                       config.property("openjpa.MetaDataFactory", "jpa(Types=" 
+ managedClassesList + old + ")");
-               }
-               config.property("openjpa.Id", config.name());
-               return createEntityManagerFactory(null, config.properties());
+               return 
createContainerEntityManagerFactory((PersistenceUnitInfo) 
PersistenceUnitInfoImpl.convert(config), config.properties());
        }
 
        @Override
diff --git 
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
 
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
index 4acc8e4b4..691873ef9 100644
--- 
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
+++ 
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
@@ -32,7 +32,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.stream.Collectors;
 
+import jakarta.persistence.PersistenceConfiguration;
 import jakarta.persistence.SharedCacheMode;
 import jakarta.persistence.ValidationMode;
 import jakarta.persistence.spi.ClassTransformer;
@@ -616,4 +618,27 @@ public class PersistenceUnitInfoImpl
        throw new UnsupportedOperationException("Not yet implemented (JPA 
3.2)");
        }
        
+       public static PersistenceUnitInfoImpl convert(PersistenceConfiguration 
config) {
+               PersistenceUnitInfoImpl pinfo = new PersistenceUnitInfoImpl();
+               pinfo.setJtaDataSourceName(config.jtaDataSource());
+               pinfo.setNonJtaDataSourceName(config.nonJtaDataSource());
+               pinfo.setPersistenceProviderClassName(config.provider());
+               pinfo.setPersistenceUnitName(config.name());
+               pinfo.setSharedCacheMode(config.sharedCacheMode());
+               pinfo.setTransactionType(config.transactionType() == 
jakarta.persistence.PersistenceUnitTransactionType.JTA ? 
+                               PersistenceUnitTransactionType.JTA : 
PersistenceUnitTransactionType.RESOURCE_LOCAL);
+               pinfo.setValidationMode(config.validationMode());
+               List<Class<?>> managedClasses = config.managedClasses();
+               if (managedClasses != null && !managedClasses.isEmpty()) {
+                       String managedClassesList = 
managedClasses.stream().map(Class::getName).collect(Collectors.joining(";"));
+                       String old = 
config.properties().containsKey("openjpa.MetaDataFactory")
+                                       ? "," + 
config.properties().get("openjpa.MetaDataFactory").toString()
+                                       : "";
+                       config.property("openjpa.MetaDataFactory", "jpa(Types=" 
+ managedClassesList + old + ")");
+               }
+               config.property("openjpa.noPersistenceXMLResource", true);
+               pinfo.setPersistenceUnitName(config.name());
+               return pinfo;
+       }
+       
 }

Reply via email to