Author: dan.j.allen
Date: 2009-04-05 01:56:22 -0400 (Sun, 05 Apr 2009)
New Revision: 10295
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
Modified: trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2009-04-05
05:56:07 UTC (rev 10294)
+++ trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2009-04-05
05:56:22 UTC (rev 10295)
@@ -23,6 +23,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;
@@ -150,6 +151,12 @@
}
@Override
+ public void setRenderFlushMode()
+ {
+ PersistenceContexts.instance().changeFlushMode(FlushModeType.MANUAL);
+ }
+
+ @Override
public boolean isDirty(EntityManager entityManager)
{
try
Modified: trunk/src/main/org/jboss/seam/persistence/PersistenceContexts.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/PersistenceContexts.java 2009-04-05 05:56:07
UTC (rev 10294)
+++ trunk/src/main/org/jboss/seam/persistence/PersistenceContexts.java 2009-04-05 05:56:22
UTC (rev 10295)
@@ -18,13 +18,15 @@
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.AbstractMutable;
import org.jboss.seam.core.Manager;
+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)
@@ -33,6 +35,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;
private FlushModeType actualFlushMode;
@@ -53,7 +56,6 @@
}
}
-
public FlushModeType getFlushMode()
{
return flushMode;
@@ -104,8 +106,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());
}
}
}
@@ -113,7 +117,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: trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2009-04-05 05:56:07
UTC (rev 10294)
+++ trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2009-04-05 05:56:22
UTC (rev 10295)
@@ -14,6 +14,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;
@@ -71,9 +72,28 @@
*/
public void setFlushModeManual(EntityManager entityManager)
{
- throw new UnsupportedOperationException("For use of FlushMode.MANUAL, please
use Hibernate as the persistence provider or use a custom PersistenceProvider");
+ throw new UnsupportedOperationException("Use of FlushMode.MANUAL requires
Hibernate as the persistence provider. Please use Hibernate, a custom persistenceProvider,
or remove the MANUAL flush mode setting.");
}
+
/**
+ * <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.
@@ -131,7 +151,7 @@
}
if ( !equal )
{
- throw new OptimisticLockException("current database version number does not
match passivated version number");
+ throw new OptimisticLockException("Current database version number does not
match passivated version number");
}
}
/**
@@ -141,7 +161,7 @@
*/
public void enableFilter(Filter filter, EntityManager entityManager)
{
- throw new UnsupportedOperationException("For filters, please use Hibernate as
the persistence provider");
+ throw new UnsupportedOperationException("Use of filters requires Hibernate as
the persistence provider. Please use Hibernate or remove the filters
configuration.");
}
/**