openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r1331051 [1/5] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/util/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/ openjpa-...
Date Thu, 26 Apr 2012 19:53:51 GMT
Author: jrbauer
Date: Thu Apr 26 19:53:49 2012
New Revision: 1331051

URL: http://svn.apache.org/viewvc?rev=1331051&view=rev
Log:
OPENJPA-2165 Minor fixes, more proxy types, testcases, and doc udpates

Added:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedHashSetProxy.java   (with props)
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedHashSetProxy.java   (with props)
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedListProxy.java   (with props)
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedPriorityQueueProxy.java   (with props)
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedTreeSetProxy.java   (with props)
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedVectorProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Award.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Certification.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/DelayedProxyCollectionsTestCase.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IAccount.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IDepartment.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IEmployee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IMember.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IUserIdentity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Location.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Product.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Account.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Department.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Employee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Member.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxyDetachLite.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/UserIdentity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Account.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Department.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Employee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Member.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/TestDelayedHashSetProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/TestDelayedHashSetProxyDetachLite.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/UserIdentity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/Account.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/Department.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/Employee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/Member.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/TestDelayedLinkedHashSetProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/TestDelayedLinkedHashSetProxyDetachLite.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/lhset/UserIdentity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/Account.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/Department.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/Employee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/Member.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/TestDelayedLinkedListProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/TestDelayedLinkedListProxyDetachLite.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/llist/UserIdentity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/Account.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/Department.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/Employee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/Member.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/TestDelayedPriorityQueueProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/TestDelayedPriorityQueueProxyDetachLite.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/pqueue/UserIdentity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/Account.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/Department.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/Employee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/Member.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/TestDelayedTreeSetProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/TestDelayedTreeSetProxyDetachLite.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/tset/UserIdentity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/Account.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/Department.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/Employee.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/Member.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/TestDelayedVectorProxy.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/TestDelayedVectorProxyDetachLite.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/vec/UserIdentity.java   (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.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/ProxyManagerImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java?rev=1331051&r1=1331050&r2=1331051&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java Thu Apr 26 19:53:49 2012
@@ -1362,6 +1362,6 @@ public class FieldMapping
     
     @Override
     public boolean isDelayCapable() {
-        return (getOrderColumn() == null && super.isDelayCapable());
+        return (getOrderColumn() == null && !isInDefaultFetchGroup() && super.isDelayCapable());
     }
 }

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=1331051&r1=1331050&r2=1331051&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 Thu Apr 26 19:53:49 2012
@@ -29,410 +29,418 @@ import java.util.ListIterator;
 import org.apache.openjpa.kernel.AutoDetach;
 import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.kernel.DetachedStateManager;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
 
-public class DelayedArrayListProxy extends ArrayList
-  implements ProxyCollection, DelayedProxy
-{
-  private transient OpenJPAStateManager sm;
-  private transient OpenJPAStateManager _ownerSm;
-  private transient int field;
-  private transient CollectionChangeTracker changeTracker;
-  private transient Class<?> elementType;
-  private transient boolean _directAccess = false;
-  private transient BrokerFactory _brokerFactory = null;
-  private transient Broker _broker = null;
-  private transient OpenJPAStateManager _delayedSm;
-  private transient int _delayedField; 
-  private transient boolean _detached = false;
-  
-  public DelayedArrayListProxy()
-  {
-  }
-  
-  public DelayedArrayListProxy(Collection paramCollection)
-  {
-    super(paramCollection);
-  }
-
-  public DelayedArrayListProxy(int paramInt)
-  {
-    super(paramInt);
-  }
-
-  public void setOwner(OpenJPAStateManager paramOpenJPAStateManager, int paramInt)
-  {
-    // 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;
-    if (sm != null && sm.getPersistenceCapable() != null) {
-        _ownerSm = (OpenJPAStateManager) sm.getPersistenceCapable().pcGetStateManager();
-    }
-    this.field = paramInt;
-    if (sm != null && sm.getContext() != null) {
-        _brokerFactory = sm.getContext().getBroker().getBrokerFactory();
-    }
-  }
-  
-  public int getDelayedField() {
-      if (field == -1) {
-          return _delayedField;
-      }
-      return field;
-  }
-  
-  public OpenJPAStateManager getDelayedOwner() {
-      if (sm == null) {
-          return _delayedSm;
-      }
-      return sm;
-  }
-
-  public OpenJPAStateManager getOwner()
-  {
-    return sm;
-  }
-
-  public int getOwnerField()
-  {
-    return field;
-  }
-
-  public Object clone()
-  {
-    if (isDirectAccess()) {
-        return super.clone();
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    Proxy localProxy = (Proxy)super.clone();
-    localProxy.setOwner(null, 0);
-    return localProxy;
-  }
-
-  public ChangeTracker getChangeTracker()
-  {
-    return this.changeTracker;
-  }
-  
-  protected void setChangeTracker(CollectionChangeTracker ct) {
-      changeTracker = ct;
-  }
-
-  public Object copy(Object paramObject)
-  {
-    return new ArrayList((Collection)paramObject);
-  }
-
-  public Class getElementType()
-  {
-    return this.elementType;
-  }
-  
-  protected void setElementType(Class<?> elemType) {
-      elementType = elemType;
-  }
-
-  @Override
-  public ProxyCollection newInstance(Class paramClass, Comparator paramComparator, boolean paramBoolean1, 
-          boolean paramBoolean2)
-  {
-    DelayedArrayListProxy proxy = new DelayedArrayListProxy();
-    proxy.elementType = paramClass;
-    proxy.changeTracker = new DelayedCollectionChangeTrackerImpl(proxy, true, true, paramBoolean2);
-    return proxy;
-  }
-
-  public boolean add(Object paramObject)
-  {
-    if (_directAccess) {
-        return super.add(paramObject);
-    }
-    ProxyCollections.beforeAdd(this, paramObject);
-    boolean bool = super.add(paramObject);
-    return ProxyCollections.afterAdd(this, paramObject, bool);
-  }
-
-  public void add(int paramInt, Object paramObject)
-  {
-    if (!_directAccess) {
+/**
+ * ArrayList proxy with delay loading capability.  Allows non-indexed
+ * add and remove operations to occur on an unloaded collection.  Operations
+ * that require a load will trigger a load.
+ */
+@SuppressWarnings({"rawtypes","unchecked"})
+public class DelayedArrayListProxy extends ArrayList implements ProxyCollection, DelayedProxy {
+
+    private transient OpenJPAStateManager sm;
+    private transient int field;
+    private transient CollectionChangeTracker changeTracker;
+    private transient Class<?> elementType;
+    private transient OpenJPAStateManager _ownerSm;
+    private transient boolean _directAccess = false;
+    private transient BrokerFactory _brokerFactory = null;
+    private transient Broker _broker = null;
+    private transient OpenJPAStateManager _delayedSm;
+    private transient int _delayedField;
+    private transient boolean _detached = false;
+
+    public DelayedArrayListProxy() {
+    }
+
+    public DelayedArrayListProxy(Collection paramCollection) {
+        super(paramCollection);
+    }
+
+    public DelayedArrayListProxy(int paramInt) {
+        super(paramInt);
+    }
+
+    public void setOwner(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        // If clearing the owner of this proxy, store away what is necessary for
+        // delayed loading
+        if (sm != null && detaching(paramOpenJPAStateManager, paramInt)) {
+            _detached = true;
+            _delayedSm = sm;
+            _delayedField = field;
+        } else {
+            _detached = false;
+        }
+
+        this.sm = paramOpenJPAStateManager;
+        if (sm != null && sm.getPersistenceCapable() != null) {
+            _ownerSm = (OpenJPAStateManager) sm.getPersistenceCapable()
+                    .pcGetStateManager();
+        }
+        this.field = paramInt;
+        if (sm != null && sm.getContext() != null) {
+            _brokerFactory = sm.getContext().getBroker().getBrokerFactory();
+        }
+    }
+
+    private boolean detaching(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        if ((paramOpenJPAStateManager == null && paramInt == -1)
+                || (paramOpenJPAStateManager != null && paramOpenJPAStateManager instanceof DetachedStateManager)) {
+            return true;
+        }
+        return false;
+    }
+
+    public int getDelayedField() {
+        if (field == -1 || _detached) {
+            return _delayedField;
+        }
+        return field;
+    }
+
+    public OpenJPAStateManager getDelayedOwner() {
+        if (sm == null || _detached) {
+            return _delayedSm;
+        }
+        return sm;
+    }
+
+    public OpenJPAStateManager getOwner() {
+        return sm;
+    }
+
+    public int getOwnerField() {
+        return field;
+    }
+
+    public Object clone() {
+        if (isDirectAccess()) {
+            return super.clone();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Proxy localProxy = (Proxy) super.clone();
+        localProxy.setOwner(null, 0);
+        return localProxy;
+    }
+
+    public ChangeTracker getChangeTracker() {
+        return this.changeTracker;
+    }
+
+    protected void setChangeTracker(CollectionChangeTracker ct) {
+        changeTracker = ct;
+    }
+
+    public Object copy(Object paramObject) {
+        if (isDelayLoad()) {
+            load();
+        }
+        return new ArrayList((Collection) paramObject);
+    }
+
+    public Class getElementType() {
+        return this.elementType;
+    }
+
+    protected void setElementType(Class<?> elemType) {
+        elementType = elemType;
+    }
+
+    @Override
+    public ProxyCollection newInstance(Class paramClass,
+            Comparator paramComparator, boolean paramBoolean1,
+            boolean paramBoolean2) {
+        DelayedArrayListProxy proxy = new DelayedArrayListProxy();
+        proxy.elementType = paramClass;
+        proxy.changeTracker = new DelayedCollectionChangeTrackerImpl(proxy,
+                true, true, paramBoolean2);
+        return proxy;
+    }
+
+    public boolean add(Object paramObject) {
+        if (_directAccess) {
+            return super.add(paramObject);
+        }
+        ProxyCollections.beforeAdd(this, paramObject);
+        boolean bool = super.add(paramObject);
+        return ProxyCollections.afterAdd(this, paramObject, bool);
+    }
+
+    public void add(int paramInt, Object paramObject) {
+        if (!_directAccess) {
+            if (isDelayLoad()) {
+                load();
+            }
+        }
+        ProxyCollections.beforeAdd(this, paramInt, paramObject);
+        super.add(paramInt, paramObject);
+    }
+
+    public void clear() {
+        if (!_directAccess) {
+            if (isDelayLoad()) {
+                load();
+            }
+            ProxyCollections.beforeClear(this);
+        }
+        super.clear();
+    }
+
+    public boolean addAll(int paramInt, Collection paramCollection) {
+        if (isDelayLoad()) {
+            load();
+        }
+        return ProxyCollections.addAll(this, paramInt, paramCollection);
+    }
+
+    public boolean addAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.addAll(paramCollection);
+        }
+        return ProxyCollections.addAll(this, paramCollection);
+    }
+
+    public boolean remove(Object paramObject) {
+        if (_directAccess) {
+            return super.remove(paramObject);
+        }
+        ProxyCollections.beforeRemove(this, paramObject);
+        setDirectAccess(true);
+        boolean bool = super.remove(paramObject);
+        setDirectAccess(false);
+        return ProxyCollections.afterRemove(this, paramObject, bool);
+    }
+
+    public Object remove(int paramInt) {
+        if (_directAccess) {
+            return super.remove(paramInt);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeRemove(this, paramInt);
+        Object localObject = super.remove(paramInt);
+        return ProxyCollections.afterRemove(this, paramInt, localObject);
+    }
+
+    public Object set(int paramInt, Object paramObject) {
+        if (_directAccess) {
+            return super.set(paramInt, paramObject);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeSet(this, paramInt, paramObject);
+        Object localObject = super.set(paramInt, paramObject);
+        return ProxyCollections.afterSet(this, paramInt, paramObject,
+                localObject);
+    }
+
+    public Iterator iterator() {
+        if (_directAccess) {
+            return super.iterator();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Iterator localIterator = super.iterator();
+        return ProxyCollections.afterIterator(this, localIterator);
+    }
+
+    public ListIterator listIterator(int paramInt) {
+        if (_directAccess) {
+            return super.listIterator(paramInt);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ListIterator localListIterator = super.listIterator(paramInt);
+        return ProxyCollections.afterListIterator(this, paramInt,
+                localListIterator);
+    }
+
+    public ListIterator listIterator() {
+        if (_directAccess) {
+            return super.listIterator();
+        }
         if (isDelayLoad()) {
             load();
         }
+        ListIterator localListIterator = super.listIterator();
+        return ProxyCollections.afterListIterator(this, localListIterator);
     }
-    ProxyCollections.beforeAdd(this, paramInt, paramObject);
-    super.add(paramInt, paramObject);
-  }
-
-  public void clear()
-  {
-    if (!_directAccess) {
+
+    public boolean removeAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.removeAll(paramCollection);
+        }
+        return ProxyCollections.removeAll(this, paramCollection);
+    }
+
+    public boolean retainAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.retainAll(paramCollection);
+        }
         if (isDelayLoad()) {
             load();
         }
-        ProxyCollections.beforeClear(this); 
+        return ProxyCollections.retainAll(this, paramCollection);
     }
-    super.clear();
-  }
 
-  public boolean addAll(int paramInt, Collection paramCollection)
-  {
-    if (isDelayLoad()) {
-        load();
-    }
-    return ProxyCollections.addAll(this, paramInt, paramCollection);
-  }
-
-  public boolean addAll(Collection paramCollection)
-  {
-    if (_directAccess) {
-        return super.addAll(paramCollection);
-    }
-    return ProxyCollections.addAll(this, paramCollection);
-  }
-
-  public boolean remove(Object paramObject)
-  {
-      if (_directAccess) {
-          return super.remove(paramObject); 
-      }
-      ProxyCollections.beforeRemove(this, paramObject);
-      setDirectAccess(true);
-      boolean bool = super.remove(paramObject);
-      setDirectAccess(false);
-      return ProxyCollections.afterRemove(this, paramObject, bool);
-  }
-
-  public Object remove(int paramInt)
-  {
-    if (_directAccess) {
-        return super.remove(paramInt);
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    ProxyCollections.beforeRemove(this, paramInt);
-    Object localObject = super.remove(paramInt);
-    return ProxyCollections.afterRemove(this, paramInt, localObject);
-  }
-
-  public Object set(int paramInt, Object paramObject)
-  {
-    if (_directAccess) {
-        return super.set(paramInt, paramObject);
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    ProxyCollections.beforeSet(this, paramInt, paramObject);
-    Object localObject = super.set(paramInt, paramObject);
-    return ProxyCollections.afterSet(this, paramInt, paramObject, localObject);
-  }
-
-  public Iterator iterator()
-  {
-    if (_directAccess) {
-        return super.iterator();
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    Iterator localIterator = super.iterator();
-    return ProxyCollections.afterIterator(this, localIterator);
-  }
-
-  public ListIterator listIterator(int paramInt)
-  {
-    if (_directAccess) {
-        return super.listIterator(paramInt);
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    ListIterator localListIterator = super.listIterator(paramInt);
-    return ProxyCollections.afterListIterator(this, paramInt, localListIterator);
-  }
-
-  public ListIterator listIterator()
-  {
-    if (_directAccess) {
-        return super.listIterator();
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    ListIterator localListIterator = super.listIterator();
-    return ProxyCollections.afterListIterator(this, localListIterator);
-  }
-
-  public boolean removeAll(Collection paramCollection)
-  {
-    if (_directAccess) {
-        return super.removeAll(paramCollection);
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    return ProxyCollections.removeAll(this, paramCollection);
-  }
-
-  public boolean retainAll(Collection paramCollection)
-  {
-    if (_directAccess) {
-        return super.retainAll(paramCollection);
-    }
-    if (isDelayLoad()) {
-        load();
-    }
-    return ProxyCollections.retainAll(this, paramCollection);
-  }
-
-  protected Object writeReplace()
-    throws ObjectStreamException
-  {
-    if (isDelayLoad()) {
-        load();
-    }
-    return Proxies.writeReplace(this, true);
-  }
-
-  public boolean isDelayLoad() {
-      return ProxyCollections.isDelayed(this);
-    }
-  
-  @Override
-  public Object get(int location) {
-    if (!_directAccess && isDelayLoad()) {
-        load();
-    }
-    return super.get(location);
-  }
-
-
-@Override
-  public int indexOf(Object object) {
-    if (!_directAccess && isDelayLoad()) {
-        load();
-    }
-    return super.indexOf(object);
-  }
-
-  @Override
-  public int lastIndexOf(Object object) {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-    return super.lastIndexOf(object);
-  }
-
-  @Override
-  public List subList(int start, int end) {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-      return super.subList(start, end);
-  }
-
-  @Override
-  public boolean contains(Object object) {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-      return super.contains(object);
-  }
-
-  @Override
-  public boolean containsAll(Collection collection) {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-      return super.containsAll(collection);
-  }
-
-  @Override
-  public boolean isEmpty() {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-      return super.isEmpty();
-  }
-
-  @Override
-  public int size() {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-      return super.size();
-  }
-
-  @Override
-  public Object[] toArray() {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-      return super.toArray();
-  }
-
-  @Override
-  public Object[] toArray(Object[] array) {
-      if (!_directAccess && isDelayLoad()) {
-          load();
-      }
-      return super.toArray(array);
-  }
-
-  public boolean isDirectAccess() {
-      return _directAccess;
-  }
-  
-  public void setDirectAccess(boolean direct) {
-      _directAccess = direct;
-  }
-  
-  public BrokerFactory getBrokerFactory() {
-      return _brokerFactory;
-  }
-
-  @Override
-  public void load() {
-      ProxyCollections.loadCollection(this);
-  }
-
-  @Override
-  public Broker getBroker() {
-    if (_broker == null || _broker.isClosed()) {
-        if (_brokerFactory != null) {
-            _broker = _brokerFactory.newBroker();
-        }
-    }
-    return _broker;
-  }
-  
-  @Override
-  public void closeBroker() {
-      if (_broker != null && !_broker.isClosed()) {
-          _broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
-          _broker.close();
-          _broker = null;
-      }
-  }
-
-  @Override
-  public OpenJPAStateManager getOwnerStateManager() {
-    return _ownerSm;
-  }
-  
-  @Override
-  public boolean isDetached() {
-      return _detached;
-  }
+    protected Object writeReplace() throws ObjectStreamException {
+        if (isDelayLoad()) {
+            load();
+        }
+        return Proxies.writeReplace(this, true);
+    }
+
+    public boolean isDelayLoad() {
+        return ProxyCollections.isDelayed(this);
+    }
+
+    @Override
+    public Object get(int location) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.get(location);
+    }
+
+    @Override
+    public int indexOf(Object object) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.indexOf(object);
+    }
+
+    @Override
+    public int lastIndexOf(Object object) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.lastIndexOf(object);
+    }
+
+    @Override
+    public List subList(int start, int end) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.subList(start, end);
+    }
+
+    @Override
+    public boolean contains(Object object) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.contains(object);
+    }
+
+    @Override
+    public boolean containsAll(Collection collection) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.containsAll(collection);
+    }
+
+    @Override
+    public boolean isEmpty() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.isEmpty();
+    }
+
+    @Override
+    public int size() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.size();
+    }
+
+    @Override
+    public Object[] toArray() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray();
+    }
+
+    @Override
+    public Object[] toArray(Object[] array) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray(array);
+    }
+
+    public boolean equals(Object paramObject) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.equals(paramObject);
+    }
+
+    public int hashCode() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.hashCode();
+    }
+
+    public boolean isDirectAccess() {
+        return _directAccess;
+    }
+
+    public void setDirectAccess(boolean direct) {
+        _directAccess = direct;
+    }
+
+    public BrokerFactory getBrokerFactory() {
+        return _brokerFactory;
+    }
+
+    @Override
+    public void load() {
+        ProxyCollections.loadCollection(this);
+    }
+
+    @Override
+    public Broker getBroker() {
+        if (_broker == null || _broker.isClosed()) {
+            if (_brokerFactory != null) {
+                _broker = _brokerFactory.newBroker();
+            }
+        }
+        return _broker;
+    }
+
+    @Override
+    public void closeBroker() {
+        if (_broker != null && !_broker.isClosed()) {
+            _broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
+            _broker.close();
+            _broker = null;
+        }
+    }
+
+    @Override
+    public OpenJPAStateManager getOwnerStateManager() {
+        return _ownerSm;
+    }
+
+    @Override
+    public boolean isDetached() {
+        return _detached;
+    }
 }

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedHashSetProxy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedHashSetProxy.java?rev=1331051&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedHashSetProxy.java (added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedHashSetProxy.java Thu Apr 26 19:53:49 2012
@@ -0,0 +1,361 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.util;
+
+import java.io.ObjectStreamException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.apache.openjpa.kernel.AutoDetach;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.kernel.DetachedStateManager;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+
+/**
+ * HashSet proxy with delay loading capability. Allows non-indexed add and
+ * remove operations to occur on an unloaded collection. Operations that require
+ * a load will trigger a load.
+ */
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public class DelayedHashSetProxy extends HashSet implements DelayedProxy, ProxyCollection {
+
+    private transient OpenJPAStateManager sm;
+    private transient int field;
+    private transient CollectionChangeTracker changeTracker;
+    private transient Class<?> elementType;
+
+    private transient OpenJPAStateManager _ownerSm;
+    private transient boolean _directAccess = false;
+    private transient BrokerFactory _brokerFactory = null;
+    private transient Broker _broker = null;
+    private transient OpenJPAStateManager _delayedSm;
+    private transient int _delayedField;
+    private transient boolean _detached = false;
+
+    public DelayedHashSetProxy(Collection<?> paramCollection) {
+        super(paramCollection);
+    }
+
+    public DelayedHashSetProxy(int paramInt, float paramFloat) {
+        super(paramInt, paramFloat);
+    }
+
+    public DelayedHashSetProxy(int paramInt) {
+        super(paramInt);
+    }
+
+    public DelayedHashSetProxy() {
+    }
+
+    public void setOwner(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        // If clearing the owner of this proxy, store away what is necessary for
+        // delayed loading
+        if (sm != null && detaching(paramOpenJPAStateManager, paramInt)) {
+            _detached = true;
+            _delayedSm = sm;
+            _delayedField = field;
+        } else {
+            _detached = false;
+        }
+
+        this.sm = paramOpenJPAStateManager;
+        if (sm != null && sm.getPersistenceCapable() != null) {
+            _ownerSm = (OpenJPAStateManager) sm.getPersistenceCapable()
+                    .pcGetStateManager();
+        }
+        this.field = paramInt;
+        if (sm != null && sm.getContext() != null) {
+            _brokerFactory = sm.getContext().getBroker().getBrokerFactory();
+        }
+    }
+
+    private boolean detaching(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        if ((paramOpenJPAStateManager == null && paramInt == -1)
+                || (paramOpenJPAStateManager != null && paramOpenJPAStateManager instanceof DetachedStateManager)) {
+            return true;
+        }
+        return false;
+    }
+
+    public OpenJPAStateManager getOwner() {
+        return this.sm;
+    }
+
+    public int getOwnerField() {
+        return this.field;
+    }
+
+    public ChangeTracker getChangeTracker() {
+        return this.changeTracker;
+    }
+
+    @Override
+    public Object copy(Object paramObject) {
+        return new HashSet((Collection) paramObject);
+    }
+
+    public Class getElementType() {
+        return this.elementType;
+    }
+
+    public ProxyCollection newInstance(Class paramClass,
+            Comparator paramComparator, boolean paramBoolean1,
+            boolean paramBoolean2) {
+        DelayedHashSetProxy localproxy = new DelayedHashSetProxy();
+        localproxy.elementType = paramClass;
+        if (paramBoolean1)
+            localproxy.changeTracker = new DelayedCollectionChangeTrackerImpl(
+                    localproxy, false, false, paramBoolean2);
+        return localproxy;
+    }
+
+    @Override
+    public Object clone() {
+        if (isDirectAccess()) {
+            return super.clone();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Proxy localProxy = (Proxy) super.clone();
+        localProxy.setOwner(null, 0);
+        return localProxy;
+    }
+
+    @Override
+    public boolean add(Object paramObject) {
+        if (_directAccess) {
+            return super.add(paramObject);
+        }
+        ProxyCollections.beforeAdd(this, paramObject);
+        boolean bool = super.add(paramObject);
+        return ProxyCollections.afterAdd(this, paramObject, bool);
+    }
+
+    @Override
+    public void clear() {
+        if (!_directAccess) {
+            if (isDelayLoad()) {
+                load();
+            }
+            ProxyCollections.beforeClear(this);
+        }
+        super.clear();
+    }
+
+    @Override
+    public Iterator iterator() {
+        if (_directAccess) {
+            return super.iterator();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Iterator localIterator = super.iterator();
+        return ProxyCollections.afterIterator(this, localIterator);
+    }
+
+    @Override
+    public boolean remove(Object paramObject) {
+        if (_directAccess) {
+            return super.remove(paramObject);
+        }
+        ProxyCollections.beforeRemove(this, paramObject);
+        setDirectAccess(true);
+        boolean bool = super.remove(paramObject);
+        setDirectAccess(false);
+        return ProxyCollections.afterRemove(this, paramObject, bool);
+    }
+
+    @Override
+    public boolean removeAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.removeAll(paramCollection);
+        }
+        return ProxyCollections.removeAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean addAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.addAll(paramCollection);
+        }
+        return ProxyCollections.addAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean retainAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.retainAll(paramCollection);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        return ProxyCollections.retainAll(this, paramCollection);
+    }
+
+    protected Object writeReplace() throws ObjectStreamException {
+        if (isDelayLoad()) {
+            load();
+        }
+        return Proxies.writeReplace(this, true);
+    }
+
+    @Override
+    public int size() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.contains(o);
+    }
+
+    @Override
+    public Object[] toArray() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray();
+    }
+
+    @Override
+    public Object[] toArray(Object[] a) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray(a);
+    }
+
+    @Override
+    public boolean containsAll(Collection c) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.containsAll(c);
+    }
+
+    @Override
+    public String toString() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toString();
+    }
+
+    public boolean equals(Object paramObject) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.equals(paramObject);
+    }
+
+    public int hashCode() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.hashCode();
+    }
+
+    // //////////////////////////////////////
+    // DelayedProxy methods
+    // //////////////////////////////////////
+    public int getDelayedField() {
+        if (field == -1 || _detached) {
+            return _delayedField;
+        }
+        return field;
+    }
+
+    public OpenJPAStateManager getDelayedOwner() {
+        if (sm == null || _detached) {
+            return _delayedSm;
+        }
+        return sm;
+    }
+
+    public boolean isDirectAccess() {
+        return _directAccess;
+    }
+
+    public void setDirectAccess(boolean direct) {
+        _directAccess = direct;
+    }
+
+    public BrokerFactory getBrokerFactory() {
+        return _brokerFactory;
+    }
+
+    @Override
+    public void load() {
+        ProxyCollections.loadCollection(this);
+    }
+
+    @Override
+    public Broker getBroker() {
+        if (_broker == null || _broker.isClosed()) {
+            if (_brokerFactory != null) {
+                _broker = _brokerFactory.newBroker();
+            }
+        }
+        return _broker;
+    }
+
+    @Override
+    public void closeBroker() {
+        if (_broker != null && !_broker.isClosed()) {
+            _broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
+            _broker.close();
+            _broker = null;
+        }
+    }
+
+    @Override
+    public OpenJPAStateManager getOwnerStateManager() {
+        return _ownerSm;
+    }
+
+    @Override
+    public boolean isDetached() {
+        return _detached;
+    }
+
+    public boolean isDelayLoad() {
+        return ProxyCollections.isDelayed(this);
+    }
+}

Propchange: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedHashSetProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedHashSetProxy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedHashSetProxy.java?rev=1331051&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedHashSetProxy.java (added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedHashSetProxy.java Thu Apr 26 19:53:49 2012
@@ -0,0 +1,361 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.util;
+
+import java.io.ObjectStreamException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+
+import org.apache.openjpa.kernel.AutoDetach;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.kernel.DetachedStateManager;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+
+/**
+ * LinkedHashSet proxy with delay loading capability.  Allows non-indexed
+ * add and remove operations to occur on an unloaded collection.  Operations
+ * that require a load will trigger a load.
+ */
+@SuppressWarnings({"rawtypes","unchecked"})
+public class DelayedLinkedHashSetProxy extends LinkedHashSet implements DelayedProxy, ProxyCollection {
+    private transient OpenJPAStateManager sm;
+    private transient int field;
+    private transient CollectionChangeTracker changeTracker;
+    private transient Class<?> elementType;
+
+    private transient OpenJPAStateManager _ownerSm;
+    private transient boolean _directAccess = false;
+    private transient BrokerFactory _brokerFactory = null;
+    private transient Broker _broker = null;
+    private transient OpenJPAStateManager _delayedSm;
+    private transient int _delayedField;
+    private transient boolean _detached = false;
+
+    public DelayedLinkedHashSetProxy(Collection<?> paramCollection) {
+        super(paramCollection);
+    }
+
+    public DelayedLinkedHashSetProxy(int paramInt, float paramFloat) {
+        super(paramInt, paramFloat);
+    }
+
+    public DelayedLinkedHashSetProxy(int paramInt) {
+        super(paramInt);
+    }
+
+    public DelayedLinkedHashSetProxy() {
+    }
+
+    public void setOwner(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        // If clearing the owner of this proxy, store away what is necessary for
+        // delayed loading
+        if (sm != null && detaching(paramOpenJPAStateManager, paramInt)) {
+            _detached = true;
+            _delayedSm = sm;
+            _delayedField = field;
+        } else {
+            _detached = false;
+        }
+
+        this.sm = paramOpenJPAStateManager;
+        if (sm != null && sm.getPersistenceCapable() != null) {
+            _ownerSm = (OpenJPAStateManager) sm.getPersistenceCapable()
+                    .pcGetStateManager();
+        }
+        this.field = paramInt;
+        if (sm != null && sm.getContext() != null) {
+            _brokerFactory = sm.getContext().getBroker().getBrokerFactory();
+        }
+    }
+
+    private boolean detaching(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        if ((paramOpenJPAStateManager == null && paramInt == -1)
+                || (paramOpenJPAStateManager != null && paramOpenJPAStateManager instanceof DetachedStateManager)) {
+            return true;
+        }
+        return false;
+    }
+
+    public OpenJPAStateManager getOwner() {
+        return this.sm;
+    }
+
+    public int getOwnerField() {
+        return this.field;
+    }
+
+    public ChangeTracker getChangeTracker() {
+        return this.changeTracker;
+    }
+
+    @Override
+    public Object copy(Object paramObject) {
+        return new LinkedHashSet((Collection) paramObject);
+    }
+
+    public Class getElementType() {
+        return this.elementType;
+    }
+
+    public ProxyCollection newInstance(Class paramClass,
+            Comparator paramComparator, boolean paramBoolean1,
+            boolean paramBoolean2) {
+        DelayedLinkedHashSetProxy localproxy = new DelayedLinkedHashSetProxy();
+        localproxy.elementType = paramClass;
+        if (paramBoolean1)
+            localproxy.changeTracker = new DelayedCollectionChangeTrackerImpl(
+                    localproxy, false, false, paramBoolean2);
+        return localproxy;
+    }
+
+    @Override
+    public Object clone() {
+        if (isDirectAccess()) {
+            return super.clone();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Proxy localProxy = (Proxy) super.clone();
+        localProxy.setOwner(null, 0);
+        return localProxy;
+    }
+
+    @Override
+    public boolean add(Object paramObject) {
+        if (_directAccess) {
+            return super.add(paramObject);
+        }
+        ProxyCollections.beforeAdd(this, paramObject);
+        boolean bool = super.add(paramObject);
+        return ProxyCollections.afterAdd(this, paramObject, bool);
+    }
+
+    @Override
+    public void clear() {
+        if (!_directAccess) {
+            if (isDelayLoad()) {
+                load();
+            }
+            ProxyCollections.beforeClear(this);
+        }
+        super.clear();
+    }
+
+    @Override
+    public Iterator iterator() {
+        if (_directAccess) {
+            return super.iterator();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Iterator localIterator = super.iterator();
+        return ProxyCollections.afterIterator(this, localIterator);
+    }
+
+    @Override
+    public boolean remove(Object paramObject) {
+        if (_directAccess) {
+            return super.remove(paramObject);
+        }
+        ProxyCollections.beforeRemove(this, paramObject);
+        setDirectAccess(true);
+        boolean bool = super.remove(paramObject);
+        setDirectAccess(false);
+        return ProxyCollections.afterRemove(this, paramObject, bool);
+    }
+
+    @Override
+    public boolean removeAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.removeAll(paramCollection);
+        }
+        return ProxyCollections.removeAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean addAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.addAll(paramCollection);
+        }
+        return ProxyCollections.addAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean retainAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.retainAll(paramCollection);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        return ProxyCollections.retainAll(this, paramCollection);
+    }
+
+    protected Object writeReplace() throws ObjectStreamException {
+        if (isDelayLoad()) {
+            load();
+        }
+        return Proxies.writeReplace(this, true);
+    }
+
+    @Override
+    public int size() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.contains(o);
+    }
+
+    @Override
+    public Object[] toArray() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray();
+    }
+
+    @Override
+    public Object[] toArray(Object[] a) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray(a);
+    }
+
+    @Override
+    public boolean containsAll(Collection c) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.containsAll(c);
+    }
+
+    @Override
+    public String toString() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toString();
+    }
+
+    public boolean equals(Object paramObject) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.equals(paramObject);
+    }
+
+    public int hashCode() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.hashCode();
+    }
+
+    // //////////////////////////////////////
+    // DelayedProxy methods
+    // //////////////////////////////////////
+    public int getDelayedField() {
+        if (field == -1 || _detached) {
+            return _delayedField;
+        }
+        return field;
+    }
+
+    public OpenJPAStateManager getDelayedOwner() {
+        if (sm == null || _detached) {
+            return _delayedSm;
+        }
+        return sm;
+    }
+
+    public boolean isDirectAccess() {
+        return _directAccess;
+    }
+
+    public void setDirectAccess(boolean direct) {
+        _directAccess = direct;
+    }
+
+    public BrokerFactory getBrokerFactory() {
+        return _brokerFactory;
+    }
+
+    @Override
+    public void load() {
+        ProxyCollections.loadCollection(this);
+    }
+
+    @Override
+    public Broker getBroker() {
+        if (_broker == null || _broker.isClosed()) {
+            if (_brokerFactory != null) {
+                _broker = _brokerFactory.newBroker();
+            }
+        }
+        return _broker;
+    }
+
+    @Override
+    public void closeBroker() {
+        if (_broker != null && !_broker.isClosed()) {
+            _broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
+            _broker.close();
+            _broker = null;
+        }
+    }
+
+    @Override
+    public OpenJPAStateManager getOwnerStateManager() {
+        return _ownerSm;
+    }
+
+    @Override
+    public boolean isDetached() {
+        return _detached;
+    }
+
+    protected boolean isDelayLoad() {
+        return ProxyCollections.isDelayed(this);
+    }
+}

Propchange: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedHashSetProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedListProxy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedListProxy.java?rev=1331051&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedListProxy.java (added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedListProxy.java Thu Apr 26 19:53:49 2012
@@ -0,0 +1,701 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.util;
+
+import java.io.ObjectStreamException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.openjpa.kernel.AutoDetach;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.kernel.DetachedStateManager;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+
+/**
+ * LinkedList proxy with delay loading capability.  Allows non-indexed
+ * add and remove operations to occur on an unloaded collection.  Operations
+ * that require a load will trigger a load.
+ */
+@SuppressWarnings({"rawtypes","unchecked"})
+public class DelayedLinkedListProxy extends LinkedList implements ProxyCollection, DelayedProxy {
+
+    private transient OpenJPAStateManager sm;
+    private transient int field;
+    private transient CollectionChangeTracker changeTracker;
+    private transient Class elementType;
+
+    private transient OpenJPAStateManager _ownerSm;
+    private transient boolean _directAccess = false;
+    private transient BrokerFactory _brokerFactory = null;
+    private transient Broker _broker = null;
+    private transient OpenJPAStateManager _delayedSm;
+    private transient int _delayedField;
+    private transient boolean _detached = false;
+
+    public DelayedLinkedListProxy(Collection paramCollection) {
+        super(paramCollection);
+    }
+
+    public DelayedLinkedListProxy() {
+    }
+
+    @Override
+    public void setOwner(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        // If clearing the owner of this proxy, store away what is necessary for
+        // delayed loading
+        if (sm != null && detaching(paramOpenJPAStateManager, paramInt)) {
+            _detached = true;
+            _delayedSm = sm;
+            _delayedField = field;
+        } else {
+            _detached = false;
+        }
+
+        this.sm = paramOpenJPAStateManager;
+        if (sm != null && sm.getPersistenceCapable() != null) {
+            _ownerSm = (OpenJPAStateManager) sm.getPersistenceCapable()
+                    .pcGetStateManager();
+        }
+        this.field = paramInt;
+        if (sm != null && sm.getContext() != null) {
+            _brokerFactory = sm.getContext().getBroker().getBrokerFactory();
+        }
+    }
+
+    private boolean detaching(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        if ((paramOpenJPAStateManager == null && paramInt == -1)
+                || (paramOpenJPAStateManager != null && paramOpenJPAStateManager instanceof DetachedStateManager)) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public OpenJPAStateManager getOwner() {
+        return this.sm;
+    }
+
+    @Override
+    public int getOwnerField() {
+        return this.field;
+    }
+
+    @Override
+    public ChangeTracker getChangeTracker() {
+        return this.changeTracker;
+    }
+
+    @Override
+    public Object copy(Object paramObject) {
+        return new LinkedList((Collection) paramObject);
+    }
+
+    @Override
+    public Class getElementType() {
+        return this.elementType;
+    }
+
+    @Override
+    public ProxyCollection newInstance(Class paramClass,
+            Comparator paramComparator, boolean paramBoolean1,
+            boolean paramBoolean2) {
+        DelayedLinkedListProxy localproxy = new DelayedLinkedListProxy();
+        localproxy.elementType = paramClass;
+        if (paramBoolean1)
+            localproxy.changeTracker = new DelayedCollectionChangeTrackerImpl(
+                    localproxy, true, true, paramBoolean2);
+        return localproxy;
+    }
+
+    // //////////////////////////////////////
+    // DelayedProxy methods
+    // //////////////////////////////////////
+    @Override
+    public int getDelayedField() {
+        if (field == -1 || _detached) {
+            return _delayedField;
+        }
+        return field;
+    }
+
+    @Override
+    public OpenJPAStateManager getDelayedOwner() {
+        if (sm == null || _detached) {
+            return _delayedSm;
+        }
+        return sm;
+    }
+
+    @Override
+    public boolean isDirectAccess() {
+        return _directAccess;
+    }
+
+    @Override
+    public void setDirectAccess(boolean direct) {
+        _directAccess = direct;
+    }
+
+    public BrokerFactory getBrokerFactory() {
+        return _brokerFactory;
+    }
+
+    @Override
+    public void load() {
+        ProxyCollections.loadCollection(this);
+    }
+
+    @Override
+    public Broker getBroker() {
+        if (_broker == null || _broker.isClosed()) {
+            if (_brokerFactory != null) {
+                _broker = _brokerFactory.newBroker();
+            }
+        }
+        return _broker;
+    }
+
+    @Override
+    public void closeBroker() {
+        if (_broker != null && !_broker.isClosed()) {
+            _broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
+            _broker.close();
+            _broker = null;
+        }
+    }
+
+    @Override
+    public OpenJPAStateManager getOwnerStateManager() {
+        return _ownerSm;
+    }
+
+    @Override
+    public boolean isDetached() {
+        return _detached;
+    }
+
+    public boolean isDelayLoad() {
+        return ProxyCollections.isDelayed(this);
+    }
+
+    // //////////////////////////////////////
+    // Implementation method wrappers
+    // //////////////////////////////////////
+
+    @Override
+    public Object clone() {
+        if (_directAccess) {
+            return super.clone();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Proxy localProxy = (Proxy) super.clone();
+        localProxy.setOwner(null, 0);
+        return localProxy;
+    }
+
+    @Override
+    public void add(int paramInt, Object paramObject) {
+        if (!_directAccess) {
+            if (isDelayLoad()) {
+                load();
+            }
+        }
+        ProxyCollections.beforeAdd(this, paramInt, paramObject);
+        super.add(paramInt, paramObject);
+    }
+
+    @Override
+    public boolean add(Object paramObject) {
+        if (_directAccess) {
+            return super.add(paramObject);
+        }
+        ProxyCollections.beforeAdd(this, paramObject);
+        boolean bool = super.add(paramObject);
+        return ProxyCollections.afterAdd(this, paramObject, bool);
+    }
+
+    @Override
+    public void clear() {
+        if (!_directAccess) {
+            if (isDelayLoad()) {
+                load();
+            }
+            ProxyCollections.beforeClear(this);
+        }
+        super.clear();
+    }
+
+    @Override
+    public boolean addAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.addAll(paramCollection);
+        }
+        return ProxyCollections.addAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean addAll(int paramInt, Collection paramCollection) {
+        if (_directAccess) {
+            return super.addAll(paramInt, paramCollection);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        return ProxyCollections.addAll(this, paramInt, paramCollection);
+    }
+
+    @Override
+    public boolean remove(Object paramObject) {
+        if (_directAccess) {
+            return super.remove(paramObject);
+        }
+        ProxyCollections.beforeRemove(this, paramObject);
+        setDirectAccess(true);
+        boolean bool = super.remove(paramObject);
+        setDirectAccess(false);
+        return ProxyCollections.afterRemove(this, paramObject, bool);
+    }
+
+    @Override
+    public Object remove(int paramInt) {
+        if (_directAccess) {
+            return super.remove(paramInt);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeRemove(this, paramInt);
+        Object localObject = super.remove(paramInt);
+        return ProxyCollections.afterRemove(this, paramInt, localObject);
+    }
+
+    @Override
+    public Object remove() {
+        if (_directAccess) {
+            return super.remove();
+        }
+        // queue operations require proper ordering. the collection
+        // must be loaded in order to ensure order.
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeRemove(this);
+        Object localObject = super.remove();
+        return ProxyCollections.afterRemove(this, localObject);
+    }
+
+    @Override
+    public Object set(int paramInt, Object paramObject) {
+        if (_directAccess) {
+            return super.set(paramInt, paramObject);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeSet(this, paramInt, paramObject);
+        Object localObject = super.set(paramInt, paramObject);
+        return ProxyCollections.afterSet(this, paramInt, paramObject,
+                localObject);
+    }
+
+    @Override
+    public Object poll() {
+        if (_directAccess) {
+            return super.poll();
+        }
+        // queue operations require proper ordering. the collection
+        // must be loaded in order to ensure order.
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforePoll(this);
+        Object localObject = super.poll();
+        return ProxyCollections.afterPoll(this, localObject);
+    }
+
+    @Override
+    public ListIterator listIterator(int paramInt) {
+        if (_directAccess) {
+            return super.listIterator(paramInt);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ListIterator localListIterator = super.listIterator(paramInt);
+        return ProxyCollections.afterListIterator(this, paramInt,
+                localListIterator);
+    }
+
+    @Override
+    public void addFirst(Object paramObject) {
+        if (_directAccess) {
+            super.addFirst(paramObject);
+            return;
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeAddFirst(this, paramObject);
+        super.addFirst(paramObject);
+    }
+
+    @Override
+    public void addLast(Object paramObject) {
+        if (_directAccess) {
+            super.addLast(paramObject);
+            return;
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeAddLast(this, paramObject);
+        super.addLast(paramObject);
+        ProxyCollections.afterAddLast(this, paramObject);
+    }
+
+    @Override
+    public boolean offer(Object paramObject) {
+        if (_directAccess) {
+            return super.offer(paramObject);
+        }
+        ProxyCollections.beforeOffer(this, paramObject);
+        boolean bool = super.offer(paramObject);
+        return ProxyCollections.afterOffer(this, paramObject, bool);
+    }
+
+    @Override
+    public Object removeFirst() {
+        if (_directAccess) {
+            return super.removeFirst();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeRemoveFirst(this);
+        Object localObject = super.removeFirst();
+        return ProxyCollections.afterRemoveFirst(this, localObject);
+    }
+
+    @Override
+    public Object removeLast() {
+        if (_directAccess) {
+            return super.removeLast();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeRemoveLast(this);
+        Object localObject = super.removeLast();
+        return ProxyCollections.afterRemoveLast(this, localObject);
+    }
+
+    @Override
+    public Iterator iterator() {
+        if (_directAccess) {
+            return super.iterator();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Iterator localIterator = super.iterator();
+        return ProxyCollections.afterIterator(this, localIterator);
+    }
+
+    @Override
+    public ListIterator listIterator() {
+        if (_directAccess) {
+            return super.listIterator();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        ListIterator localListIterator = super.listIterator();
+        return ProxyCollections.afterListIterator(this, localListIterator);
+    }
+
+    @Override
+    public boolean removeAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.removeAll(paramCollection);
+        }
+        return ProxyCollections.removeAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean retainAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.retainAll(paramCollection);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        return ProxyCollections.retainAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean removeFirstOccurrence(Object paramObject) {
+        if (_directAccess) {
+            return super.removeFirstOccurrence(paramObject);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Proxies.dirty(this, true);
+        return super.removeFirstOccurrence(paramObject);
+    }
+
+    @Override
+    public boolean removeLastOccurrence(Object paramObject) {
+        if (_directAccess) {
+            return super.removeLastOccurrence(paramObject);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Proxies.dirty(this, true);
+        return super.removeLastOccurrence(paramObject);
+    }
+
+    protected Object writeReplace() throws ObjectStreamException {
+        if (isDelayLoad()) {
+            load();
+        }
+        return Proxies.writeReplace(this, true);
+    }
+
+    @Override
+    public boolean equals(Object paramObject) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.equals(paramObject);
+    }
+
+    @Override
+    public int hashCode() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.hashCode();
+    }
+
+    @Override
+    public List subList(int fromIndex, int toIndex) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.subList(fromIndex, toIndex);
+    }
+
+    @Override
+    public int lastIndexOf(Object o) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.lastIndexOf(o);
+    }
+
+    @Override
+    public int indexOf(Object o) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.indexOf(o);
+    }
+
+    @Override
+    public Object get(int index) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.get(index);
+    }
+
+    @Override
+    public boolean containsAll(Collection c) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.containsAll(c);
+    }
+
+    @Override
+    public Object[] toArray() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray();
+    }
+
+    @Override
+    public Object[] toArray(Object[] array) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray(array);
+    }
+
+    @Override
+    public boolean contains(Object object) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.contains(object);
+    }
+
+    @Override
+    public boolean isEmpty() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.isEmpty();
+    }
+
+    @Override
+    public int size() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.size();
+    }
+
+    @Override
+    public boolean offerFirst(Object paramObject) {
+        if (_directAccess) {
+            return super.offerFirst(paramObject);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        return super.offerFirst(paramObject);
+    }
+
+    @Override
+    public boolean offerLast(Object paramObject) {
+        if (_directAccess) {
+            return super.offerLast(paramObject);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        return super.offerLast(paramObject);
+    }
+
+    @Override
+    public Object pollFirst() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.pollFirst();
+        
+    }
+
+    @Override
+    public Object pollLast() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.pollLast();
+    }
+    
+    @Override
+    public Object getFirst() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.getFirst();        
+    }
+
+    @Override
+    public Object getLast() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.getLast();
+    }
+    
+    @Override
+    public Object peekFirst() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.peekFirst();
+    }
+    
+    @Override
+    public Object peekLast() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.peekLast();
+    }
+
+    @Override
+    public Object element() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.element();
+    }
+    
+    @Override
+    public Object peek() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.peek();
+    }
+    
+    @Override
+    public void push(Object o) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        super.push(o);
+    }
+    
+    @Override
+    public Object pop() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.pop();
+    }
+
+    @Override
+    public Iterator descendingIterator() {
+        if (_directAccess) {
+            return super.descendingIterator();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Iterator localIterator = super.descendingIterator();
+        return ProxyCollections.afterIterator(this, localIterator);
+    }
+}

Propchange: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedLinkedListProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedPriorityQueueProxy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedPriorityQueueProxy.java?rev=1331051&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedPriorityQueueProxy.java (added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedPriorityQueueProxy.java Thu Apr 26 19:53:49 2012
@@ -0,0 +1,429 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.util;
+
+import java.io.ObjectStreamException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.PriorityQueue;
+import java.util.SortedSet;
+
+import org.apache.openjpa.kernel.AutoDetach;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.kernel.DetachedStateManager;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+
+/**
+ * PriorityQueue proxy with delay loading capability.  Allows non-indexed
+ * add and remove operations to occur on an unloaded collection.  Operations
+ * that require a load will trigger a load.
+ */
+@SuppressWarnings({"rawtypes","unchecked"})
+public class DelayedPriorityQueueProxy extends PriorityQueue implements ProxyCollection, DelayedProxy {
+    private transient OpenJPAStateManager sm;
+    private transient int field;
+    private transient CollectionChangeTracker changeTracker;
+    private transient Class elementType;
+
+    private transient OpenJPAStateManager _ownerSm;
+    private transient boolean _directAccess = false;
+    private transient BrokerFactory _brokerFactory = null;
+    private transient Broker _broker = null;
+    private transient OpenJPAStateManager _delayedSm;
+    private transient int _delayedField;
+    private transient boolean _detached = false;
+
+    public DelayedPriorityQueueProxy(int paramInt) {
+        super(paramInt);
+    }
+
+    public DelayedPriorityQueueProxy(int paramInt, Comparator paramComparator) {
+        super(paramInt, paramComparator);
+    }
+
+    public DelayedPriorityQueueProxy(Collection paramCollection) {
+        super(paramCollection);
+    }
+
+    public DelayedPriorityQueueProxy(PriorityQueue paramPriorityQueue) {
+        super(paramPriorityQueue);
+    }
+
+    public DelayedPriorityQueueProxy(SortedSet paramSortedSet) {
+        super(paramSortedSet);
+    }
+
+    public DelayedPriorityQueueProxy() {
+    }
+
+    @Override
+    public void setOwner(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        // If clearing the owner of this proxy, store away what is necessary for
+        // delayed loading
+        if (sm != null && detaching(paramOpenJPAStateManager, paramInt)) {
+            _detached = true;
+            _delayedSm = sm;
+            _delayedField = field;
+        } else {
+            _detached = false;
+        }
+
+        this.sm = paramOpenJPAStateManager;
+        if (sm != null && sm.getPersistenceCapable() != null) {
+            _ownerSm = (OpenJPAStateManager) sm.getPersistenceCapable()
+                    .pcGetStateManager();
+        }
+        this.field = paramInt;
+        if (sm != null && sm.getContext() != null) {
+            _brokerFactory = sm.getContext().getBroker().getBrokerFactory();
+        }
+    }
+
+    private boolean detaching(OpenJPAStateManager paramOpenJPAStateManager,
+            int paramInt) {
+        if ((paramOpenJPAStateManager == null && paramInt == -1)
+                || (paramOpenJPAStateManager != null && paramOpenJPAStateManager instanceof DetachedStateManager)) {
+            return true;
+        }
+        return false;
+    }
+
+    public OpenJPAStateManager getOwner() {
+        return this.sm;
+    }
+
+    public int getOwnerField() {
+        return this.field;
+    }
+
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        if (_directAccess) {
+            return super.clone();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Proxy localProxy = (Proxy) super.clone();
+        localProxy.setOwner(null, 0);
+        return localProxy;
+    }
+
+    public ChangeTracker getChangeTracker() {
+        return this.changeTracker;
+    }
+
+    public Object copy(Object paramObject) {
+        return new PriorityQueue((PriorityQueue) paramObject);
+    }
+
+    public Class getElementType() {
+        return this.elementType;
+    }
+
+    public ProxyCollection newInstance(Class paramClass,
+            Comparator paramComparator, boolean paramBoolean1,
+            boolean paramBoolean2) {
+        DelayedPriorityQueueProxy localproxy = new DelayedPriorityQueueProxy();
+        localproxy.elementType = paramClass;
+        if (paramBoolean1)
+            localproxy.changeTracker = new DelayedCollectionChangeTrackerImpl(
+                    localproxy, true, false, paramBoolean2);
+        return localproxy;
+    }
+
+    @Override
+    public boolean add(Object paramObject) {
+        if (_directAccess) {
+            return super.add(paramObject);
+        }
+        ProxyCollections.beforeAdd(this, paramObject);
+        boolean bool = false;
+        try {
+            setDirectAccess(true);
+            bool = super.add(paramObject);
+        } finally {
+            setDirectAccess(false);
+        }
+        return ProxyCollections.afterAdd(this, paramObject, bool);
+    }
+
+    @Override
+    public void clear() {
+        if (!_directAccess) {
+            if (isDelayLoad()) {
+                load();
+            }
+            ProxyCollections.beforeClear(this);
+        }
+        super.clear();
+    }
+
+    @Override
+    public Iterator iterator() {
+        if (_directAccess) {
+            return super.iterator();
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        Iterator localIterator = super.iterator();
+        return ProxyCollections.afterIterator(this, localIterator);
+    }
+
+    @Override
+    public boolean remove(Object paramObject) {
+        if (_directAccess) {
+            return super.remove(paramObject);
+        }
+        ProxyCollections.beforeRemove(this, paramObject);
+        setDirectAccess(true);
+        boolean bool = super.remove(paramObject);
+        setDirectAccess(false);
+        return ProxyCollections.afterRemove(this, paramObject, bool);
+    }
+
+    @Override
+    public Object poll() {
+        if (_directAccess) {
+            return super.poll();
+        }
+        // queue operations require proper ordering. the collection
+        // must be loaded in order to ensure order.
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforePoll(this);
+        Object localObject = super.poll();
+        return ProxyCollections.afterPoll(this, localObject);
+    }
+
+    @Override
+    public boolean offer(Object paramObject) {
+        if (_directAccess) {
+            return super.offer(paramObject);
+        }
+        ProxyCollections.beforeOffer(this, paramObject);
+        boolean bool = super.offer(paramObject);
+        return ProxyCollections.afterOffer(this, paramObject, bool);
+    }
+
+    @Override
+    public boolean addAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.addAll(paramCollection);
+        }
+        return ProxyCollections.addAll(this, paramCollection);
+    }
+
+    @Override
+    public Object remove() {
+        if (_directAccess) {
+            return super.remove();
+        }
+        // queue operations require proper ordering. the collection
+        // must be loaded in order to ensure order.
+        if (isDelayLoad()) {
+            load();
+        }
+        ProxyCollections.beforeRemove(this);
+        Object localObject = super.remove();
+        return ProxyCollections.afterRemove(this, localObject);
+    }
+
+    @Override
+    public boolean removeAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.removeAll(paramCollection);
+        }
+        return ProxyCollections.removeAll(this, paramCollection);
+    }
+
+    @Override
+    public boolean retainAll(Collection paramCollection) {
+        if (_directAccess) {
+            return super.retainAll(paramCollection);
+        }
+        if (isDelayLoad()) {
+            load();
+        }
+        return ProxyCollections.retainAll(this, paramCollection);
+    }
+
+    protected Object writeReplace() throws ObjectStreamException {
+        if (isDelayLoad()) {
+            load();
+        }
+        return Proxies.writeReplace(this, true);
+    }
+
+    @Override
+    public int size() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object object) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.contains(object);
+    }
+
+    @Override
+    public Object[] toArray() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray();
+    }
+
+    @Override
+    public Object[] toArray(Object[] array) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.toArray(array);
+    }
+
+    @Override
+    public boolean containsAll(Collection c) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.containsAll(c);
+    }
+
+    @Override
+    public Object element() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.element();
+    }
+
+    @Override
+    public Object peek() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.peek();
+    }
+
+    @Override
+    public boolean equals(Object paramObject) {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.equals(paramObject);
+    }
+
+    @Override
+    public int hashCode() {
+        if (!_directAccess && isDelayLoad()) {
+            load();
+        }
+        return super.hashCode();
+    }
+
+    // //////////////////////////////////////
+    // DelayedProxy methods
+    // //////////////////////////////////////
+    @Override
+    public int getDelayedField() {
+        if (field == -1 || _detached) {
+            return _delayedField;
+        }
+        return field;
+    }
+
+    @Override
+    public OpenJPAStateManager getDelayedOwner() {
+        if (sm == null || _detached) {
+            return _delayedSm;
+        }
+        return sm;
+    }
+
+    @Override
+    public boolean isDirectAccess() {
+        return _directAccess;
+    }
+
+    @Override
+    public void setDirectAccess(boolean direct) {
+        _directAccess = direct;
+    }
+
+    public BrokerFactory getBrokerFactory() {
+        return _brokerFactory;
+    }
+
+    @Override
+    public void load() {
+        ProxyCollections.loadCollection(this);
+    }
+
+    @Override
+    public Broker getBroker() {
+        if (_broker == null || _broker.isClosed()) {
+            if (_brokerFactory != null) {
+                _broker = _brokerFactory.newBroker();
+            }
+        }
+        return _broker;
+    }
+
+    @Override
+    public void closeBroker() {
+        if (_broker != null && !_broker.isClosed()) {
+            _broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
+            _broker.close();
+            _broker = null;
+        }
+    }
+
+    @Override
+    public OpenJPAStateManager getOwnerStateManager() {
+        return _ownerSm;
+    }
+
+    @Override
+    public boolean isDetached() {
+        return _detached;
+    }
+
+    public boolean isDelayLoad() {
+        return ProxyCollections.isDelayed(this);
+    }
+}

Propchange: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/DelayedPriorityQueueProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message