[isis] 24/34: ISIS-1756 remove reflective access to DN's EnhancementHelper since we've got a dedicated method instead

2018-02-22 Thread ahuber
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch dev/2.0.0-M2
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 6769dde68417f475b9c0899463963ea6f7050f9f
Author: Andi Huber 
AuthorDate: Sat Dec 9 09:55:21 2017 +0100

ISIS-1756 remove reflective access to DN's EnhancementHelper since we've
got a dedicated method instead
---
 .../datanucleus/DataNucleusLifeCycleHelper.java| 136 +
 1 file changed, 136 insertions(+)

diff --git 
a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
 
b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
new file mode 100644
index 000..fc5669e
--- /dev/null
+++ 
b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
@@ -0,0 +1,136 @@
+/*
+ *  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.objectstore.jdo.datanucleus;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.datanucleus.ClassLoaderResolver;
+import org.datanucleus.PersistenceNucleusContext;
+import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
+import org.datanucleus.enhancer.EnhancementHelper;
+import org.datanucleus.store.AbstractStoreManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * Purges any state associated with DataNucleus.
+ * 
+ * @author ahu...@apache.org
+ * @since 2.0.0
+ *
+ */
+public class DataNucleusLifeCycleHelper {
+   
+private static final Logger LOG = 
LoggerFactory.getLogger(DataNucleusLifeCycleHelper.class);
+
+   public static void cleanUp(PersistenceManagerFactory 
persistenceManagerFactory) {
+   
+   try {
+   
+   final ClassLoader cl = IsisContext.getClassLoader();
+
+//  XXX not needed according to 
https://github.com/datanucleus/datanucleus-core/issues/272 
+// 
+// if(persistenceManagerFactory instanceof 
JDOPersistenceManagerFactory) {
+// 
+// final JDOPersistenceManagerFactory jdoPMF = 
+// (JDOPersistenceManagerFactory) 
persistenceManagerFactory;
+// final PersistenceNucleusContext nucleusContext 
= jdoPMF.getNucleusContext();
+// final AbstractStoreManager storeManager = 
+// 
(AbstractStoreManager)nucleusContext.getStoreManager();
+// 
+// 
+// persistenceManagerFactory.getManagedClasses()
+// .forEach(clazz->{
+// final ClassLoaderResolver clr = 
nucleusContext.getClassLoaderResolver(cl);
+// 
+// // Un-manage from the store
+// storeManager.unmanageClass(clr, 
clazz.getName(), false);
+// 
+//  // Unload the meta-data for this class
+// 
nucleusContext.getMetaDataManager().unloadMetaDataForClass(clazz.getName());
+// });
+// }
+   
+   persistenceManagerFactory.close();
+   
+   // XXX uses reflection prior to DN v5.1.5
+   // remove once DN v5.1.5 is released
+   // dnUnregisterClassesManagedBy(cl);
+   
+   // XXX for info, why we do this see
+   // 
https://github.com/datanucleus/datanucleus-core/issues/272
+   

[isis] 24/34: ISIS-1756 remove reflective access to DN's EnhancementHelper since we've got a dedicated method instead

2018-02-21 Thread ahuber
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch dev/2.0.0-M2
in repository https://gitbox.apache.org/repos/asf/isis.git

commit e180741d43fb5a1a543680aeaa11d3006c060617
Author: Andi Huber 
AuthorDate: Sat Dec 9 09:55:21 2017 +0100

ISIS-1756 remove reflective access to DN's EnhancementHelper since we've
got a dedicated method instead
---
 .../datanucleus/DataNucleusLifeCycleHelper.java| 136 +
 1 file changed, 136 insertions(+)

diff --git 
a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
 
b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
new file mode 100644
index 000..fc5669e
--- /dev/null
+++ 
b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
@@ -0,0 +1,136 @@
+/*
+ *  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.objectstore.jdo.datanucleus;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.datanucleus.ClassLoaderResolver;
+import org.datanucleus.PersistenceNucleusContext;
+import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
+import org.datanucleus.enhancer.EnhancementHelper;
+import org.datanucleus.store.AbstractStoreManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * Purges any state associated with DataNucleus.
+ * 
+ * @author ahu...@apache.org
+ * @since 2.0.0
+ *
+ */
+public class DataNucleusLifeCycleHelper {
+   
+private static final Logger LOG = 
LoggerFactory.getLogger(DataNucleusLifeCycleHelper.class);
+
+   public static void cleanUp(PersistenceManagerFactory 
persistenceManagerFactory) {
+   
+   try {
+   
+   final ClassLoader cl = IsisContext.getClassLoader();
+
+//  XXX not needed according to 
https://github.com/datanucleus/datanucleus-core/issues/272 
+// 
+// if(persistenceManagerFactory instanceof 
JDOPersistenceManagerFactory) {
+// 
+// final JDOPersistenceManagerFactory jdoPMF = 
+// (JDOPersistenceManagerFactory) 
persistenceManagerFactory;
+// final PersistenceNucleusContext nucleusContext 
= jdoPMF.getNucleusContext();
+// final AbstractStoreManager storeManager = 
+// 
(AbstractStoreManager)nucleusContext.getStoreManager();
+// 
+// 
+// persistenceManagerFactory.getManagedClasses()
+// .forEach(clazz->{
+// final ClassLoaderResolver clr = 
nucleusContext.getClassLoaderResolver(cl);
+// 
+// // Un-manage from the store
+// storeManager.unmanageClass(clr, 
clazz.getName(), false);
+// 
+//  // Unload the meta-data for this class
+// 
nucleusContext.getMetaDataManager().unloadMetaDataForClass(clazz.getName());
+// });
+// }
+   
+   persistenceManagerFactory.close();
+   
+   // XXX uses reflection prior to DN v5.1.5
+   // remove once DN v5.1.5 is released
+   // dnUnregisterClassesManagedBy(cl);
+   
+   // XXX for info, why we do this see
+   // 
https://github.com/datanucleus/datanucleus-core/issues/272
+