[seam-commits] Seam SVN: r13673 - in modules/persistence/trunk/impl/src: test/java/org/jboss/seam/persistence/test and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Aug 31 04:50:07 EDT 2010


Author: swd847
Date: 2010-08-31 04:50:05 -0400 (Tue, 31 Aug 2010)
New Revision: 13673

Modified:
   modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
   modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/HibernateSearchTest.java
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.java
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
Log:
refactor SMPC proxy handler



Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java	2010-08-31 08:44:47 UTC (rev 13672)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java	2010-08-31 08:50:05 UTC (rev 13673)
@@ -25,6 +25,7 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.util.Collections;
 import java.util.Set;
 
 import javax.enterprise.context.ContextNotActiveException;
@@ -34,6 +35,7 @@
 import javax.transaction.Synchronization;
 import javax.transaction.SystemException;
 
+import org.jboss.seam.persistence.transaction.FlushModeType;
 import org.jboss.seam.persistence.transaction.SeamTransaction;
 import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
 import org.jboss.seam.persistence.util.InstanceResolver;
@@ -61,13 +63,19 @@
 
    private final PersistenceContexts persistenceContexts;
 
+   private final Set<Annotation> qualifiers;
+
+   private final SeamPersistenceProvider provider;
+
    private boolean persistenceContextsTouched = false;
 
    static final Logger log = LoggerFactory.getLogger(ManagedPersistenceContextProxyHandler.class);
 
    public ManagedPersistenceContextProxyHandler(EntityManager delegate, BeanManager beanManager, Set<Annotation> qualifiers, PersistenceContexts persistenceContexts, SeamPersistenceProvider provider)
    {
-      super(delegate, beanManager, qualifiers, provider);
+      super(delegate, beanManager);
+      this.qualifiers = qualifiers;
+      this.provider = provider;
       this.delegate = delegate;
       this.userTransactionInstance = InstanceResolver.getInstance(SeamTransaction.class, beanManager, DefaultTransactionLiteral.INSTANCE);
       this.persistenceContexts = persistenceContexts;
@@ -80,6 +88,23 @@
          joinTransaction();
       }
       touch((ManagedPersistenceContext) proxy);
+      if ("changeFlushMode".equals(method.getName()) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(FlushModeType.class))
+      {
+         changeFushMode((FlushModeType) args[0]);
+         return null;
+      }
+      if ("getBeanType".equals(method.getName()) && method.getParameterTypes().length == 0)
+      {
+         return EntityManager.class;
+      }
+      if ("getQualifiers".equals(method.getName()) && method.getParameterTypes().length == 0)
+      {
+         return Collections.unmodifiableSet(qualifiers);
+      }
+      if ("getPersistenceProvider".equals(method.getName()) && method.getParameterTypes().length == 0)
+      {
+         return provider;
+      }
       return super.invoke(proxy, method, args);
    }
 
@@ -104,6 +129,11 @@
       }
    }
 
+   private void changeFushMode(FlushModeType flushModeType)
+   {
+      provider.setFlushMode(delegate, flushModeType);
+   }
+
    void touch(ManagedPersistenceContext delegate)
    {
       if (!persistenceContextsTouched)

Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java	2010-08-31 08:44:47 UTC (rev 13672)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java	2010-08-31 08:50:05 UTC (rev 13673)
@@ -22,18 +22,13 @@
 package org.jboss.seam.persistence;
 
 import java.io.Serializable;
-import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
 
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
-import org.jboss.seam.persistence.transaction.FlushModeType;
 import org.jboss.seam.persistence.util.InstanceResolver;
 import org.jboss.weld.extensions.el.Expressions;
 import org.slf4j.Logger;
@@ -55,21 +50,12 @@
 
    private final Instance<Expressions> expressionsInstance;
 
-   private final Instance<DefaultPersistenceProvider> persistenceProvider;
-
-   private final Set<Annotation> qualifiers;
-
-   private final SeamPersistenceProvider provider;
-
    static final Logger log = LoggerFactory.getLogger(ManagedPersistenceContextProxyHandler.class);
 
-   public PersistenceContextProxyHandler(EntityManager delegate, BeanManager beanManager, Set<Annotation> qualifiers, SeamPersistenceProvider provider)
+   public PersistenceContextProxyHandler(EntityManager delegate, BeanManager beanManager)
    {
       this.delegate = delegate;
-      this.provider = provider;
       expressionsInstance = InstanceResolver.getInstance(Expressions.class, beanManager);
-      persistenceProvider = InstanceResolver.getInstance(DefaultPersistenceProvider.class, beanManager);
-      this.qualifiers = new HashSet<Annotation>(qualifiers);
    }
 
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
@@ -78,31 +64,10 @@
       {
          return handleCreateQueryWithString(method, args);
       }
-      if ("changeFlushMode".equals(method.getName()) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(FlushModeType.class))
-      {
-         changeFushMode((FlushModeType) args[0]);
-         return null;
-      }
-      if ("getBeanType".equals(method.getName()) && method.getParameterTypes().length == 0)
-      {
-         return EntityManager.class;
-      }
-      if ("getQualifiers".equals(method.getName()) && method.getParameterTypes().length == 0)
-      {
-         return Collections.unmodifiableSet(qualifiers);
-      }
-      if ("getPersistenceProvider".equals(method.getName()) && method.getParameterTypes().length == 0)
-      {
-         return provider;
-      }
+
       return method.invoke(delegate, args);
    }
 
-   private void changeFushMode(FlushModeType flushModeType)
-   {
-      persistenceProvider.get().setFlushMode(delegate, flushModeType);
-   }
-
    protected Object handleCreateQueryWithString(Method method, Object[] args) throws Throwable
    {
       if (args[0] == null)

Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/HibernateSearchTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/HibernateSearchTest.java	2010-08-31 08:44:47 UTC (rev 13672)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/HibernateSearchTest.java	2010-08-31 08:50:05 UTC (rev 13673)
@@ -34,7 +34,7 @@
 import org.hibernate.search.jpa.FullTextEntityManager;
 import org.jboss.arquillian.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.persistence.PersistenceContextExtension;
+import org.jboss.seam.persistence.SePersistenceContextExtension;
 import org.jboss.seam.persistence.transaction.DefaultTransaction;
 import org.jboss.seam.persistence.transaction.SeamTransaction;
 import org.jboss.seam.persistence.transaction.TransactionExtension;
@@ -66,7 +66,7 @@
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.LUCENE_ANALYZERS));
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.LUCENE_CORE));
       war.addPackage(TransactionExtension.class.getPackage());
-      war.addPackage(PersistenceContextExtension.class.getPackage());
+      war.addPackage(SePersistenceContextExtension.class.getPackage());
       war.addPackage(TransactionScopeExtension.class.getPackage());
       war.addPackage(NamingUtils.class.getPackage());
       war.addClasses(HibernateSearchTest.class, IndexedHotel.class, ManagedPersistenceContextProvider.class, HelloService.class);

Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.java	2010-08-31 08:44:47 UTC (rev 13672)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.java	2010-08-31 08:50:05 UTC (rev 13673)
@@ -31,7 +31,7 @@
 
 import org.jboss.arquillian.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.persistence.PersistenceContextExtension;
+import org.jboss.seam.persistence.SePersistenceContextExtension;
 import org.jboss.seam.persistence.transaction.DefaultTransaction;
 import org.jboss.seam.persistence.transaction.SeamTransaction;
 import org.jboss.seam.persistence.transaction.TransactionExtension;
@@ -60,7 +60,7 @@
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
       war.addPackage(TransactionExtension.class.getPackage());
-      war.addPackage(PersistenceContextExtension.class.getPackage());
+      war.addPackage(SePersistenceContextExtension.class.getPackage());
       war.addPackage(TransactionExtension.class.getPackage());
       war.addPackage(TransactionScopeExtension.class.getPackage());
       war.addPackage(NamingUtils.class.getPackage());

Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java	2010-08-31 08:44:47 UTC (rev 13672)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java	2010-08-31 08:50:05 UTC (rev 13673)
@@ -38,7 +38,7 @@
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.seam.persistence.FlushModeManager;
 import org.jboss.seam.persistence.ManagedPersistenceContext;
-import org.jboss.seam.persistence.PersistenceContextExtension;
+import org.jboss.seam.persistence.SePersistenceContextExtension;
 import org.jboss.seam.persistence.PersistenceContexts;
 import org.jboss.seam.persistence.transaction.FlushModeType;
 import org.jboss.seam.persistence.transaction.TransactionExtension;
@@ -66,7 +66,7 @@
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
       war.addPackage(TransactionExtension.class.getPackage());
-      war.addPackage(PersistenceContextExtension.class.getPackage());
+      war.addPackage(SePersistenceContextExtension.class.getPackage());
       war.addPackage(TransactionScopeExtension.class.getPackage());
       war.addPackage(NamingUtils.class.getPackage());
       war.addClasses(ManagedPersistenceContextFlushModeTest.class, Hotel.class, ManagedPersistenceContextProvider.class, HelloService.class);

Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java	2010-08-31 08:44:47 UTC (rev 13672)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java	2010-08-31 08:50:05 UTC (rev 13673)
@@ -35,7 +35,7 @@
 
 import org.jboss.arquillian.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.persistence.PersistenceContextExtension;
+import org.jboss.seam.persistence.SePersistenceContextExtension;
 import org.jboss.seam.persistence.transaction.DefaultTransaction;
 import org.jboss.seam.persistence.transaction.SeamTransaction;
 import org.jboss.seam.persistence.transaction.TransactionExtension;
@@ -63,7 +63,7 @@
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
       war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
       war.addPackage(TransactionExtension.class.getPackage());
-      war.addPackage(PersistenceContextExtension.class.getPackage());
+      war.addPackage(SePersistenceContextExtension.class.getPackage());
       war.addPackage(TransactionScopeExtension.class.getPackage());
       war.addPackage(NamingUtils.class.getPackage());
       war.addClasses(ManagedPersistenceContextTest.class, Hotel.class, ManagedPersistenceContextProvider.class, HelloService.class);



More information about the seam-commits mailing list