diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-10-15 17:50:08 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-10-15 17:50:08 +0000 |
commit | f0ec30fd9cc7fa19f9f9bf82d7d7449a65d90359 (patch) | |
tree | ffb5f5fecb4282f1bdb6e8bbb3e572f256310a70 /src/main/java/com/amazon/carbonado/repo/indexed | |
parent | 4ceddfc456e83a79e782599b5b86b68e38b6ef94 (diff) |
Created StorageCollection.
More tests added.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/indexed')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java | 47 |
1 files changed, 24 insertions, 23 deletions
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<Repository> mRootRef;
private final Repository mRepository;
private final String mName;
- private final Map<Class<?>, IndexedStorage<?>> mStorages;
+ private final StorageCollection mStorages;
IndexedRepository(AtomicReference<Repository> rootRef, String name, Repository repository) {
mRootRef = rootRef;
mRepository = repository;
mName = name;
- mStorages = new IdentityHashMap<Class<?>, 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 <S extends Storable> Storage<S> storageFor(Class<S> type)
- throws MalformedTypeException, SupportException, RepositoryException
- {
- synchronized (mStorages) {
- IndexedStorage<S> storage = (IndexedStorage<S>) mStorages.get(type);
- if (storage == null) {
+ mStorages = new StorageCollection() {
+ protected <S extends Storable> Storage<S> createStorage(Class<S> type)
+ throws RepositoryException
+ {
Storage<S> masterStorage = mRepository.storageFor(type);
if (Unindexed.class.isAssignableFrom(type)) {
@@ -98,13 +85,27 @@ class IndexedRepository implements Repository, return masterStorage;
}
- storage = new IndexedStorage<S>(this, masterStorage);
- mStorages.put(type, storage);
+ return new IndexedStorage<S>(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 <S extends Storable> Storage<S> storageFor(Class<S> type)
+ throws MalformedTypeException, SupportException, RepositoryException
+ {
+ return mStorages.storageFor(type);
+ }
+
public Transaction enterTransaction() {
return mRepository.enterTransaction();
}
|