Author: dan.j.allen
Date: 2009-04-08 13:50:00 -0400 (Wed, 08 Apr 2009)
New Revision: 10355
Modified:
trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
trunk/src/main/org/jboss/seam/persistence/PersistenceContexts.java
trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java
Log:
JBSEAM-3030 fix regression where actual flush mode was not being restored after render
Modified: trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2009-04-08
17:48:06 UTC (rev 10354)
+++ trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2009-04-08
17:50:00 UTC (rev 10355)
@@ -153,7 +153,7 @@
@Override
public void setRenderFlushMode()
{
- PersistenceContexts.instance().changeFlushMode(FlushModeType.MANUAL);
+ PersistenceContexts.instance().changeFlushMode(FlushModeType.MANUAL, true);
}
@Override
Modified: trunk/src/main/org/jboss/seam/persistence/PersistenceContexts.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/PersistenceContexts.java 2009-04-08 17:48:06
UTC (rev 10354)
+++ trunk/src/main/org/jboss/seam/persistence/PersistenceContexts.java 2009-04-08 17:50:00
UTC (rev 10355)
@@ -38,7 +38,8 @@
private static final LogProvider log =
Logging.getLogProvider(PersistenceContexts.class);
private Set<String> set = new HashSet<String>();
private FlushModeType flushMode;
- private FlushModeType actualFlushMode;
+ // the real flush mode is a backup of the flush mode when doing a temporary switch
(such as during render)
+ private FlushModeType realFlushMode;
@Create
public void create()
@@ -47,12 +48,10 @@
if (defaultFlushMode != null)
{
flushMode = defaultFlushMode;
- actualFlushMode = defaultFlushMode;
}
else
{
flushMode = FlushModeType.AUTO;
- actualFlushMode = FlushModeType.AUTO;
}
}
@@ -90,11 +89,30 @@
public void changeFlushMode(FlushModeType flushMode)
{
+ changeFlushMode(flushMode, false);
+ }
+
+ public void changeFlushMode(FlushModeType flushMode, boolean temporary)
+ {
+ if (temporary) {
+ realFlushMode = this.flushMode;
+ }
this.flushMode = flushMode;
- this.actualFlushMode = flushMode;
- changeFlushModes();
+ changeFlushModes();
}
+ /**
+ * Restore the previous flush mode if the current flush mode is marked
+ * as temporary.
+ */
+ public void restoreFlushMode() {
+ if (realFlushMode != null && realFlushMode != flushMode) {
+ flushMode = realFlushMode;
+ realFlushMode = null;
+ changeFlushModes();
+ }
+ }
+
private void changeFlushModes()
{
for (String name: set)
@@ -120,13 +138,11 @@
// some JPA providers may not support MANUAL flushing
// defer the decision to the provider manager component
PersistenceProvider.instance().setRenderFlushMode();
- changeFlushModes();
}
public void afterRender()
{
- flushMode = actualFlushMode;
- changeFlushModes();
+ restoreFlushMode();
}
}
Modified: trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2009-04-08 17:48:06
UTC (rev 10354)
+++ trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2009-04-08 17:50:00
UTC (rev 10355)
@@ -78,9 +78,11 @@
/**
* <p>
* Set the FlushMode the persistence contexts should use during rendering by
- * calling {@link PersistenceContexts#changeFlushMode(FlushModeType)}. The
+ * calling {@link PersistenceContexts#changeFlushMode(FlushModeType, true)}. The
* actual changing of the flush mode is handled by the
- * {@link PersistenceContexts} instance.
+ * {@link PersistenceContexts} instance. The boolean argument should be true
+ * to indicate that this is a temporary change and that the old flush mode
+ * should be restored after render.
* </p>
* <p>
* Ideally, this should be MANUAL since changes should never flush to the
Show replies by date