You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2008/05/12 20:41:33 UTC
svn commit: r655595 - in /openjpa/branches/1.1.x:
openjpa-kernel/src/main/java/org/apache/openjpa/conf/
openjpa-kernel/src/main/java/org/apache/openjpa/kernel/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/
openjpa-projec...
Author: pcl
Date: Mon May 12 11:41:33 2008
New Revision: 655595
URL: http://svn.apache.org/viewvc?rev=655595&view=rev
Log:
OPENJPA-591. Porting Mike's work to 1.1.x.
Added:
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java
- copied unchanged from r654227, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java
Modified:
openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java
openjpa/branches/1.1.x/openjpa-project/src/doc/manual/ref_guide_remote.xml
Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java?rev=655595&r1=655594&r2=655595&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java (original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java Mon May 12 11:41:33 2008
@@ -55,6 +55,7 @@
private boolean _nonOptimisticVersionCheck = false;
private int _jpql = JPQL_WARN;
private boolean _storeMapCollectionInEntityAsBlob = false;
+ private boolean _flushBeforeDetach = true;
/**
* Whether to require exact identity value types when creating object
@@ -237,4 +238,35 @@
public void setStoreMapCollectionInEntityAsBlob(boolean storeAsBlob) {
_storeMapCollectionInEntityAsBlob = storeAsBlob;
}
+
+ /**
+ * Whether OpenJPA should flush changes before detaching or serializing an
+ * entity. In JPA this is usually false, but other persistence frameworks
+ * (ie JDO) may expect it to be true.
+ * <P>Prior to version 1.0.3 and 1.2.0 changes were always flushed.
+ *
+ * @since 1.0.3
+ * @since 1.2.0
+ * @return true if changes should be flushed, otherwise false.
+ */
+ public boolean getFlushBeforeDetach() {
+ return _flushBeforeDetach;
+ }
+
+ /**
+ * Whether OpenJPA should flush changes before detaching or serializing an
+ * entity. In JPA this is usually false, but other persistence frameworks
+ * (ie JDO) may expect it to be true.
+ * <P>Prior to version 1.0.3 and 1.2.0 changes were always flushed.
+ *
+ * @param beforeDetach if true changes will be flushed before detaching or
+ * serializing an entity.
+ *
+ * @since 1.0.3
+ * @since 1.2.0
+ */
+ public void setFlushBeforeDetach(boolean beforeDetach) {
+ _flushBeforeDetach = beforeDetach;
+ }
+
}
Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java?rev=655595&r1=655594&r2=655595&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java (original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java Mon May 12 11:41:33 2008
@@ -67,6 +67,7 @@
private final OpCallbacks _call;
private final boolean _failFast;
private boolean _flushed = false;
+ private boolean _flushBeforeDetach;
// if we're not detaching full, we need to track all detached objects;
// if we are, then we use a special field manager for more efficient
@@ -82,7 +83,10 @@
if (!sm.isPersistent())
return false;
- flushDirty(sm);
+ if (sm.getBroker().getConfiguration().getCompatibilityInstance()
+ .getFlushBeforeDetach()) {
+ flushDirty(sm);
+ }
ClassMetaData meta = sm.getMetaData();
boolean setState = meta.getDetachedState() != null
@@ -270,6 +274,9 @@
_detached = new IdentityMap();
_fullFM = null;
}
+ _flushBeforeDetach =
+ broker.getConfiguration().getCompatibilityInstance()
+ .getFlushBeforeDetach();
}
/**
@@ -415,8 +422,14 @@
_broker.fireLifecycleEvent(toDetach, null, sm.getMetaData(),
LifecycleEvent.BEFORE_DETACH);
- // any dirty instances cause a flush to occur
- _flushed = _flushed || flushDirty(sm);
+ if(! _flushed) {
+ if(_flushBeforeDetach) {
+ // any dirty instances cause a flush to occur
+ flushDirty(sm);
+ }
+ _flushed = true;
+ }
+
BitSet fields = new BitSet();
preDetach(_broker, sm, fields);
Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java?rev=655595&r1=655594&r2=655595&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java (original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java Mon May 12 11:41:33 2008
@@ -18,6 +18,8 @@
*/
package org.apache.openjpa.persistence.simple;
+import java.io.Serializable;
+
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -28,8 +30,10 @@
@Entity
@Table(name = "ITEM")
-public class Item {
+public class Item implements Serializable {
+ private static final long serialVersionUID = 489786296539819572L;
+
public int itemId;
public String itemName;
public java.math.BigDecimal itemPrice;
Modified: openjpa/branches/1.1.x/openjpa-project/src/doc/manual/ref_guide_remote.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-project/src/doc/manual/ref_guide_remote.xml?rev=655595&r1=655594&r2=655595&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-project/src/doc/manual/ref_guide_remote.xml (original)
+++ openjpa/branches/1.1.x/openjpa-project/src/doc/manual/ref_guide_remote.xml Mon May 12 11:41:33 2008
@@ -124,21 +124,43 @@
concurrency exception.
</para>
<para>
-You can stop OpenJPA from assuming the transaction will commit by invoking
-<methodname>EntityTransaction.setRollbackOnly</methodname> prior to detaching
-your objects. Setting the <literal>RollbackOnly</literal> flag prevents OpenJPA
-from flushing when detaching dirty objects; instead OpenJPA just runs its
-pre-flush actions (see the <methodname>OpenJPAEntityManager.preFlush
-</methodname>
+You can stop OpenJPA from assuming the transaction will commit in the following
+ways :
+ <itemizedlist>
+ <listitem>
+ <para>
+ Invoke <methodname>EntityTransaction.setRollbackOnly
+ </methodname> prior to detachingyour objects. Setting the
+ <literal>RollbackOnly</literal> flag prevents OpenJPA from
+ flushing when detaching dirty objects; instead OpenJPA just
+ runs its pre-flush actions (see the
+ <methodname>OpenJPAEntityManager.preFlush</methodname>
<ulink url="../javadoc/org/apache/openjpa/persistence/OpenJPAEntityManager.html">
Javadoc</ulink> for details).
</para>
<para>
This allows you to use the same instances in multiple
-attach/modify/detach/rollback cycles. Alternatively, you might also prevent a
-flush by making your modifications outside of a transaction (with <literal>
+attach/modify/detach/rollback cycles.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Make your modifications outside of a transaction (with <literal>
NontransactionalWrite</literal> enabled) before detaching.
</para>
+ </listitem>
+ <listitem>
+ <para>
+ Set <literal>flushBeforeDetach</literal>
+ to false (see <methodname>Compatibility.setFlushBeforeDetach
+ </methodname>
+ <ulink url="../javadoc/org/apache/openjpa/conf/Compatibility.html">
+Javadoc</ulink> ). This option is similar to the first option, but does not
+ affect the current transaction.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
</section>
<section id="ref_guide_attach_behavior">
<title>