From 4709f38ba23244ad1c876ccf16704ccfdb099b73 Mon Sep 17 00:00:00 2001 From: Maxim Solodovnik Date: Tue, 25 Sep 2018 15:16:54 +0000 Subject: [PATCH] [OPENJPA-2748] commons-collection is updated to most recent version git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1841941 13f79535-47bb-0310-9956-ffa450edef68 --- .gitignore | 2 + openjpa-features/src/main/feature/feature.xml | 2 +- .../openjpa/jdbc/sql/InformixDictionary.java | 3 +- .../apache/openjpa/jdbc/sql/SelectImpl.java | 2 +- .../openjpa/datacache/AbstractQueryCache.java | 7 +- .../datacache/QueryCacheStoreQuery.java | 2 +- .../apache/openjpa/enhance/PCRegistry.java | 7 +- .../apache/openjpa/enhance/Reflection.java | 15 +-- .../event/SingleJVMRemoteCommitProvider.java | 4 +- .../openjpa/kernel/AbstractBrokerFactory.java | 9 +- .../openjpa/kernel/AbstractStoreQuery.java | 2 +- .../apache/openjpa/kernel/AttachManager.java | 4 +- .../org/apache/openjpa/kernel/BrokerImpl.java | 19 ++-- .../openjpa/kernel/DelegatingQuery.java | 2 +- .../apache/openjpa/kernel/DetachManager.java | 6 +- .../org/apache/openjpa/kernel/ExtentImpl.java | 11 ++- .../apache/openjpa/kernel/ManagedCache.java | 3 +- .../apache/openjpa/kernel/QueryContext.java | 2 +- .../org/apache/openjpa/kernel/QueryImpl.java | 5 +- .../openjpa/kernel/QueryStatistics.java | 5 +- .../org/apache/openjpa/kernel/StoreQuery.java | 2 +- .../apache/openjpa/meta/FieldMetaData.java | 2 +- .../apache/openjpa/meta/ValueStrategies.java | 2 +- .../openjpa/util/AbstractChangeTracker.java | 6 +- .../util/AbstractLRSProxyCollection.java | 12 +-- .../openjpa/util/AbstractLRSProxyMap.java | 12 +-- .../openjpa/util/BlacklistClassResolver.java | 5 +- .../org/apache/openjpa/util/CacheMap.java | 11 ++- .../org/apache/openjpa/util/ImplHelper.java | 9 +- .../org/apache/openjpa/util/OpenJPAId.java | 3 +- openjpa-lib/pom.xml | 4 +- .../openjpa/lib/conf/Configurations.java | 13 ++- .../apache/openjpa/lib/conf/ObjectValue.java | 3 +- .../lib/rop/SoftRandomAccessResultList.java | 2 +- .../org/apache/openjpa/lib/util/LRUMap.java | 2 +- .../openjpa/lib/util/ReferenceHashMap.java | 96 ++++--------------- .../openjpa/lib/util/ReferenceHashSet.java | 32 ++----- .../apache/openjpa/lib/util/ReferenceMap.java | 5 - .../ConcurrentReferenceHashMap.java | 37 +++---- .../ConcurrentReferenceHashSet.java | 31 ++---- .../openjpa/lib/util/TestReferenceSet.java | 7 +- openjpa-persistence-jdbc/pom.xml | 4 +- .../jdbc/common/apps/HorizRelation.java | 12 ++- .../persistence/kernel/TestProxies2.java | 2 +- .../kernel/common/apps/ProxiesPC.java | 2 +- openjpa-project/assembly.xml | 3 +- openjpa-project/bin-assembly.xml | 3 +- pom.xml | 6 +- 48 files changed, 175 insertions(+), 265 deletions(-) diff --git a/.gitignore b/.gitignore index 334886a99..64d12b7f0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ target velocity.log derby.log *.iml +dependency-reduced-pom.xml + diff --git a/openjpa-features/src/main/feature/feature.xml b/openjpa-features/src/main/feature/feature.xml index 96f771f2a..4acc18825 100644 --- a/openjpa-features/src/main/feature/feature.xml +++ b/openjpa-features/src/main/feature/feature.xml @@ -26,7 +26,7 @@ mvn:org.apache.geronimo.specs/geronimo-el_1.0_spec/1.0.1 mvn:org.apache.commons/commons-pool2/2.6.0 mvn:org.apache.commons/commons-dbcp2/2.5.0 - mvn:commons-collections/commons-collections/3.2.2 + mvn:commons-collections/commons-collections4/4.3 mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.serp/1.14.1_1 mvn:org.apache.xbean/xbean-asm6-shaded/4.9 mvn:org.apache.openjpa/openjpa/${project.version} diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InformixDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InformixDictionary.java index bf6016ced..10ef1de6d 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InformixDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/InformixDictionary.java @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.Map; import java.util.Set; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.jdbc.identifier.DBIdentifier; import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; import org.apache.openjpa.jdbc.kernel.exps.FilterValue; @@ -84,7 +85,7 @@ public class InformixDictionary protected boolean useJCC = false; // weak set of connections we've already executed lock mode sql on private final Collection _seenConnections = Collections.synchronizedSet( - new ReferenceHashSet(ReferenceHashSet.WEAK)); + new ReferenceHashSet(ReferenceStrength.WEAK)); public boolean disableRetainUpdateLocksSQL=false; diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java index 9fd833cd3..6f9456ae8 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java @@ -38,7 +38,7 @@ import java.util.SortedMap; import java.util.Stack; import java.util.TreeMap; -import org.apache.commons.collections.iterators.EmptyIterator; +import org.apache.commons.collections4.iterators.EmptyIterator; import org.apache.openjpa.lib.util.StringUtil; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.kernel.EagerFetchModes; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java index 160720bd6..3561f58f1 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.event.RemoteCommitEvent; import org.apache.openjpa.event.RemoteCommitListener; @@ -397,7 +398,7 @@ public abstract class AbstractQueryCache * the only reference is held by the list of expiration listeners. */ protected Collection newListenerCollection() { - return new ConcurrentReferenceHashSet (ConcurrentReferenceHashSet.WEAK); + return new ConcurrentReferenceHashSet(ReferenceStrength.WEAK); } /** @@ -493,12 +494,12 @@ public abstract class AbstractQueryCache private void initializeMaps() { ConcurrentReferenceHashMap statsMap = - new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); + new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR); statsMap.setMaxSize(FIXED_SIZE); stats = statsMap; ConcurrentReferenceHashMap aStatsMap = - new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); + new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR); aStatsMap.setMaxSize(FIXED_SIZE); astats = aStatsMap; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java index a7026c541..602a942c1 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java @@ -30,7 +30,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; -import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.collections4.map.LinkedMap; import org.apache.openjpa.datacache.AbstractQueryCache.EvictPolicy; import org.apache.openjpa.kernel.FetchConfiguration; import org.apache.openjpa.kernel.LockLevels; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java index 2149441b5..c3f61a841 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; @@ -40,14 +41,14 @@ public class PCRegistry { private static final Localizer _loc = Localizer.forPackage(PCRegistry.class); // map of persistent classes to meta structures; weak so the VM can GC classes - private static final Map,Meta> _metas = new ConcurrentReferenceHashMap(ReferenceMap.WEAK, - ReferenceMap.HARD); + private static final Map,Meta> _metas = new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, + ReferenceStrength.HARD); // register class listeners // Weak reference prevents OutOfMemeoryError as described in OPENJPA-2042 private static final Collection _listeners = new ConcurrentReferenceHashSet( - ConcurrentReferenceHashSet.WEAK); + ReferenceStrength.WEAK); /** * Register a {@link RegisterClassListener}. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/Reflection.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/Reflection.java index 4bf522ba1..6cbe14ef5 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/Reflection.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/Reflection.java @@ -30,6 +30,7 @@ import java.util.Set; import java.util.TreeSet; import org.apache.openjpa.lib.util.StringUtil; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.J2DoPrivHelper; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.ReferenceMap; @@ -52,11 +53,11 @@ public class Reflection { // Weak HashMap caches of getter/setter/beanProperty methods private static Map, Map> getterMethodCache = - new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); + new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD); private static Map, Map> setterMethodCache = - new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); + new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD); private static Map, Set> beanPropertiesNameCache = - new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); + new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD); private static Method getGetterMethod(Class cls, String prop) { Method rtnMethod = null; @@ -71,8 +72,8 @@ public class Reflection { Method method) { Map clsMap = getterMethodCache.get(cls); if (clsMap == null) { - clsMap = new ConcurrentReferenceHashMap(ReferenceMap.HARD, - ReferenceMap.WEAK); + clsMap = new ConcurrentReferenceHashMap(ReferenceStrength.HARD, + ReferenceStrength.WEAK); getterMethodCache.put(cls, clsMap); } clsMap.put(prop, method); @@ -91,8 +92,8 @@ public class Reflection { Method method) { Map clsMap = setterMethodCache.get(cls); if (clsMap == null) { - clsMap = new ConcurrentReferenceHashMap(ReferenceMap.HARD, - ReferenceMap.WEAK); + clsMap = new ConcurrentReferenceHashMap(ReferenceStrength.HARD, + ReferenceStrength.WEAK); setterMethodCache.put(cls, clsMap); } clsMap.put(prop, method); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/event/SingleJVMRemoteCommitProvider.java b/openjpa-kernel/src/main/java/org/apache/openjpa/event/SingleJVMRemoteCommitProvider.java index b796f26cf..ac136ad55 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/event/SingleJVMRemoteCommitProvider.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/event/SingleJVMRemoteCommitProvider.java @@ -21,6 +21,7 @@ package org.apache.openjpa.event; import java.util.Iterator; import java.util.Set; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet; /** @@ -37,8 +38,7 @@ import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet; public class SingleJVMRemoteCommitProvider extends AbstractRemoteCommitProvider { - private static Set s_providers = new ConcurrentReferenceHashSet( - ConcurrentReferenceHashSet.HARD); + private static Set s_providers = new ConcurrentReferenceHashSet(ReferenceStrength.HARD); public SingleJVMRemoteCommitProvider() { s_providers.add(this); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java index ff6f67c83..8cc2daced 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java @@ -39,7 +39,8 @@ import javax.transaction.Synchronization; import javax.transaction.Transaction; import javax.transaction.TransactionManager; -import org.apache.commons.collections.set.MapBackedSet; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; +import org.apache.commons.collections4.set.MapBackedSet; import org.apache.openjpa.lib.util.StringUtil; import org.apache.openjpa.audit.Auditor; import org.apache.openjpa.conf.BrokerValue; @@ -489,9 +490,9 @@ public abstract class AbstractBrokerFactory bv = (BrokerValue) _conf.getValue(BrokerValue.KEY); if (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf))) { - return MapBackedSet.decorate(new ConcurrentHashMap(), new Object() { }); + return MapBackedSet.mapBackedSet(new ConcurrentHashMap(), new Object() { }); } else { - return new ConcurrentReferenceHashSet(ConcurrentReferenceHashSet.WEAK); + return new ConcurrentReferenceHashSet(ReferenceStrength.WEAK); } } @@ -829,7 +830,7 @@ public abstract class AbstractBrokerFactory */ private Collection getPcClassLoaders() { if (_pcClassLoaders == null) - _pcClassLoaders = new ConcurrentReferenceHashSet(ConcurrentReferenceHashSet.WEAK); + _pcClassLoaders = new ConcurrentReferenceHashSet(ReferenceStrength.WEAK); return _pcClassLoaders; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractStoreQuery.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractStoreQuery.java index 2638fd52a..92a55368a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractStoreQuery.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractStoreQuery.java @@ -20,7 +20,7 @@ package org.apache.openjpa.kernel; import java.util.Map; -import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.collections4.map.LinkedMap; import org.apache.openjpa.datacache.DataCache; import org.apache.openjpa.kernel.exps.AggregateListener; import org.apache.openjpa.kernel.exps.FilterListener; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java index 0f40ab38a..188eec63d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.collections.map.IdentityMap; +import java.util.IdentityHashMap; import org.apache.openjpa.enhance.PersistenceCapable; import org.apache.openjpa.event.CallbackModes; import org.apache.openjpa.event.LifecycleEvent; @@ -59,7 +59,7 @@ public class AttachManager { private final OpCallbacks _call; private final boolean _copyNew; private final boolean _failFast; - private final IdentityMap _attached = new IdentityMap(); + private final IdentityHashMap _attached = new IdentityHashMap(); private final Collection _visitedNodes = new ArrayList(); // reusable strategies diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java index e429fce18..3a1207b86 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java @@ -44,9 +44,10 @@ import java.util.concurrent.locks.ReentrantLock; import javax.transaction.Status; import javax.transaction.Synchronization; -import org.apache.commons.collections.iterators.IteratorChain; -import org.apache.commons.collections.map.LinkedMap; -import org.apache.commons.collections.set.MapBackedSet; +import org.apache.commons.collections4.iterators.IteratorChain; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; +import org.apache.commons.collections4.map.LinkedMap; +import org.apache.commons.collections4.set.MapBackedSet; import org.apache.openjpa.lib.util.StringUtil; import org.apache.openjpa.conf.Compatibility; import org.apache.openjpa.conf.OpenJPAConfiguration; @@ -404,7 +405,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl private void initializeOperatingSet() { if(_operatingDirty) { _operatingDirty = false; - _operating = MapBackedSet.decorate(new IdentityHashMap()); + _operating = MapBackedSet.mapBackedSet(new IdentityHashMap()); } } @@ -430,7 +431,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl * {@link ReferenceMap} with soft values. */ protected Map newManagedObjectCache() { - return new ReferenceHashMap(ReferenceMap.HARD, ReferenceMap.SOFT); + return new ReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.SOFT); } ////////////////////////////////// @@ -3749,7 +3750,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl try { ExtentImpl extent = new ExtentImpl(this, type, subclasses, fetch); if (_extents == null) - _extents = new ReferenceHashSet(ReferenceHashSet.WEAK); + _extents = new ReferenceHashSet(ReferenceStrength.WEAK); _extents.add(extent); return extent; @@ -3800,7 +3801,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl // track queries if (_queries == null) - _queries = new ReferenceHashSet(ReferenceHashSet.WEAK); + _queries = new ReferenceHashSet(ReferenceStrength.WEAK); _queries.add(q); return q; } catch (OpenJPAException ke) { @@ -4906,7 +4907,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl private boolean addCleanInternal(StateManagerImpl sm) { if (_clean == null) - _clean = new ReferenceHashSet(ReferenceHashSet.SOFT); + _clean = new ReferenceHashSet(ReferenceStrength.SOFT); return _clean.add(sm); } @@ -4916,7 +4917,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl public void addDirty(StateManagerImpl sm) { if (_dirty == null) { if (_orderDirty) - _dirty = MapBackedSet.decorate(new LinkedMap()); + _dirty = MapBackedSet.mapBackedSet(new LinkedMap()); else _dirty = new HashSet(); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingQuery.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingQuery.java index 316fb1ae4..e2a678242 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingQuery.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingQuery.java @@ -21,7 +21,7 @@ package org.apache.openjpa.kernel; import java.util.Collection; import java.util.Map; -import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.collections4.map.LinkedMap; import org.apache.openjpa.kernel.exps.AggregateListener; import org.apache.openjpa.kernel.exps.FilterListener; import org.apache.openjpa.lib.util.OrderedMap; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java index ab9638688..9f777e9a2 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java @@ -33,7 +33,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.apache.commons.collections.map.IdentityMap; +import java.util.IdentityHashMap; import org.apache.openjpa.conf.Compatibility; import org.apache.openjpa.conf.DetachOptions; import org.apache.openjpa.enhance.PersistenceCapable; @@ -75,7 +75,7 @@ public class DetachManager // if we're not detaching full, we need to track all detached objects; // if we are, then we use a special field manager for more efficient // detachment than the standard one - private final IdentityMap _detached; + private final IdentityHashMap _detached; private final DetachFieldManager _fullFM; /** @@ -279,7 +279,7 @@ public class DetachManager _detached = null; _fullFM = new DetachFieldManager(); } else { - _detached = new IdentityMap(); + _detached = new IdentityHashMap(); _fullFM = null; } Compatibility compatibility = diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExtentImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExtentImpl.java index ea14985d5..690941971 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExtentImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExtentImpl.java @@ -23,9 +23,10 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; -import org.apache.commons.collections.Predicate; -import org.apache.commons.collections.iterators.FilterIterator; -import org.apache.commons.collections.iterators.IteratorChain; +import org.apache.commons.collections4.Predicate; +import org.apache.commons.collections4.iterators.FilterIterator; +import org.apache.commons.collections4.iterators.IteratorChain; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.rop.ResultObjectProvider; import org.apache.openjpa.lib.rop.ResultObjectProviderIterator; import org.apache.openjpa.lib.util.Closeable; @@ -156,7 +157,7 @@ public class ExtentImpl lock(); try { if (_openItrs == null) - _openItrs = new ReferenceHashSet(ReferenceHashSet.WEAK); + _openItrs = new ReferenceHashSet(ReferenceStrength.WEAK); _openItrs.add(citr); } finally { unlock(); @@ -263,7 +264,7 @@ public class ExtentImpl } _closed = true; - for (Iterator itr = getIterators().iterator(); itr.hasNext();) + for (Iterator itr = this; itr.hasNext();) ((Closeable) itr.next()).close(); } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ManagedCache.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ManagedCache.java index de4f2a01c..ae1b6777e 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ManagedCache.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ManagedCache.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.ReferenceHashSet; import org.apache.openjpa.util.Exceptions; @@ -105,7 +106,7 @@ class ManagedCache implements Serializable { if (!sm.isPersistent() || sm.isEmbedded()) { if (_embeds == null) - _embeds = new ReferenceHashSet(ReferenceHashSet.WEAK); + _embeds = new ReferenceHashSet(ReferenceStrength.WEAK); _embeds.add(sm); return; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryContext.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryContext.java index 1869b541d..3058e94f8 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryContext.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryContext.java @@ -21,7 +21,7 @@ package org.apache.openjpa.kernel; import java.util.Collection; import java.util.Map; -import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.collections4.map.LinkedMap; import org.apache.openjpa.kernel.exps.AggregateListener; import org.apache.openjpa.kernel.exps.Constant; import org.apache.openjpa.kernel.exps.FilterListener; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java index 6cde7952e..c7f2d54c3 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java @@ -32,7 +32,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.locks.ReentrantLock; -import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; +import org.apache.commons.collections4.map.LinkedMap; import java.util.Objects; import org.apache.openjpa.lib.util.StringUtil; @@ -129,7 +130,7 @@ public class QueryImpl // remember the list of all the results we have returned so we // can free their resources when close or closeAll is called private transient final Collection _resultLists = - new ReferenceHashSet(ReferenceHashSet.WEAK); + new ReferenceHashSet(ReferenceStrength.WEAK); private boolean _printParameters = false; /** diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java index 40eec08aa..40eb9da8d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java @@ -25,6 +25,7 @@ import java.util.Date; import java.util.Map; import java.util.Set; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; @@ -165,12 +166,12 @@ public interface QueryStatistics extends Serializable { private void initializeMaps() { ConcurrentReferenceHashMap statsMap = - new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); + new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR); statsMap.setMaxSize(FIXED_SIZE); stats = statsMap; ConcurrentReferenceHashMap aStatsMap = - new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); + new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR); aStatsMap.setMaxSize(FIXED_SIZE); astats = aStatsMap; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java index 204d6a331..dda30449b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java @@ -22,7 +22,7 @@ import java.io.Serializable; import java.util.Iterator; import java.util.Map; -import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.collections4.map.LinkedMap; import org.apache.openjpa.kernel.exps.AggregateListener; import org.apache.openjpa.kernel.exps.Constant; import org.apache.openjpa.kernel.exps.FilterListener; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java index acdc01814..d993f7f19 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java @@ -45,7 +45,7 @@ import java.util.Properties; import java.util.Set; import java.util.TimeZone; -import org.apache.commons.collections.comparators.ComparatorChain; +import org.apache.commons.collections4.comparators.ComparatorChain; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.kernel.OpenJPAStateManager; import org.apache.openjpa.kernel.StoreContext; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java index 18fa7d91f..70eaccdbd 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java @@ -18,7 +18,7 @@ */ package org.apache.openjpa.meta; -import org.apache.commons.collections.bidimap.TreeBidiMap; +import org.apache.commons.collections4.bidimap.TreeBidiMap; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.StringDistance; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractChangeTracker.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractChangeTracker.java index dd9c71a27..5f412514d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractChangeTracker.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractChangeTracker.java @@ -24,7 +24,7 @@ import java.util.HashSet; import java.util.IdentityHashMap; import java.util.Set; -import org.apache.commons.collections.set.MapBackedSet; +import org.apache.commons.collections4.set.MapBackedSet; /** * Base class that provides utilities to change trackers. @@ -186,7 +186,7 @@ public abstract class AbstractChangeTracker */ protected Set newSet() { if (_identity == Boolean.TRUE) - return MapBackedSet.decorate(new IdentityHashMap()); + return MapBackedSet.mapBackedSet(new IdentityHashMap()); return new HashSet(); } @@ -220,7 +220,7 @@ public abstract class AbstractChangeTracker if (identity && cur instanceof HashSet) { if (cur.isEmpty()) return null; - Set replace = MapBackedSet.decorate(new IdentityHashMap()); + Set replace = MapBackedSet.mapBackedSet(new IdentityHashMap()); replace.addAll(cur); return replace; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyCollection.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyCollection.java index f8eb1057b..f94c6a58a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyCollection.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyCollection.java @@ -26,9 +26,9 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.Set; -import org.apache.commons.collections.Predicate; -import org.apache.commons.collections.iterators.FilterIterator; -import org.apache.commons.collections.iterators.IteratorChain; +import org.apache.commons.collections4.Predicate; +import org.apache.commons.collections4.iterators.FilterIterator; +import org.apache.commons.collections4.iterators.IteratorChain; import org.apache.openjpa.kernel.OpenJPAStateManager; import org.apache.openjpa.lib.util.Closeable; import org.apache.openjpa.lib.util.Localizer; @@ -410,10 +410,8 @@ public abstract class AbstractLRSProxyCollection if (_state != OPEN) return; - List itrs = _itr.getIterators(); - Iterator itr; - for (int i = 0; i < itrs.size(); i++) { - itr = (Iterator) itrs.get(i); + for (Iterator itr = _itr; itr.hasNext();) { + itr.next(); if (itr instanceof FilterIterator) itr = ((FilterIterator) itr).getIterator(); ImplHelper.close(itr); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyMap.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyMap.java index b87388b79..7b7c7aad9 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyMap.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/AbstractLRSProxyMap.java @@ -30,9 +30,9 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; -import org.apache.commons.collections.Predicate; -import org.apache.commons.collections.iterators.FilterIterator; -import org.apache.commons.collections.iterators.IteratorChain; +import org.apache.commons.collections4.Predicate; +import org.apache.commons.collections4.iterators.FilterIterator; +import org.apache.commons.collections4.iterators.IteratorChain; import org.apache.openjpa.kernel.OpenJPAStateManager; import org.apache.openjpa.lib.util.Closeable; import org.apache.openjpa.lib.util.Localizer; @@ -507,10 +507,8 @@ public abstract class AbstractLRSProxyMap if (_state != OPEN) return; - List itrs = _itr.getIterators(); - Iterator itr; - for (int i = 0; i < itrs.size(); i++) { - itr = (Iterator) itrs.get(i); + for (Iterator itr = _itr; itr.hasNext();) { + itr.next(); if (itr instanceof FilterIterator) itr = ((FilterIterator) itr).getIterator(); ImplHelper.close(itr); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java index a7e3c37b3..7e689db1b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/BlacklistClassResolver.java @@ -22,7 +22,7 @@ public class BlacklistClassResolver { public static final BlacklistClassResolver DEFAULT = new BlacklistClassResolver( toArray(System.getProperty( "openjpa.serialization.class.blacklist", - "org.codehaus.groovy.runtime.,org.apache.commons.collections.functors.,org.apache.xalan")), + "org.codehaus.groovy.runtime.,org.apache.commons.collections4.functors.,org.apache.xalan")), toArray(System.getProperty("openjpa.serialization.class.whitelist"))); private final String[] blacklist; @@ -59,6 +59,3 @@ public class BlacklistClassResolver { return false; } } - - - diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/CacheMap.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/CacheMap.java index 120e19125..fd6c90585 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/CacheMap.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/CacheMap.java @@ -26,9 +26,10 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; -import org.apache.commons.collections.Predicate; -import org.apache.commons.collections.iterators.FilterIterator; -import org.apache.commons.collections.iterators.IteratorChain; +import org.apache.commons.collections4.Predicate; +import org.apache.commons.collections4.iterators.FilterIterator; +import org.apache.commons.collections4.iterators.IteratorChain; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.LRUMap; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.SizedMap; @@ -112,8 +113,8 @@ public class CacheMap if (size < 0) size = 500; - softMap = new ConcurrentReferenceHashMap(ReferenceMap.HARD, - ReferenceMap.SOFT, size, load) { + softMap = new ConcurrentReferenceHashMap(ReferenceStrength.HARD, + ReferenceStrength.SOFT, size, load) { public void overflowRemoved(Object key, Object value) { softMapOverflowRemoved(key, value); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java index 0b5767b5e..649bb330b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java @@ -46,6 +46,7 @@ import org.apache.openjpa.meta.FieldMetaData; import org.apache.openjpa.meta.JavaTypes; import org.apache.openjpa.meta.SequenceMetaData; import org.apache.openjpa.meta.ValueStrategies; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.conf.OpenJPAConfiguration; /** @@ -58,11 +59,11 @@ public class ImplHelper { // Cache for from/to type assignments private static final Map _assignableTypes = - new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); + new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD); // map of all new unenhanced instances active in this classloader public static final Map _unenhancedInstanceMap = - new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD) { + new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD) { protected boolean eq(Object x, Object y) { // the Entries in ConcurrentReferenceHashMap delegate back to @@ -252,8 +253,8 @@ public class ImplHelper { Boolean isAssignable = null; Map assignableTo = (Map) _assignableTypes.get(from); if (assignableTo == null) { // "to" cache doesn't exist, so create it... - assignableTo = new ConcurrentReferenceHashMap(ReferenceMap.WEAK, - ReferenceMap.HARD); + assignableTo = new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, + ReferenceStrength.HARD); _assignableTypes.put(from, assignableTo); } else { // "to" cache exists... isAssignable = (Boolean) assignableTo.get(to); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java index e5237d915..c525dbc9f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java @@ -20,6 +20,7 @@ package org.apache.openjpa.util; import java.io.Serializable; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; @@ -35,7 +36,7 @@ public abstract class OpenJPAId // cache the types' generated hash codes private static ConcurrentReferenceHashMap _typeCache = - new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); + new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD); protected Class type; protected boolean subs = true; diff --git a/openjpa-lib/pom.xml b/openjpa-lib/pom.xml index fbfdeed51..32dee6b54 100644 --- a/openjpa-lib/pom.xml +++ b/openjpa-lib/pom.xml @@ -66,8 +66,8 @@ provided - commons-collections - commons-collections + org.apache.commons + commons-collections4 net.sourceforge.serp diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java index 8374e9d2d..1394f8db7 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java @@ -35,6 +35,7 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.util.ClassUtil; import org.apache.openjpa.lib.util.J2DoPrivHelper; @@ -53,12 +54,10 @@ import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; */ public class Configurations { - private static final Localizer _loc = Localizer.forPackage - (Configurations.class); - + private static final Localizer _loc = Localizer.forPackage(Configurations.class); + private static final ConcurrentReferenceHashMap _loaders = new - ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.WEAK, - ConcurrentReferenceHashMap.HARD); + ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD); private static final Object NULL_LOADER = "null-loader"; @@ -195,8 +194,8 @@ public class Configurations { Map> loaderCache = (Map>) _loaders.get(key); if (loaderCache == null) { // We don't have a cache for this loader. //OPENJPA-2636: Changed to HARD/WEAK to avoid Classloader leak: - loaderCache = new ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.HARD, - ConcurrentReferenceHashMap.WEAK); + loaderCache = new ConcurrentReferenceHashMap(ReferenceStrength.HARD, + ReferenceStrength.WEAK); _loaders.put(key, loaderCache); } else { // We have a cache for this loader. cls = (Class) loaderCache.get(clsName); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java index f972d8531..aaad1048d 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java @@ -21,6 +21,7 @@ package org.apache.openjpa.lib.conf; import java.security.AccessController; import java.util.Objects; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.J2DoPrivHelper; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.ReferenceMap; @@ -38,7 +39,7 @@ public class ObjectValue extends Value { // cache the types' classloader private static ConcurrentReferenceHashMap _classloaderCache = - new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.WEAK); + new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.WEAK); private Object _value = null; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/SoftRandomAccessResultList.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/SoftRandomAccessResultList.java index c0b86ccee..346501cc3 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/SoftRandomAccessResultList.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/SoftRandomAccessResultList.java @@ -20,7 +20,7 @@ package org.apache.openjpa.lib.rop; import java.util.Map; -import org.apache.commons.collections.ReferenceMap; +import org.apache.commons.collections4.map.ReferenceMap; /** * Specialization of the {@link RandomAccessResultList} that only maintains diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java index 45d202699..c4e78f034 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java @@ -29,7 +29,7 @@ import java.util.Map; * * @author Abe White */ -public class LRUMap extends org.apache.commons.collections.map.LRUMap +public class LRUMap extends org.apache.commons.collections4.map.LRUMap implements SizedMap { private int _max = -1; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java index f8bdf0cea..7dae89f83 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java @@ -30,33 +30,18 @@ import java.lang.ref.Reference; * @since 0.4.0 */ public class ReferenceHashMap - extends org.apache.commons.collections.map.ReferenceMap + extends org.apache.commons.collections4.map.ReferenceMap implements ReferenceMap, SizedMap { private int _maxSize = Integer.MAX_VALUE; - public ReferenceHashMap(int keyType, int valueType) { - super(toReferenceConstant(keyType), toReferenceConstant(valueType)); + public ReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType) { + super(keyType, valueType); } - public ReferenceHashMap(int keyType, int valueType, int capacity, + public ReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType, int capacity, float loadFactor) { - super(toReferenceConstant(keyType), toReferenceConstant(valueType), - capacity, loadFactor); - } - - /** - * Concver our reference constants to Apache's. - */ - private static int toReferenceConstant(int type) { - switch (type) { - case ReferenceMap.HARD: - return org.apache.commons.collections.map.ReferenceMap. HARD; - case ReferenceMap.SOFT: - return org.apache.commons.collections.map.ReferenceMap. SOFT; - default: - return org.apache.commons.collections.map.ReferenceMap. WEAK; - } + super(keyType, valueType, capacity, loadFactor); } public int getMaxSize() { @@ -104,63 +89,11 @@ public class ReferenceHashMap super.addMapping(hashIndex, hashCode, key, value); } - protected HashEntry createEntry(HashEntry next, int hashCode, Object key, + protected ReferenceEntry createEntry(HashEntry next, int hashCode, Object key, Object value) { return new AccessibleEntry(this, next, hashCode, key, value); } - protected void purge(Reference ref) { - // the logic for this method is taken from the original purge method - // we're overriding, with added logic to track the expired key/value - int index = hashIndex(ref.hashCode(), data.length); - AccessibleEntry entry = (AccessibleEntry) data[index]; - AccessibleEntry prev = null; - Object key = null, value = null; - while (entry != null) { - if (purge(entry, ref)) { - if (isHard(keyType)) - key = entry.key(); - else if (isHard(valueType)) - value = entry.value(); - - if (prev == null) - data[index] = entry.nextEntry(); - else - prev.setNextEntry(entry.nextEntry()); - size--; - break; - } - prev = entry; - entry = entry.nextEntry(); - } - - if (key != null) - valueExpired(key); - else if (value != null) - keyExpired(value); - } - - /** - * See the code for ReferenceMap.ReferenceEntry.purge. - */ - private boolean purge(AccessibleEntry entry, Reference ref) { - boolean match = (!isHard(keyType) && entry.key() == ref) - || (!isHard(valueType) && entry.value() == ref); - if (match) { - if (!isHard(keyType)) - ((Reference) entry.key()).clear(); - if (!isHard(valueType)) - ((Reference) entry.value()).clear(); - else if (purgeValues) - entry.nullValue(); - } - return match; - } - - private static boolean isHard(int type) { - return type == org.apache.commons.collections.map. ReferenceMap.HARD; - } - protected void doWriteObject(ObjectOutputStream out) throws IOException { out.writeInt(_maxSize); super.doWriteObject(out); @@ -177,11 +110,13 @@ public class ReferenceHashMap * protected state. */ private static class AccessibleEntry extends ReferenceEntry { + private final ReferenceHashMap parent; - public AccessibleEntry(org.apache.commons.collections.map. + public AccessibleEntry(org.apache.commons.collections4.map. AbstractReferenceMap map, HashEntry next, int hashCode, Object key, Object value) { super(map, next, hashCode, key, value); + parent = (ReferenceHashMap)map; } public Object key() { @@ -192,10 +127,6 @@ public class ReferenceHashMap return value; } - public void nullValue() { - value = null; - } - public AccessibleEntry nextEntry() { return (AccessibleEntry) next; } @@ -203,5 +134,14 @@ public class ReferenceHashMap public void setNextEntry(AccessibleEntry next) { this.next = next; } + + @Override + protected void onPurge() { + if (parent.isKeyType(ReferenceStrength.HARD)) { + parent.valueExpired(key); + } else if (parent.isValueType(ReferenceStrength.HARD)) { + parent.keyExpired(value); + } + } } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java index 1d25bfb41..ce6a6ac79 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java @@ -24,7 +24,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import org.apache.commons.collections.set.MapBackedSet; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; +import org.apache.commons.collections4.set.MapBackedSet; /** * A set whose values may be stored as weak or soft references. @@ -32,22 +33,6 @@ import org.apache.commons.collections.set.MapBackedSet; * @author Abe White */ public class ReferenceHashSet implements Set, Serializable { - - /** - * Hard reference marker. - */ - public static final int HARD = 0; - - /** - * Soft reference marker. - */ - public static final int SOFT = 1; - - /** - * Weak reference marker. - */ - public static final int WEAK = 2; - private static final Object DUMMY_VAL = new Serializable() { public String toString() { return ReferenceHashSet.class.getName() + ".DUMMY_VAL"; @@ -59,17 +44,12 @@ public class ReferenceHashSet implements Set, Serializable { /** * Construct a set with the given reference type. */ - public ReferenceHashSet(int refType) { - if (refType == HARD) + public ReferenceHashSet(ReferenceStrength refType) { + if (refType == ReferenceStrength.HARD) _set = new HashSet(); else { - int mapRefType = (refType == WEAK) ? org.apache.commons. - collections.map.ReferenceMap.WEAK : org.apache. - commons.collections.map.ReferenceMap.SOFT; - _set = MapBackedSet.decorate(new org.apache.commons. - collections.map.ReferenceMap(mapRefType, - org.apache.commons.collections.map. - ReferenceMap.HARD), DUMMY_VAL); + _set = MapBackedSet.mapBackedSet(new org.apache.commons. + collections4.map.ReferenceMap(refType, ReferenceStrength.HARD), DUMMY_VAL); } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java index 1ee59c57a..d1fd2c895 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java @@ -27,11 +27,6 @@ import java.util.Map; * @author Abe White */ public interface ReferenceMap extends Map { - - public static final int HARD = 0; - public static final int WEAK = 1; - public static final int SOFT = 2; - /** * Purge stale entries. */ diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java index 0c6a8ddac..fafd4d34c 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java @@ -29,6 +29,7 @@ import java.util.NoSuchElementException; import java.util.Random; import java.util.Set; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.SizedMap; @@ -83,12 +84,12 @@ public class ConcurrentReferenceHashMap extends AbstractMap /** * The key reference type. */ - private int keyType; + private ReferenceStrength keyType; /** * The value reference type. */ - private int valueType; + private ReferenceStrength valueType; /** * Reference queue for cleared Entries @@ -138,7 +139,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * references, if the initial capacity is less than or equal to zero, or if * the load factor is less than or equal to zero */ - public ConcurrentReferenceHashMap(int keyType, int valueType, + public ConcurrentReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType, int initialCapacity, float loadFactor) { if (initialCapacity < 0) { throw new IllegalArgumentException("Illegal Initial Capacity: " + @@ -148,7 +149,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap throw new IllegalArgumentException("Illegal Load factor: " + loadFactor); } - if (keyType != HARD && valueType != HARD) { + if (keyType != ReferenceStrength.HARD && valueType != ReferenceStrength.HARD) { throw new IllegalArgumentException("Either keys or values must " + "use hard references."); } @@ -167,7 +168,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * @param valueType the reference type of map values * @param initialCapacity the initial capacity of the HashMap. */ - public ConcurrentReferenceHashMap(int keyType, int valueType, + public ConcurrentReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType, int initialCapacity) { this(keyType, valueType, initialCapacity, 0.75f); } @@ -178,7 +179,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * @param keyType the reference type of map keys * @param valueType the reference type of map values */ - public ConcurrentReferenceHashMap(int keyType, int valueType) { + public ConcurrentReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType) { this(keyType, valueType, 11, 0.75f); } @@ -191,7 +192,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * @param keyType the reference type of map keys * @param valueType the reference type of map values */ - public ConcurrentReferenceHashMap(int keyType, int valueType, Map t) { + public ConcurrentReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType, Map t) { this(keyType, valueType, Math.max(3 * t.size(), 11), 0.75f); putAll(t); } @@ -243,7 +244,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap Entry[] tab = table; if (value == null) { - if (valueType != HARD) + if (valueType != ReferenceStrength.HARD) return false; for (int i = tab.length; i-- > 0;) for (Entry e = tab[i]; e != null; e = e.getNext()) @@ -264,7 +265,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * @param key key whose presence in this Map is to be tested. */ public boolean containsKey(Object key) { - if (key == null && keyType != HARD) + if (key == null && keyType != ReferenceStrength.HARD) return false; Entry[] tab = table; @@ -283,7 +284,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * @param key key whose associated value is to be returned. */ public Object get(Object key) { - if (key == null && keyType != HARD) + if (key == null && keyType != ReferenceStrength.HARD) return null; Entry[] tab = table; @@ -311,8 +312,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap for (int i = oldCapacity; i-- > 0;) { for (Entry old = oldMap[i]; old != null;) { - if ((keyType != HARD && old.getKey() == null) - || valueType != HARD && old.getValue() == null) { + if ((keyType != ReferenceStrength.HARD && old.getKey() == null) + || valueType != ReferenceStrength.HARD && old.getValue() == null) { Entry e = old; old = old.getNext(); e.setNext(null); @@ -344,8 +345,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap * the HashMap previously associated null with the specified key. */ public Object put(Object key, Object value) { - if ((key == null && keyType != HARD) - || (value == null && valueType != HARD)) + if ((key == null && keyType != ReferenceStrength.HARD) + || (value == null && valueType != ReferenceStrength.HARD)) throw new IllegalArgumentException("Null references not supported"); int hash = hc(key); @@ -360,7 +361,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap e = e.getNext()) { if ((e.getHash() == hash) && eq(key, e.getKey())) { Object old = e.getValue(); - if (valueType == HARD) + if (valueType == ReferenceStrength.HARD) e.setValue(value); else { e = newEntry(hash, e.getKey(), value, e.getNext()); @@ -393,7 +394,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * Creates a new entry. */ private Entry newEntry(int hash, Object key, Object value, Entry next) { - int refType = (keyType != HARD) ? keyType : valueType; + ReferenceStrength refType = (keyType != ReferenceStrength.HARD) ? keyType : valueType; switch (refType) { case WEAK: return new WeakEntry(hash, key, value, refType == keyType, next, @@ -427,7 +428,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap * the HashMap previously associated null with the specified key. */ public Object remove(Object key) { - if (key == null && keyType != HARD) + if (key == null && keyType != ReferenceStrength.HARD) return null; int hash = hc(key); @@ -748,7 +749,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap tab[index] = e.getNext(); count--; - if (keyType == HARD) + if (keyType == ReferenceStrength.HARD) valueExpired(e.getKey()); else keyExpired(e.getValue()); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java index 40f8f5a0f..16011695a 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java @@ -24,7 +24,8 @@ import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.apache.commons.collections.set.MapBackedSet; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; +import org.apache.commons.collections4.set.MapBackedSet; /** * A concurrent set whose values may be stored as weak or soft references. If @@ -36,22 +37,6 @@ import org.apache.commons.collections.set.MapBackedSet; */ @SuppressWarnings("serial") public class ConcurrentReferenceHashSet implements Set, Serializable { - - /** - * Hard reference marker. - */ - public static final int HARD = 0; - - /** - * Soft reference marker. - */ - public static final int SOFT = 1; - - /** - * Weak reference marker. - */ - public static final int WEAK = 2; - private static final Object DUMMY_VAL = new Object(); private final Set _set; @@ -59,14 +44,12 @@ public class ConcurrentReferenceHashSet implements Set, Serializable { /** * Construct a set with the given reference type. */ - public ConcurrentReferenceHashSet(int refType) { - if (refType == HARD) - _set = MapBackedSet.decorate(new ConcurrentHashMap(), DUMMY_VAL); + public ConcurrentReferenceHashSet(ReferenceStrength refType) { + if (refType == ReferenceStrength.HARD) + _set = MapBackedSet.mapBackedSet(new ConcurrentHashMap(), DUMMY_VAL); else { - int mapRefType = (refType == WEAK) ? ConcurrentReferenceHashMap.WEAK - : ConcurrentReferenceHashMap.SOFT; - _set = MapBackedSet.decorate(new ConcurrentReferenceHashMap - (mapRefType, ConcurrentReferenceHashMap.HARD), DUMMY_VAL); + _set = MapBackedSet.mapBackedSet(new ConcurrentReferenceHashMap + (refType, ReferenceStrength.HARD), DUMMY_VAL); } } diff --git a/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestReferenceSet.java b/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestReferenceSet.java index 96dd955e9..589901f35 100644 --- a/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestReferenceSet.java +++ b/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestReferenceSet.java @@ -21,6 +21,8 @@ package org.apache.openjpa.lib.util; import java.util.Collection; import java.util.Iterator; +import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength; + import junit.framework.TestCase; /** @@ -30,8 +32,7 @@ import junit.framework.TestCase; */ public class TestReferenceSet extends TestCase { - private ReferenceHashSet _coll = new ReferenceHashSet - (ReferenceHashSet.WEAK); + private ReferenceHashSet _coll = new ReferenceHashSet(ReferenceStrength.WEAK); private Object _heldValue = new Integer(2); @@ -48,7 +49,7 @@ public class TestReferenceSet extends TestCase { * Tests basic add/contains/remove functionality. */ public void testBasics() { - Collection coll = new ReferenceHashSet(ReferenceHashSet.WEAK); + Collection coll = new ReferenceHashSet(ReferenceStrength.WEAK); assertEquals(0, coll.size()); assertTrue(!coll.contains("foo")); diff --git a/openjpa-persistence-jdbc/pom.xml b/openjpa-persistence-jdbc/pom.xml index d5eb83613..1022d53fd 100644 --- a/openjpa-persistence-jdbc/pom.xml +++ b/openjpa-persistence-jdbc/pom.xml @@ -852,8 +852,8 @@ ${project.version} - commons-collections - commons-collections + org.apache.commons + commons-collections4 test diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/HorizRelation.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/HorizRelation.java index f2c34033d..7638919fa 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/HorizRelation.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/HorizRelation.java @@ -18,12 +18,16 @@ */ package org.apache.openjpa.persistence.jdbc.common.apps; -import java.io.*; -import java.util.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.Vector; import javax.persistence.Entity; -import org.apache.commons.collections.*; +import org.apache.commons.collections4.map.LinkedMap; /** * Normal class that has relations to and from various horizontal @@ -107,7 +111,7 @@ public class HorizRelation private ArrayList cHorizInterVerticalD = new ArrayList(); public Map getCollections() { - Map map = new SequencedHashMap(); + Map map = new LinkedMap(); map.put("HorizA", cHorizA); map.put("HorizB", cHorizB); map.put("HorizC", cHorizC); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestProxies2.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestProxies2.java index 0f636aaf7..787ad741f 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestProxies2.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestProxies2.java @@ -29,7 +29,7 @@ import java.util.TreeSet; import org.apache.openjpa.persistence.kernel.common.apps.ProxiesPC; -import org.apache.commons.collections.comparators.ComparableComparator; +import org.apache.commons.collections4.comparators.ComparableComparator; import org.apache.openjpa.persistence.OpenJPAEntityManager; import org.apache.openjpa.util.Proxy; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/ProxiesPC.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/ProxiesPC.java index 2820f23fe..cc6f79674 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/ProxiesPC.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/ProxiesPC.java @@ -40,7 +40,7 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import org.apache.openjpa.persistence.jdbc.KeyColumn; -import org.apache.commons.collections.comparators.ComparableComparator; +import org.apache.commons.collections4.comparators.ComparableComparator; import org.apache.openjpa.persistence.PersistentCollection; import org.apache.openjpa.persistence.PersistentMap; diff --git a/openjpa-project/assembly.xml b/openjpa-project/assembly.xml index e76713e30..c9be0a14c 100644 --- a/openjpa-project/assembly.xml +++ b/openjpa-project/assembly.xml @@ -133,8 +133,7 @@ net.sourceforge.serp:serp org.apache.derby:derby - commons-lang:commons-lang - commons-collections:commons-collections + org.apache.commons:commons-collections4 org.apache.commons:commons-pool2 commons-logging:commons-logging org.apache.commons:commons-dbcp2 diff --git a/openjpa-project/bin-assembly.xml b/openjpa-project/bin-assembly.xml index 5c6f7348f..e23b2fbe8 100644 --- a/openjpa-project/bin-assembly.xml +++ b/openjpa-project/bin-assembly.xml @@ -72,8 +72,7 @@ net.sourceforge.serp:serp org.apache.derby:derby - commons-lang:commons-lang - commons-collections:commons-collections + org.apache.commons:commons-collections4 org.apache.commons:commons-pool2 commons-logging:commons-logging org.apache.commons:commons-dbcp2 diff --git a/pom.xml b/pom.xml index 1dda00a4a..27166afca 100644 --- a/pom.xml +++ b/pom.xml @@ -508,9 +508,9 @@ 1.2 - commons-collections - commons-collections - 3.2.2 + org.apache.commons + commons-collections4 + 4.3-SNAPSHOT net.sourceforge.serp