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 2018/03/01 22:51:26 UTC

[isis] branch master updated: ISIS-1767 possibly allows use of axon plugin on JEE

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 71d9daf  ISIS-1767 possibly allows use of axon plugin on JEE
71d9daf is described below

commit 71d9dafd233e2d951d7fbf8c20e792f60e848903
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Mar 1 23:51:24 2018 +0100

    ISIS-1767 possibly allows use of axon plugin on JEE
---
 .../webapp/jee/PersistenceUnitNoopProvider.java    | 114 +++++++++++++++++++++
 .../src/main/resources/META-INF/persistence.xml    |   8 ++
 2 files changed, 122 insertions(+)

diff --git a/core/plugins/eventbus-axon/src/main/java/org/apache/isis/core/webapp/jee/PersistenceUnitNoopProvider.java b/core/plugins/eventbus-axon/src/main/java/org/apache/isis/core/webapp/jee/PersistenceUnitNoopProvider.java
new file mode 100644
index 0000000..5cf6670
--- /dev/null
+++ b/core/plugins/eventbus-axon/src/main/java/org/apache/isis/core/webapp/jee/PersistenceUnitNoopProvider.java
@@ -0,0 +1,114 @@
+/*
+ * 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.core.webapp.jee;
+
+import java.util.Map;
+
+import javax.persistence.Cache;
+import javax.persistence.EntityGraph;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnitUtil;
+import javax.persistence.Query;
+import javax.persistence.SynchronizationType;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.metamodel.Metamodel;
+import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.ProviderUtil;
+import javax.resource.NotSupportedException;
+
+/**
+ * [ahuber] still work in progress, some information given here might be wrong ... <br/><br/> 
+ * 
+ * Implements a PersistenceProvider that does nothing.
+ * <p>
+ * Note: the axon framework on JEE requires at least a dummy persistence unit. 
+ * This requires that the {@code web.xml} includes a {@code persistence-context-ref} entry as follows:
+ * 
+ * <pre>{@code
+ * <persistence-context-ref>
+ *     <persistence-context-ref-name>org.axonframework.common.jpa.ContainerManagedEntityManagerProvider/entityManager</persistence-context-ref-name>
+ *     <persistence-unit-name>noop</persistence-unit-name>
+ * </persistence-context-ref>
+ * }
+ * </pre>
+ * </p>
+ * <p>
+ * A {@code META_INF/persistence.xml} that declares the 'noop' persistence-unit 
+ * is bundled with this module. 
+ * </p>
+ * 
+ * @since 2.0.0
+ *
+ */
+@SuppressWarnings("rawtypes") 
+public class PersistenceUnitNoopProvider implements javax.persistence.spi.PersistenceProvider{
+
+	@Override
+	public EntityManagerFactory createEntityManagerFactory(String emName, Map map) {
+		return noopEntityManagerFactory();
+	}
+
+	@Override
+	public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
+		return noopEntityManagerFactory();
+	}
+
+	@Override
+	public void generateSchema(PersistenceUnitInfo info, Map map) {
+		throw notSupported();	
+	}
+
+	@Override
+	public boolean generateSchema(String persistenceUnitName, Map map) {
+		throw notSupported();
+	}
+
+	@Override
+	public ProviderUtil getProviderUtil() {
+		throw notSupported();
+	}
+
+	// -- HELPER
+
+	private static RuntimeException notSupported() {
+		return new RuntimeException(
+				new NotSupportedException("This PersistenceProvider is just a dummy."));
+	}
+	
+	private EntityManagerFactory noopEntityManagerFactory() {
+		return new EntityManagerFactory() {
+			@Override public EntityManager createEntityManager() {	return null; }
+			@Override public EntityManager createEntityManager(Map map) { return null; }
+			@Override public EntityManager createEntityManager(SynchronizationType synchronizationType) { return null;	}
+			@Override public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) { return null;	}
+			@Override public CriteriaBuilder getCriteriaBuilder() { return null; }
+			@Override public Metamodel getMetamodel() { return null; }
+			@Override public boolean isOpen() {	return false; }
+			@Override public void close() {	}
+			@Override public Map<String, Object> getProperties() { return null;	}
+			@Override public Cache getCache() { return null; }
+			@Override public PersistenceUnitUtil getPersistenceUnitUtil() {	return null; }
+			@Override public void addNamedQuery(String name, Query query) {	}
+			@Override public <T> T unwrap(Class<T> cls) { return null; }
+			@Override public <T> void addNamedEntityGraph(String graphName, EntityGraph<T> entityGraph) { }
+		};
+	}
+	
+}
diff --git a/core/plugins/eventbus-axon/src/main/resources/META-INF/persistence.xml b/core/plugins/eventbus-axon/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..356a2aa
--- /dev/null
+++ b/core/plugins/eventbus-axon/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+
+	<!-- declares a persistence unit that does nothing -->
+	<persistence-unit name="noop">
+		<provider>org.apache.isis.core.webapp.jee.PersistenceUnitNoopProvider</provider>
+	</persistence-unit>
+</persistence>

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.