[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
This commit is contained in:
Maxim Solodovnik 2018-09-25 15:16:54 +00:00
parent f399f912cf
commit 4709f38ba2
48 changed files with 175 additions and 265 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ target
velocity.log velocity.log
derby.log derby.log
*.iml *.iml
dependency-reduced-pom.xml

View File

@ -26,7 +26,7 @@
<bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-el_1.0_spec/1.0.1</bundle> <bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-el_1.0_spec/1.0.1</bundle>
<bundle dependency="true">mvn:org.apache.commons/commons-pool2/2.6.0</bundle> <bundle dependency="true">mvn:org.apache.commons/commons-pool2/2.6.0</bundle>
<bundle dependency="true">mvn:org.apache.commons/commons-dbcp2/2.5.0</bundle> <bundle dependency="true">mvn:org.apache.commons/commons-dbcp2/2.5.0</bundle>
<bundle dependency="true">mvn:commons-collections/commons-collections/3.2.2</bundle> <bundle dependency="true">mvn:commons-collections/commons-collections4/4.3</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.serp/1.14.1_1</bundle> <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.serp/1.14.1_1</bundle>
<bundle dependency="true">mvn:org.apache.xbean/xbean-asm6-shaded/4.9</bundle> <bundle dependency="true">mvn:org.apache.xbean/xbean-asm6-shaded/4.9</bundle>
<bundle>mvn:org.apache.openjpa/openjpa/${project.version}</bundle> <bundle>mvn:org.apache.openjpa/openjpa/${project.version}</bundle>

View File

@ -31,6 +31,7 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; 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;
import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
import org.apache.openjpa.jdbc.kernel.exps.FilterValue; import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
@ -84,7 +85,7 @@ public class InformixDictionary
protected boolean useJCC = false; protected boolean useJCC = false;
// weak set of connections we've already executed lock mode sql on // weak set of connections we've already executed lock mode sql on
private final Collection _seenConnections = Collections.synchronizedSet( private final Collection _seenConnections = Collections.synchronizedSet(
new ReferenceHashSet(ReferenceHashSet.WEAK)); new ReferenceHashSet(ReferenceStrength.WEAK));
public boolean disableRetainUpdateLocksSQL=false; public boolean disableRetainUpdateLocksSQL=false;

View File

@ -38,7 +38,7 @@ import java.util.SortedMap;
import java.util.Stack; import java.util.Stack;
import java.util.TreeMap; 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.lib.util.StringUtil;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.kernel.EagerFetchModes; import org.apache.openjpa.jdbc.kernel.EagerFetchModes;

View File

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.event.RemoteCommitEvent; import org.apache.openjpa.event.RemoteCommitEvent;
import org.apache.openjpa.event.RemoteCommitListener; 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. * the only reference is held by the list of expiration listeners.
*/ */
protected Collection newListenerCollection() { protected Collection newListenerCollection() {
return new ConcurrentReferenceHashSet (ConcurrentReferenceHashSet.WEAK); return new ConcurrentReferenceHashSet(ReferenceStrength.WEAK);
} }
/** /**
@ -493,12 +494,12 @@ public abstract class AbstractQueryCache
private void initializeMaps() { private void initializeMaps() {
ConcurrentReferenceHashMap statsMap = ConcurrentReferenceHashMap statsMap =
new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR);
statsMap.setMaxSize(FIXED_SIZE); statsMap.setMaxSize(FIXED_SIZE);
stats = statsMap; stats = statsMap;
ConcurrentReferenceHashMap aStatsMap = ConcurrentReferenceHashMap aStatsMap =
new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR);
aStatsMap.setMaxSize(FIXED_SIZE); aStatsMap.setMaxSize(FIXED_SIZE);
astats = aStatsMap; astats = aStatsMap;
} }

View File

@ -30,7 +30,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; 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.datacache.AbstractQueryCache.EvictPolicy;
import org.apache.openjpa.kernel.FetchConfiguration; import org.apache.openjpa.kernel.FetchConfiguration;
import org.apache.openjpa.kernel.LockLevels; import org.apache.openjpa.kernel.LockLevels;

View File

@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; 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.Localizer;
import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.ReferenceMap;
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
@ -40,14 +41,14 @@ public class PCRegistry {
private static final Localizer _loc = Localizer.forPackage(PCRegistry.class); private static final Localizer _loc = Localizer.forPackage(PCRegistry.class);
// map of persistent classes to meta structures; weak so the VM can GC classes // map of persistent classes to meta structures; weak so the VM can GC classes
private static final Map<Class<?>,Meta> _metas = new ConcurrentReferenceHashMap(ReferenceMap.WEAK, private static final Map<Class<?>,Meta> _metas = new ConcurrentReferenceHashMap(ReferenceStrength.WEAK,
ReferenceMap.HARD); ReferenceStrength.HARD);
// register class listeners // register class listeners
// Weak reference prevents OutOfMemeoryError as described in OPENJPA-2042 // Weak reference prevents OutOfMemeoryError as described in OPENJPA-2042
private static final Collection<RegisterClassListener> _listeners = private static final Collection<RegisterClassListener> _listeners =
new ConcurrentReferenceHashSet<RegisterClassListener>( new ConcurrentReferenceHashSet<RegisterClassListener>(
ConcurrentReferenceHashSet.WEAK); ReferenceStrength.WEAK);
/** /**
* Register a {@link RegisterClassListener}. * Register a {@link RegisterClassListener}.

View File

@ -30,6 +30,7 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.apache.openjpa.lib.util.StringUtil; 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.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.ReferenceMap;
@ -52,11 +53,11 @@ public class Reflection {
// Weak HashMap caches of getter/setter/beanProperty methods // Weak HashMap caches of getter/setter/beanProperty methods
private static Map<Class<?>, Map<String, Method>> getterMethodCache = private static Map<Class<?>, Map<String, Method>> getterMethodCache =
new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD);
private static Map<Class<?>, Map<String, Method>> setterMethodCache = private static Map<Class<?>, Map<String, Method>> setterMethodCache =
new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD);
private static Map<Class<?>, Set<String>> beanPropertiesNameCache = private static Map<Class<?>, Set<String>> beanPropertiesNameCache =
new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD);
private static Method getGetterMethod(Class<?> cls, String prop) { private static Method getGetterMethod(Class<?> cls, String prop) {
Method rtnMethod = null; Method rtnMethod = null;
@ -71,8 +72,8 @@ public class Reflection {
Method method) { Method method) {
Map<String, Method> clsMap = getterMethodCache.get(cls); Map<String, Method> clsMap = getterMethodCache.get(cls);
if (clsMap == null) { if (clsMap == null) {
clsMap = new ConcurrentReferenceHashMap(ReferenceMap.HARD, clsMap = new ConcurrentReferenceHashMap(ReferenceStrength.HARD,
ReferenceMap.WEAK); ReferenceStrength.WEAK);
getterMethodCache.put(cls, clsMap); getterMethodCache.put(cls, clsMap);
} }
clsMap.put(prop, method); clsMap.put(prop, method);
@ -91,8 +92,8 @@ public class Reflection {
Method method) { Method method) {
Map<String, Method> clsMap = setterMethodCache.get(cls); Map<String, Method> clsMap = setterMethodCache.get(cls);
if (clsMap == null) { if (clsMap == null) {
clsMap = new ConcurrentReferenceHashMap(ReferenceMap.HARD, clsMap = new ConcurrentReferenceHashMap(ReferenceStrength.HARD,
ReferenceMap.WEAK); ReferenceStrength.WEAK);
setterMethodCache.put(cls, clsMap); setterMethodCache.put(cls, clsMap);
} }
clsMap.put(prop, method); clsMap.put(prop, method);

View File

@ -21,6 +21,7 @@ package org.apache.openjpa.event;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
/** /**
@ -37,8 +38,7 @@ import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
public class SingleJVMRemoteCommitProvider public class SingleJVMRemoteCommitProvider
extends AbstractRemoteCommitProvider { extends AbstractRemoteCommitProvider {
private static Set s_providers = new ConcurrentReferenceHashSet( private static Set s_providers = new ConcurrentReferenceHashSet(ReferenceStrength.HARD);
ConcurrentReferenceHashSet.HARD);
public SingleJVMRemoteCommitProvider() { public SingleJVMRemoteCommitProvider() {
s_providers.add(this); s_providers.add(this);

View File

@ -39,7 +39,8 @@ import javax.transaction.Synchronization;
import javax.transaction.Transaction; import javax.transaction.Transaction;
import javax.transaction.TransactionManager; 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.lib.util.StringUtil;
import org.apache.openjpa.audit.Auditor; import org.apache.openjpa.audit.Auditor;
import org.apache.openjpa.conf.BrokerValue; import org.apache.openjpa.conf.BrokerValue;
@ -489,9 +490,9 @@ public abstract class AbstractBrokerFactory
bv = (BrokerValue) _conf.getValue(BrokerValue.KEY); bv = (BrokerValue) _conf.getValue(BrokerValue.KEY);
if (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf))) { if (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf))) {
return MapBackedSet.decorate(new ConcurrentHashMap(), new Object() { }); return MapBackedSet.mapBackedSet(new ConcurrentHashMap(), new Object() { });
} else { } else {
return new ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK); return new ConcurrentReferenceHashSet<Broker>(ReferenceStrength.WEAK);
} }
} }
@ -829,7 +830,7 @@ public abstract class AbstractBrokerFactory
*/ */
private Collection<ClassLoader> getPcClassLoaders() { private Collection<ClassLoader> getPcClassLoaders() {
if (_pcClassLoaders == null) if (_pcClassLoaders == null)
_pcClassLoaders = new ConcurrentReferenceHashSet<ClassLoader>(ConcurrentReferenceHashSet.WEAK); _pcClassLoaders = new ConcurrentReferenceHashSet<ClassLoader>(ReferenceStrength.WEAK);
return _pcClassLoaders; return _pcClassLoaders;
} }

View File

@ -20,7 +20,7 @@ package org.apache.openjpa.kernel;
import java.util.Map; 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.datacache.DataCache;
import org.apache.openjpa.kernel.exps.AggregateListener; import org.apache.openjpa.kernel.exps.AggregateListener;
import org.apache.openjpa.kernel.exps.FilterListener; import org.apache.openjpa.kernel.exps.FilterListener;

View File

@ -28,7 +28,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; 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.enhance.PersistenceCapable;
import org.apache.openjpa.event.CallbackModes; import org.apache.openjpa.event.CallbackModes;
import org.apache.openjpa.event.LifecycleEvent; import org.apache.openjpa.event.LifecycleEvent;
@ -59,7 +59,7 @@ public class AttachManager {
private final OpCallbacks _call; private final OpCallbacks _call;
private final boolean _copyNew; private final boolean _copyNew;
private final boolean _failFast; private final boolean _failFast;
private final IdentityMap _attached = new IdentityMap(); private final IdentityHashMap _attached = new IdentityHashMap();
private final Collection<StateManagerImpl> _visitedNodes = new ArrayList(); private final Collection<StateManagerImpl> _visitedNodes = new ArrayList();
// reusable strategies // reusable strategies

View File

@ -44,9 +44,10 @@ import java.util.concurrent.locks.ReentrantLock;
import javax.transaction.Status; import javax.transaction.Status;
import javax.transaction.Synchronization; import javax.transaction.Synchronization;
import org.apache.commons.collections.iterators.IteratorChain; import org.apache.commons.collections4.iterators.IteratorChain;
import org.apache.commons.collections.map.LinkedMap; import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
import org.apache.commons.collections.set.MapBackedSet; 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.lib.util.StringUtil;
import org.apache.openjpa.conf.Compatibility; import org.apache.openjpa.conf.Compatibility;
import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfiguration;
@ -404,7 +405,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
private void initializeOperatingSet() { private void initializeOperatingSet() {
if(_operatingDirty) { if(_operatingDirty) {
_operatingDirty = false; _operatingDirty = false;
_operating = MapBackedSet.decorate(new IdentityHashMap<Object, Object>()); _operating = MapBackedSet.mapBackedSet(new IdentityHashMap<Object, Object>());
} }
} }
@ -430,7 +431,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
* {@link ReferenceMap} with soft values. * {@link ReferenceMap} with soft values.
*/ */
protected Map<?,?> newManagedObjectCache() { 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 { try {
ExtentImpl extent = new ExtentImpl(this, type, subclasses, fetch); ExtentImpl extent = new ExtentImpl(this, type, subclasses, fetch);
if (_extents == null) if (_extents == null)
_extents = new ReferenceHashSet(ReferenceHashSet.WEAK); _extents = new ReferenceHashSet(ReferenceStrength.WEAK);
_extents.add(extent); _extents.add(extent);
return extent; return extent;
@ -3800,7 +3801,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
// track queries // track queries
if (_queries == null) if (_queries == null)
_queries = new ReferenceHashSet(ReferenceHashSet.WEAK); _queries = new ReferenceHashSet(ReferenceStrength.WEAK);
_queries.add(q); _queries.add(q);
return q; return q;
} catch (OpenJPAException ke) { } catch (OpenJPAException ke) {
@ -4906,7 +4907,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
private boolean addCleanInternal(StateManagerImpl sm) { private boolean addCleanInternal(StateManagerImpl sm) {
if (_clean == null) if (_clean == null)
_clean = new ReferenceHashSet(ReferenceHashSet.SOFT); _clean = new ReferenceHashSet(ReferenceStrength.SOFT);
return _clean.add(sm); return _clean.add(sm);
} }
@ -4916,7 +4917,7 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
public void addDirty(StateManagerImpl sm) { public void addDirty(StateManagerImpl sm) {
if (_dirty == null) { if (_dirty == null) {
if (_orderDirty) if (_orderDirty)
_dirty = MapBackedSet.decorate(new LinkedMap()); _dirty = MapBackedSet.mapBackedSet(new LinkedMap());
else else
_dirty = new HashSet<StateManagerImpl>(); _dirty = new HashSet<StateManagerImpl>();
} }

View File

@ -21,7 +21,7 @@ package org.apache.openjpa.kernel;
import java.util.Collection; import java.util.Collection;
import java.util.Map; 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.AggregateListener;
import org.apache.openjpa.kernel.exps.FilterListener; import org.apache.openjpa.kernel.exps.FilterListener;
import org.apache.openjpa.lib.util.OrderedMap; import org.apache.openjpa.lib.util.OrderedMap;

View File

@ -33,7 +33,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; 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.Compatibility;
import org.apache.openjpa.conf.DetachOptions; import org.apache.openjpa.conf.DetachOptions;
import org.apache.openjpa.enhance.PersistenceCapable; 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're not detaching full, we need to track all detached objects;
// if we are, then we use a special field manager for more efficient // if we are, then we use a special field manager for more efficient
// detachment than the standard one // detachment than the standard one
private final IdentityMap _detached; private final IdentityHashMap _detached;
private final DetachFieldManager _fullFM; private final DetachFieldManager _fullFM;
/** /**
@ -279,7 +279,7 @@ public class DetachManager
_detached = null; _detached = null;
_fullFM = new DetachFieldManager(); _fullFM = new DetachFieldManager();
} else { } else {
_detached = new IdentityMap(); _detached = new IdentityHashMap();
_fullFM = null; _fullFM = null;
} }
Compatibility compatibility = Compatibility compatibility =

View File

@ -23,9 +23,10 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.apache.commons.collections.Predicate; import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections.iterators.FilterIterator; import org.apache.commons.collections4.iterators.FilterIterator;
import org.apache.commons.collections.iterators.IteratorChain; 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.ResultObjectProvider;
import org.apache.openjpa.lib.rop.ResultObjectProviderIterator; import org.apache.openjpa.lib.rop.ResultObjectProviderIterator;
import org.apache.openjpa.lib.util.Closeable; import org.apache.openjpa.lib.util.Closeable;
@ -156,7 +157,7 @@ public class ExtentImpl<T>
lock(); lock();
try { try {
if (_openItrs == null) if (_openItrs == null)
_openItrs = new ReferenceHashSet(ReferenceHashSet.WEAK); _openItrs = new ReferenceHashSet(ReferenceStrength.WEAK);
_openItrs.add(citr); _openItrs.add(citr);
} finally { } finally {
unlock(); unlock();
@ -263,7 +264,7 @@ public class ExtentImpl<T>
} }
_closed = true; _closed = true;
for (Iterator itr = getIterators().iterator(); itr.hasNext();) for (Iterator itr = this; itr.hasNext();)
((Closeable) itr.next()).close(); ((Closeable) itr.next()).close();
} }
} }

View File

@ -27,6 +27,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; 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.Localizer;
import org.apache.openjpa.lib.util.ReferenceHashSet; import org.apache.openjpa.lib.util.ReferenceHashSet;
import org.apache.openjpa.util.Exceptions; import org.apache.openjpa.util.Exceptions;
@ -105,7 +106,7 @@ class ManagedCache implements Serializable {
if (!sm.isPersistent() || sm.isEmbedded()) { if (!sm.isPersistent() || sm.isEmbedded()) {
if (_embeds == null) if (_embeds == null)
_embeds = new ReferenceHashSet(ReferenceHashSet.WEAK); _embeds = new ReferenceHashSet(ReferenceStrength.WEAK);
_embeds.add(sm); _embeds.add(sm);
return; return;
} }

View File

@ -21,7 +21,7 @@ package org.apache.openjpa.kernel;
import java.util.Collection; import java.util.Collection;
import java.util.Map; 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.AggregateListener;
import org.apache.openjpa.kernel.exps.Constant; import org.apache.openjpa.kernel.exps.Constant;
import org.apache.openjpa.kernel.exps.FilterListener; import org.apache.openjpa.kernel.exps.FilterListener;

View File

@ -32,7 +32,8 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.locks.ReentrantLock; 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 java.util.Objects;
import org.apache.openjpa.lib.util.StringUtil; 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 // remember the list of all the results we have returned so we
// can free their resources when close or closeAll is called // can free their resources when close or closeAll is called
private transient final Collection<RemoveOnCloseResultList> _resultLists = private transient final Collection<RemoveOnCloseResultList> _resultLists =
new ReferenceHashSet(ReferenceHashSet.WEAK); new ReferenceHashSet(ReferenceStrength.WEAK);
private boolean _printParameters = false; private boolean _printParameters = false;
/** /**

View File

@ -25,6 +25,7 @@ import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; 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.ReferenceMap;
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
@ -165,12 +166,12 @@ public interface QueryStatistics<T> extends Serializable {
private void initializeMaps() { private void initializeMaps() {
ConcurrentReferenceHashMap statsMap = ConcurrentReferenceHashMap statsMap =
new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR);
statsMap.setMaxSize(FIXED_SIZE); statsMap.setMaxSize(FIXED_SIZE);
stats = statsMap; stats = statsMap;
ConcurrentReferenceHashMap aStatsMap = ConcurrentReferenceHashMap aStatsMap =
new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY, LOAD_FACTOR); new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.HARD, CONCURRENCY, LOAD_FACTOR);
aStatsMap.setMaxSize(FIXED_SIZE); aStatsMap.setMaxSize(FIXED_SIZE);
astats = aStatsMap; astats = aStatsMap;
} }

View File

@ -22,7 +22,7 @@ import java.io.Serializable;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; 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.AggregateListener;
import org.apache.openjpa.kernel.exps.Constant; import org.apache.openjpa.kernel.exps.Constant;
import org.apache.openjpa.kernel.exps.FilterListener; import org.apache.openjpa.kernel.exps.FilterListener;

View File

@ -45,7 +45,7 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; 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.conf.OpenJPAConfiguration;
import org.apache.openjpa.kernel.OpenJPAStateManager; import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.kernel.StoreContext; import org.apache.openjpa.kernel.StoreContext;

View File

@ -18,7 +18,7 @@
*/ */
package org.apache.openjpa.meta; 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.conf.OpenJPAConfiguration;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.StringDistance; import org.apache.openjpa.lib.util.StringDistance;

View File

@ -24,7 +24,7 @@ import java.util.HashSet;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.Set; 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. * Base class that provides utilities to change trackers.
@ -186,7 +186,7 @@ public abstract class AbstractChangeTracker
*/ */
protected Set newSet() { protected Set newSet() {
if (_identity == Boolean.TRUE) if (_identity == Boolean.TRUE)
return MapBackedSet.decorate(new IdentityHashMap()); return MapBackedSet.mapBackedSet(new IdentityHashMap());
return new HashSet(); return new HashSet();
} }
@ -220,7 +220,7 @@ public abstract class AbstractChangeTracker
if (identity && cur instanceof HashSet) { if (identity && cur instanceof HashSet) {
if (cur.isEmpty()) if (cur.isEmpty())
return null; return null;
Set replace = MapBackedSet.decorate(new IdentityHashMap()); Set replace = MapBackedSet.mapBackedSet(new IdentityHashMap());
replace.addAll(cur); replace.addAll(cur);
return replace; return replace;
} }

View File

@ -26,9 +26,9 @@ import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections.Predicate; import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections.iterators.FilterIterator; import org.apache.commons.collections4.iterators.FilterIterator;
import org.apache.commons.collections.iterators.IteratorChain; import org.apache.commons.collections4.iterators.IteratorChain;
import org.apache.openjpa.kernel.OpenJPAStateManager; import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.lib.util.Closeable; import org.apache.openjpa.lib.util.Closeable;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
@ -410,10 +410,8 @@ public abstract class AbstractLRSProxyCollection
if (_state != OPEN) if (_state != OPEN)
return; return;
List itrs = _itr.getIterators(); for (Iterator itr = _itr; itr.hasNext();) {
Iterator itr; itr.next();
for (int i = 0; i < itrs.size(); i++) {
itr = (Iterator) itrs.get(i);
if (itr instanceof FilterIterator) if (itr instanceof FilterIterator)
itr = ((FilterIterator) itr).getIterator(); itr = ((FilterIterator) itr).getIterator();
ImplHelper.close(itr); ImplHelper.close(itr);

View File

@ -30,9 +30,9 @@ import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections.Predicate; import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections.iterators.FilterIterator; import org.apache.commons.collections4.iterators.FilterIterator;
import org.apache.commons.collections.iterators.IteratorChain; import org.apache.commons.collections4.iterators.IteratorChain;
import org.apache.openjpa.kernel.OpenJPAStateManager; import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.lib.util.Closeable; import org.apache.openjpa.lib.util.Closeable;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
@ -507,10 +507,8 @@ public abstract class AbstractLRSProxyMap<K,V>
if (_state != OPEN) if (_state != OPEN)
return; return;
List itrs = _itr.getIterators(); for (Iterator itr = _itr; itr.hasNext();) {
Iterator itr; itr.next();
for (int i = 0; i < itrs.size(); i++) {
itr = (Iterator) itrs.get(i);
if (itr instanceof FilterIterator) if (itr instanceof FilterIterator)
itr = ((FilterIterator) itr).getIterator(); itr = ((FilterIterator) itr).getIterator();
ImplHelper.close(itr); ImplHelper.close(itr);

View File

@ -22,7 +22,7 @@ public class BlacklistClassResolver {
public static final BlacklistClassResolver DEFAULT = new BlacklistClassResolver( public static final BlacklistClassResolver DEFAULT = new BlacklistClassResolver(
toArray(System.getProperty( toArray(System.getProperty(
"openjpa.serialization.class.blacklist", "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"))); toArray(System.getProperty("openjpa.serialization.class.whitelist")));
private final String[] blacklist; private final String[] blacklist;
@ -59,6 +59,3 @@ public class BlacklistClassResolver {
return false; return false;
} }
} }

View File

@ -26,9 +26,10 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections.Predicate; import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections.iterators.FilterIterator; import org.apache.commons.collections4.iterators.FilterIterator;
import org.apache.commons.collections.iterators.IteratorChain; 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.LRUMap;
import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.ReferenceMap;
import org.apache.openjpa.lib.util.SizedMap; import org.apache.openjpa.lib.util.SizedMap;
@ -112,8 +113,8 @@ public class CacheMap
if (size < 0) if (size < 0)
size = 500; size = 500;
softMap = new ConcurrentReferenceHashMap(ReferenceMap.HARD, softMap = new ConcurrentReferenceHashMap(ReferenceStrength.HARD,
ReferenceMap.SOFT, size, load) { ReferenceStrength.SOFT, size, load) {
public void overflowRemoved(Object key, Object value) { public void overflowRemoved(Object key, Object value) {
softMapOverflowRemoved(key, value); softMapOverflowRemoved(key, value);
} }

View File

@ -46,6 +46,7 @@ import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes; import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.meta.SequenceMetaData; import org.apache.openjpa.meta.SequenceMetaData;
import org.apache.openjpa.meta.ValueStrategies; import org.apache.openjpa.meta.ValueStrategies;
import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfiguration;
/** /**
@ -58,11 +59,11 @@ public class ImplHelper {
// Cache for from/to type assignments // Cache for from/to type assignments
private static final Map _assignableTypes = 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 // map of all new unenhanced instances active in this classloader
public static final Map _unenhancedInstanceMap = public static final Map _unenhancedInstanceMap =
new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD) { new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD) {
protected boolean eq(Object x, Object y) { protected boolean eq(Object x, Object y) {
// the Entries in ConcurrentReferenceHashMap delegate back to // the Entries in ConcurrentReferenceHashMap delegate back to
@ -252,8 +253,8 @@ public class ImplHelper {
Boolean isAssignable = null; Boolean isAssignable = null;
Map assignableTo = (Map) _assignableTypes.get(from); Map assignableTo = (Map) _assignableTypes.get(from);
if (assignableTo == null) { // "to" cache doesn't exist, so create it... if (assignableTo == null) { // "to" cache doesn't exist, so create it...
assignableTo = new ConcurrentReferenceHashMap(ReferenceMap.WEAK, assignableTo = new ConcurrentReferenceHashMap(ReferenceStrength.WEAK,
ReferenceMap.HARD); ReferenceStrength.HARD);
_assignableTypes.put(from, assignableTo); _assignableTypes.put(from, assignableTo);
} else { // "to" cache exists... } else { // "to" cache exists...
isAssignable = (Boolean) assignableTo.get(to); isAssignable = (Boolean) assignableTo.get(to);

View File

@ -20,6 +20,7 @@ package org.apache.openjpa.util;
import java.io.Serializable; 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.ReferenceMap;
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
@ -35,7 +36,7 @@ public abstract class OpenJPAId
// cache the types' generated hash codes // cache the types' generated hash codes
private static ConcurrentReferenceHashMap _typeCache = private static ConcurrentReferenceHashMap _typeCache =
new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD); new ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD);
protected Class type; protected Class type;
protected boolean subs = true; protected boolean subs = true;

View File

@ -66,8 +66,8 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-collections</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections4</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sourceforge.serp</groupId> <groupId>net.sourceforge.serp</groupId>

View File

@ -35,6 +35,7 @@ import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.ClassUtil; import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.J2DoPrivHelper; import org.apache.openjpa.lib.util.J2DoPrivHelper;
@ -53,12 +54,10 @@ import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
*/ */
public class Configurations { public class Configurations {
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer.forPackage(Configurations.class);
(Configurations.class);
private static final ConcurrentReferenceHashMap _loaders = new private static final ConcurrentReferenceHashMap _loaders = new
ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.WEAK, ConcurrentReferenceHashMap(ReferenceStrength.WEAK, ReferenceStrength.HARD);
ConcurrentReferenceHashMap.HARD);
private static final Object NULL_LOADER = "null-loader"; private static final Object NULL_LOADER = "null-loader";
@ -195,8 +194,8 @@ public class Configurations {
Map<String,Class<?>> loaderCache = (Map<String,Class<?>>) _loaders.get(key); Map<String,Class<?>> loaderCache = (Map<String,Class<?>>) _loaders.get(key);
if (loaderCache == null) { // We don't have a cache for this loader. if (loaderCache == null) { // We don't have a cache for this loader.
//OPENJPA-2636: Changed to HARD/WEAK to avoid Classloader leak: //OPENJPA-2636: Changed to HARD/WEAK to avoid Classloader leak:
loaderCache = new ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.HARD, loaderCache = new ConcurrentReferenceHashMap(ReferenceStrength.HARD,
ConcurrentReferenceHashMap.WEAK); ReferenceStrength.WEAK);
_loaders.put(key, loaderCache); _loaders.put(key, loaderCache);
} else { // We have a cache for this loader. } else { // We have a cache for this loader.
cls = (Class<?>) loaderCache.get(clsName); cls = (Class<?>) loaderCache.get(clsName);

View File

@ -21,6 +21,7 @@ package org.apache.openjpa.lib.conf;
import java.security.AccessController; import java.security.AccessController;
import java.util.Objects; 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.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.ReferenceMap;
@ -38,7 +39,7 @@ public class ObjectValue extends Value {
// cache the types' classloader // cache the types' classloader
private static ConcurrentReferenceHashMap _classloaderCache = private static ConcurrentReferenceHashMap _classloaderCache =
new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.WEAK); new ConcurrentReferenceHashMap(ReferenceStrength.HARD, ReferenceStrength.WEAK);
private Object _value = null; private Object _value = null;

View File

@ -20,7 +20,7 @@ package org.apache.openjpa.lib.rop;
import java.util.Map; 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 * Specialization of the {@link RandomAccessResultList} that only maintains

View File

@ -29,7 +29,7 @@ import java.util.Map;
* *
* @author Abe White * @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 { implements SizedMap {
private int _max = -1; private int _max = -1;

View File

@ -30,33 +30,18 @@ import java.lang.ref.Reference;
* @since 0.4.0 * @since 0.4.0
*/ */
public class ReferenceHashMap public class ReferenceHashMap
extends org.apache.commons.collections.map.ReferenceMap extends org.apache.commons.collections4.map.ReferenceMap
implements ReferenceMap, SizedMap { implements ReferenceMap, SizedMap {
private int _maxSize = Integer.MAX_VALUE; private int _maxSize = Integer.MAX_VALUE;
public ReferenceHashMap(int keyType, int valueType) { public ReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType) {
super(toReferenceConstant(keyType), toReferenceConstant(valueType)); super(keyType, valueType);
} }
public ReferenceHashMap(int keyType, int valueType, int capacity, public ReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType, int capacity,
float loadFactor) { float loadFactor) {
super(toReferenceConstant(keyType), toReferenceConstant(valueType), super(keyType, valueType, capacity, loadFactor);
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;
}
} }
public int getMaxSize() { public int getMaxSize() {
@ -104,63 +89,11 @@ public class ReferenceHashMap
super.addMapping(hashIndex, hashCode, key, value); 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) { Object value) {
return new AccessibleEntry(this, next, hashCode, key, 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 <code>ReferenceMap.ReferenceEntry.purge</code>.
*/
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 { protected void doWriteObject(ObjectOutputStream out) throws IOException {
out.writeInt(_maxSize); out.writeInt(_maxSize);
super.doWriteObject(out); super.doWriteObject(out);
@ -177,11 +110,13 @@ public class ReferenceHashMap
* protected state. * protected state.
*/ */
private static class AccessibleEntry extends ReferenceEntry { 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, AbstractReferenceMap map, HashEntry next,
int hashCode, Object key, Object value) { int hashCode, Object key, Object value) {
super(map, next, hashCode, key, value); super(map, next, hashCode, key, value);
parent = (ReferenceHashMap)map;
} }
public Object key() { public Object key() {
@ -192,10 +127,6 @@ public class ReferenceHashMap
return value; return value;
} }
public void nullValue() {
value = null;
}
public AccessibleEntry nextEntry() { public AccessibleEntry nextEntry() {
return (AccessibleEntry) next; return (AccessibleEntry) next;
} }
@ -203,5 +134,14 @@ public class ReferenceHashMap
public void setNextEntry(AccessibleEntry next) { public void setNextEntry(AccessibleEntry next) {
this.next = 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);
}
}
} }
} }

View File

@ -24,7 +24,8 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; 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. * 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 * @author Abe White
*/ */
public class ReferenceHashSet implements Set, Serializable { 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() { private static final Object DUMMY_VAL = new Serializable() {
public String toString() { public String toString() {
return ReferenceHashSet.class.getName() + ".DUMMY_VAL"; return ReferenceHashSet.class.getName() + ".DUMMY_VAL";
@ -59,17 +44,12 @@ public class ReferenceHashSet implements Set, Serializable {
/** /**
* Construct a set with the given reference type. * Construct a set with the given reference type.
*/ */
public ReferenceHashSet(int refType) { public ReferenceHashSet(ReferenceStrength refType) {
if (refType == HARD) if (refType == ReferenceStrength.HARD)
_set = new HashSet(); _set = new HashSet();
else { else {
int mapRefType = (refType == WEAK) ? org.apache.commons. _set = MapBackedSet.mapBackedSet(new org.apache.commons.
collections.map.ReferenceMap.WEAK : org.apache. collections4.map.ReferenceMap(refType, ReferenceStrength.HARD), DUMMY_VAL);
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);
} }
} }

View File

@ -27,11 +27,6 @@ import java.util.Map;
* @author Abe White * @author Abe White
*/ */
public interface ReferenceMap extends Map { 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. * Purge stale entries.
*/ */

View File

@ -29,6 +29,7 @@ import java.util.NoSuchElementException;
import java.util.Random; import java.util.Random;
import java.util.Set; 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.ReferenceMap;
import org.apache.openjpa.lib.util.SizedMap; import org.apache.openjpa.lib.util.SizedMap;
@ -83,12 +84,12 @@ public class ConcurrentReferenceHashMap extends AbstractMap
/** /**
* The key reference type. * The key reference type.
*/ */
private int keyType; private ReferenceStrength keyType;
/** /**
* The value reference type. * The value reference type.
*/ */
private int valueType; private ReferenceStrength valueType;
/** /**
* Reference queue for cleared Entries * 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 * references, if the initial capacity is less than or equal to zero, or if
* the load factor is less than or equal to zero * 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) { int initialCapacity, float loadFactor) {
if (initialCapacity < 0) { if (initialCapacity < 0) {
throw new IllegalArgumentException("Illegal Initial Capacity: " + throw new IllegalArgumentException("Illegal Initial Capacity: " +
@ -148,7 +149,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
throw new IllegalArgumentException("Illegal Load factor: " + throw new IllegalArgumentException("Illegal Load factor: " +
loadFactor); loadFactor);
} }
if (keyType != HARD && valueType != HARD) { if (keyType != ReferenceStrength.HARD && valueType != ReferenceStrength.HARD) {
throw new IllegalArgumentException("Either keys or values must " + throw new IllegalArgumentException("Either keys or values must " +
"use hard references."); "use hard references.");
} }
@ -167,7 +168,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
* @param valueType the reference type of map values * @param valueType the reference type of map values
* @param initialCapacity the initial capacity of the HashMap. * @param initialCapacity the initial capacity of the HashMap.
*/ */
public ConcurrentReferenceHashMap(int keyType, int valueType, public ConcurrentReferenceHashMap(ReferenceStrength keyType, ReferenceStrength valueType,
int initialCapacity) { int initialCapacity) {
this(keyType, valueType, initialCapacity, 0.75f); this(keyType, valueType, initialCapacity, 0.75f);
} }
@ -178,7 +179,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
* @param keyType the reference type of map keys * @param keyType the reference type of map keys
* @param valueType the reference type of map values * @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); this(keyType, valueType, 11, 0.75f);
} }
@ -191,7 +192,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
* @param keyType the reference type of map keys * @param keyType the reference type of map keys
* @param valueType the reference type of map values * @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); this(keyType, valueType, Math.max(3 * t.size(), 11), 0.75f);
putAll(t); putAll(t);
} }
@ -243,7 +244,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
Entry[] tab = table; Entry[] tab = table;
if (value == null) { if (value == null) {
if (valueType != HARD) if (valueType != ReferenceStrength.HARD)
return false; return false;
for (int i = tab.length; i-- > 0;) for (int i = tab.length; i-- > 0;)
for (Entry e = tab[i]; e != null; e = e.getNext()) 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. * @param key key whose presence in this Map is to be tested.
*/ */
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
if (key == null && keyType != HARD) if (key == null && keyType != ReferenceStrength.HARD)
return false; return false;
Entry[] tab = table; Entry[] tab = table;
@ -283,7 +284,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
* @param key key whose associated value is to be returned. * @param key key whose associated value is to be returned.
*/ */
public Object get(Object key) { public Object get(Object key) {
if (key == null && keyType != HARD) if (key == null && keyType != ReferenceStrength.HARD)
return null; return null;
Entry[] tab = table; Entry[] tab = table;
@ -311,8 +312,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap
for (int i = oldCapacity; i-- > 0;) { for (int i = oldCapacity; i-- > 0;) {
for (Entry old = oldMap[i]; old != null;) { for (Entry old = oldMap[i]; old != null;) {
if ((keyType != HARD && old.getKey() == null) if ((keyType != ReferenceStrength.HARD && old.getKey() == null)
|| valueType != HARD && old.getValue() == null) { || valueType != ReferenceStrength.HARD && old.getValue() == null) {
Entry e = old; Entry e = old;
old = old.getNext(); old = old.getNext();
e.setNext(null); e.setNext(null);
@ -344,8 +345,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap
* the HashMap previously associated null with the specified key. * the HashMap previously associated null with the specified key.
*/ */
public Object put(Object key, Object value) { public Object put(Object key, Object value) {
if ((key == null && keyType != HARD) if ((key == null && keyType != ReferenceStrength.HARD)
|| (value == null && valueType != HARD)) || (value == null && valueType != ReferenceStrength.HARD))
throw new IllegalArgumentException("Null references not supported"); throw new IllegalArgumentException("Null references not supported");
int hash = hc(key); int hash = hc(key);
@ -360,7 +361,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
e = e.getNext()) { e = e.getNext()) {
if ((e.getHash() == hash) && eq(key, e.getKey())) { if ((e.getHash() == hash) && eq(key, e.getKey())) {
Object old = e.getValue(); Object old = e.getValue();
if (valueType == HARD) if (valueType == ReferenceStrength.HARD)
e.setValue(value); e.setValue(value);
else { else {
e = newEntry(hash, e.getKey(), value, e.getNext()); e = newEntry(hash, e.getKey(), value, e.getNext());
@ -393,7 +394,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
* Creates a new entry. * Creates a new entry.
*/ */
private Entry newEntry(int hash, Object key, Object value, Entry next) { 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) { switch (refType) {
case WEAK: case WEAK:
return new WeakEntry(hash, key, value, refType == keyType, next, 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. * the HashMap previously associated null with the specified key.
*/ */
public Object remove(Object key) { public Object remove(Object key) {
if (key == null && keyType != HARD) if (key == null && keyType != ReferenceStrength.HARD)
return null; return null;
int hash = hc(key); int hash = hc(key);
@ -748,7 +749,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap
tab[index] = e.getNext(); tab[index] = e.getNext();
count--; count--;
if (keyType == HARD) if (keyType == ReferenceStrength.HARD)
valueExpired(e.getKey()); valueExpired(e.getKey());
else else
keyExpired(e.getValue()); keyExpired(e.getValue());

View File

@ -24,7 +24,8 @@ import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; 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 * 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") @SuppressWarnings("serial")
public class ConcurrentReferenceHashSet<E> implements Set<E>, Serializable { public class ConcurrentReferenceHashSet<E> implements Set<E>, 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 static final Object DUMMY_VAL = new Object();
private final Set<E> _set; private final Set<E> _set;
@ -59,14 +44,12 @@ public class ConcurrentReferenceHashSet<E> implements Set<E>, Serializable {
/** /**
* Construct a set with the given reference type. * Construct a set with the given reference type.
*/ */
public ConcurrentReferenceHashSet(int refType) { public ConcurrentReferenceHashSet(ReferenceStrength refType) {
if (refType == HARD) if (refType == ReferenceStrength.HARD)
_set = MapBackedSet.decorate(new ConcurrentHashMap(), DUMMY_VAL); _set = MapBackedSet.mapBackedSet(new ConcurrentHashMap(), DUMMY_VAL);
else { else {
int mapRefType = (refType == WEAK) ? ConcurrentReferenceHashMap.WEAK _set = MapBackedSet.mapBackedSet(new ConcurrentReferenceHashMap
: ConcurrentReferenceHashMap.SOFT; (refType, ReferenceStrength.HARD), DUMMY_VAL);
_set = MapBackedSet.decorate(new ConcurrentReferenceHashMap
(mapRefType, ConcurrentReferenceHashMap.HARD), DUMMY_VAL);
} }
} }

View File

@ -21,6 +21,8 @@ package org.apache.openjpa.lib.util;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
@ -30,8 +32,7 @@ import junit.framework.TestCase;
*/ */
public class TestReferenceSet extends TestCase { public class TestReferenceSet extends TestCase {
private ReferenceHashSet _coll = new ReferenceHashSet private ReferenceHashSet _coll = new ReferenceHashSet(ReferenceStrength.WEAK);
(ReferenceHashSet.WEAK);
private Object _heldValue = new Integer(2); private Object _heldValue = new Integer(2);
@ -48,7 +49,7 @@ public class TestReferenceSet extends TestCase {
* Tests basic add/contains/remove functionality. * Tests basic add/contains/remove functionality.
*/ */
public void testBasics() { public void testBasics() {
Collection coll = new ReferenceHashSet(ReferenceHashSet.WEAK); Collection coll = new ReferenceHashSet(ReferenceStrength.WEAK);
assertEquals(0, coll.size()); assertEquals(0, coll.size());
assertTrue(!coll.contains("foo")); assertTrue(!coll.contains("foo"));

View File

@ -852,8 +852,8 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-collections</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections4</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -18,12 +18,16 @@
*/ */
package org.apache.openjpa.persistence.jdbc.common.apps; package org.apache.openjpa.persistence.jdbc.common.apps;
import java.io.*; import java.io.Serializable;
import java.util.*; 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 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 * Normal class that has relations to and from various horizontal
@ -107,7 +111,7 @@ public class HorizRelation
private ArrayList cHorizInterVerticalD = new ArrayList(); private ArrayList cHorizInterVerticalD = new ArrayList();
public Map getCollections() { public Map getCollections() {
Map map = new SequencedHashMap(); Map map = new LinkedMap();
map.put("HorizA", cHorizA); map.put("HorizA", cHorizA);
map.put("HorizB", cHorizB); map.put("HorizB", cHorizB);
map.put("HorizC", cHorizC); map.put("HorizC", cHorizC);

View File

@ -29,7 +29,7 @@ import java.util.TreeSet;
import org.apache.openjpa.persistence.kernel.common.apps.ProxiesPC; 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.persistence.OpenJPAEntityManager;
import org.apache.openjpa.util.Proxy; import org.apache.openjpa.util.Proxy;

View File

@ -40,7 +40,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.apache.openjpa.persistence.jdbc.KeyColumn; 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.PersistentCollection;
import org.apache.openjpa.persistence.PersistentMap; import org.apache.openjpa.persistence.PersistentMap;

View File

@ -133,8 +133,7 @@
<include>net.sourceforge.serp:serp</include> <include>net.sourceforge.serp:serp</include>
<include>org.apache.derby:derby</include> <include>org.apache.derby:derby</include>
<include>commons-lang:commons-lang</include> <include>org.apache.commons:commons-collections4</include>
<include>commons-collections:commons-collections</include>
<include>org.apache.commons:commons-pool2</include> <include>org.apache.commons:commons-pool2</include>
<include>commons-logging:commons-logging</include> <include>commons-logging:commons-logging</include>
<include>org.apache.commons:commons-dbcp2</include> <include>org.apache.commons:commons-dbcp2</include>

View File

@ -72,8 +72,7 @@
<include>net.sourceforge.serp:serp</include> <include>net.sourceforge.serp:serp</include>
<include>org.apache.derby:derby</include> <include>org.apache.derby:derby</include>
<include>commons-lang:commons-lang</include> <include>org.apache.commons:commons-collections4</include>
<include>commons-collections:commons-collections</include>
<include>org.apache.commons:commons-pool2</include> <include>org.apache.commons:commons-pool2</include>
<include>commons-logging:commons-logging</include> <include>commons-logging:commons-logging</include>
<include>org.apache.commons:commons-dbcp2</include> <include>org.apache.commons:commons-dbcp2</include>

View File

@ -508,9 +508,9 @@
<version>1.2</version> <version>1.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-collections</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections4</artifactId>
<version>3.2.2</version> <version>4.3-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sourceforge.serp</groupId> <groupId>net.sourceforge.serp</groupId>