summaryrefslogtreecommitdiff
path: root/src
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
parent48d34d65928010cf022913bf0126629604a6398d (diff)
More cursor closing paranoia.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/amazon/carbonado/layout/Layout.java14
-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
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java20
4 files changed, 56 insertions, 41 deletions
diff --git a/src/main/java/com/amazon/carbonado/layout/Layout.java b/src/main/java/com/amazon/carbonado/layout/Layout.java
index 62e29f2..1c6b63d 100644
--- a/src/main/java/com/amazon/carbonado/layout/Layout.java
+++ b/src/main/java/com/amazon/carbonado/layout/Layout.java
@@ -231,13 +231,17 @@ public class Layout {
.orderBy("ordinal")
.fetch();
- List<LayoutProperty> list = new ArrayList<LayoutProperty>();
+ try {
+ List<LayoutProperty> list = new ArrayList<LayoutProperty>();
- while (cursor.hasNext()) {
- list.add(new LayoutProperty(cursor.next()));
- }
+ while (cursor.hasNext()) {
+ list.add(new LayoutProperty(cursor.next()));
+ }
- mAllProperties = Collections.unmodifiableList(list);
+ mAllProperties = Collections.unmodifiableList(list);
+ } finally {
+ cursor.close();
+ }
}
return mAllProperties;
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();
}
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
index 7792536..6fc7cdd 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
@@ -245,16 +245,20 @@ abstract class BDBRepository<Txn>
metaRepo.storageFor(StoredDatabaseInfo.class)
.query().orderBy("databaseName").fetch();
- ArrayList<String> names = new ArrayList<String>();
- while (cursor.hasNext()) {
- StoredDatabaseInfo info = cursor.next();
- // Ordinary user types support evolution.
- if (info.getEvolutionStrategy() != StoredDatabaseInfo.EVOLUTION_NONE) {
- names.add(info.getDatabaseName());
+ try {
+ ArrayList<String> names = new ArrayList<String>();
+ while (cursor.hasNext()) {
+ StoredDatabaseInfo info = cursor.next();
+ // Ordinary user types support evolution.
+ if (info.getEvolutionStrategy() != StoredDatabaseInfo.EVOLUTION_NONE) {
+ names.add(info.getDatabaseName());
+ }
}
- }
- return names.toArray(new String[names.size()]);
+ return names.toArray(new String[names.size()]);
+ } finally {
+ cursor.close();
+ }
}
public boolean isSupported(Class<Storable> type) {