summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/indexed
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-01-30 03:19:58 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-01-30 03:19:58 +0000
commitf1d68efbd516ea37ed12a0d2da430b59b8e418f9 (patch)
tree01bfd180cc3f1366e0abb5c31702d902450cb5e1 /src/main/java/com/amazon/carbonado/repo/indexed
parent48d34d65928010cf022913bf0126629604a6398d (diff)
More cursor closing paranoia.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/indexed')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java10
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java53
2 files changed, 35 insertions, 28 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 b9380fc..8516628 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedRepository.java
@@ -159,9 +159,13 @@ class IndexedRepository implements Repository,
mRepository.storageFor(StoredIndexInfo.class)
.query().fetch();
- while (cursor.hasNext()) {
- StoredIndexInfo info = cursor.next();
- names.remove(info.getIndexName());
+ try {
+ while (cursor.hasNext()) {
+ StoredIndexInfo info = cursor.next();
+ names.remove(info.getIndexName());
+ }
+ } finally {
+ cursor.close();
}
return names.toArray(new String[names.size()]);
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java
index bb17067..ebdea0b 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java
@@ -302,37 +302,40 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> {
Transaction txn = repo.enterTopTransaction(IsolationLevel.NONE);
try {
Cursor<S> cursor = masterStorage.query().fetch();
- if (!cursor.hasNext()) {
- // Nothing exists in master, so nothing to populate.
- cursor.close();
- return;
- }
+ try {
+ if (!cursor.hasNext()) {
+ // Nothing exists in master, so nothing to populate.
+ return;
+ }
- Log log = LogFactory.getLog(IndexedStorage.class);
- if (log.isInfoEnabled()) {
- StringBuilder b = new StringBuilder();
- b.append("Populating index on ");
- b.append(masterStorage.getStorableType().getName());
- b.append(": ");
- try {
- mIndex.appendTo(b);
- } catch (java.io.IOException e) {
- // Not gonna happen.
+ Log log = LogFactory.getLog(IndexedStorage.class);
+ if (log.isInfoEnabled()) {
+ StringBuilder b = new StringBuilder();
+ b.append("Populating index on ");
+ b.append(masterStorage.getStorableType().getName());
+ b.append(": ");
+ try {
+ mIndex.appendTo(b);
+ } catch (java.io.IOException e) {
+ // Not gonna happen.
+ }
+ log.info(b.toString());
}
- log.info(b.toString());
- }
- // Preload and sort all index entries for improved performance.
+ // Preload and sort all index entries for improved performance.
- buffer = new MergeSortBuffer(mIndexEntryStorage);
- c = mGenerator.getComparator();
- buffer.prepare(c);
+ buffer = new MergeSortBuffer(mIndexEntryStorage);
+ c = mGenerator.getComparator();
+ buffer.prepare(c);
- while (cursor.hasNext()) {
- buffer.add(makeIndexEntry(cursor.next()));
- }
+ while (cursor.hasNext()) {
+ buffer.add(makeIndexEntry(cursor.next()));
+ }
- // No need to commit transaction because no changes should have been made.
+ // No need to commit transaction because no changes should have been made.
+ } finally {
+ cursor.close();
+ }
} finally {
txn.exit();
}