From 6b128f6b4bafe78400e96759f109da22a647103c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 3 Oct 2011 21:55:21 +0000 Subject: Fix index entry class generation when using mix of repository types. --- .../repo/indexed/IndexEntryGenerator.java | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java index b245d2e..1a8de2e 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java @@ -18,11 +18,7 @@ package com.amazon.carbonado.repo.indexed; -import java.util.Comparator; -import java.util.Map; -import java.util.WeakHashMap; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; +import com.amazon.carbonado.util.SoftValuedCache; import com.amazon.carbonado.Storable; import com.amazon.carbonado.SupportException; @@ -41,9 +37,8 @@ import com.amazon.carbonado.synthetic.SyntheticStorableReferenceBuilder; */ class IndexEntryGenerator { - // cache for access classes - private static Map> cCache = - new WeakHashMap>(); + private static final SoftValuedCache cCache = + SoftValuedCache.newCache(11); /** * Returns a new or cached index access instance. The caching of accessors @@ -87,14 +82,13 @@ class IndexEntryGenerator { SyntheticStorableReferenceAccess getIndexAccess(StorableIndex index) throws SupportException { + // Strip out index property not related to its identity. + index = index.clustered(false); + synchronized (cCache) { - SyntheticStorableReferenceAccess access; - Reference ref = cCache.get(index); - if (ref != null) { - access = ref.get(); - if (access != null) { - return access; - } + SyntheticStorableReferenceAccess access = cCache.get(index); + if (access != null) { + return access; } // Need to try to find the base type. This is an awkward way to do @@ -112,7 +106,7 @@ class IndexEntryGenerator { builder.build(); access = builder.getReferenceAccess(); - cCache.put(index, new SoftReference(access)); + cCache.put(index, access); return access; } -- cgit v1.2.3