You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2018/09/14 16:11:58 UTC
[isis] 17/19: ISIS-1974: needs to initialize DN eagerly,
alongside SpecLoader doing its thing
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 84a8d5dfc77dc25e8bbf663bcbf372e045e22d5b
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Sep 14 16:37:34 2018 +0100
ISIS-1974: needs to initialize DN eagerly, alongside SpecLoader doing its thing
---
.../system/persistence/DataNucleusApplicationComponents4.java | 10 ++++++++++
.../runtime/system/persistence/PersistenceSessionFactory4.java | 4 ++++
.../system/persistence/DataNucleusApplicationComponents5.java | 10 ++++++++++
.../runtime/system/persistence/PersistenceSessionFactory5.java | 6 +++++-
.../apache/isis/objectstore/jdo/service/RegisterEntities.java | 2 +-
5 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents4.java b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents4.java
index fbe6318..f10f703 100644
--- a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents4.java
+++ b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents4.java
@@ -122,11 +122,21 @@ public class DataNucleusApplicationComponents4 implements ApplicationScopedCompo
private static boolean isSchemaAwareStoreManager(Map<String,String> datanucleusProps) {
+ // this saves some time, but also avoids the (still undiagnosed) issue that instantiating the
+ // PMF can cause the ClassMetadata for the entity classes to be loaded in and cached prior to
+ // registering the CreateSchemaObjectFromClassData (to invoke 'create schema' first)
+ final String connectionUrl = datanucleusProps.get("javax.jdo.option.ConnectionURL");
+ if(connectionUrl != null) {
+ if (connectionUrl.startsWith("jdbc:hsqldb")) return true;
+ if (connectionUrl.startsWith("jdbc:sqlserver")) return true;
+ }
+
// we create a throw-away instance of PMF so that we can probe whether DN has
// been configured with a schema-aware store manager or not.
final JDOPersistenceManagerFactory probePmf =
(JDOPersistenceManagerFactory) newPersistenceManagerFactory(datanucleusProps);
+
try {
final PersistenceNucleusContext nucleusContext = probePmf.getNucleusContext();
final StoreManager storeManager = nucleusContext.getStoreManager();
diff --git a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java
index 1bd9df9..5e6e6e3 100644
--- a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java
+++ b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java
@@ -69,6 +69,10 @@ PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstalledFlag {
@Override
public void init(final IsisConfigurationDefault configuration) {
this.configuration = configuration;
+ // need to eagerly build, ... must be completed before catalogNamedQueries().
+ // Why? because that method causes entity classes to be loaded which register with DN's EnhancementHelper,
+ // which are then cached in DN. It results in our CreateSchema listener not firing.
+ createDataNucleusApplicationComponents();
}
@Programmatic
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents5.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents5.java
index 26cf114..0298cba 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents5.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents5.java
@@ -122,11 +122,21 @@ public class DataNucleusApplicationComponents5 implements ApplicationScopedCompo
private static boolean isSchemaAwareStoreManager(Map<String,String> datanucleusProps) {
+ // this saves some time, but also avoids the (still undiagnosed) issue that instantiating the
+ // PMF can cause the ClassMetadata for the entity classes to be loaded in and cached prior to
+ // registering the CreateSchemaObjectFromClassData (to invoke 'create schema' first)
+ final String connectionUrl = datanucleusProps.get("javax.jdo.option.ConnectionURL");
+ if(connectionUrl != null) {
+ if (connectionUrl.startsWith("jdbc:hsqldb")) return true;
+ if (connectionUrl.startsWith("jdbc:sqlserver")) return true;
+ }
+
// we create a throw-away instance of PMF so that we can probe whether DN has
// been configured with a schema-aware store manager or not.
final JDOPersistenceManagerFactory probePmf =
(JDOPersistenceManagerFactory) newPersistenceManagerFactory(datanucleusProps);
+
try {
final PersistenceNucleusContext nucleusContext = probePmf.getNucleusContext();
final StoreManager storeManager = nucleusContext.getStoreManager();
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
index bb12c9e..12014b4 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
@@ -69,6 +69,10 @@ implements PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstal
@Override
public void init(final IsisConfigurationDefault configuration) {
this.configuration = configuration;
+ // need to eagerly build, ... must be completed before catalogNamedQueries().
+ // Why? because that method causes entity classes to be loaded which register with DN's EnhancementHelper,
+ // which are then cached in DN. It results in our CreateSchema listener not firing.
+ createDataNucleusApplicationComponents();
}
@Programmatic
@@ -184,7 +188,7 @@ implements PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstal
final ServicesInjector servicesInjector,
final AuthenticationSession authenticationSession) {
- Objects.requireNonNull(applicationComponents, "PersistenceSession5 requires initialization. "+this.hashCode());
+ Objects.requireNonNull(applicationComponents.get(), "PersistenceSession5 requires initialization. "+this.hashCode());
final FixturesInstalledFlag fixturesInstalledFlag = this;
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
index b9b8fd1..c2244be 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
@@ -55,7 +55,7 @@ public class RegisterEntities {
private Set<String> findEntityTypes() {
- Set<String> entityTypes = new LinkedHashSet<String>();
+ Set<String> entityTypes = new LinkedHashSet<>();
Set<Class<?>> persistenceCapableTypes = AppManifest.Registry.instance().getPersistenceCapableTypes();