diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/amazon/carbonado/layout/Layout.java | 12 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/layout/LayoutFactory.java | 10 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/com/amazon/carbonado/layout/Layout.java b/src/main/java/com/amazon/carbonado/layout/Layout.java index f784e84..d127835 100644 --- a/src/main/java/com/amazon/carbonado/layout/Layout.java +++ b/src/main/java/com/amazon/carbonado/layout/Layout.java @@ -408,7 +408,17 @@ public class Layout { throw new IllegalStateException();
}
mStoredLayout.setGeneration(generation);
- mStoredLayout.insert();
+ if (!mStoredLayout.tryInsert()) {
+ StoredLayout existing = mLayoutFactory.mLayoutStorage.prepare();
+ mStoredLayout.copyPrimaryKeyProperties(existing);
+ try {
+ existing.load();
+ } catch (FetchException e) {
+ throw e.toPersistException();
+ }
+ mStoredLayout.setVersionNumber(existing.getVersionNumber());
+ mStoredLayout.update();
+ }
for (LayoutProperty property : mAllProperties) {
property.insert();
}
diff --git a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java index 6deb3ee..dc77b75 100644 --- a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java +++ b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java @@ -125,6 +125,13 @@ public class LayoutFactory implements LayoutCapability { break loadLayout;
}
+ if (knownLayout.getAllProperties().size() == 0) {
+ // This is clearly wrong. All Storables must have
+ // at least one property. Assume that layout record
+ // is corrupt so rebuild it.
+ break;
+ }
+
// If this point is reached, then there was a hash collision in
// the generated layout ID. This should be extremely rare.
// Rehash and try again.
@@ -133,7 +140,8 @@ public class LayoutFactory implements LayoutCapability { // No more rehashes to attempt. This should be extremely,
// extremely rare, unless there is a bug somewhere.
throw new FetchException
- ("Unable to generate unique layout identifier");
+ ("Unable to generate unique layout identifier for " +
+ type.getName());
}
}
|