diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2007-02-02 04:22:35 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2007-02-02 04:22:35 +0000 |
commit | b7dc20f3a6f215c38612dc82e32efd9bf64ea8cc (patch) | |
tree | 45ea417091cb0fbaa597fdf579dbaeaa93d11a47 | |
parent | ab268b8230416d1d8eebb96fc48a4b4dd1e32ced (diff) |
Fixed bug when decoding old Storable generations - new properties must be cleared. Otherwise, indexes on newly added properties might not get updated.
-rw-r--r-- | RELEASE-NOTES.txt | 5 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java | 42 |
2 files changed, 46 insertions, 1 deletions
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<S extends Storable> implements StorableCodec<S private Decoder<S> generateDecoder(int generation) throws FetchException {
// Create an encoding strategy against the reconstructed storable.
+ Class<? extends Storable> altStorable;
GenericEncodingStrategy<? extends Storable> altStrategy;
try {
- Class<? extends Storable> 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<S extends Storable> implements StorableCodec<S throw new CorruptEncodingException(e);
}
+ // Clear all properties available in the current generation which
+ // aren't in the alt generation.
+
+ Map<String, ? extends StorableProperty> currentProps =
+ StorableIntrospector.examine(mType).getAllProperties();
+
+ Map<String, ? extends StorableProperty> 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<? extends Decoder> clazz = ci.defineClass(cf);
|