openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r1308194 - in /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/util/
Date Sun, 01 Apr 2012 20:23:47 GMT
Author: jrbauer
Date: Sun Apr  1 20:23:47 2012
New Revision: 1308194

URL: http://svn.apache.org/viewvc?rev=1308194&view=rev
Log:
OPENJPA-2165 minor improvements to delayed collection loading

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedArrayListProxy.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedProxy.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java?rev=1308194&r1=1308193&r2=1308194&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
Sun Apr  1 20:23:47 2012
@@ -688,27 +688,19 @@ public class JDBCStoreManager implements
     }
 
     private boolean isDelayedLoadOnly(OpenJPAStateManager sm, BitSet fields, ClassMapping
mapping) {
-        if (!sm.getContext().getConfiguration().getProxyManagerInstance().getDelayCollectionLoading())
{
+        if (!sm.getContext().getConfiguration().getProxyManagerInstance().getDelayCollectionLoading()

+            || fields.isEmpty()) {
             return false;
         }
-        boolean allDelayed = false;
-        if (!fields.isEmpty()) {
-            FieldMapping[] fms = mapping.getFieldMappings();
-            int fCount = 0;
-            int dfCount = 0;
-            for (int i = fields.nextSetBit(0); i < fms.length; i++) {
-                if (fields.get(i)) {
-                    fCount++;
-                    if (!(fms[i].isDelayCapable() && (!sm.getLoaded().get(i) || sm.isDelayed(i))))
{
-                        break;
-                    } else {
-                        dfCount++;
-                    }
+        FieldMapping[] fms = mapping.getFieldMappings();
+        for (int i = 0; i < fms.length; i++) {
+            if (fields.get(i)) {
+                if (!(fms[i].isDelayCapable() && (!sm.getLoaded().get(i) || sm.isDelayed(i))))
{
+                    return false;
                 }
             }
-            allDelayed = (fCount == dfCount);
         }
-        return allDelayed;
+        return true;
     }
     
     /**

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=1308194&r1=1308193&r2=1308194&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
Sun Apr  1 20:23:47 2012
@@ -494,12 +494,13 @@ public abstract class StoreCollectionFie
         throws SQLException {
         
         Object coll = null;
-        boolean delayed = sm.isDelayed(field.getIndex());
+        final int fieldIndex = field.getIndex();
+        final boolean delayed = sm.isDelayed(fieldIndex);
         if (!delayed && field.isDelayCapable()) {
-            coll = sm.newProxy(field.getIndex());
+            coll = sm.newProxy(fieldIndex);
             if (coll instanceof DelayedProxy) {
-                sm.storeObject(field.getIndex(), coll);
-                sm.setDelayed(field.getIndex(), true);
+                sm.storeObject(fieldIndex, coll);
+                sm.setDelayed(fieldIndex, true);
                 return;
             }
         }
@@ -532,7 +533,7 @@ public abstract class StoreCollectionFie
                     res.close();
                 }
             }
-            sm.storeObjectField(field.getIndex(), pcoll);
+            sm.storeObjectField(fieldIndex, pcoll);
             return;
         }
 
@@ -553,11 +554,11 @@ public abstract class StoreCollectionFie
         ChangeTracker ct = null;
         if (delayed) {
             if (sm.isDetached() || sm.getOwner() == null) {
-                sm.getPersistenceCapable().pcProvideField(field.getIndex());
+                sm.getPersistenceCapable().pcProvideField(fieldIndex);
                 coll = 
-                    ((FieldManager)sm.getPersistenceCapable().pcGetStateManager()).fetchObjectField(field.getIndex());
+                    ((FieldManager)sm.getPersistenceCapable().pcGetStateManager()).fetchObjectField(fieldIndex);
             } else {
-                coll = sm.fetchObjectField(field.getIndex());
+                coll = sm.fetchObjectField(fieldIndex);
             }
             if (coll instanceof Proxy)
                 ct = ((Proxy) coll).getChangeTracker();
@@ -566,7 +567,7 @@ public abstract class StoreCollectionFie
                 coll = new ArrayList();
             else {
                 if (coll == null) {
-                    coll = sm.newProxy(field.getIndex());
+                    coll = sm.newProxy(fieldIndex);
                 }
                 if (coll instanceof Proxy)
                     ct = ((Proxy) coll).getChangeTracker();
@@ -593,10 +594,10 @@ public abstract class StoreCollectionFie
         // if not a delayed collection, set into sm
         if (!delayed) {
             if (field.getTypeCode() == JavaTypes.ARRAY)
-                sm.storeObject(field.getIndex(), JavaTypes.toArray
+                sm.storeObject(fieldIndex, JavaTypes.toArray
                     ((Collection) coll, field.getElement().getType()));
             else
-                sm.storeObject(field.getIndex(), coll);
+                sm.storeObject(fieldIndex, coll);
         }
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedArrayListProxy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedArrayListProxy.java?rev=1308194&r1=1308193&r2=1308194&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedArrayListProxy.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedArrayListProxy.java
Sun Apr  1 20:23:47 2012
@@ -44,7 +44,7 @@ public class DelayedArrayListProxy exten
   private transient Broker _broker = null;
   private transient OpenJPAStateManager _delayedSm;
   private transient int _delayedField; 
-  private transient boolean dirtyCollection = true;
+  private transient boolean _detached = false;
   
   public DelayedArrayListProxy()
   {
@@ -65,8 +65,11 @@ public class DelayedArrayListProxy exten
     // If clearing the owner of this proxy, store away what is necessary for 
     // delayed loading 
     if (paramOpenJPAStateManager == null && paramInt == -1 && sm != null)
{
+        _detached = true;
         _delayedSm = sm;
         _delayedField = field;
+    } else {
+        _detached = false;
     }
     
     this.sm = paramOpenJPAStateManager;
@@ -427,4 +430,9 @@ public class DelayedArrayListProxy exten
   public OpenJPAStateManager getOwnerStateManager() {
     return _ownerSm;
   }
+  
+  @Override
+  public boolean isDetached() {
+      return _detached;
+  }
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedProxy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedProxy.java?rev=1308194&r1=1308193&r2=1308194&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedProxy.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedProxy.java Sun
Apr  1 20:23:47 2012
@@ -38,4 +38,6 @@ public interface DelayedProxy {
     OpenJPAStateManager getDelayedOwner();
     
     int getDelayedField();
+    
+    boolean isDetached();
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java?rev=1308194&r1=1308193&r2=1308194&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java
Sun Apr  1 20:23:47 2012
@@ -590,13 +590,13 @@ public class ProxyCollections 
             // If the broker assigned to this proxy is null, closed or no longer
             // manages the pc, produce a new one
             Broker broker = sm.getContext().getBroker();
-            if (broker == null || broker.isClosed() 
+            if (dProxy.isDetached() || broker == null || broker.isClosed() 
                 || (!broker.isClosed() && !broker.isPersistent(sm.getPersistenceCapable())))
{
                 state[0] = true;
                 broker = dProxy.getBroker();
                 ((StateManagerImpl)sm).setBroker((BrokerImpl)broker);
             }
-            if (sm.getPersistenceCapable().pcGetStateManager() == null) {
+            if (dProxy.isDetached() || sm.getPersistenceCapable().pcGetStateManager() ==
null) {
                 state[1] = true;
                 if (dProxy.getOwnerStateManager() != null) {
                     sm.getPersistenceCapable().pcReplaceStateManager(dProxy.getOwnerStateManager());



Mime
View raw message