From a92760945cbc83d2f9f8543f6b905701b1b8ac6a Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 12 Sep 2007 00:45:52 +0000 Subject: More lenient with Nullable Independent properties which aren't supported. --- .../carbonado/repo/jdbc/JDBCStorableGenerator.java | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java index c8f636c..ca8188b 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java @@ -222,19 +222,38 @@ class JDBCStorableGenerator { defineExtractDataMethod(lobLoaderMap); // For all unsupported properties, override get/set method to throw - // UnsupportedOperationException. + // UnsupportedOperationException. Special treatment given if property + // is also Nullable. Get returns null and set only allows null. { for (JDBCStorableProperty property : mAllProperties.values()) { if (property.isDerived() || property.isJoin() || property.isSupported()) { continue; } + + CodeBuilder b; + Class exClass = UnsupportedOperationException.class; String message = "Independent property \"" + property.getName() + "\" is not supported by the SQL schema: "; - message += mInfo.getTableName(); - CodeBuilder b = new CodeBuilder(mClassFile.addMethod(property.getReadMethod())); - CodeBuilderUtil.throwException(b, UnsupportedOperationException.class, message); - b = new CodeBuilder(mClassFile.addMethod(property.getWriteMethod())); - CodeBuilderUtil.throwException(b, UnsupportedOperationException.class, message); + + if (property.isNullable()) { + b = new CodeBuilder(mClassFile.addMethod(property.getReadMethod())); + b.loadNull(); + b.returnValue(TypeDesc.OBJECT); + + b = new CodeBuilder(mClassFile.addMethod(property.getWriteMethod())); + b.loadLocal(b.getParameter(0)); + Label notNull = b.createLabel(); + b.ifNullBranch(notNull, false); + b.returnVoid(); + notNull.setLocation(); + CodeBuilderUtil.throwException(b, exClass, message); + } else { + message += mInfo.getTableName(); + b = new CodeBuilder(mClassFile.addMethod(property.getReadMethod())); + CodeBuilderUtil.throwException(b, exClass, message); + b = new CodeBuilder(mClassFile.addMethod(property.getWriteMethod())); + CodeBuilderUtil.throwException(b, exClass, message); + } } } -- cgit v1.2.3