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 18:19:51 UTC

svn commit: r1593319 - in /onami/sandbox/persist/src: main/java/org/apache/onami/persist/ site/apt/ test/java/org/apache/onami/persist/ test/java/org/apache/onami/persist/test/transaction/

Author: sclassen
Date: Thu May  8 16:19:50 2014
New Revision: 1593319

URL: http://svn.apache.org/r1593319
Log:
onami-persist: more comments and minor code cleanups

Added:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java   (with props)
Removed:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfigurator.java
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfiguratorTest.java
Modified:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModule.java
    onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm
    onami/sandbox/persist/src/site/apt/simpleWebApp.apt.vm
    onami/sandbox/persist/src/site/apt/standaloneApp.apt.vm
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/NestedTransactionTest.java
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/SingleTransactionTest.java

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java?rev=1593319&r1=1593318&r2=1593319&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java Thu May  8 16:19:50 2014
@@ -23,10 +23,8 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Key;
 import com.google.inject.Provider;
 import com.google.inject.TypeLiteral;
-import com.google.inject.matcher.Matcher;
 
 import javax.persistence.EntityManagerFactory;
-import java.lang.reflect.AnnotatedElement;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -36,141 +34,177 @@ import static org.apache.onami.persist.P
 
 /**
  * Main module of the onami persist guice extension.
- * <p/>
- * Add persistence unit using the methods
- * <ul>
- * <li>{@link #addApplicationManagedPersistenceUnit(String)}</li>
- * <li>{@link #addContainerManagedPersistenceUnitWithJndiName(String)}</li>
- * <li>{@link #addContainerManagedPersistenceUnit(EntityManagerFactory)}</li>
- * <li>{@link #addContainerManagedPersistenceUnitProvidedBy(Provider<EntityManagerFactory>)}</li>
- * </ul>
  */
 public abstract class PersistenceModule
     extends AbstractModule
 {
 
     /**
-     * List of configurators. Each configurator can be used to build a {@link PersistenceUnitModule}.
+     * List of configurations. Each configurator can be used to build a {@link PersistenceUnitModule}.
      */
-    private List<PersistenceUnitModuleConfigurator> configurators;
-
-    private final Matcher<AnnotatedElement> transactionalMatcher = annotatedWith( Transactional.class );
-
-    private final Matcher<Object> anyMatcher = any();
+    private List<PersistenceUnitModuleConfiguration> configurations;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected final void configure()
     {
-        if ( configurators != null )
+        if ( configurations != null )
         {
             throw new RuntimeException( "cannot reenter the configure method" );
         }
         try
         {
-            configurators = new ArrayList<PersistenceUnitModuleConfigurator>();
-            doConfigure();
+            configurations = new ArrayList<PersistenceUnitModuleConfiguration>();
+            configurePersistenceUnits();
         }
         finally
         {
-            configurators = null;
+            configurations = null;
         }
     }
 
-    private void doConfigure()
+    /**
+     * Configures the persistence units.
+     */
+    private void configurePersistenceUnits()
     {
         configurePersistence();
 
-        final AllPersistenceUnits container = new AllPersistenceUnits();
-        bind( AllPersistenceServices.class ).toInstance( container );
-        bind( AllUnitsOfWork.class ).toInstance( container );
+        final AllPersistenceUnits allPersistenceUnits = new AllPersistenceUnits();
+        bind( AllPersistenceServices.class ).toInstance( allPersistenceUnits );
+        bind( AllUnitsOfWork.class ).toInstance( allPersistenceUnits );
 
-        for ( PersistenceUnitModuleConfigurator config : configurators )
+        for ( PersistenceUnitModuleConfiguration config : configurations )
         {
-            final PersistenceUnitModule pu = config.createPuModule();
             final TxnInterceptor txnInterceptor = new TxnInterceptor();
-            pu.setPersistenceUnitContainer( container );
-            pu.setTransactionInterceptor( txnInterceptor );
 
-            install( pu );
+            install( new PersistenceUnitModule( config, txnInterceptor, allPersistenceUnits ) );
 
-            bindInterceptor( anyMatcher, transactionalMatcher, txnInterceptor );
-            bindInterceptor( transactionalMatcher, anyMatcher, txnInterceptor );
+            bindInterceptor( any(), annotatedWith( Transactional.class ), txnInterceptor );
+            bindInterceptor( annotatedWith( Transactional.class ), any(), txnInterceptor );
         }
     }
 
+    /**
+     * Configures the persistence units over the exposed methods.
+     */
     protected abstract void configurePersistence();
 
-    protected UnannotatedPersistenceUnitBuilder addApplicationManagedPersistenceUnit( String puName )
+    /**
+     * Binds an application managed persistence unit.
+     *
+     * @param puName the name of the persistence unit as defined in the persistence.xml.
+     * @return the next builder step.
+     */
+    protected UnannotatedPersistenceUnitBuilder bindApplicationManagedPersistenceUnit( String puName )
     {
-        checkNotNull( configurators,
-                      "calling addApplicationManagedPersistenceUnit outside of configurePersistence is not supported" );
-        final PersistenceUnitModuleConfigurator configurator = createAndAddConfigurator();
+        checkNotNull( configurations,
+                      "calling bindApplicationManagedPersistenceUnit outside of configurePersistence is not supported" );
+        final PersistenceUnitModuleConfiguration configurator = createAndAddConfiguration();
         configurator.setPuName( puName );
         return configurator;
     }
 
-    protected UnannotatedPersistenceUnitBuilder addContainerManagedPersistenceUnit( EntityManagerFactory emf )
+    /**
+     * Binds a container managed persistence unit for a given entity manager factory.
+     *
+     * @param emf the entity manager factory to use when creating new entity managers.
+     * @return the next builder step.
+     */
+    protected UnannotatedPersistenceUnitBuilder bindContainerManagedPersistenceUnit( EntityManagerFactory emf )
     {
-        checkNotNull( configurators,
-                      "calling addContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
-        final PersistenceUnitModuleConfigurator configurator = createAndAddConfigurator();
+        checkNotNull( configurations,
+                      "calling bindContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
+        final PersistenceUnitModuleConfiguration configurator = createAndAddConfiguration();
         configurator.setEmf( emf );
         return configurator;
     }
 
-    protected UnannotatedPersistenceUnitBuilder addContainerManagedPersistenceUnitWithJndiName( String jndiName )
+    /**
+     * Binds a container managed persistence unit. The entity manager factory will be retrieved from the JNDI context.
+     *
+     * @param jndiName the JNDI name of the entity manager factory.
+     * @return the next builder step.
+     */
+    protected UnannotatedPersistenceUnitBuilder bindContainerManagedPersistenceUnitWithJndiName( String jndiName )
     {
-        checkNotNull( configurators,
-                      "calling addContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
-        final PersistenceUnitModuleConfigurator configurator = createAndAddConfigurator();
+        checkNotNull( configurations,
+                      "calling bindContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
+        final PersistenceUnitModuleConfiguration configurator = createAndAddConfiguration();
         configurator.setEmfJndiName( jndiName );
         return configurator;
     }
 
-    protected UnannotatedPersistenceUnitBuilder addContainerManagedPersistenceUnitProvidedBy(
+    /**
+     * Binds a container managed persistence unit. The entity manager factory will be retrieved from the given provider.
+     *
+     * @param emfProvider the provider for the entity manager factory.
+     * @return the next builder step.
+     */
+    protected UnannotatedPersistenceUnitBuilder bindContainerManagedPersistenceUnitProvidedBy(
         Provider<EntityManagerFactory> emfProvider )
     {
-        checkNotNull( configurators,
-                      "calling addContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
-        final PersistenceUnitModuleConfigurator configurator = createAndAddConfigurator();
+        checkNotNull( configurations,
+                      "calling bindContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
+        final PersistenceUnitModuleConfiguration configurator = createAndAddConfiguration();
         configurator.setEmfProvider( emfProvider );
         return configurator;
     }
 
-    protected UnannotatedPersistenceUnitBuilder addContainerManagedPersistenceUnitProvidedBy(
+    /**
+     * Binds a container managed persistence unit. The entity manager factory will be retrieved from the given provider.
+     *
+     * @param emfProviderClass the provider for the entity manager factory.
+     * @return the next builder step.
+     */
+    protected UnannotatedPersistenceUnitBuilder bindContainerManagedPersistenceUnitProvidedBy(
         Class<? extends Provider<EntityManagerFactory>> emfProviderClass )
     {
-        checkNotNull( configurators,
-                      "calling addContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
-        final PersistenceUnitModuleConfigurator configurator = createAndAddConfigurator();
+        checkNotNull( configurations,
+                      "calling bindContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
+        final PersistenceUnitModuleConfiguration configurator = createAndAddConfiguration();
         configurator.setEmfProviderClass( emfProviderClass );
         return configurator;
     }
 
-    protected UnannotatedPersistenceUnitBuilder addContainerManagedPersistenceUnitProvidedBy(
+    /**
+     * Binds a container managed persistence unit. The entity manager factory will be retrieved from the given provider.
+     *
+     * @param emfProviderType the provider for the entity manager factory.
+     * @return the next builder step.
+     */
+    protected UnannotatedPersistenceUnitBuilder bindContainerManagedPersistenceUnitProvidedBy(
         TypeLiteral<? extends Provider<EntityManagerFactory>> emfProviderType )
     {
-        checkNotNull( configurators,
-                      "calling addContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
-        final PersistenceUnitModuleConfigurator configurator = createAndAddConfigurator();
+        checkNotNull( configurations,
+                      "calling bindContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
+        final PersistenceUnitModuleConfiguration configurator = createAndAddConfiguration();
         configurator.setEmfProviderType( emfProviderType );
         return configurator;
     }
 
-    protected UnannotatedPersistenceUnitBuilder addContainerManagedPersistenceUnitProvidedBy(
+    /**
+     * Binds a container managed persistence unit. The entity manager factory will be retrieved from the given provider.
+     *
+     * @param emfProviderKey the provider for the entity manager factory.
+     * @return the next builder step.
+     */
+    protected UnannotatedPersistenceUnitBuilder bindContainerManagedPersistenceUnitProvidedBy(
         Key<? extends Provider<EntityManagerFactory>> emfProviderKey )
     {
-        checkNotNull( configurators,
-                      "calling addContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
-        final PersistenceUnitModuleConfigurator configurator = createAndAddConfigurator();
-        configurator.setEmfProviderKey( emfProviderKey );
-        return configurator;
+        checkNotNull( configurations,
+                      "calling bindContainerManagedPersistenceUnit outside of configurePersistence is not supported" );
+        final PersistenceUnitModuleConfiguration configuration = createAndAddConfiguration();
+        configuration.setEmfProviderKey( emfProviderKey );
+        return configuration;
     }
 
-    private PersistenceUnitModuleConfigurator createAndAddConfigurator()
+    private PersistenceUnitModuleConfiguration createAndAddConfiguration()
     {
-        final PersistenceUnitModuleConfigurator configurator = new PersistenceUnitModuleConfigurator();
-        configurators.add( configurator );
+        final PersistenceUnitModuleConfiguration configurator = new PersistenceUnitModuleConfiguration();
+        configurations.add( configurator );
         return configurator;
     }
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModule.java?rev=1593319&r1=1593318&r2=1593319&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModule.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModule.java Thu May  8 16:19:50 2014
@@ -41,46 +41,31 @@ class PersistenceUnitModule
     /**
      * The configuration for the persistence unit.
      */
-    private final PersistenceUnitModuleConfigurator config;
+    private final PersistenceUnitModuleConfiguration config;
 
     /**
-     * Transaction interceptor which can be passed in from the outside for injecting dependencies
+     * Transaction interceptor for this persistence unit.
      */
-    private TxnInterceptor transactionInterceptor;
+    private final TxnInterceptor transactionInterceptor;
 
     /**
-     * Persistence unit container which can be passed in from the outside for adding this persistence unit to it.
+     * Container for adding this persistence unit.
      */
-    private AllPersistenceUnits container;
+    private final AllPersistenceUnits allPersistenceUnits;
 
     /**
      * Constructor.
      *
-     * @param configurator the configuration holding all configs.
+     * @param configurator           the configuration holding all configs.
+     * @param transactionInterceptor interceptor for the transactional annotation.
+     * @param allPersistenceUnits    container holding all persistence units.
      */
-    PersistenceUnitModule( PersistenceUnitModuleConfigurator configurator )
+    PersistenceUnitModule( PersistenceUnitModuleConfiguration configurator, TxnInterceptor transactionInterceptor,
+                           AllPersistenceUnits allPersistenceUnits )
     {
         this.config = checkNotNull( configurator, "config is mandatory!" );
-    }
-
-    /**
-     * Sets the transaction interceptor for injection of dependencies.
-     *
-     * @param transactionInterceptor the interceptor into which to inject dependencies.
-     */
-    void setTransactionInterceptor( TxnInterceptor transactionInterceptor )
-    {
-        this.transactionInterceptor = transactionInterceptor;
-    }
-
-    /**
-     * Sets the persistence unit container for adding this persistence unit to it.
-     *
-     * @param container the container to which to add the persistence unit.
-     */
-    void setPersistenceUnitContainer( AllPersistenceUnits container )
-    {
-        this.container = container;
+        this.transactionInterceptor = checkNotNull( transactionInterceptor, "transactionInterceptor is mandatory!" );
+        this.allPersistenceUnits = checkNotNull( allPersistenceUnits, "allPersistenceUnits is mandatory!" );
     }
 
     /**
@@ -105,10 +90,10 @@ class PersistenceUnitModule
             requestInjection( transactionInterceptor );
         }
 
-        // request injection into persistence unit container - this adds the current persistence unit to the container.
-        if ( container != null )
+        // request injection into allPersistenceUnits - this adds the current persistence unit to the allPersistenceUnits.
+        if ( allPersistenceUnits != null )
         {
-            requestInjection( container );
+            requestInjection( allPersistenceUnits );
         }
     }
 

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java?rev=1593319&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java Thu May  8 16:19:50 2014
@@ -0,0 +1,297 @@
+package org.apache.onami.persist;
+
+/*
+ * 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.
+ */
+
+import com.google.inject.Key;
+import com.google.inject.Provider;
+import com.google.inject.TypeLiteral;
+
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.UserTransaction;
+import java.lang.annotation.Annotation;
+import java.util.Properties;
+
+/**
+ * Class holding the configuration for a single persistence unit.
+ */
+class PersistenceUnitModuleConfiguration
+    implements UnannotatedPersistenceUnitBuilder, AnnotatedPersistenceUnitBuilder, UnconfiguredPersistenceUnitBuilder
+{
+    private Class<? extends Annotation> annotation;
+
+    private boolean isJta = false;
+
+    private UserTransaction userTransaction;
+
+    private String utJndiName;
+
+    private Provider<UserTransaction> utProvider;
+
+    private Key<? extends Provider<UserTransaction>> utProviderKey;
+
+    private Properties properties;
+
+    private String puName;
+
+    private EntityManagerFactory emf;
+
+    private String emfJndiName;
+
+    private Provider<EntityManagerFactory> emfProvider;
+
+    private Key<? extends Provider<EntityManagerFactory>> emfProviderKey;
+
+    /**
+     * {@inheritDoc}
+     */
+    public AnnotatedPersistenceUnitBuilder annotatedWith( Class<? extends Annotation> annotation )
+    {
+        this.annotation = annotation;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UnconfiguredPersistenceUnitBuilder useLocalTransaction()
+    {
+        isJta = false;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UnconfiguredPersistenceUnitBuilder useGlobalTransaction( UserTransaction userTransaction )
+    {
+        this.isJta = true;
+        this.userTransaction = userTransaction;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UnconfiguredPersistenceUnitBuilder useGlobalTransactionWithJndiName( String utJndiName )
+    {
+        this.isJta = true;
+        this.utJndiName = utJndiName;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy( Provider<UserTransaction> utProvider )
+    {
+        this.isJta = true;
+        this.utProvider = utProvider;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy(
+        Class<? extends Provider<UserTransaction>> utProviderClass )
+    {
+        return useGlobalTransactionProvidedBy( Key.get( utProviderClass ) );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy(
+        TypeLiteral<? extends Provider<UserTransaction>> utProviderType )
+    {
+        return useGlobalTransactionProvidedBy( Key.get( utProviderType ) );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy(
+        Key<? extends Provider<UserTransaction>> utProviderKey )
+    {
+        this.isJta = true;
+        this.utProviderKey = utProviderKey;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setProperties( Properties properties )
+    {
+        this.properties = properties;
+    }
+
+    void setPuName( String puName )
+    {
+        this.puName = puName;
+    }
+
+    void setEmf( EntityManagerFactory emf )
+    {
+        this.emf = emf;
+    }
+
+    void setEmfJndiName( String emfJndiName )
+    {
+        this.emfJndiName = emfJndiName;
+    }
+
+    void setEmfProvider( Provider<EntityManagerFactory> emfProvider )
+    {
+        this.emfProvider = emfProvider;
+    }
+
+    void setEmfProviderClass( Class<? extends Provider<EntityManagerFactory>> emfProviderClass )
+    {
+        this.emfProviderKey = Key.get( emfProviderClass );
+    }
+
+    void setEmfProviderType( TypeLiteral<? extends Provider<EntityManagerFactory>> emfProviderType )
+    {
+        this.emfProviderKey = Key.get( emfProviderType );
+    }
+
+    void setEmfProviderKey( Key<? extends Provider<EntityManagerFactory>> emfProviderKey )
+    {
+        this.emfProviderKey = emfProviderKey;
+    }
+
+    boolean isApplicationManagedPersistenceUnit()
+    {
+        return puName != null;
+    }
+
+
+    UserTransaction getUserTransaction()
+    {
+        return userTransaction;
+    }
+
+    String getUtJndiName()
+    {
+        return utJndiName;
+    }
+
+    Provider<UserTransaction> getUtProvider()
+    {
+        return utProvider;
+    }
+
+    Key<? extends Provider<UserTransaction>> getUtProviderKey()
+    {
+        return utProviderKey;
+    }
+
+    Properties getProperties()
+    {
+        return properties;
+    }
+
+    String getPuName()
+    {
+        return puName;
+    }
+
+    EntityManagerFactory getEmf()
+    {
+        return emf;
+    }
+
+    String getEmfJndiName()
+    {
+        return emfJndiName;
+    }
+
+    Provider<EntityManagerFactory> getEmfProvider()
+    {
+        return emfProvider;
+    }
+
+    Key<? extends Provider<EntityManagerFactory>> getEmfProviderKey()
+    {
+        return emfProviderKey;
+    }
+
+    boolean isEmfProvidedByJndiLookup()
+    {
+        return emfJndiName != null;
+    }
+
+    boolean isEmfProvidedByInstance()
+    {
+        return emf != null;
+    }
+
+    boolean isEmfProvidedByProvider()
+    {
+        return emfProvider != null;
+    }
+
+    boolean isEmfProvidedByProviderKey()
+    {
+        return emfProviderKey != null;
+    }
+
+    boolean isJta()
+    {
+        return isJta;
+    }
+
+    boolean isUserTransactionProvidedByJndiLookup()
+    {
+        return utJndiName != null;
+    }
+
+
+    boolean isUserTransactionProvidedByInstance()
+    {
+        return userTransaction != null;
+    }
+
+    boolean isUserTransactionProvidedByProvider()
+    {
+        return utProvider != null;
+    }
+
+    boolean isUserTransactionProvidedByProviderKey()
+    {
+        return utProviderKey != null;
+    }
+
+    boolean isAnnotated()
+    {
+        return annotation != null;
+    }
+
+    AnnotationHolder getAnnotationHolder()
+    {
+        return new AnnotationHolder( annotation );
+    }
+
+    Class<? extends Annotation> getAnnotation()
+    {
+        return annotation;
+    }
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 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=1593319&r1=1593318&r2=1593319&view=diff
==============================================================================
--- onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm (original)
+++ onami/sandbox/persist/src/site/apt/complexWebApp.apt.vm Thu May  8 16:19:50 2014
@@ -34,15 +34,15 @@ public class BootstrapServletListener ex
         final PersistenceModule persistenceModule = new PersistenceModule() {
             @Override
             protected void configurePersistence() {
-                addContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/mainPuJndiName")
+                bindContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/mainPuJndiName")
                     .annotatedWith(MainPU.class)
                     .useGlobalTransactionWithJndiName("java:comp/env/UserTransaction");
 
-                addContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/alternativePUJndiName")
+                bindContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/alternativePUJndiName")
                     .annotatedWith(AlternativePU.class)
                     .useGlobalTransactionWithJndiName("java:comp/env/UserTransaction");
 
-                addContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/systemPuJndiName")
+                bindContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/systemPuJndiName")
                     .annotatedWith(SystemPU.class)
                     .useLocalTransaction();
             }

Modified: onami/sandbox/persist/src/site/apt/simpleWebApp.apt.vm
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/site/apt/simpleWebApp.apt.vm?rev=1593319&r1=1593318&r2=1593319&view=diff
==============================================================================
--- onami/sandbox/persist/src/site/apt/simpleWebApp.apt.vm (original)
+++ onami/sandbox/persist/src/site/apt/simpleWebApp.apt.vm Thu May  8 16:19:50 2014
@@ -34,7 +34,7 @@ public class BootstrapServletListener ex
         final PersistenceModule persistenceModule = new PersistenceModule() {
             @Override
             protected void configurePersistence() {
-                addContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/puJndiName");
+                bindContainerManagedPersistenceUnitWithJndiName("java:comp/env/foobar/puJndiName");
             }
         };
 

Modified: onami/sandbox/persist/src/site/apt/standaloneApp.apt.vm
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/site/apt/standaloneApp.apt.vm?rev=1593319&r1=1593318&r2=1593319&view=diff
==============================================================================
--- onami/sandbox/persist/src/site/apt/standaloneApp.apt.vm (original)
+++ onami/sandbox/persist/src/site/apt/standaloneApp.apt.vm Thu May  8 16:19:50 2014
@@ -33,7 +33,7 @@ public static void main(String[] args) {
     final PersistenceModule persistenceModule = new PersistenceModule() {
         @Override
         protected void configurePersistence() {
-            addApplicationManagedPersistenceUnit( "puName" );
+            bindApplicationManagedPersistenceUnit( "puName" );
         }
     };
     final Injector injector = Guice.createInjector(persistenceModule, getApplicationSpecificModules());

Added: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java?rev=1593319&view=auto
==============================================================================
--- onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java (added)
+++ onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java Thu May  8 16:19:50 2014
@@ -0,0 +1,285 @@
+package org.apache.onami.persist;
+
+/*
+ * 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.
+ */
+
+import com.google.inject.Key;
+import com.google.inject.Provider;
+import com.google.inject.TypeLiteral;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.UserTransaction;
+import java.lang.annotation.Annotation;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Test for {@link PersistenceUnitModuleConfiguration}.
+ */
+public class PersistenceUnitModuleConfigurationTest
+{
+    private PersistenceUnitModuleConfiguration sut;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        sut = new PersistenceUnitModuleConfiguration();
+    }
+
+    @Test
+    public void shouldHandleAnnotation()
+    {
+        // given
+        Class<? extends Annotation> annotation = Annotation.class;
+        // when
+        sut.annotatedWith( annotation );
+        // then
+        assertThat( sut.getAnnotation(), sameInstance( (Class) annotation ) );
+    }
+
+    @Test
+    public void shouldHandleResourceLocale()
+    {
+        // when
+        sut.useLocalTransaction();
+        // then
+        assertThat( sut.isJta(), is( false ) );
+    }
+
+    @Test
+    public void shouldHandleUserTransaction()
+    {
+        // given
+        final UserTransaction userTransaction = mock( UserTransaction.class );
+        // when
+        sut.useGlobalTransaction( userTransaction );
+        // then
+        assertThat( sut.isJta(), is( true ) );
+        assertThat( sut.getUserTransaction(), sameInstance( userTransaction ) );
+    }
+
+    @Test
+    public void shouldHandleUserTransactionInJndi()
+    {
+        // given
+        final String utJndiName = "ut";
+        // when
+        sut.useGlobalTransactionWithJndiName( utJndiName );
+        // then
+        assertThat( sut.isJta(), is( true ) );
+        assertThat( sut.getUtJndiName(), is( utJndiName ) );
+    }
+
+    @Test
+    @SuppressWarnings( "unchecked" )
+    public void shouldHandleUserTransactionProvider()
+    {
+        // given
+        final Provider<UserTransaction> utProvider = new MockUserTransactionProvider();
+        // when
+        sut.useGlobalTransactionProvidedBy( utProvider );
+        // then
+        assertThat( sut.isJta(), is( true ) );
+        assertThat( sut.getUtProvider(), sameInstance( utProvider ) );
+    }
+
+    @Test
+    public void shouldHandleUserTransactionProviderClass()
+    {
+        // given
+        final Class<? extends Provider<UserTransaction>> utProviderClass = MockUserTransactionProvider.class;
+        // when
+        sut.useGlobalTransactionProvidedBy( utProviderClass );
+        // then
+        assertThat( sut.isJta(), is( true ) );
+        assertThat( (Key) sut.getUtProviderKey(), is( (Key) Key.get( utProviderClass ) ) );
+    }
+
+    @Test
+    public void shouldHandleUserTransactionProviderType()
+    {
+        // given
+        final TypeLiteral<? extends Provider<UserTransaction>> utProviderType =
+            TypeLiteral.get( MockUserTransactionProvider.class );
+        // when
+        sut.useGlobalTransactionProvidedBy( utProviderType );
+        // then
+        assertThat( sut.isJta(), is( true ) );
+        assertThat( (Key) sut.getUtProviderKey(), is( (Key) Key.get( utProviderType ) ) );
+    }
+
+    @Test
+    public void shouldHandleUserTransactionProviderKey()
+    {
+        // given
+        final Key<? extends Provider<UserTransaction>> utProviderKey = Key.get( MockUserTransactionProvider.class );
+        // when
+        sut.useGlobalTransactionProvidedBy( utProviderKey );
+        // then
+        assertThat( sut.isJta(), is( true ) );
+        assertThat( (Key) sut.getUtProviderKey(), is( (Key) utProviderKey ) );
+    }
+
+    @Test
+    public void shouldHandleProperties()
+    {
+        // given
+        Properties properties = mock( Properties.class );
+        // when
+        sut.setProperties( properties );
+        // then
+        assertThat( sut.getProperties(), sameInstance( properties ) );
+    }
+
+    @Test
+    public void shouldHandlePuName()
+    {
+        // given
+        final String puName = "puName";
+        // when
+        sut.setPuName( puName );
+        // then
+        assertThat( sut.isApplicationManagedPersistenceUnit(), is( true ) );
+        assertThat( sut.getPuName(), sameInstance( puName ) );
+    }
+
+    @Test
+    public void shouldHandleEmf()
+    {
+        // given
+        final EntityManagerFactory emf = mock( EntityManagerFactory.class );
+        // when
+        sut.setEmf( emf );
+        // then
+        assertThat( sut.isApplicationManagedPersistenceUnit(), is( false ) );
+        assertThat( sut.getEmf(), sameInstance( emf ) );
+        assertThat( sut.isEmfProvidedByInstance(), is( true ) );
+        assertThat( sut.isEmfProvidedByJndiLookup(), is( false ) );
+        assertThat( sut.isEmfProvidedByProvider(), is( false ) );
+        assertThat( sut.isEmfProvidedByProviderKey(), is( false ) );
+    }
+
+    @Test
+    public void shouldHandleEmfJndiName()
+    {
+        // given
+        final String emfJndiName = "emfJndiName";
+        // when
+        sut.setEmfJndiName( emfJndiName );
+        // then
+        assertThat( sut.isApplicationManagedPersistenceUnit(), is( false ) );
+        assertThat( sut.getEmfJndiName(), is( emfJndiName ) );
+        assertThat( sut.isEmfProvidedByInstance(), is( false ) );
+        assertThat( sut.isEmfProvidedByJndiLookup(), is( true ) );
+        assertThat( sut.isEmfProvidedByProvider(), is( false ) );
+        assertThat( sut.isEmfProvidedByProviderKey(), is( false ) );
+    }
+
+    @Test
+    public void shouldHandleEmfProvider()
+    {
+        // given
+        final Provider<EntityManagerFactory> emfProvider = new MockEmfProvider();
+        // when
+        sut.setEmfProvider( emfProvider );
+        // then
+        assertThat( sut.isApplicationManagedPersistenceUnit(), is( false ) );
+        assertThat( sut.getEmfProvider(), sameInstance( emfProvider ) );
+        assertThat( sut.isEmfProvidedByInstance(), is( false ) );
+        assertThat( sut.isEmfProvidedByJndiLookup(), is( false ) );
+        assertThat( sut.isEmfProvidedByProvider(), is( true ) );
+        assertThat( sut.isEmfProvidedByProviderKey(), is( false ) );
+    }
+
+    @Test
+    public void shouldHandleEmfProviderClass()
+    {
+        // given
+        final Class<? extends Provider<EntityManagerFactory>> emfProviderClass = MockEmfProvider.class;
+        // when
+        sut.setEmfProviderClass( emfProviderClass );
+        // then
+        assertThat( sut.isApplicationManagedPersistenceUnit(), is( false ) );
+        assertThat( (Key) sut.getEmfProviderKey(), is( (Key) Key.get( emfProviderClass ) ) );
+        assertThat( sut.isEmfProvidedByInstance(), is( false ) );
+        assertThat( sut.isEmfProvidedByJndiLookup(), is( false ) );
+        assertThat( sut.isEmfProvidedByProvider(), is( false ) );
+        assertThat( sut.isEmfProvidedByProviderKey(), is( true ) );
+    }
+
+    @Test
+    public void shouldHandleEmfProviderType()
+    {
+        // given
+        final TypeLiteral<? extends Provider<EntityManagerFactory>> emfProviderType =
+            TypeLiteral.get( MockEmfProvider.class );
+        // when
+        sut.setEmfProviderType( emfProviderType );
+        // then
+        assertThat( sut.isApplicationManagedPersistenceUnit(), is( false ) );
+        assertThat( (Key) sut.getEmfProviderKey(), is( (Key) Key.get( emfProviderType ) ) );
+        assertThat( sut.isEmfProvidedByInstance(), is( false ) );
+        assertThat( sut.isEmfProvidedByJndiLookup(), is( false ) );
+        assertThat( sut.isEmfProvidedByProvider(), is( false ) );
+        assertThat( sut.isEmfProvidedByProviderKey(), is( true ) );
+    }
+
+    @Test
+    public void shouldHandleEmfProviderKey()
+    {
+        // given
+        final Key<? extends Provider<EntityManagerFactory>> emfProviderKey = Key.get( MockEmfProvider.class );
+        // when
+        sut.setEmfProviderKey( emfProviderKey );
+        // then
+        assertThat( sut.isApplicationManagedPersistenceUnit(), is( false ) );
+        assertThat( (Key) sut.getEmfProviderKey(), is( (Key) emfProviderKey ) );
+        assertThat( sut.isEmfProvidedByInstance(), is( false ) );
+        assertThat( sut.isEmfProvidedByJndiLookup(), is( false ) );
+        assertThat( sut.isEmfProvidedByProvider(), is( false ) );
+        assertThat( sut.isEmfProvidedByProviderKey(), is( true ) );
+    }
+
+    // helpers
+
+    private static class MockUserTransactionProvider
+        implements Provider<UserTransaction>
+    {
+        public UserTransaction get()
+        {
+            return mock( UserTransaction.class );
+        }
+    }
+
+    private static class MockEmfProvider
+        implements Provider<EntityManagerFactory>
+    {
+        public EntityManagerFactory get()
+        {
+            return mock( EntityManagerFactory.class );
+        }
+    }
+
+}

Propchange: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitModuleConfigurationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/NestedTransactionTest.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/NestedTransactionTest.java?rev=1593319&r1=1593318&r2=1593319&view=diff
==============================================================================
--- onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/NestedTransactionTest.java (original)
+++ onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/NestedTransactionTest.java Thu May  8 16:19:50 2014
@@ -408,7 +408,7 @@ public class NestedTransactionTest
             @Override
             protected void configurePersistence()
             {
-                addApplicationManagedPersistenceUnit( "testUnit" );
+                bindApplicationManagedPersistenceUnit( "testUnit" );
             }
         };
     }

Modified: onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/SingleTransactionTest.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/SingleTransactionTest.java?rev=1593319&r1=1593318&r2=1593319&view=diff
==============================================================================
--- onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/SingleTransactionTest.java (original)
+++ onami/sandbox/persist/src/test/java/org/apache/onami/persist/test/transaction/SingleTransactionTest.java Thu May  8 16:19:50 2014
@@ -70,7 +70,7 @@ public class SingleTransactionTest
             @Override
             protected void configurePersistence()
             {
-                addApplicationManagedPersistenceUnit( "testUnit" );
+                bindApplicationManagedPersistenceUnit( "testUnit" );
             }
         };
     }