From b04929437cf6cbfd9c2a4a64cb453ce072084a4e Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 27 Mar 2009 00:20:53 +0000 Subject: Make sure FetchException propagates from generated index Storable correctly. --- .../carbonado/repo/indexed/DependentStorableFetcher.java | 2 +- .../amazon/carbonado/repo/indexed/IndexEntryAccessor.java | 7 ++++--- .../com/amazon/carbonado/repo/indexed/ManagedIndex.java | 10 ++++++---- .../synthetic/SyntheticStorableReferenceAccess.java | 13 +++++++------ .../synthetic/SyntheticStorableReferenceBuilder.java | 7 ++++--- 5 files changed, 22 insertions(+), 17 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/DependentStorableFetcher.java b/src/main/java/com/amazon/carbonado/repo/indexed/DependentStorableFetcher.java index d9e9f32..5141788 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/DependentStorableFetcher.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/DependentStorableFetcher.java @@ -132,7 +132,7 @@ class DependentStorableFetcher { /** * @return amount added to list */ - public int createIndexEntries(D master, List indexEntries) { + public int createIndexEntries(D master, List indexEntries) throws FetchException { IndexEntryAccessor[] accessors = mIndexEntryAccessors; int length = accessors.length; for (int i=0; i extends IndexInfo { * @param indexEntry source of property values * @param master master whose primary key properties will be set */ - void copyToMasterPrimaryKey(Storable indexEntry, S master); + void copyToMasterPrimaryKey(Storable indexEntry, S master) throws FetchException; /** * Sets all the properties of the given index entry, using the applicable @@ -55,7 +56,7 @@ public interface IndexEntryAccessor extends IndexInfo { * @param indexEntry index entry whose properties will be set * @param master source of property values */ - void copyFromMaster(Storable indexEntry, S master); + void copyFromMaster(Storable indexEntry, S master) throws FetchException; /** * Returns true if the properties of the given index entry match those @@ -65,7 +66,7 @@ public interface IndexEntryAccessor extends IndexInfo { * @param indexEntry index entry whose properties will be tested * @param master source of property values */ - boolean isConsistent(Storable indexEntry, S master); + boolean isConsistent(Storable indexEntry, S master) throws FetchException; /** * Repairs the index by inserting missing entries and fixing 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 8219ac1..e730c6e 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java @@ -146,17 +146,17 @@ class ManagedIndex implements IndexEntryAccessor { } // Required by IndexEntryAccessor interface. - public void copyToMasterPrimaryKey(Storable indexEntry, S master) { + public void copyToMasterPrimaryKey(Storable indexEntry, S master) throws FetchException { mAccessor.copyToMasterPrimaryKey(indexEntry, master); } // Required by IndexEntryAccessor interface. - public void copyFromMaster(Storable indexEntry, S master) { + public void copyFromMaster(Storable indexEntry, S master) throws FetchException { mAccessor.copyFromMaster(indexEntry, master); } // Required by IndexEntryAccessor interface. - public boolean isConsistent(Storable indexEntry, S master) { + public boolean isConsistent(Storable indexEntry, S master) throws FetchException { return mAccessor.isConsistent(indexEntry, master); } @@ -561,7 +561,7 @@ class ManagedIndex implements IndexEntryAccessor { } // If index entry already exists, then index might be corrupt. - { + try { Storable freshEntry = mIndexEntryStorage.prepare(); mAccessor.copyFromMaster(freshEntry, userStorable); indexEntry.copyVersionProperty(freshEntry); @@ -571,6 +571,8 @@ class ManagedIndex implements IndexEntryAccessor { // user error. return !isUnique(); } + } catch (FetchException e) { + throw e.toPersistException(); } // Run the repair outside a transaction. diff --git a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java index 778b4ac..f83be02 100644 --- a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java +++ b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java @@ -24,6 +24,7 @@ import java.lang.reflect.UndeclaredThrowableException; import java.util.Comparator; import java.util.Iterator; +import com.amazon.carbonado.FetchException; import com.amazon.carbonado.Storable; import com.amazon.carbonado.cursor.SortedCursor; @@ -109,11 +110,11 @@ public class SyntheticStorableReferenceAccess { * @param reference source of property values * @param master master whose primary key properties will be set */ - public void copyToMasterPrimaryKey(Storable reference, S master) { + public void copyToMasterPrimaryKey(Storable reference, S master) throws FetchException { try { mCopyToMasterPkMethod.invoke(reference, master); } catch (Exception e) { - ThrowUnchecked.fireFirstDeclaredCause(e); + ThrowUnchecked.fireFirstDeclaredCause(e, FetchException.class); } } @@ -124,11 +125,11 @@ public class SyntheticStorableReferenceAccess { * @param reference reference whose properties will be set * @param master source of property values */ - public void copyFromMaster(Storable reference, S master) { + public void copyFromMaster(Storable reference, S master) throws FetchException { try { mCopyFromMasterMethod.invoke(reference, master); } catch (Exception e) { - ThrowUnchecked.fireFirstDeclaredCause(e); + ThrowUnchecked.fireFirstDeclaredCause(e, FetchException.class); } } @@ -140,11 +141,11 @@ public class SyntheticStorableReferenceAccess { * @param reference reference whose properties will be tested * @param master source of property values */ - public boolean isConsistent(Storable reference, S master) { + public boolean isConsistent(Storable reference, S master) throws FetchException { try { return (Boolean) mIsConsistentMethod.invoke(reference, master); } catch (Exception e) { - ThrowUnchecked.fireFirstDeclaredCause(e); + ThrowUnchecked.fireFirstDeclaredCause(e, FetchException.class); // Not reached. return false; } diff --git a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java index a06c557..75f1701 100644 --- a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java +++ b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java @@ -26,6 +26,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import com.amazon.carbonado.FetchException; import com.amazon.carbonado.Storable; import com.amazon.carbonado.SupportException; import com.amazon.carbonado.info.Direction; @@ -350,7 +351,7 @@ public class SyntheticStorableReferenceBuilder * @deprecated call getReferenceAccess */ @Deprecated - public void copyToMasterPrimaryKey(Storable indexEntry, S master) { + public void copyToMasterPrimaryKey(Storable indexEntry, S master) throws FetchException { getReferenceAccess().copyToMasterPrimaryKey(indexEntry, master); } @@ -363,7 +364,7 @@ public class SyntheticStorableReferenceBuilder * @deprecated call getReferenceAccess */ @Deprecated - public void copyFromMaster(Storable indexEntry, S master) { + public void copyFromMaster(Storable indexEntry, S master) throws FetchException { getReferenceAccess().copyFromMaster(indexEntry, master); } @@ -379,7 +380,7 @@ public class SyntheticStorableReferenceBuilder * @deprecated call getReferenceAccess */ @Deprecated - public boolean isConsistent(Storable indexEntry, S master) { + public boolean isConsistent(Storable indexEntry, S master) throws FetchException { return getReferenceAccess().isConsistent(indexEntry, master); } -- cgit v1.2.3