openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r446799 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/...
Date Sat, 16 Sep 2006 00:44:58 GMT
Author: mprudhom
Date: Fri Sep 15 17:44:55 2006
New Revision: 446799

URL: http://svn.apache.org/viewvc?view=rev&rev=446799
Log:
Non-optimistic transactions will no longer perform a version check when committing dirty objects,
unless the NonOptimisticVersionCheck compatibility property is set to true. This allows dirty
instances enlisted in a non-optimistic transaction to be allowed to overwrite conflicting
versions in the database.

Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java?view=diff&rev=446799&r1=446798&r2=446799
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
Fri Sep 15 17:44:55 2006
@@ -35,6 +35,7 @@
 import org.apache.openjpa.kernel.PCState;
 import org.apache.openjpa.lib.conf.Configurable;
 import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.OpenJPAException;
 import org.apache.openjpa.util.OptimisticException;
 
@@ -139,6 +140,8 @@
         RowManager rowMgr, JDBCStore store, Collection exceps,
         Collection customs) {
         try {
+            BitSet dirty;
+
             if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) {
                 insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
                     customs);
@@ -146,18 +149,9 @@
                 || sm.getPCState() == PCState.PDELETED) {
                 delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
                     customs);
-            } else if ((sm.getPCState() == PCState.PDIRTY && (!sm.isFlushed() ||
sm
-                .isFlushedDirty()))
-                || (sm.getPCState() == PCState.PNEW && sm.isFlushedDirty())) {
-                BitSet dirty = sm.getDirty();
-                if (sm.isFlushed()) {
-                    dirty = (BitSet) dirty.clone();
-                    dirty.andNot(sm.getFlushed());
-                }
-
-                if (dirty.length() > 0)
-                    update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr,
-                        store, customs);
+            } else if ((dirty = ImplHelper.getUpdateFields(sm)) != null) {
+                update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr,
+                    store, customs);
             } else if (sm.isVersionUpdateRequired()) {
                 updateIndicators(sm, (ClassMapping) sm.getMetaData(), rowMgr,
                     store, customs, true);

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java?view=diff&rev=446799&r1=446798&r2=446799
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ColumnVersionStrategy.java
Fri Sep 15 17:44:55 2006
@@ -138,7 +138,7 @@
 
         // set where and update conditions on row
         for (int i = 0; i < cols.length; i++) {
-            if (curVersion != null)
+            if (curVersion != null && sm.isVersionCheckRequired())
                 row.whereObject(cols[i], curVersion);
             if (vers.getColumnIO().isUpdatable(i, nextVersion == null))
                 row.setObject(cols[i], nextVersion);

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java?view=diff&rev=446799&r1=446798&r2=446799
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java
Fri Sep 15 17:44:55 2006
@@ -101,28 +101,30 @@
         // db values match our previous image
         FieldMapping[] fields = (FieldMapping[]) sm.getMetaData().getFields();
         Row row;
-        for (int i = 0, max = loaded.length(); i < max; i++) {
-            if (!loaded.get(i))
-                continue;
+        if (sm.isVersionCheckRequired()) {
+            for (int i = 0, max = loaded.length(); i < max; i++) {
+                if (!loaded.get(i))
+                    continue;
 
-            // update our next state image with the new field value
-            if (sm.getDirty().get(i) && !sm.getFlushed().get(i))
-                nextState[i] = sm.fetch(fields[i].getIndex());
+                // update our next state image with the new field value
+                if (sm.getDirty().get(i) && !sm.getFlushed().get(i))
+                    nextState[i] = sm.fetch(fields[i].getIndex());
 
-            // fetch the row for this field; if no row exists, then we can't
-            // add one because we have no updates to perform; that means we
-            // won't detect OL exceptions when another transaction changes
-            // fields that aren't in any of the same tables as fields that
-            // this transaction changed
-            row = rm.getRow(fields[i].getTable(), Row.ACTION_UPDATE,
-                sm, false);
-            if (row == null)
-                continue;
+                // fetch the row for this field; if no row exists, then we can't
+                // add one because we have no updates to perform; that means we
+                // won't detect OL exceptions when another transaction changes
+                // fields that aren't in any of the same tables as fields that
+                // this transaction changed
+                row = rm.getRow(fields[i].getTable(), Row.ACTION_UPDATE,
+                    sm, false);
+                if (row == null)
+                    continue;
 
-            // set WHERE criteria matching the previous state image so the
-            // update will fail if any changes have been made by another trans
-            fields[i].where(sm, store, rm, state[i]);
-            row.setFailedObject(sm.getManagedInstance());
+                // set WHERE criteria matching the previous state image so the
+                // update will fail for any changes made by another transaction
+                fields[i].where(sm, store, rm, state[i]);
+                row.setFailedObject(sm.getManagedInstance());
+            }
         }
         sm.setNextVersion(nextState);
     }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java?view=diff&rev=446799&r1=446798&r2=446799
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
Fri Sep 15 17:44:55 2006
@@ -26,6 +26,7 @@
     private boolean _copyIds = false;
     private boolean _closeOnCommit = true;
     private boolean _quotedNumbers = false;
+    private boolean _nonOptimisticVersionCheck = false;
 
     /**
      * Whether to require exact identity value types when creating object
@@ -136,4 +137,24 @@
     public void setCloseOnManagedCommit(boolean close) {
         _closeOnCommit = close;
 	}	
+
+    /** 
+     * Whether or not to perform a version check on instances being updated
+     * in a datastore transaction. Version of OpenJPA prior to 4.1 always
+     * forced a version check.
+     */
+    public void setNonOptimisticVersionCheck
+        (boolean nonOptimisticVersionCheck) {
+        _nonOptimisticVersionCheck = nonOptimisticVersionCheck;
+    }
+
+    /** 
+     * Whether or not to perform a version check on instances being updated
+     * in a datastore transaction. Version of OpenJPA prior to 4.1 always
+     * forced a version check.
+     */
+    public boolean getNonOptimisticVersionCheck() {
+        return _nonOptimisticVersionCheck;
+    }
+
 }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?view=diff&rev=446799&r1=446798&r2=446799
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Fri Sep 15 17:44:55 2006
@@ -38,6 +38,7 @@
 import org.apache.openjpa.meta.ValueStrategies;
 import org.apache.openjpa.util.ApplicationIds;
 import org.apache.openjpa.util.Exceptions;
+import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.InternalException;
 import org.apache.openjpa.util.InvalidStateException;
 import org.apache.openjpa.util.ObjectNotFoundException;
@@ -2926,7 +2927,23 @@
      * Returns whether this instance needs a version check.
      */
     public boolean isVersionCheckRequired() {
-        return (_flags & FLAG_VERSION_CHECK) > 0;
+
+        // explicit flag for version check
+        if ((_flags & FLAG_VERSION_CHECK) > 0)
+            return true;
+
+        // need to check version if we have any dirty fields, unless we
+        // are in a datastore transaction
+        if (ImplHelper.getUpdateFields(this) != null) {
+            if (_broker.getOptimistic()) {
+                return true;
+            } else {
+                return _broker.getConfiguration().
+                    getCompatibilityInstance().getNonOptimisticVersionCheck();
+            }
+        }
+
+        return false;
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java?view=diff&rev=446799&r1=446798&r2=446799
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java
Fri Sep 15 17:44:55 2006
@@ -17,6 +17,7 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -164,6 +165,30 @@
             default:
                 return null;
         }
+    }
+
+    /** 
+     * Returns the fields of the state that require an update. 
+     *  
+     * @param  sm  the state to check
+     * @return the BitSet of fields that need update, or null if none
+     */
+    public static BitSet getUpdateFields(OpenJPAStateManager sm) {
+
+        if ((sm.getPCState() == PCState.PDIRTY
+            && (!sm.isFlushed() || sm.isFlushedDirty()))
+            || (sm.getPCState() == PCState.PNEW && sm.isFlushedDirty())) {
+            BitSet dirty = sm.getDirty();
+            if (sm.isFlushed()) {
+                dirty = (BitSet) dirty.clone();
+                dirty.andNot(sm.getFlushed());
+            }
+
+            if (dirty.length() > 0)
+                return dirty;
+        }
+
+        return null;
     }
 
     /**



Mime
View raw message