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. --- RELEASE-NOTES.txt | 5 +++ .../amazon/carbonado/raw/GenericStorableCodec.java | 42 +++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index ef99b2d..4aaf1e3 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,6 +1,11 @@ Carbonado change history ------------------------ +1.1-BETA10 to 1.1-BETA11 +------------------------------- +- Fixed bug when decoding old Storable generations - new properties must be + cleared. Otherwise, indexes on newly added properties might not get updated. + 1.1-BETA9 to 1.1-BETA10 ------------------------------- - JDBCSupportStrategy cleans up database product name before using it to 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