summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java
index 4506bc1..4b9bd07 100644
--- a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java
+++ b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java
@@ -90,7 +90,8 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S
Layout layout, RawSupport support)
throws SupportException
{
- Object key = KeyFactory.createKey(new Object[] {encodingStrategy, isMaster, layout});
+ Object layoutKey = layout == null ? null : new LayoutKey(layout);
+ Object key = KeyFactory.createKey(new Object[] {encodingStrategy, isMaster, layoutKey});
Class<? extends S> storableImpl = (Class<? extends S>) cCache.get(key);
if (storableImpl == null) {
@@ -913,4 +914,40 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S
*/
void decode(S dest, byte[] data) throws CorruptEncodingException;
}
+
+ /**
+ * Compares layouts for equivalence with respect to class creation and
+ * sharing.
+ */
+ private static class LayoutKey {
+ private final Layout mLayout;
+
+ LayoutKey(Layout layout) {
+ mLayout = layout;
+ }
+
+ @Override
+ public int hashCode() {
+ return mLayout.getStorableTypeName().hashCode() * 7 + mLayout.getGeneration();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof LayoutKey) {
+ LayoutKey other = (LayoutKey) obj;
+ try {
+ return mLayout.getStorableTypeName()
+ .equals(other.mLayout.getStorableTypeName()) &&
+ mLayout.getGeneration() == other.mLayout.getGeneration() &&
+ mLayout.equalLayouts(other.mLayout);
+ } catch (FetchException e) {
+ return false;
+ }
+ }
+ return false;
+ }
+ }
}