[seam-commits] Seam SVN: r10610 - branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Apr 23 09:35:51 EDT 2009


Author: manaRH
Date: 2009-04-23 09:35:51 -0400 (Thu, 23 Apr 2009)
New Revision: 10610

Modified:
   branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
   branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceContexts.java
   branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceProvider.java
Log:
JBPAPP-1918

Modified: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2009-04-23 12:46:43 UTC (rev 10609)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2009-04-23 13:35:51 UTC (rev 10610)
@@ -22,6 +22,7 @@
 import org.jboss.seam.Entity;
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.Entity.NotEntityException;
+import org.jboss.seam.annotations.FlushModeType;
 import org.jboss.seam.annotations.Install;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
@@ -142,6 +143,12 @@
    }
    
    @Override
+   public void setRenderFlushMode()
+   {
+      PersistenceContexts.instance().changeFlushMode(FlushModeType.MANUAL, true);
+   }
+
+   @Override
    public boolean isDirty(EntityManager entityManager)
    {
        try

Modified: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceContexts.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceContexts.java	2009-04-23 12:46:43 UTC (rev 10609)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceContexts.java	2009-04-23 13:35:51 UTC (rev 10610)
@@ -16,13 +16,15 @@
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.core.AbstractMutable;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
 
 /**
- * Maintains the set of persistence contexts that have been
- * touched in a conversation.
+ * Maintains the set of persistence contexts that have been touched in a
+ * conversation. Also controls the flush mode used by the persistence contexts
+ * during the render phase.
  * 
  * @author Gavin King
- *
  */
 @Name("org.jboss.seam.persistence.persistenceContexts")
 @Scope(ScopeType.CONVERSATION)
@@ -31,9 +33,10 @@
 public class PersistenceContexts extends AbstractMutable implements Serializable
 {
    private static final long serialVersionUID = -4897350516435283182L;
+   private static final LogProvider log = Logging.getLogProvider(PersistenceContexts.class);
    private Set<String> set = new HashSet<String>();
    private FlushModeType flushMode = FlushModeType.AUTO;
-   private FlushModeType actualFlushMode = FlushModeType.AUTO;
+   private FlushModeType originalFlushMode;
  
    public FlushModeType getFlushMode()
    {
@@ -66,11 +69,18 @@
          return null;
       }
    }
-   
+
    public void changeFlushMode(FlushModeType flushMode)
    {
+     changeFlushMode(flushMode, false);
+   }
+   
+   public void changeFlushMode(FlushModeType flushMode, boolean temporary)
+   {
+      if (temporary) {
+         this.originalFlushMode = this.flushMode;
+      }
       this.flushMode = flushMode;
-      this.actualFlushMode = flushMode;
       changeFlushModes();   
    }
 
@@ -85,8 +95,10 @@
             {
                pcm.changeFlushMode(flushMode);
             }
-            catch (UnsupportedOperationException uoe) { 
-               //swallow 
+            catch (UnsupportedOperationException uoe)
+            {
+               // we won't be nasty and throw and exception, but we'll log a warning to the developer
+               log.warn(uoe.getMessage());
             }
          }
       }
@@ -94,14 +106,17 @@
    
    public void beforeRender()
    {
-      flushMode = FlushModeType.MANUAL;
-      changeFlushModes();
+      // some JPA providers may not support MANUAL flushing
+      // defer the decision to the provider manager component
+      PersistenceProvider.instance().setRenderFlushMode();
    }
    
    public void afterRender()
    {
-      flushMode = actualFlushMode;
-      changeFlushModes();
+      if (originalFlushMode != null && originalFlushMode != flushMode) {
+         flushMode = originalFlushMode;
+         changeFlushModes();
+      }
    }
    
 }

Modified: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2009-04-23 12:46:43 UTC (rev 10609)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2009-04-23 13:35:51 UTC (rev 10610)
@@ -11,6 +11,7 @@
 import org.jboss.seam.Component;
 import org.jboss.seam.Entity;
 import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.FlushModeType;
 import org.jboss.seam.annotations.Install;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
@@ -42,7 +43,28 @@
    {
       throw new UnsupportedOperationException("For use of FlushMode.MANUAL, please use Hibernate as the persistence provider or use a custom PersistenceProvider");
    }
+   
    /**
+    * <p>
+    * Set the FlushMode the persistence contexts should use during rendering by
+    * calling {@link PersistenceContexts#changeFlushMode(FlushModeType, boolean)}. The
+    * actual changing of the flush mode is handled by the
+    * {@link PersistenceContexts} instance. The boolean argument indicates whether
+	* the flush mode is temporary and should be set to true. The original flush
+	* mode will be restore after rendering is complete.
+    * </p>
+    * <p>
+    * Ideally, this should be MANUAL since changes should never flush to the
+    * database while in render response and the cost of a dirty check can be
+    * avoided. However, since the MANUAL mode is not officially part of the JPA
+    * specification, the default implementation will perform no operation.
+    * </p>
+    */
+   public void setRenderFlushMode() {
+      // no-op in default implementation
+   }
+   
+   /**
     * Does the persistence context have unflushed changes? If
     * it does not, persistence context replication can be
     * optimized.




More information about the seam-commits mailing list