You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by sc...@apache.org on 2014/05/08 07:53:32 UTC

svn commit: r1593185 - in /onami/sandbox/persist/src: main/java/org/apache/onami/persist/EntityManagerProvider.java site/apt/complexWebApp.apt.vm site/apt/emProvider.apt.vm site/apt/guicePersist.apt.vm site/apt/index.apt.vm site/site.xml

Author: sclassen
Date: Thu May  8 05:53:31 2014
New Revision: 1593185

URL: http://svn.apache.org/r1593185
Log:
onami-persist: added more sites

Added:
    onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm   (with props)
Modified:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java
    onami/sandbox/persist/src/site/apt/emProvider.apt.vm
    onami/sandbox/persist/src/site/apt/guicePersist.apt.vm
    onami/sandbox/persist/src/site/apt/index.apt.vm
    onami/sandbox/persist/src/site/site.xml

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java?rev=1593185&r1=1593184&r2=1593185&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java Thu May  8 05:53:31 2014
@@ -40,7 +40,7 @@ import javax.persistence.EntityManager;
  * <p/>
  * The {@link EntityManagerProvider} is thread save.
  */
-public interface EntityManagerProvider
+public interface EntityManagerProvider extends Provider<EntityManager>
 {
 
     /**

Added: onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm?rev=1593185&view=auto
==============================================================================
--- onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm (added)
+++ onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm Thu May  8 05:53:31 2014
@@ -0,0 +1,160 @@
+                                    ------
+                                    Multi Datasource Web Application
+                                    ------
+                                    The Apache Onami developers team
+                                    ------
+                                     2014
+
+~~
+~~ 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.
+~~
+
+Multi Datasource Web Application
+
+* java code
+
++--------------------------------------+
+public class BootstrapServletListener extends GuiceServletContextListener {
+    protected Injector getInjector() {
+        final PersistenceModule persistenceModule = new PersistenceModule() {
+            @Override
+            protected void configurePersistence() {
+                addContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/mainPuJndiName")
+                    .annotatedWith(MainPU.class)
+                    .useGlobalTransactionWithJndiName("java:comp/env/UserTransaction");
+
+                addContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/alternativePUJndiName")
+                    .annotatedWith(AlternativePU.class)
+                    .useGlobalTransactionWithJndiName("java:comp/env/UserTransaction");
+
+                addContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/systemPuJndiName")
+                    .annotatedWith(SystemPU.class)
+                    .useLocalTransaction();
+            }
+        };
+
+        final ServletModule servletModule = new ServletModule() {
+            filter("/*").through(PersistenceFilter.class);
+        };
+
+        return Guice.createInjector(servletModule, persistenceModule, getApplicationSpecificModules());
+    }
++--------------------------------------+
+
+* web.xml
+
++--------------------------------------+
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+    <display-name>FooBar App</display-name>
+    <filter>
+        <filter-name>guiceFilter</filter-name>
+        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
+    </filter>
+    <filter-mapping>
+        <filter-name>guiceFilter</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+    <listener>
+        <listener-class>foo.bar.BootstrapServletListener</listener-class>
+    </listener>
+    <!-- More config. -->
+</web-app>
++--------------------------------------+
+
+* persistence.xml
+
++--------------------------------------+
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
+    <persistence-unit name="mainPuName" transaction-type="JTA">
+        <!-- your configuration -->
+    </peristence-unit>
+    <persistence-unit name="alternativePuName" transaction-type="JTA">
+        <!-- your configuration -->
+    </peristence-unit>
+    <persistence-unit name="systemPuName" transaction-type="RESOURCE_LOCAL">
+        <!-- your configuration -->
+    </peristence-unit>
+</peristence>
++--------------------------------------+
+
+* JNDI Binding
+
+  In order to allow container managed persistence units the persistence unit must be bound in the JNDI framework.
+
+  If your container follows the J2EE Standard 5.0 add the following to your web.xml
+
++--------------------------------------+
+<peristence-unit-ref>
+    <peristence-unit-ref-name>foobar/mainPuJndiName</peristence-unit-ref-name>
+    <peristence-unit-name>mainPuName</peristence-unit-name>
+</peristence-unit-ref>
+<peristence-unit-ref>
+    <peristence-unit-ref-name>foobar/alternativePuJndiName</peristence-unit-ref-name>
+    <peristence-unit-name>alterantivePuName</peristence-unit-name>
+</peristence-unit-ref>
+<peristence-unit-ref>
+    <peristence-unit-ref-name>foobar/systemPuJndiName</peristence-unit-ref-name>
+    <peristence-unit-name>systemPuName</peristence-unit-name>
+</peristence-unit-ref>
++--------------------------------------+
+
+  Important: JBoss AS7.x do not support placing the JNDI binding in the web.xml.
+  Instead add the following to your persistence.xml
+
++--------------------------------------+
+<property name="jboss.entity.manager.factory.jndi.name" value="java:comp/env/foobar/mainPuJndiName" />
+<property name="jboss.as.jpa.managed" value="true" />
+
+<property name="jboss.entity.manager.factory.jndi.name" value="java:comp/env/foobar/alternativePuJndiName" />
+<property name="jboss.as.jpa.managed" value="true" />
+
+<property name="jboss.entity.manager.factory.jndi.name" value="java:comp/env/foobar/systemPuJndiName" />
+<property name="jboss.as.jpa.managed" value="true" />
++--------------------------------------+
+
+  Important: JBoss AS 7.x makes all datasources defined in the standalone.xml JTA managed. If you want one or more of
+  the datasources to be resource local you must add the attribute "jta" to the datasource element.
+
++--------------------------------------+
+<datasource jndi-name="java:jboss/datasources/systemDS" pool-name="systemDS" enabled="true" use-java-context="true" jta="false">
+    ...
+</datasource>
++--------------------------------------+
+
+* Structure of the .war
+
++--------------------------------------+
++ app.war
+|    + META-INF
+|    |    + MANIFEST.MF
+|    |    + persistence.xml
+|    + WEB-INF
+|    |    + classes
+|    |    |    + META-INF
+|    |    |    |    + MANIFEST.MF
+|    |    |    + foo
+|    |    |    |    + bar
+|    |    |    |    |    + BootstrapServletListener.class
+|    |    + lib
+|    |    |    + guice.jar
+|    |    |    + onami-persist.jar
++--------------------------------------+
+

Propchange: onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: onami/sandbox/persist/src/site/apt/emProvider.apt.vm
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/site/apt/emProvider.apt.vm?rev=1593185&r1=1593184&r2=1593185&view=diff
==============================================================================
--- onami/sandbox/persist/src/site/apt/emProvider.apt.vm (original)
+++ onami/sandbox/persist/src/site/apt/emProvider.apt.vm Thu May  8 05:53:31 2014
@@ -53,11 +53,12 @@ public class ExampleService {
 +--------------------------------------+
 
   The above implementation will always use the very same EntityManager for all threads and all calls to its methods.
-  This won't work. To make it more obvious that the EntityManager should not be injected into a class guice-jpa does
-  not bind the EntityManager. Instead it binds an EntityManagerProvider. The EntityManagerProvider has only one method
+  This won't work. To prevent injection of the EntityManager into a field or constructor Onami-Persist does not
+  bind the EntityManager. Instead it binds an EntityManagerProvider. The EntityManagerProvider has only one method
   get() which returns the EntityManager. This EntityManager should be used by the calling thread to access the
   persistence unit.
 
+  EntityManagerProvider extends Provider\<EntityManager\>.
   If you need the EntityManager to be bound in the injector you can do this as follows:
 
 +--------------------------------------+
@@ -67,20 +68,9 @@ public class MyPersistenceModule extends
     protected void configurePersistence() {
         addApplicationManagedPersistenceUnit("main").annotatedWith(MainPU.class);
 
-        bind(EntityManager.class).annotatedWith(MainPU.class).toProvider(MainEntityManagerExposingProvider.class);
-    }
-}
-
-public class MainEntityManagerExposingProvider implements Provider<EntityManager> {
-    private final EntityManagerProvider emProvider;
-
-    @Inject
-    public MainEntityManagerExposingProvider(@MainPU EntityManagerProvider emProvider) {
-        this.emProvider = emProvider;
-    }
-
-    public EntityManager get() {
-        ret emProvider.get();
+        bind(EntityManager.class)
+            .annotatedWith(MainPU.class)
+            .toProvider(Key.get(EntityManagerProvider.class, MainPU.class));
     }
 }
 +--------------------------------------+

Modified: onami/sandbox/persist/src/site/apt/guicePersist.apt.vm
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/site/apt/guicePersist.apt.vm?rev=1593185&r1=1593184&r2=1593185&view=diff
==============================================================================
--- onami/sandbox/persist/src/site/apt/guicePersist.apt.vm (original)
+++ onami/sandbox/persist/src/site/apt/guicePersist.apt.vm Thu May  8 05:53:31 2014
@@ -28,27 +28,27 @@ Onami-Persist vs. Guice-Persist
 
   Onami-Persist is inspired and based upon Guice-Persist. Most of the concepts and ideas have been adapted and/or reused.
 
-  *  UnitOfWork as the life cycle manager for EntityManagers.
+  * UnitOfWork as the life cycle manager for EntityManagers.
 
-  *  PersistFilter for spanning a UnitOfWork around a request.
+  * PersistFilter for spanning a UnitOfWork around a request.
 
-  *  PersistenceService for starting and stopping the entire persistence engine.
+  * PersistenceService for starting and stopping the entire persistence engine.
 
-  *  @Transactional annotation on methods to span a transaction around the method.
+  * @Transactional annotation on methods to span a transaction around the method.
 
   []
 
   The most notable changes to guice-persist:
 
-  *  EntityManager cannot be injected. Instead an EntityManagerProvider has to be injected. ({{{./emProvider.html}details}}).
+  * Integrated support for multiple persistence units, JTA and custom annotation.
 
-  *  @Transactional annotation allows to specify which persistence units are involved in the transaction.
+  * EntityManager cannot be injected. Instead an EntityManagerProvider has to be injected ({{{./emProvider.html}details}}).
 
-  *  UnitOfWork has a new method isActive()
+  * @Transactional annotation allows to specify which persistence units are involved in the transaction.
 
-  *  Retrieving an EntityManager does not start a UnitOfWork. Instead it will throw an Exception if the UnitOfWork is not active.
+  * UnitOfWork has a new method isActive()
 
-  *  PersistenceService can be restarted after it has been stopped.
+  * Retrieving an EntityManager does not start a UnitOfWork. Instead it will throw an Exception if the UnitOfWork is not active.
 
-  *  @Finder annotation is not yet supported
+  * PersistenceService can be restarted after it has been stopped.
 

Modified: onami/sandbox/persist/src/site/apt/index.apt.vm
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/site/apt/index.apt.vm?rev=1593185&r1=1593184&r2=1593185&view=diff
==============================================================================
--- onami/sandbox/persist/src/site/apt/index.apt.vm (original)
+++ onami/sandbox/persist/src/site/apt/index.apt.vm Thu May  8 05:53:31 2014
@@ -53,10 +53,24 @@ Why Onami-Persist
 
   It supports:
 
-  *  multiple persistence units
+  * multiple persistence units
 
-  *  application manged and container managed persistence units
+  * application manged and container managed persistence units
 
-  *  resource local and JTA transactions.
+  * resource local and JTA transactions.
 
+Overview
+
+  {{{./daoExample.html}Here}} you find a sample code of how a DAO or service may look if it uses guice-jpa
+
+  If you have used guice-persist before you may be interested in the
+  {{{./guicePersist.html}differences between guice-jpa and guice-persist.}}
+
+  The most difficult part to get right is the configuration and setup of the persistence unit. Some examples are provided:
+
+  * {{{./standaloneApp.html}Standalone Application Setup}}
+
+  * {{{./simpleWebApp.html}Simple Web Application Setup}}
+
+  * {{{./complexWebApp.html}Multi Datasource Web Application Setup}}
 

Modified: onami/sandbox/persist/src/site/site.xml
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/site/site.xml?rev=1593185&r1=1593184&r2=1593185&view=diff
==============================================================================
--- onami/sandbox/persist/src/site/site.xml (original)
+++ onami/sandbox/persist/src/site/site.xml Thu May  8 05:53:31 2014
@@ -42,6 +42,7 @@
     <menu name="Samples">
       <item name="Standalone Application" href="standaloneApp.html" />
       <item name="Simple Web Application" href="simpleWebApp.html" />
+      <item name="Multi Datasource Web Application" href="complexWebApp.html" />
     </menu>
 
     <menu ref="reports" />