[seam-commits] Seam SVN: r10294 - branches/community/Seam_2_0/src/main/org/jboss/seam/persistence.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun Apr 5 01:56:08 EDT 2009


Author: dan.j.allen
Date: 2009-04-05 01:56:07 -0400 (Sun, 05 Apr 2009)
New Revision: 10294

Modified:
   branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
   branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceContexts.java
   branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
Log:
JBSEAM-3030


Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2009-04-05 04:44:05 UTC (rev 10293)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2009-04-05 05:56:07 UTC (rev 10294)
@@ -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);
+   }
+
+   @Override
    public boolean isDirty(EntityManager entityManager)
    {
        try

Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceContexts.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceContexts.java	2009-04-05 04:44:05 UTC (rev 10293)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceContexts.java	2009-04-05 05:56:07 UTC (rev 10294)
@@ -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,6 +33,7 @@
 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;
@@ -85,8 +88,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,7 +99,9 @@
    
    public void beforeRender()
    {
-      flushMode = FlushModeType.MANUAL;
+      // some JPA providers may not support MANUAL flushing
+      // defer the decision to the provider manager component
+      PersistenceProvider.instance().setRenderFlushMode();
       changeFlushModes();
    }
    

Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2009-04-05 04:44:05 UTC (rev 10293)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2009-04-05 05:56:07 UTC (rev 10294)
@@ -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,26 @@
    {
       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)}. The
+    * actual changing of the flush mode is handled by the
+    * {@link PersistenceContexts} instance.
+    * </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