From 64f320d5259ac229bf1040bab005d1a72b80a194 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Tue, 1 May 2012 18:08:27 +0000 Subject: Fixed add trigger exception in subsequent constructions of IndexedStorage when the first throws an exception. --- .../carbonado/repo/indexed/IndexedStorage.java | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo') diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java index 7552834..b00b0b4 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedStorage.java @@ -75,7 +75,7 @@ class IndexedStorage implements Storage, StorageAccess private final StorableIndexSet mQueryableIndexSet; private final QueryEngine mQueryEngine; - + IndexedStorage(IndexAnalysis analysis) throws RepositoryException { mRepository = analysis.repository; mMasterStorage = analysis.masterStorage; @@ -89,14 +89,22 @@ class IndexedStorage implements Storage, StorageAccess } } - // Okay, now start doing some damage. First, remove unnecessary indexes. - for (StorableIndex index : analysis.removeIndexSet) { - removeIndex(index); - } + try { + // Okay, now start doing some damage. First, remove unnecessary indexes. + for (StorableIndex index : analysis.removeIndexSet) { + removeIndex(index); + } - // Now add new indexes. - for (StorableIndex index : analysis.addIndexSet) { - registerIndex((ManagedIndex) mAllIndexInfoMap.get(index)); + // Now add new indexes. + for (StorableIndex index : analysis.addIndexSet) { + registerIndex((ManagedIndex) mAllIndexInfoMap.get(index)); + } + } catch (RepositoryException e) { + // Something went wrong. Cleanup the trigger to avoid an exception if we try again. + if (analysis.indexesTrigger != null) { + removeTrigger(analysis.indexesTrigger); + } + throw e; } mQueryEngine = new QueryEngine(mMasterStorage.getStorableType(), mRepository); -- cgit v1.2.3