You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/02/23 09:31:13 UTC

[isis] branch master updated: ISIS-2539: create a dynamic-pu with all the entities

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

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 1243dc4  ISIS-2539: create a dynamic-pu with all the entities
1243dc4 is described below

commit 1243dc41bdf9177a288294e3158147cd7de8daf0
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Feb 23 10:30:53 2021 +0100

    ISIS-2539: create a dynamic-pu with all the entities
    
    allows DN to create all the tables in one blow
    datanucleus.generateSchema.create
---
 .../isis/core/config/presets/IsisPresets.java      | 31 ----------------------
 .../jdo/datanucleus/IsisModuleJdoDatanucleus.java  | 25 ++++++++++++++---
 2 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/core/config/src/main/java/org/apache/isis/core/config/presets/IsisPresets.java b/core/config/src/main/java/org/apache/isis/core/config/presets/IsisPresets.java
index 8028fb2..eaae619 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/presets/IsisPresets.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/presets/IsisPresets.java
@@ -18,12 +18,6 @@
  */
 package org.apache.isis.core.config.presets;
 
-import java.util.List;
-
-import org.apache.isis.commons.internal.collections._Lists;
-
-import lombok.RequiredArgsConstructor;
-
 /**
  * Supports Spring's {@code @PropertySource} annotation.
  * 
@@ -80,30 +74,5 @@ public final class IsisPresets  {
         System.setProperty("logging.level." + clazz.getName(), loggingLevel);
     }
     
-    @RequiredArgsConstructor
-    public static enum DebugLoggingPreset {
-        PERSISTENCE(_Lists.of(
-                "org.apache.isis.persistence.jdo.datanucleus5.persistence.IsisPlatformTransactionManagerForJdo",
-                "org.apache.isis.persistence.jdo.datanucleus5.persistence.PersistenceSession5",
-                "org.apache.isis.persistence.jdo.datanucleus5.persistence.IsisTransactionJdo"                
-                )), 
-        ISIS_SESSION(_Lists.of(
-                "org.apache.isis.core.runtimeservices.session.IsisInteractionFactoryDefault"
-                )),
-        VAADIN(_Lists.of(
-                "com.vaadin",
-                "org.apache.isis.incubator.viewer.vaadin.ui.auth.VaadinAuthenticationHandler"
-                )),
-        ;
-        private final List<String> include;        
-        public void apply() {
-            include.forEach(className->
-                System.setProperty("logging.level." + className, "debug"));
-        }
-    }
-    
-    
-    
-    
 
 }
diff --git a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/IsisModuleJdoDatanucleus.java b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/IsisModuleJdoDatanucleus.java
index cc742dc..effd540 100644
--- a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/IsisModuleJdoDatanucleus.java
+++ b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/IsisModuleJdoDatanucleus.java
@@ -24,6 +24,7 @@ import javax.jdo.PersistenceManagerFactory;
 import javax.sql.DataSource;
 
 import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
+import org.datanucleus.metadata.PersistenceUnitMetaData;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
@@ -36,6 +37,7 @@ import org.springframework.transaction.interceptor.TransactionInterceptor;
 import org.apache.isis.applib.services.eventbus.EventBusService;
 import org.apache.isis.commons.internal.assertions._Assert;
 import org.apache.isis.core.config.IsisConfiguration;
+import org.apache.isis.core.config.beans.IsisBeanTypeRegistry;
 import org.apache.isis.core.config.beans.aoppatch.TransactionInterceptorFactory;
 import org.apache.isis.core.metamodel.context.MetaModelContext;
 import org.apache.isis.core.transaction.changetracking.EntityChangeTracker;
@@ -106,6 +108,7 @@ public class IsisModuleJdoDatanucleus {
             final MetaModelContext metaModelContext,
             final EventBusService eventBusService,
             final Provider<EntityChangeTracker> entityChangeTrackerProvider,
+            final IsisBeanTypeRegistry beanTypeRegistry,
             final DnSettings dnSettings) {
         
         _Assert.assertNotNull(dataSource, "a datasource is required");
@@ -115,7 +118,8 @@ public class IsisModuleJdoDatanucleus {
         val lpmfBean = new LocalPersistenceManagerFactoryBean() {
             @Override
             protected PersistenceManagerFactory newPersistenceManagerFactory(java.util.Map<?,?> props) {
-                val pmf = new JDOPersistenceManagerFactory(props);
+                val pu = createDefaultPersistenceUnit(beanTypeRegistry);
+                val pmf = new JDOPersistenceManagerFactory(pu, props);
                 pmf.setConnectionFactory(dataSource);
                 integrateWithApplicationLayer(metaModelContext, eventBusService, entityChangeTrackerProvider, pmf);
                 return pmf;
@@ -210,14 +214,18 @@ public class IsisModuleJdoDatanucleus {
 
         if(!persistenceSchemaConf.getAutoCreateSchemas().isEmpty()) {
 
-            log.info("about to create db schema(s) {}", persistenceSchemaConf.getAutoCreateSchemas());
+            log.info("About to create db schema(s) {} with template '{}'", 
+                    persistenceSchemaConf.getAutoCreateSchemas(),
+                    persistenceSchemaConf.getCreateSchemaSqlTemplate());
 
             try(val con = dataSource.getConnection()){
 
                 val s = con.createStatement();
 
                 for(val schema : persistenceSchemaConf.getAutoCreateSchemas()) {
-                    s.execute(String.format(persistenceSchemaConf.getCreateSchemaSqlTemplate(), schema));
+                    val sql = String.format(persistenceSchemaConf.getCreateSchemaSqlTemplate(), schema);
+                    log.info("SQL '{}'", sql);
+                    s.execute(sql);
                 }
 
             }
@@ -226,6 +234,17 @@ public class IsisModuleJdoDatanucleus {
         return dataSource;
     }
     
+    private static PersistenceUnitMetaData createDefaultPersistenceUnit (
+            final IsisBeanTypeRegistry beanTypeRegistry) {
+        val pumd = new PersistenceUnitMetaData(
+                "dynamic-unit", "RESOURCE_LOCAL", null);
+        pumd.setExcludeUnlistedClasses(false);
+        beanTypeRegistry.getEntityTypes().stream()
+        .map(Class::getName)
+        .forEach(pumd::addClassName);
+        return pumd;
+    }
+    
     private static void integrateWithApplicationLayer(
             final MetaModelContext metaModelContext,
             final EventBusService eventBusService,