From 41bc565cc82b87d1c1ef9f85705a1fc8fdd6f0f1 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 8 Jun 2010 02:33:09 +0000 Subject: Fix serialization of adapted primary key properties. --- .../amazon/carbonado/gen/StorableGenerator.java | 35 +++++++--------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java index 8242941..ddde311 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -966,9 +966,7 @@ public final class StorableGenerator { // Note: Calling these methods does not affect any state bits. // They are only intended to be used by subclasses during loading. - if (property.getAdapter() != null && - (!property.isDerived() || (property.getWriteMethod() != null))) - { + if (property.getAdapter() != null && !property.isDerived()) { // End name with '$' to prevent any possible collisions. String writeName = property.getWriteMethodName() + '$'; @@ -996,7 +994,9 @@ public final class StorableGenerator { b.loadLocal(b.getParameter(0)); b.invoke(adaptMethod); - storeProperty(b, property, type); + // Always store to field directly, to prevent state + // bits from changing. + b.storeField(property.getName(), type); b.returnVoid(); } @@ -1991,7 +1991,12 @@ public final class StorableGenerator { b.loadLocal(target); // [target loadThisProperty(b, property, type); // [target, this.propValue - storeProperty(b, property, type); + if (property.getWriteMethod() != null) { + // Favor the write method, if it exists. + b.invoke(property.getWriteMethod()); + } else { + b.storeField(property.getName(), type); + } skipCopy.setLocation(); } @@ -2067,26 +2072,6 @@ public final class StorableGenerator { } } - /** - * Puts the value on the stack into the specified storable. If a write - * method is defined, use it. Otherwise, just shove the value into the - * appropriate field. - * - * entry stack: [storable, value - * exit stack: [ - * - * @param b - {@link CodeBuilder} to which to add the mutation code - * @param property - property to mutate - * @param type - type of the property - */ - private void storeProperty(CodeBuilder b, StorableProperty property, TypeDesc type) { - if (property.getWriteMethod() == null && !property.isDerived()) { - b.storeField(property.getName(), type); - } else { - b.invoke(property.getWriteMethod()); - } - } - /** * Generates code that loads a property annotation to the stack. */ -- cgit v1.2.3