openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1469649 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: meta/strats/RelationFieldStrategy.java sql/RowImpl.java
Date Fri, 19 Apr 2013 00:55:11 GMT
Author: ppoddar
Date: Fri Apr 19 00:55:11 2013
New Revision: 1469649

URL: http://svn.apache.org/r1469649
Log:
OPENJPA-2373: special processing path for MapsId with auto-generated identity

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=1469649&r1=1469648&r2=1469649&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Fri Apr 19 00:55:11 2013
@@ -57,6 +57,7 @@ import org.apache.openjpa.jdbc.sql.Selec
 import org.apache.openjpa.jdbc.sql.Union;
 import org.apache.openjpa.kernel.LockManager;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.kernel.StateManagerImpl;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
@@ -268,13 +269,26 @@ public class RelationFieldStrategy
         throws SQLException {
         if (field.getMappedBy() != null)
             return;
-
+        Row row = null;
         OpenJPAStateManager rel = RelationStrategies.getStateManager
             (sm.fetchObjectField(field.getIndex()), store.getContext());
-        if (field.getJoinDirection() == field.JOIN_INVERSE)
+        // Checks if the field being inserted is a MapsId field and 
+        // the related object is using auto-assigned identity
+        // If the above conditions are satisfied and the related instance has
+        // already been inserted in the RowManger, then returns without further
+        // processing
+        if (sm instanceof StateManagerImpl) {
+	        List<FieldMetaData> mappedByIdFields = ((StateManagerImpl)sm).getMappedByIdFields();
+	        if (rel != null && ((ClassMapping)rel.getMetaData()).getTable().getAutoAssignedColumns().length
> 0
+	        &&  mappedByIdFields!= null && mappedByIdFields.contains(field))
{
+	        	row = rm.getRow(((ClassMapping)rel.getMetaData()).getTable(), Row.ACTION_INSERT,
rel, false); 
+	        	if (row != null) return;
+	        }
+        }
+        if (field.getJoinDirection() == FieldMapping.JOIN_INVERSE)
             updateInverse(sm, rel, store, rm);
         else {
-            Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
+            if (row == null) row =  field.getRow(sm, store, rm, Row.ACTION_INSERT);
             if (row != null && !field.isBiMTo1JT()) {
                 field.setForeignKey(row, rel);
                 // this is for bi-directional maps, the key and value of the 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java?rev=1469649&r1=1469648&r2=1469649&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java Fri
Apr 19 00:55:11 2013
@@ -897,6 +897,7 @@ public class RowImpl
                 idx++;
             }
         }
+        setFlushed(true);
     }
 
     /**



Mime
View raw message