From ef4d716bcbd1532dea306e2309b770d8d95e3bbe Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 17 Sep 2007 00:30:11 +0000 Subject: Missing many-to-one join always returns null now. --- .../amazon/carbonado/gen/StorableGenerator.java | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java index 6a66528..e28f07c 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -617,18 +617,15 @@ public final class StorableGenerator { // Now load the object. b.loadLocal(join); - if (!property.isNullable()) { - b.invokeInterface(storableDesc, LOAD_METHOD_NAME, null, null); - } else { - b.invokeInterface - (storableDesc, TRY_LOAD_METHOD_NAME, TypeDesc.BOOLEAN, null); - Label wasLoaded = b.createLabel(); - b.ifZeroComparisonBranch(wasLoaded, "!="); - // Not loaded, so replace joined object with null. - b.loadNull(); - b.storeLocal(join); - wasLoaded.setLocation(); - } + // Always call "try load", even for non-nullable joins. + b.invokeInterface + (storableDesc, TRY_LOAD_METHOD_NAME, TypeDesc.BOOLEAN, null); + Label wasLoaded = b.createLabel(); + b.ifZeroComparisonBranch(wasLoaded, "!="); + // Not loaded, so replace joined object with null. + b.loadNull(); + b.storeLocal(join); + wasLoaded.setLocation(); } else { // Generate query load form. @@ -671,11 +668,9 @@ public final class StorableGenerator { // Just save and return the query. b.storeLocal(join); } else { - String loadMethod = - property.isNullable() ? - TRY_LOAD_ONE_METHOD_NAME : - LOAD_ONE_METHOD_NAME; - b.invokeInterface(queryType, loadMethod, storableDesc, null); + // Always call "try load", even for non-nullable joins. + b.invokeInterface + (queryType, TRY_LOAD_ONE_METHOD_NAME, storableDesc, null); b.checkCast(type); b.storeLocal(join); } @@ -687,7 +682,14 @@ public final class StorableGenerator { b.loadLocal(join); b.storeField(property.getName(), type); - // Add code to identify this property as being loaded. + // Add code to identify this property as being loaded, + // except if value is null and join is not nullable. + + if (!property.isNullable()) { + b.loadLocal(join); + b.ifNullBranch(isLoaded, true); + } + b.loadThis(); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); -- cgit v1.2.3