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 f482514dd7e8573bf40b21108c926cbb657a4427 Author: Andi Huber <ahu...@apache.org> AuthorDate: Sun Oct 29 09:29:38 2017 +0100 ISIS-1756 JEE 7+ Isis App life-cycling --- .../webapp/jee/IsisDomainAppLifecycleBean.java | 61 +++++++++++ .../webapp/jee/PersistenceUnitNoopProvider.java | 112 +++++++++++++++++++++ .../src/main/resources/META-INF/persistence.xml | 8 ++ 3 files changed, 181 insertions(+) diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/IsisDomainAppLifecycleBean.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/IsisDomainAppLifecycleBean.java new file mode 100644 index 0000000..07881e3 --- /dev/null +++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/IsisDomainAppLifecycleBean.java @@ -0,0 +1,61 @@ +/* + * 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 javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import javax.enterprise.context.ApplicationScoped; + +import org.apache.isis.core.runtime.system.context.IsisContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * + * JEE singleton that hooks into an Isis-Application's life-cycle. + * + * <p> + * This CDI managed Bean ensures proper destruction of Isis's context. + * </p> + * + * @author ahu...@apache.org + * + */ +@Singleton +@Startup +@ApplicationScoped +public class IsisDomainAppLifecycleBean { + + private static final Logger log = LoggerFactory.getLogger(IsisDomainAppLifecycleBean.class); + + @PostConstruct + public void init() { + log.info("initializing ..."); + } + + @PreDestroy + public void destroy() { + IsisContext.destroy(); + log.info("detroyed."); + } + +} diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/PersistenceUnitNoopProvider.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/PersistenceUnitNoopProvider.java new file mode 100644 index 0000000..3a9bac1 --- /dev/null +++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/PersistenceUnitNoopProvider.java @@ -0,0 +1,112 @@ +/* + * 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; + +/** + * 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> + * + * @author ahu...@apache.org + * + */ +@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/runtime/src/main/resources/META-INF/persistence.xml b/core/runtime/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..356a2aa --- /dev/null +++ b/core/runtime/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 ahu...@apache.org.