summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-12-19 02:29:16 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-12-19 02:29:16 +0000
commitbeffd324a69aab98494839098f32c57de34e101e (patch)
tree957ec0323094635b6403e232f723740372dd6665 /src/main/java
parent4f7a814bc1ac9230904234b2724c09f84052e05a (diff)
Allow generated classes to be shared among repositories whose relevant metadata does not differ.
Diffstat (limited to 'src/main/java')
-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;
+ }
+ }
}