From b7dc20f3a6f215c38612dc82e32efd9bf64ea8cc Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 2 Feb 2007 04:22:35 +0000 Subject: Fixed bug when decoding old Storable generations - new properties must be cleared. Otherwise, indexes on newly added properties might not get updated. --- .../amazon/carbonado/raw/GenericStorableCodec.java | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java index 8113b32..54eca76 100644 --- a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java +++ b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java @@ -708,9 +708,10 @@ public class GenericStorableCodec implements StorableCodec generateDecoder(int generation) throws FetchException { // Create an encoding strategy against the reconstructed storable. + Class altStorable; GenericEncodingStrategy altStrategy; try { - Class altStorable = mLayout.getGeneration(generation) + altStorable = mLayout.getGeneration(generation) .reconstruct(mStorableClass.getClassLoader()); altStrategy = mFactory.createStrategy(altStorable, null); } catch (RepositoryException e) { @@ -758,6 +759,45 @@ public class GenericStorableCodec implements StorableCodec currentProps = + StorableIntrospector.examine(mType).getAllProperties(); + + Map altProps = + StorableIntrospector.examine(altStorable).getAllProperties(); + + for (StorableProperty prop : currentProps.values()) { + if (altProps.keySet().contains(prop.getName())) { + continue; + } + + b.loadLocal(destVar); + + TypeDesc propType = TypeDesc.forClass(prop.getType()); + + switch (propType.getTypeCode()) { + case TypeDesc.OBJECT_CODE: + b.loadNull(); + break; + case TypeDesc.LONG_CODE: + b.loadConstant(0L); + break; + case TypeDesc.FLOAT_CODE: + b.loadConstant(0.0f); + break; + case TypeDesc.DOUBLE_CODE: + b.loadConstant(0.0d); + break; + default: + b.loadConstant(0); + break; + } + + b.storeField(destVar.getType(), prop.getName(), propType); + } + b.returnVoid(); Class clazz = ci.defineClass(cf); -- cgit v1.2.3