From f0ec30fd9cc7fa19f9f9bf82d7d7449a65d90359 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 15 Oct 2006 17:50:08 +0000 Subject: Created StorageCollection. More tests added. --- .../carbonado/repo/indexed/IndexedRepository.java | 47 +++++++++++----------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/indexed') diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java index 59a359b..6fc6d57 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java @@ -20,8 +20,6 @@ package com.amazon.carbonado.repo.indexed; import java.util.ArrayList; import java.util.Arrays; -import java.util.Map; -import java.util.IdentityHashMap; import java.util.concurrent.atomic.AtomicReference; @@ -45,6 +43,8 @@ import com.amazon.carbonado.info.StorableIntrospector; import com.amazon.carbonado.qe.RepositoryAccess; import com.amazon.carbonado.qe.StorageAccess; +import com.amazon.carbonado.spi.StorageCollection; + /** * Wraps another repository in order to make it support indexes. The wrapped * repository must support creation of new types. @@ -60,30 +60,17 @@ class IndexedRepository implements Repository, private final AtomicReference mRootRef; private final Repository mRepository; private final String mName; - private final Map, IndexedStorage> mStorages; + private final StorageCollection mStorages; IndexedRepository(AtomicReference rootRef, String name, Repository repository) { mRootRef = rootRef; mRepository = repository; mName = name; - mStorages = new IdentityHashMap, IndexedStorage>(); - if (repository.getCapability(IndexInfoCapability.class) == null) { - throw new UnsupportedOperationException - ("Wrapped repository doesn't support being indexed"); - } - } - - public String getName() { - return mName; - } - @SuppressWarnings("unchecked") - public Storage storageFor(Class type) - throws MalformedTypeException, SupportException, RepositoryException - { - synchronized (mStorages) { - IndexedStorage storage = (IndexedStorage) mStorages.get(type); - if (storage == null) { + mStorages = new StorageCollection() { + protected Storage createStorage(Class type) + throws RepositoryException + { Storage masterStorage = mRepository.storageFor(type); if (Unindexed.class.isAssignableFrom(type)) { @@ -98,13 +85,27 @@ class IndexedRepository implements Repository, return masterStorage; } - storage = new IndexedStorage(this, masterStorage); - mStorages.put(type, storage); + return new IndexedStorage(IndexedRepository.this, masterStorage); } - return storage; + }; + + if (repository.getCapability(IndexInfoCapability.class) == null) { + throw new UnsupportedOperationException + ("Wrapped repository doesn't support being indexed"); } } + public String getName() { + return mName; + } + + @SuppressWarnings("unchecked") + public Storage storageFor(Class type) + throws MalformedTypeException, SupportException, RepositoryException + { + return mStorages.storageFor(type); + } + public Transaction enterTransaction() { return mRepository.enterTransaction(); } -- cgit v1.2.3