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 2020/01/04 09:37:50 UTC
[isis] branch master updated: ISIS-2248: move new code to its own
utility class and cleanup
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 1dac8e8 ISIS-2248: move new code to its own utility class and cleanup
1dac8e8 is described below
commit 1dac8e8aae0440af24f31f4225d985342c8a580b
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Jan 4 10:37:38 2020 +0100
ISIS-2248: move new code to its own utility class and cleanup
---
.../datanucleus/DataNucleusContextUtil.java | 59 ++++++++++++++++++++++
.../datanucleus/JDOStateManagerForIsis.java | 19 ++-----
.../DataNucleusApplicationComponents5.java | 9 ----
.../persistence/PersistenceSessionFactory5.java | 18 +++----
4 files changed, 73 insertions(+), 32 deletions(-)
diff --git a/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/datanucleus/DataNucleusContextUtil.java b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/datanucleus/DataNucleusContextUtil.java
new file mode 100644
index 0000000..dd8099e
--- /dev/null
+++ b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/datanucleus/DataNucleusContextUtil.java
@@ -0,0 +1,59 @@
+/*
+ * 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.isis.persistence.jdo.datanucleus5.datanucleus;
+
+import java.util.Map;
+import java.util.Optional;
+
+import org.datanucleus.ExecutionContext;
+
+import org.apache.isis.metamodel.context.MetaModelContext;
+
+import lombok.val;
+import lombok.experimental.UtilityClass;
+
+/**
+ *
+ * @since 2.0
+ *
+ */
+@UtilityClass
+public class DataNucleusContextUtil {
+
+ // required to be lower-case for DN to be accepted
+ private final static String METAMODELCONTEXT_PROPERTY_KEY = "isis.metamodelcontext";
+
+ public static void putMetaModelContext(
+ Map<String, Object> map,
+ MetaModelContext metaModelContext) {
+
+ map.put(METAMODELCONTEXT_PROPERTY_KEY, metaModelContext);
+ }
+
+ public static Optional<MetaModelContext> extractMetaModelContext(ExecutionContext ec) {
+
+ val metaModelContext = (MetaModelContext) ec.getNucleusContext()
+ .getConfiguration()
+ .getPersistenceProperties()
+ .get(METAMODELCONTEXT_PROPERTY_KEY);
+
+ return Optional.ofNullable(metaModelContext);
+ }
+
+}
diff --git a/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/datanucleus/JDOStateManagerForIsis.java b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/datanucleus/JDOStateManagerForIsis.java
index bdc42a6..f9e0a11 100644
--- a/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/datanucleus/JDOStateManagerForIsis.java
+++ b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/datanucleus/JDOStateManagerForIsis.java
@@ -31,7 +31,6 @@ import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.metamodel.context.MetaModelContext;
import org.apache.isis.persistence.jdo.datanucleus5.datanucleus.service.eventbus.EventBusServiceJdo;
-import lombok.val;
import lombok.extern.log4j.Log4j2;
/**
@@ -57,7 +56,7 @@ public class JDOStateManagerForIsis extends ReferentialStateManagerImpl {
final ExecutionContext ec,
final AbstractClassMetaData cmd) {
super(ec, cmd);
- initServiceInjector(extractMetaModelContext(ec));
+ initServiceInjector(ec);
}
/**
@@ -240,19 +239,11 @@ public class JDOStateManagerForIsis extends ReferentialStateManagerImpl {
// -- HELPER
- private MetaModelContext extractMetaModelContext(ExecutionContext ec) {
+ private void initServiceInjector(ExecutionContext ec) {
- return (MetaModelContext) ec.getNucleusContext()
- .getConfiguration()
- .getPersistenceProperties()
- .get("isis.metamodelcontext");
- }
-
- private void initServiceInjector(MetaModelContext metaModelContext) {
-
- if(metaModelContext!=null) {
- this.serviceInjector = metaModelContext.getServiceInjector();
- }
+ this.serviceInjector = DataNucleusContextUtil.extractMetaModelContext(ec)
+ .map(MetaModelContext::getServiceInjector)
+ .orElse(null);
if(this.serviceInjector==null) {
log.warn("could not retrieve a ServiceInjector from the ExecutionContext");
diff --git a/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/DataNucleusApplicationComponents5.java b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/DataNucleusApplicationComponents5.java
index 304654f..7e23788 100644
--- a/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/DataNucleusApplicationComponents5.java
+++ b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/DataNucleusApplicationComponents5.java
@@ -36,7 +36,6 @@ import org.datanucleus.metadata.MetaDataManager;
import org.datanucleus.store.schema.SchemaAwareStoreManager;
import org.apache.isis.commons.internal.base._NullSafe;
-import org.apache.isis.commons.internal.base._Strings;
import org.apache.isis.commons.internal.collections._Maps;
import org.apache.isis.commons.internal.factory.InstanceUtil;
import org.apache.isis.config.IsisConfiguration;
@@ -72,14 +71,6 @@ public class DataNucleusApplicationComponents5 {
this.configuration = configuration;
this.datanucleusProps = datanucleusProps;
this.persistableClassNameSet = persistableClassNameSet;
-
-
- val pmfClass = configuration.getPersistor().getDatanucleus().getImpl()
- .getJavax().getJdo().getPersistenceManagerFactoryClass();
-
- if(_Strings.isNotEmpty(pmfClass)) {
- datanucleusProps.put("javax.jdo.PersistenceManagerFactoryClass", pmfClass);
- }
persistenceManagerFactory = createPmfAndSchemaIfRequired(
this.persistableClassNameSet, this.datanucleusProps);
diff --git a/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/PersistenceSessionFactory5.java b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/PersistenceSessionFactory5.java
index 10f527b..19ef0da 100644
--- a/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/PersistenceSessionFactory5.java
+++ b/core/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/persistence/PersistenceSessionFactory5.java
@@ -42,9 +42,9 @@ import org.apache.isis.commons.internal.collections._Maps;
import org.apache.isis.config.IsisConfiguration;
import org.apache.isis.config.beans.IsisBeanTypeRegistryHolder;
import org.apache.isis.metamodel.context.MetaModelContext;
-import org.apache.isis.metamodel.context.MetaModelContextAware;
import org.apache.isis.persistence.jdo.applib.fixturestate.FixturesInstalledState;
import org.apache.isis.persistence.jdo.applib.fixturestate.FixturesInstalledStateHolder;
+import org.apache.isis.persistence.jdo.datanucleus5.datanucleus.DataNucleusContextUtil;
import org.apache.isis.persistence.jdo.datanucleus5.datanucleus.DataNucleusSettings;
import org.apache.isis.persistence.jdo.datanucleus5.datanucleus.JDOStateManagerForIsis;
import org.apache.isis.persistence.jdo.datanucleus5.entities.JdoEntityTypeRegistry;
@@ -109,12 +109,7 @@ implements PersistenceSessionFactory, FixturesInstalledStateHolder {
private DataNucleusApplicationComponents5 createDataNucleusApplicationComponents() {
val dnSettings = metaModelContext.getServiceRegistry().lookupServiceElseFail(DataNucleusSettings.class);
- val datanucleusProps = _Maps.<String, Object>newHashMap();
- datanucleusProps.putAll(dnSettings.getAsMap());
- datanucleusProps.put("isis.metamodelcontext", metaModelContext);
-
- addDataNucleusPropertiesIfRequired(datanucleusProps);
-
+ val datanucleusProps = addDataNucleusPropertiesAsRequired(dnSettings);
val typeRegistry = isisBeanTypeRegistryHolder.getIsisBeanTypeRegistry();
val classesToBePersisted = jdoEntityTypeRegistry.getEntityTypes(typeRegistry);
@@ -134,7 +129,11 @@ implements PersistenceSessionFactory, FixturesInstalledStateHolder {
metaModelContext.getSpecificationLoader());
}
- private static void addDataNucleusPropertiesIfRequired(Map<String, Object> props) {
+ private Map<String, Object> addDataNucleusPropertiesAsRequired(DataNucleusSettings dnSettings) {
+
+ val props = _Maps.<String, Object>newHashMap();
+ props.putAll(dnSettings.getAsMap());
+ DataNucleusContextUtil.putMetaModelContext(props, metaModelContext);
// new feature in DN 3.2.3; enables dependency injection into entities
putIfNotPresent(props, PropertyNames.PROPERTY_OBJECT_PROVIDER_CLASS_NAME, JDOStateManagerForIsis.class.getName());
@@ -169,7 +168,6 @@ implements PersistenceSessionFactory, FixturesInstalledStateHolder {
log.info("... and config properties for second '-nontx' JNDI datasource also found; {}", connectionFactory2Name);
}
// nothing further to do
- return;
} else {
// use JDBC connection properties; put if not present
@@ -185,6 +183,8 @@ implements PersistenceSessionFactory, FixturesInstalledStateHolder {
}
+
+ return props;
}
private static void putIfNotPresent(