diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2011-10-03 21:55:21 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2011-10-03 21:55:21 +0000 |
commit | 6b128f6b4bafe78400e96759f109da22a647103c (patch) | |
tree | 69875ad6914930a91b29235d9496c4536eb68233 /src/main/java/com/amazon/carbonado/repo | |
parent | 312018c6ef5a3231c260e4ecdcd4c83588b56479 (diff) |
Fix index entry class generation when using mix of repository types.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java | 26 |
1 files changed, 10 insertions, 16 deletions
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 <S extends Storable> {
- // cache for access classes
- private static Map<StorableIndex, Reference<SyntheticStorableReferenceAccess>> cCache =
- new WeakHashMap<StorableIndex, Reference<SyntheticStorableReferenceAccess>>();
+ private static final SoftValuedCache<StorableIndex, SyntheticStorableReferenceAccess> cCache =
+ SoftValuedCache.newCache(11);
/**
* Returns a new or cached index access instance. The caching of accessors
@@ -87,14 +82,13 @@ class IndexEntryGenerator <S extends Storable> { SyntheticStorableReferenceAccess<S> getIndexAccess(StorableIndex<S> index)
throws SupportException
{
+ // Strip out index property not related to its identity.
+ index = index.clustered(false);
+
synchronized (cCache) {
- SyntheticStorableReferenceAccess<S> access;
- Reference<SyntheticStorableReferenceAccess> ref = cCache.get(index);
- if (ref != null) {
- access = ref.get();
- if (access != null) {
- return access;
- }
+ SyntheticStorableReferenceAccess<S> 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 <S extends Storable> { builder.build();
access = builder.getReferenceAccess();
- cCache.put(index, new SoftReference<SyntheticStorableReferenceAccess>(access));
+ cCache.put(index, access);
return access;
}
|