From f1d68efbd516ea37ed12a0d2da430b59b8e418f9 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 30 Jan 2007 03:19:58 +0000 Subject: More cursor closing paranoia. --- .../carbonado/repo/indexed/IndexedRepository.java | 10 ++-- .../carbonado/repo/indexed/ManagedIndex.java | 53 ++++++++++++---------- 2 files changed, 35 insertions(+), 28 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 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 implements IndexEntryAccessor { Transaction txn = repo.enterTopTransaction(IsolationLevel.NONE); try { Cursor 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(); } -- cgit v1.2.3