onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sclas...@apache.org
Subject svn commit: r1592452 - in /onami/sandbox/persist/src: main/java/org/apache/onami/persist/ test/java/org/apache/onami/persist/
Date Mon, 05 May 2014 05:41:24 GMT
Author: sclassen
Date: Mon May  5 05:41:23 2014
New Revision: 1592452

URL: http://svn.apache.org/r1592452
Log:
onami-persist: code cleanup

Added:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/AllPersistenceUnitsTest.java   (with props)
Removed:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceAnnotation.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitContainer.java
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceUnitContainerTest.java
Modified:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AggregatedException.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceServices.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllUnitsOfWork.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotatedPersistenceUnitBuilder.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotationHolder.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryFactory.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySource.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceByJndiLookup.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceViaProvider.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceService.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitModule.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ResourceLocalTransactionFacadeFactory.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionFacade.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationHelper.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationReader.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/TxnInterceptor.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnannotatedPersistenceUnitBuilder.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnconfiguredPersistenceUnitBuilder.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnitOfWork.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionFacade.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionProviderByJndiLookup.java
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterTest.java

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AggregatedException.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AggregatedException.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AggregatedException.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AggregatedException.java Mon May  5 05:41:23 2014
@@ -34,23 +34,24 @@ class AggregatedException
     extends RuntimeException
 {
 
-    private static final Throwable[] EMPTY = new Throwable[0];
-
     private static final long serialVersionUID = 1L;
 
+
     /**
      * Builder for AggregatedException
      */
     static class Builder
     {
 
+        private static final Throwable[] EMPTY = new Throwable[0];
+
         /**
-         * list of causes for the aggregated exception
+         * list of causes for the aggregated exception.
          */
         private List<Throwable> causes = new ArrayList<Throwable>();
 
         /**
-         * Add an exception to the list of aggregated exceptions
+         * Adds an exception to the list of aggregated exceptions.
          *
          * @param cause the exception to add
          */
@@ -62,7 +63,7 @@ class AggregatedException
         /**
          * Throws a runtime exception if the builder has causes.
          *
-         * @param msg the message to of the aggregated exception.
+         * @param msg the message of the aggregated exception.
          */
         void throwRuntimeExceptionIfHasCauses( String msg )
         {
@@ -82,10 +83,10 @@ class AggregatedException
         /**
          * Converts the collected causes into a runtime exception
          *
-         * @param msg the message to of the aggregated exception.
+         * @param msg the message of the aggregated exception.
          * @return the exception to throw
          */
-        RuntimeException getRuntimeException( String msg )
+        private RuntimeException getRuntimeException( String msg )
         {
             if ( causes.size() == 1 )
             {
@@ -110,11 +111,16 @@ class AggregatedException
     private final int numCauses;
 
     /**
-     * @return the number of causes collected into this exception
+     * Constructor.
+     *
+     * @param message the message
+     * @param causes  all the causes
      */
-    public int getNumCauses()
+    private AggregatedException( String message, Throwable[] causes )
     {
-        return numCauses;
+        super( message );
+        this.causes = causes;
+        this.numCauses = this.causes.length;
     }
 
     /**
@@ -126,16 +132,11 @@ class AggregatedException
     }
 
     /**
-     * Constructor.
-     *
-     * @param message the message
-     * @param causes  all the causes
+     * @return the number of causes collected into this exception
      */
-    private AggregatedException( String message, Throwable[] causes )
+    public int getNumCauses()
     {
-        super( message );
-        this.causes = causes;
-        this.numCauses = this.causes.length;
+        return numCauses;
     }
 
     /**
@@ -157,14 +158,7 @@ class AggregatedException
             for ( int i = 0; i < numCauses; i++ )
             {
                 s.println( "Cause " + ( i + 1 ) + ":" );
-                if ( causes[i] == null )
-                {
-                    s.println( "<null>" );
-                }
-                else
-                {
-                    causes[i].printStackTrace( s );
-                }
+                causes[i].printStackTrace( s );
             }
         }
     }
@@ -188,14 +182,7 @@ class AggregatedException
             for ( int i = 0; i < numCauses; i++ )
             {
                 s.println( "Cause " + ( i + 1 ) + ":" );
-                if ( causes[i] == null )
-                {
-                    s.println( "<null>" );
-                }
-                else
-                {
-                    causes[i].printStackTrace( s );
-                }
+                causes[i].printStackTrace( s );
             }
         }
     }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceServices.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceServices.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceServices.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceServices.java Mon May  5 05:41:23 2014
@@ -26,12 +26,12 @@ public interface AllPersistenceServices
 {
 
     /**
-     * Calls {@link PersistenceService#start()} on all stopped persistence services.
+     * Calls {@link PersistenceService#start()} on all persistence services which are not running.
      */
     void startAllStoppedPersistenceServices();
 
     /**
      * Calls {@link PersistenceService#stop()} on all persistence services.
      */
-    void stopAllRunningPersistenceServices();
+    void stopAllPersistenceServices();
 }

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java?rev=1592452&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java Mon May  5 05:41:23 2014
@@ -0,0 +1,157 @@
+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.Inject;
+import com.google.inject.Singleton;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * All persistence units. This is a convenience wrapper for multiple persistence units.
+ */
+@Singleton
+class AllPersistenceUnits
+    implements AllPersistenceServices, AllUnitsOfWork
+{
+
+    /**
+     * Collection of all known persistence services.
+     */
+    private final Set<PersistenceService> persistenceServices = new HashSet<PersistenceService>();
+
+    /**
+     * Collection of all known units of work.
+     */
+    private final Set<UnitOfWork> unitsOfWork = new HashSet<UnitOfWork>();
+
+    /**
+     * Adds a persistence service and a unit of work to this collection.
+     *
+     * @param ps  the persistence service to add. Must not be {@code null}.
+     * @param uow the unit of work to add. Must not be {@code null}.
+     */
+    @Inject
+    void add( PersistenceService ps, UnitOfWork uow )
+    {
+        checkNotNull( ps );
+        checkNotNull( uow );
+        persistenceServices.add( ps );
+        unitsOfWork.add( uow );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void startAllStoppedPersistenceServices()
+    {
+        AggregatedException.Builder exceptionBuilder = new AggregatedException.Builder();
+        for ( PersistenceService ps : persistenceServices )
+        {
+            try
+            {
+                if ( !ps.isRunning() )
+                {
+                    ps.start();
+                }
+            }
+            catch ( Exception e )
+            {
+                exceptionBuilder.add( e );
+            }
+        }
+        exceptionBuilder.throwRuntimeExceptionIfHasCauses(
+            "multiple exception occurred while starting the persistence service" );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void stopAllPersistenceServices()
+    {
+        AggregatedException.Builder exceptionBuilder = new AggregatedException.Builder();
+        for ( PersistenceService ps : persistenceServices )
+        {
+            try
+            {
+                ps.stop();
+            }
+            catch ( Exception e )
+            {
+                exceptionBuilder.add( e );
+            }
+        }
+        exceptionBuilder.throwRuntimeExceptionIfHasCauses(
+            "multiple exception occurred while stopping the persistence service" );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void beginAllInactiveUnitsOfWork()
+    {
+        AggregatedException.Builder exceptionBuilder = new AggregatedException.Builder();
+        for ( UnitOfWork unitOfWork : unitsOfWork )
+        {
+            try
+            {
+                if ( !unitOfWork.isActive() )
+                {
+                    unitOfWork.begin();
+                }
+            }
+            catch ( Exception e )
+            {
+                exceptionBuilder.add( e );
+            }
+        }
+        exceptionBuilder.throwRuntimeExceptionIfHasCauses(
+            "multiple exception occurred while starting the unit of work" );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void endAllUnitsOfWork()
+    {
+        AggregatedException.Builder exceptionBuilder = new AggregatedException.Builder();
+        for ( UnitOfWork unitOfWork : unitsOfWork )
+        {
+            try
+            {
+                unitOfWork.end();
+            }
+            catch ( Exception e )
+            {
+                exceptionBuilder.add( e );
+            }
+        }
+        exceptionBuilder.throwRuntimeExceptionIfHasCauses(
+            "multiple exception occurred while ending the unit of work" );
+    }
+
+}

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

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

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

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllUnitsOfWork.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllUnitsOfWork.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllUnitsOfWork.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllUnitsOfWork.java Mon May  5 05:41:23 2014
@@ -26,12 +26,12 @@ public interface AllUnitsOfWork
 {
 
     /**
-     * Calls {@link UnitOfWork#begin()} on all units of work which are not active
+     * Calls {@link UnitOfWork#begin()} on all units of work which are not active.
      */
     void beginAllInactiveUnitsOfWork();
 
     /**
-     * Calls {@link UnitOfWork#end()} on all units of work
+     * Calls {@link UnitOfWork#end()} on all units of work.
      */
     void endAllUnitsOfWork();
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotatedPersistenceUnitBuilder.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotatedPersistenceUnitBuilder.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotatedPersistenceUnitBuilder.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotatedPersistenceUnitBuilder.java Mon May  5 05:41:23 2014
@@ -25,23 +25,69 @@ import com.google.inject.TypeLiteral;
 
 import javax.transaction.UserTransaction;
 
+/**
+ * 3rd step of the persistence unit builder process.
+ * Define the transaction type.
+ */
 public interface AnnotatedPersistenceUnitBuilder
     extends UnconfiguredPersistenceUnitBuilder
 {
+
+    /**
+     * Mark the persistence unit to use resource local transactions.
+     *
+     * @return the next builder step.
+     */
     UnconfiguredPersistenceUnitBuilder useLocalTransaction();
 
+    /**
+     * Mark the persistence unit to use JTA transactions.
+     *
+     * @param userTransaction the instance of the UserTransaction object to use.
+     * @return the next builder step.
+     */
     UnconfiguredPersistenceUnitBuilder useGlobalTransaction( UserTransaction userTransaction );
 
+    /**
+     * Mark the persistence unit to use JTA transactions.
+     *
+     * @param utJndiName the JNDI name to use for looking up the user transaction instance.
+     * @return the next builder step.
+     */
     UnconfiguredPersistenceUnitBuilder useGlobalTransactionWithJndiName( String utJndiName );
 
+    /**
+     * Mark the persistence unit to use JTA transactions.
+     *
+     * @param utProvider a provider to retrieve the user transaction instance.
+     * @return the next builder step.
+     */
     UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy( Provider<UserTransaction> utProvider );
 
+    /**
+     * Mark the persistence unit to use JTA transactions.
+     *
+     * @param utProviderClass a provider to retrieve the user transaction instance.
+     * @return the next builder step.
+     */
     UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy(
         Class<? extends Provider<UserTransaction>> utProviderClass );
 
+    /**
+     * Mark the persistence unit to use JTA transactions.
+     *
+     * @param utProviderType a provider to retrieve the user transaction instance.
+     * @return the next builder step.
+     */
     UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy(
         TypeLiteral<? extends Provider<UserTransaction>> utProviderType );
 
+    /**
+     * Mark the persistence unit to use JTA transactions.
+     *
+     * @param utProviderKey a provider to retrieve the user transaction instance.
+     * @return the next builder step.
+     */
     UnconfiguredPersistenceUnitBuilder useGlobalTransactionProvidedBy(
         Key<? extends Provider<UserTransaction>> utProviderKey );
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotationHolder.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotationHolder.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotationHolder.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AnnotationHolder.java Mon May  5 05:41:23 2014
@@ -24,7 +24,7 @@ import java.lang.annotation.Annotation;
 /**
  * Object to hold the annotation of a persistence unit. may contain {@code null}.
  */
-public class AnnotationHolder
+class AnnotationHolder
 {
 
     /**
@@ -45,7 +45,8 @@ public class AnnotationHolder
     /**
      * @return the annotation for the current persistence unit. May return {@code null}.
      */
-    Class<? extends Annotation> getAnnotation() {
+    Class<? extends Annotation> getAnnotation()
+    {
         return annotation;
     }
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java Mon May  5 05:41:23 2014
@@ -30,8 +30,6 @@ import static org.apache.onami.persist.P
 /**
  * Implementation of {@link PersistenceService} and {@link EntityManagerFactoryProvider} for
  * application managed persistence units.
- * <p/>
- * This class is a singleton and all methods of the {@link PersistenceService} interface are synchronized.
  */
 @Singleton
 class ApplicationManagedEntityManagerFactoryProvider
@@ -78,7 +76,7 @@ class ApplicationManagedEntityManagerFac
      * {@inheritDoc}
      */
     // @Override
-    public synchronized void start()
+    public void start()
     {
         if ( isRunning() )
         {
@@ -91,7 +89,7 @@ class ApplicationManagedEntityManagerFac
      * {@inheritDoc}
      */
     // @Override
-    public synchronized boolean isRunning()
+    public boolean isRunning()
     {
         return null != emf;
     }
@@ -100,7 +98,7 @@ class ApplicationManagedEntityManagerFac
      * {@inheritDoc}
      */
     // @Override
-    public synchronized void stop()
+    public void stop()
     {
         if ( isRunning() )
         {

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java Mon May  5 05:41:23 2014
@@ -29,9 +29,7 @@ import static org.apache.onami.persist.P
 
 /**
  * Implementation of {@link PersistenceService} and {@link EntityManagerFactoryProvider} for
- * container managed entity manager factories.
- * <p/>
- * This class is a singleton and all methods of the {@link PersistenceService} interface are synchronized.
+ * container managed persistence units.
  */
 @Singleton
 class ContainerManagedEntityManagerFactoryProvider
@@ -78,7 +76,7 @@ class ContainerManagedEntityManagerFacto
      * {@inheritDoc}
      */
     // @Override
-    public synchronized void start()
+    public void start()
     {
         if ( isRunning() )
         {
@@ -92,7 +90,7 @@ class ContainerManagedEntityManagerFacto
      * {@inheritDoc}
      */
     // @Override
-    public synchronized boolean isRunning()
+    public boolean isRunning()
     {
         return null != emf;
     }
@@ -101,12 +99,12 @@ class ContainerManagedEntityManagerFacto
      * {@inheritDoc}
      */
     // @Override
-    public synchronized void stop()
+    public void stop()
     {
         emf = null;
         // the entity manager factory must NOT be closed:
-        // - because it was created by the container and it is therefore the responsibility of the container to close it
-        // - because we cannot know if another part of the application has obtained the same instance over JNDI
+        // - it was created by the container and it is therefore the responsibility of the container to close it
+        // - we cannot know if another part of the application has obtained the same instance
     }
 
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryFactory.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryFactory.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryFactory.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryFactory.java Mon May  5 05:41:23 2014
@@ -49,7 +49,8 @@ class EntityManagerFactoryFactory
      * Constructor.
      *
      * @param puName     the name of the persistence unit as defined in the persistence.xml. Must not be {@code null}.
-     * @param properties the additional properties. Theses override the ones defined in the persistence.xml. Must not be {@code null}.
+     * @param properties the additional properties. Theses override the ones defined in the persistence.xml.
+     *                   Must not be {@code null}.
      */
     @Inject
     EntityManagerFactoryFactory( @ForApplicationManaged String puName,

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySource.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySource.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySource.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySource.java Mon May  5 05:41:23 2014
@@ -24,10 +24,10 @@ import javax.persistence.EntityManagerFa
 
 /**
  * Source for {@link EntityManagerFactory}.
- *
+ * <p/>
  * A source indicates that the instance is not created within the instance (compared to factory)
  */
-public interface EntityManagerFactorySource
+interface EntityManagerFactorySource
 {
 
     /**

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceByJndiLookup.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceByJndiLookup.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceByJndiLookup.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceByJndiLookup.java Mon May  5 05:41:23 2014
@@ -35,8 +35,14 @@ class EntityManagerFactorySourceByJndiLo
     implements EntityManagerFactorySource
 {
 
+    /**
+     * The JNDI name of the persistence unit.
+     */
     private final String jndiName;
 
+    /**
+     * Helper for JNDI lookup.
+     */
     private final JndiLookupHelper jndiLookupHelper;
 
     /**

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceViaProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceViaProvider.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceViaProvider.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactorySourceViaProvider.java Mon May  5 05:41:23 2014
@@ -30,7 +30,8 @@ import javax.persistence.EntityManagerFa
  * The sourced instance is provided by guice.
  */
 @Singleton
-public class EntityManagerFactorySourceViaProvider implements EntityManagerFactorySource
+class EntityManagerFactorySourceViaProvider
+    implements EntityManagerFactorySource
 {
     private final Provider<EntityManagerFactory> emfProvider;
 

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java Mon May  5 05:41:23 2014
@@ -55,7 +55,7 @@ class EntityManagerProviderImpl
     /**
      * Constructor.
      *
-     * @param emfProvider the provider for {@link javax.persistence.EntityManagerFactory}. Must not be {@code null}.
+     * @param emfProvider the provider for {@link EntityManagerFactory}. Must not be {@code null}.
      * @param properties  additional properties to be set on every {@link EntityManager} which is created.
      */
     @Inject

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java Mon May  5 05:41:23 2014
@@ -45,12 +45,12 @@ public class JndiLookupHelper
         try
         {
             final InitialContext ctx = new InitialContext();
-            final T emf = (T) ctx.lookup( jndiName );
+            final T result = (T) ctx.lookup( jndiName );
 
-            Preconditions.checkNotNull( emf, "lookup for " + type.getSimpleName() + " with JNDI name '" + jndiName
+            Preconditions.checkNotNull( result, "lookup for " + type.getSimpleName() + " with JNDI name '" + jndiName
                 + "' returned null" );
 
-            return emf;
+            return result;
         }
         catch ( NamingException e )
         {

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java Mon May  5 05:41:23 2014
@@ -40,7 +40,7 @@ import static org.apache.onami.persist.P
  * <pre>
  *  public class MyModule extends ServletModule {
  *    public void configure() {
- *      // bind your persistence units here
+ *      // other bindings
  *
  *      filter("/*").through(PersistenceFilter.class);
  *    }
@@ -54,7 +54,7 @@ public class PersistenceFilter
     /**
      * Container of all known persistence unit and units of work.
      */
-    private final PersistenceUnitContainer persistenceUnitsContainer;
+    private final AllPersistenceUnits persistenceUnitsContainer;
 
     /**
      * Constructor.
@@ -62,7 +62,7 @@ public class PersistenceFilter
      * @param persistenceUnitsContainer container of all known persistence unit and units of work.
      */
     @Inject
-    PersistenceFilter( PersistenceUnitContainer persistenceUnitsContainer )
+    PersistenceFilter( AllPersistenceUnits persistenceUnitsContainer )
     {
         checkNotNull( persistenceUnitsContainer );
         this.persistenceUnitsContainer = persistenceUnitsContainer;
@@ -102,6 +102,6 @@ public class PersistenceFilter
     // @Override
     public void destroy()
     {
-        persistenceUnitsContainer.stopAllRunningPersistenceServices();
+        persistenceUnitsContainer.stopAllPersistenceServices();
     }
 }

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=1592452&r1=1592451&r2=1592452&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 Mon May  5 05:41:23 2014
@@ -49,10 +49,11 @@ public abstract class PersistenceModule
     extends AbstractModule
 {
 
+    /**
+     * List of configurators. Each configurator can be used to build a {@link PersistenceUnitModule}.
+     */
     private List<PersistenceUnitModuleConfigurator> configurators;
 
-    private final PersistenceUnitContainer container = new PersistenceUnitContainer();
-
     private final Matcher<AnnotatedElement> transactionalMatcher = annotatedWith( Transactional.class );
 
     private final Matcher<Object> anyMatcher = any();
@@ -79,6 +80,10 @@ public abstract class PersistenceModule
     {
         configurePersistence();
 
+        final AllPersistenceUnits container = new AllPersistenceUnits();
+        bind( AllPersistenceServices.class ).toInstance( container );
+        bind( AllUnitsOfWork.class ).toInstance( container );
+
         for ( PersistenceUnitModuleConfigurator config : configurators )
         {
             final PersistenceUnitModule pu = config.createPuModule();

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceService.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceService.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceService.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceService.java Mon May  5 05:41:23 2014
@@ -33,10 +33,10 @@ public interface PersistenceService
      * If you are using onami-persist in a web container {@link PersistenceFilter} will call this
      * method upon initialization of the web application.
      *
-     * @throws IllegalArgumentException if the service is already running.
+     * @throws IllegalStateException if the service is already running.
      */
     void start()
-        throws IllegalArgumentException;
+        throws IllegalStateException;
 
     /**
      * @return {@code true} if the underlying persistence engine is running.

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=1592452&r1=1592451&r2=1592452&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 Mon May  5 05:41:23 2014
@@ -51,7 +51,7 @@ class PersistenceUnitModule
     /**
      * Persistence unit container which can be passed in from the outside for adding this persistence unit to it.
      */
-    private PersistenceUnitContainer container;
+    private AllPersistenceUnits container;
 
     /**
      * Constructor.
@@ -78,7 +78,7 @@ class PersistenceUnitModule
      *
      * @param container the container to which to add the persistence unit.
      */
-    void setPersistenceUnitContainer( PersistenceUnitContainer container )
+    void setPersistenceUnitContainer( AllPersistenceUnits container )
     {
         this.container = container;
     }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ResourceLocalTransactionFacadeFactory.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/ResourceLocalTransactionFacadeFactory.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/ResourceLocalTransactionFacadeFactory.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/ResourceLocalTransactionFacadeFactory.java Mon May  5 05:41:23 2014
@@ -71,7 +71,7 @@ class ResourceLocalTransactionFacadeFact
     /**
      * TransactionFacade representing an inner (nested) transaction.
      * Starting and committing a transaction has no effect.
-     * This Facade will set the rollbackOnly flag in case of a roll back.
+     * This facade will set the rollbackOnly flag in case of a roll back.
      */
     private static class Inner
         implements TransactionFacade
@@ -113,9 +113,8 @@ class ResourceLocalTransactionFacadeFact
 
     /**
      * TransactionFacade representing an outer transaction.
-     * This Facade starts and ends the transaction.
-     * If an inner transaction has set the rollbackOnly flag the transaction will be rolled back
-     * in any case.
+     * This facade starts and ends the transaction.
+     * If an inner transaction has set the rollbackOnly flag the transaction will be rolled back in any case.
      */
     private static class Outer
         implements TransactionFacade

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionFacade.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionFacade.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionFacade.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionFacade.java Mon May  5 05:41:23 2014
@@ -20,8 +20,8 @@ package org.apache.onami.persist;
  */
 
 /**
- * Interface which hides away the details of inner (nested) and outer transactions as well
- * as the details between {@link javax.persistence.EntityTransaction} and {@link javax.transaction.UserTransaction}.
+ * Interface which hides away the details of inner (nested) and outer transactions as well as the details between
+ * {@link javax.persistence.EntityTransaction} and {@link javax.transaction.UserTransaction}.
  */
 interface TransactionFacade
 {
@@ -29,25 +29,22 @@ interface TransactionFacade
     /**
      * Starts a transaction.
      * <p/>
-     * The first call to begin will start the actual transaction. Subsequent calls will start a
-     * 'nested' transaction.
+     * The first call to begin will start the outer transaction. Subsequent calls will start a inner transaction.
      */
     void begin();
 
     /**
      * Commits a transaction.
      * <p/>
-     * Only the actual transaction can be committed. Calls to commit on nested transactions have
-     * no effect.
+     * Only the outer transaction can be committed. Calls to commit on inner transactions have no effect.
      */
     void commit();
 
     /**
      * Rolls a transaction back.
      * <p/>
-     * Only the actual transaction can be rolled back. Calls to rollback on nested transactions will
-     * set the onlyRollBack flag on the actual transaction. Setting this flag wil cause an actual
-     * transaction to be rolled back in any case.
+     * Only the outer transaction can be rolled back. Calls to rollback on inner transactions will set the rollbackOnly
+     * flag on the outer transaction. Setting this flag wil cause an outer transaction to be rolled back in any case.
      */
     void rollback();
 

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationHelper.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationHelper.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationHelper.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationHelper.java Mon May  5 05:41:23 2014
@@ -38,7 +38,7 @@ class TransactionalAnnotationHelper
     /**
      * Annotation of the persistence unit.
      */
-    private final Class<? extends Annotation> puAnntoation;
+    private final Class<? extends Annotation> puAnnotation;
 
     /**
      * Reader for {@link Transactional @Transactional} annotations.
@@ -54,7 +54,7 @@ class TransactionalAnnotationHelper
     @Inject
     TransactionalAnnotationHelper( AnnotationHolder annotationHolder, TransactionalAnnotationReader txnAnnoReader )
     {
-        this.puAnntoation = annotationHolder.getAnnotation();
+        this.puAnnotation = annotationHolder.getAnnotation();
         this.txnAnnoReader = checkNotNull( txnAnnoReader, "txnAnnoReader is mandatory!" );
     }
 
@@ -66,9 +66,9 @@ class TransactionalAnnotationHelper
      * @param methodInvocation the method invocation which may be wrapped in a transaction.
      * @return {@code true} if the current persistence unit participates in a transaction for the given method.
      */
-    public boolean persistenceUnitParticipatesInTransactionFor( MethodInvocation methodInvocation )
+    boolean persistenceUnitParticipatesInTransactionFor( MethodInvocation methodInvocation )
     {
-        return puAnntoation == null || participates( methodInvocation );
+        return puAnnotation == null || participates( methodInvocation );
     }
 
     /**
@@ -82,7 +82,7 @@ class TransactionalAnnotationHelper
     {
         final Transactional transactional = txnAnnoReader.readAnnotationFrom( methodInvocation );
         final Class<? extends Annotation>[] onUnits = transactional.onUnits();
-        return isEmpty( onUnits ) || contains( onUnits, puAnntoation );
+        return isEmpty( onUnits ) || contains( onUnits, puAnnotation );
     }
 
     /**
@@ -115,7 +115,7 @@ class TransactionalAnnotationHelper
      * @param exc              the exception which was thrown
      * @return {@code true} if the transaction needs to be rolled back.
      */
-    public boolean isRollbackNecessaryFor( MethodInvocation methodInvocation, Throwable exc )
+    boolean isRollbackNecessaryFor( MethodInvocation methodInvocation, Throwable exc )
     {
         final Transactional transactional = txnAnnoReader.readAnnotationFrom( methodInvocation );
         return isRollbackNecessaryFor( transactional, exc );
@@ -130,32 +130,26 @@ class TransactionalAnnotationHelper
      */
     private boolean isRollbackNecessaryFor( Transactional transactional, Throwable exc )
     {
-        for ( Class<? extends Exception> rollbackOn : transactional.rollbackOn() )
-        {
-            if ( rollbackOn.isInstance( exc ) )
-            {
-                return isNotIgnoredForRollback( transactional, exc );
-            }
-        }
-        return false;
+        return containsSuper( transactional.rollbackOn(), exc ) && !containsSuper( transactional.ignore(), exc );
     }
 
     /**
-     * Decides if a rollback is not performed for the given transactional annotation and a thrown exception.
+     * Decides if the array of classes contains a super class of exc.
      *
-     * @param transactional the transactional annotation of the method during which an exception was thrown.
-     * @param exc           the exception which was thrown
-     * @return {@code true} if the transaction needs to be rolled back.
+     * @param classes the classes in which to look fore
+     * @param exc     the class to search for
+     * @return {@code true} when the array contains a super class of exc.
      */
-    private boolean isNotIgnoredForRollback( Transactional transactional, Throwable exc )
+    private boolean containsSuper( Class<? extends Exception>[] classes, Throwable exc )
     {
-        for ( Class<? extends Exception> ignore : transactional.ignore() )
+        for ( Class<? extends Exception> c : classes )
         {
-            if ( ignore.isInstance( exc ) )
+            if ( c.isInstance( exc ) )
             {
-                return false;
+                return true;
             }
         }
-        return true;
+        return false;
     }
+
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationReader.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationReader.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationReader.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationReader.java Mon May  5 05:41:23 2014
@@ -31,7 +31,7 @@ import java.lang.reflect.Method;
 class TransactionalAnnotationReader
 {
     /**
-     * Constant holding the a transactional instance with all default values.
+     * Constant holding a transactional instance with all default values.
      */
     private static final Transactional DEFAULT_TRANSACTIONAL =
         DefaultTransactional.class.getAnnotation( Transactional.class );

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/TxnInterceptor.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/TxnInterceptor.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/TxnInterceptor.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/TxnInterceptor.java Mon May  5 05:41:23 2014
@@ -24,7 +24,7 @@ import org.aopalliance.intercept.MethodI
 import org.aopalliance.intercept.MethodInvocation;
 
 /**
- * Interceptor for methods and classes annotated with @{@link Transactional} annotation.
+ * Interceptor for methods and classes annotated with {@link Transactional @Transactional} annotation.
  */
 class TxnInterceptor
     implements MethodInterceptor
@@ -69,6 +69,14 @@ class TxnInterceptor
 
     }
 
+    /**
+     * Decides if the current persistence unit participates in a transaction for the given method invocation.
+     * For a detailed description of when a persistence unit participates see the documentation at the
+     * {@link Transactional @Transactional} annotation.
+     *
+     * @param methodInvocation the method invocation which may be wrapped in a transaction.
+     * @return {@code true} if the current persistence unit participates in a transaction for the given method.
+     */
     private boolean persistenceUnitParticipatesInTransactionFor( MethodInvocation methodInvocation )
     {
         return txnAnnotationHelper.persistenceUnitParticipatesInTransactionFor( methodInvocation );
@@ -104,18 +112,20 @@ class TxnInterceptor
         {
             if ( weStartedTheUnitOfWork )
             {
-                endUnitOfWorkAndThrow( originalException );
+                endUnitOfWork( originalException );
             }
         }
     }
 
     /**
-     * Ends the unit of work and throws the original exception if not null.
+     * Ends the unit of work. If an exception occurs while ending the unit of work it is neglected in preference of an
+     * original exception.
      *
-     * @param originalException the original transaction to throw if not null.
-     * @throws Throwable the original exception or an exception which occurred when closing the unit of work.
+     * @param originalException the original exception. will be thrown in preference to an exception occurring during
+     *                          execution of this method.
+     * @throws Throwable if an exception happened while ending the unit of work.
      */
-    private void endUnitOfWorkAndThrow( Throwable originalException )
+    private void endUnitOfWork( Throwable originalException )
         throws Throwable
     {
         try
@@ -205,6 +215,13 @@ class TxnInterceptor
         }
     }
 
+    /**
+     * Decides if a rollback is necessary for the given method invocation and a thrown exception.
+     *
+     * @param methodInvocation the method invocation during which an exception was thrown.
+     * @param exc              the exception which was thrown
+     * @return {@code true} if the transaction needs to be rolled back.
+     */
     private boolean isRollbackNecessaryFor( MethodInvocation methodInvocation, Throwable exc )
     {
         return txnAnnotationHelper.isRollbackNecessaryFor( methodInvocation, exc );

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnannotatedPersistenceUnitBuilder.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnannotatedPersistenceUnitBuilder.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnannotatedPersistenceUnitBuilder.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnannotatedPersistenceUnitBuilder.java Mon May  5 05:41:23 2014
@@ -21,8 +21,19 @@ package org.apache.onami.persist;
 
 import java.lang.annotation.Annotation;
 
+/**
+ * 2nd step of the persistence unit builder process.
+ * Define an annotation
+ */
 public interface UnannotatedPersistenceUnitBuilder
     extends AnnotatedPersistenceUnitBuilder
 {
+
+    /**
+     * Defines an annotation for the persistence unit.
+     *
+     * @param annotation the annotation to use when referencing the persistence unit.
+     * @return the next builder step.
+     */
     AnnotatedPersistenceUnitBuilder annotatedWith( Class<? extends Annotation> annotation );
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnconfiguredPersistenceUnitBuilder.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnconfiguredPersistenceUnitBuilder.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnconfiguredPersistenceUnitBuilder.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnconfiguredPersistenceUnitBuilder.java Mon May  5 05:41:23 2014
@@ -21,7 +21,17 @@ package org.apache.onami.persist;
 
 import java.util.Properties;
 
+/**
+ * 4th step of the persistence unit builder process.
+ * Define properties.
+ */
 public interface UnconfiguredPersistenceUnitBuilder
 {
+
+    /**
+     * Defines additional properties to use. These properties overrule the ones defined in the persistence.xml
+     *
+     * @param properties the properties to use for the persistence unit.
+     */
     void setProperties( Properties properties );
 }

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnitOfWork.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnitOfWork.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnitOfWork.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnitOfWork.java Mon May  5 05:41:23 2014
@@ -61,10 +61,9 @@ public interface UnitOfWork
 
     /**
      * Starts the unit of work.
-     * When the unit of work has already been started for the current thread an
-     * {@link IllegalStateException} is thrown.
+     * When a unit of work has already been started for the current thread an {@link IllegalStateException} is thrown.
      *
-     * @throws IllegalStateException if the unit of work is already running for this thread.
+     * @throws IllegalStateException if a unit of work is already active for this thread.
      */
     void begin()
         throws IllegalStateException;

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionFacade.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionFacade.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionFacade.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionFacade.java Mon May  5 05:41:23 2014
@@ -177,10 +177,10 @@ class UserTransactionFacade
     }
 
     /**
+     * Retries several times when the status is {@link Status#STATUS_UNKNOWN}.
+     * Will abort retrying after approximately one second.
+     *
      * @see {@link javax.transaction.UserTransaction#getStatus()}.
-     *      <p/>
-     *      Retries several times when the status is {@link Status#STATUS_UNKNOWN}.
-     *      Will abort retrying after aproximatly one second.
      */
     private int getStatus()
     {

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionProviderByJndiLookup.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionProviderByJndiLookup.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionProviderByJndiLookup.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionProviderByJndiLookup.java Mon May  5 05:41:23 2014
@@ -30,7 +30,7 @@ import static org.apache.onami.persist.P
  * Provider fro {@link UserTransaction} which retrieves the value from the JNDI context.
  */
 @Singleton
-public class UserTransactionProviderByJndiLookup
+class UserTransactionProviderByJndiLookup
     implements Provider<UserTransaction>
 {
 

Added: onami/sandbox/persist/src/test/java/org/apache/onami/persist/AllPersistenceUnitsTest.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/test/java/org/apache/onami/persist/AllPersistenceUnitsTest.java?rev=1592452&view=auto
==============================================================================
--- onami/sandbox/persist/src/test/java/org/apache/onami/persist/AllPersistenceUnitsTest.java (added)
+++ onami/sandbox/persist/src/test/java/org/apache/onami/persist/AllPersistenceUnitsTest.java Mon May  5 05:41:23 2014
@@ -0,0 +1,244 @@
+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 org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.*;
+
+/**
+ * Test for {@link AllPersistenceUnits}.
+ */
+public class AllPersistenceUnitsTest
+{
+    private AllPersistenceUnits sut;
+
+    private PersistenceService ps1;
+
+    private PersistenceService ps2;
+
+    private UnitOfWork uow1;
+
+    private UnitOfWork uow2;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        sut = new AllPersistenceUnits();
+
+        ps1 = mock( PersistenceService.class );
+        ps2 = mock( PersistenceService.class );
+
+        uow1 = mock( UnitOfWork.class );
+        uow2 = mock( UnitOfWork.class );
+
+        sut.add( ps1, uow1 );
+        sut.add( ps2, uow2 );
+    }
+
+    @Test
+    public void shouldStartOnAllPersistenceServices()
+        throws Exception
+    {
+        // when
+        sut.startAllStoppedPersistenceServices();
+
+        // then
+        verify( ps1 ).start();
+        verify( ps2 ).start();
+    }
+
+    @Test
+    public void shouldStartOnRunningPersistenceServices()
+        throws Exception
+    {
+        // given
+        doReturn( true ).when( ps1 ).isRunning();
+        doReturn( true ).when( ps2 ).isRunning();
+
+        // when
+        sut.startAllStoppedPersistenceServices();
+
+        // then
+        verify( ps1, never() ).start();
+        verify( ps2, never() ).start();
+    }
+
+    @Test
+    public void shouldStartOnAllPersistenceServicesEvenInCaseOfException()
+        throws Exception
+    {
+        // given
+        doThrow( new RuntimeException() ).when( ps1 ).start();
+        doThrow( new RuntimeException() ).when( ps2 ).start();
+
+        // when
+        try
+        {
+            sut.startAllStoppedPersistenceServices();
+        }
+
+        // then
+        catch ( AggregatedException e )
+        {
+            verify( ps1 ).start();
+            verify( ps2 ).start();
+            assertThat( e.getNumCauses(), is( 2 ) );
+            return;
+        }
+
+        fail( "must throw AggregatedException" );
+    }
+
+    @Test
+    public void shouldStopOnAllPersistenceServices()
+        throws Exception
+    {
+        // when
+        sut.stopAllPersistenceServices();
+
+        // then
+        verify( ps1 ).stop();
+        verify( ps2 ).stop();
+    }
+
+    @Test
+    public void shouldStopOnAllPersistenceServicesEvenInCaseOfException()
+        throws Exception
+    {
+        // given
+        doThrow( new RuntimeException() ).when( ps1 ).stop();
+        doThrow( new RuntimeException() ).when( ps2 ).stop();
+
+        // when
+        try
+        {
+            sut.stopAllPersistenceServices();
+        }
+
+        // then
+        catch ( AggregatedException e )
+        {
+            verify( ps1 ).stop();
+            verify( ps2 ).stop();
+            assertThat( e.getNumCauses(), is( 2 ) );
+            return;
+        }
+
+        fail( "must throw AggregatedException" );
+    }
+
+    @Test
+    public void shouldBeginOnAllUnitsOfWork()
+        throws Exception
+    {
+        // when
+        sut.beginAllInactiveUnitsOfWork();
+
+        // then
+        verify( uow1 ).begin();
+        verify( uow2 ).begin();
+    }
+
+    @Test
+    public void shouldNotBeginOnActiveUnitsOfWork()
+        throws Exception
+    {
+        // given
+        doReturn( true ).when( uow1 ).isActive();
+        doReturn( true ).when( uow2 ).isActive();
+
+        // when
+        sut.beginAllInactiveUnitsOfWork();
+
+        // then
+        verify( uow1, never() ).begin();
+        verify( uow2, never() ).begin();
+    }
+
+    @Test
+    public void shouldBeginOnAllUnitsOfWorkEvenInCaseOfException()
+        throws Exception
+    {
+        // given
+        doThrow( new RuntimeException() ).when( uow1 ).begin();
+        doThrow( new RuntimeException() ).when( uow2 ).begin();
+
+        // when
+        try
+        {
+            sut.beginAllInactiveUnitsOfWork();
+        }
+
+        // then
+        catch ( AggregatedException e )
+        {
+            verify( uow1 ).begin();
+            verify( uow2 ).begin();
+            assertThat( e.getNumCauses(), is( 2 ) );
+            return;
+        }
+
+        fail( "must throw AggregatedException" );
+    }
+
+    @Test
+    public void shouldEndOnAllUnitsOfWork()
+        throws Exception
+    {
+        // when
+        sut.endAllUnitsOfWork();
+
+        // then
+        verify( uow1 ).end();
+        verify( uow2 ).end();
+    }
+
+    @Test
+    public void shouldEndOnAllUnitsOfWorkEvenInCaseOfException()
+        throws Exception
+    {
+        // given
+        doThrow( new RuntimeException() ).when( uow1 ).end();
+        doThrow( new RuntimeException() ).when( uow2 ).end();
+
+        // when
+        try
+        {
+            sut.endAllUnitsOfWork();
+        }
+
+        // then
+        catch ( AggregatedException e )
+        {
+            verify( uow1 ).end();
+            verify( uow2 ).end();
+            assertThat( e.getNumCauses(), is( 2 ) );
+            return;
+        }
+
+        fail( "must throw AggregatedException" );
+    }
+}

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

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

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

Modified: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterTest.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterTest.java?rev=1592452&r1=1592451&r2=1592452&view=diff
==============================================================================
--- onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterTest.java (original)
+++ onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterTest.java Mon May  5 05:41:23 2014
@@ -37,13 +37,13 @@ public class PersistenceFilterTest
 {
     private PersistenceFilter sut;
 
-    private PersistenceUnitContainer persistenceUnitsContainer;
+    private AllPersistenceUnits persistenceUnitsContainer;
 
     @Before
     public void setUp()
         throws Exception
     {
-        persistenceUnitsContainer = mock( PersistenceUnitContainer.class );
+        persistenceUnitsContainer = mock( AllPersistenceUnits.class );
         sut = new PersistenceFilter( persistenceUnitsContainer );
     }
 
@@ -59,7 +59,7 @@ public class PersistenceFilterTest
     public void destroyShouldStopService()
     {
         sut.destroy();
-        verify( persistenceUnitsContainer ).stopAllRunningPersistenceServices();
+        verify( persistenceUnitsContainer ).stopAllPersistenceServices();
     }
 
     @Test



Mime
View raw message