From a0221d4424075bf52dff218361ddd2848ea39126 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 26 Jul 2007 05:10:00 +0000 Subject: Improved support for String and character types. --- .../carbonado/repo/jdbc/JDBCStorableGenerator.java | 23 +++++++++++- .../repo/jdbc/JDBCStorableIntrospector.java | 43 ++++++++++++++++++++-- 2 files changed, 60 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 57f7bbc..0e5b74e 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java @@ -1520,7 +1520,14 @@ class JDBCStorableGenerator { b.storeToArray(TypeDesc.OBJECT); } } else { - b.convert(fromType, psType); + if (psType == TypeDesc.STRING && fromType.toPrimitiveType() == TypeDesc.CHAR) { + // Special case for converting character to String. + b.convert(fromType, fromType.toPrimitiveType()); + b.invokeStatic(String.class.getName(), "valueOf", + TypeDesc.STRING, new TypeDesc[] {TypeDesc.CHAR}); + } else { + b.convert(fromType, psType); + } b.invoke(property.getPreparedStatementSetMethod()); } @@ -1863,7 +1870,19 @@ class JDBCStorableGenerator { StorablePropertyAdapter adapter = property.getAppliedAdapter(); if (adapter == null) { TypeDesc propertyType = TypeDesc.forClass(property.getType()); - b.convert(resultSetType, propertyType); + + if (resultSetType == TypeDesc.STRING && + propertyType.toPrimitiveType() == TypeDesc.CHAR) + { + // Special case for converting String to character. + b.loadConstant(0); + b.invokeVirtual(String.class.getName(), "charAt", + TypeDesc.CHAR, new TypeDesc[] {TypeDesc.INT}); + b.convert(TypeDesc.CHAR, propertyType); + } else { + b.convert(resultSetType, propertyType); + } + wasNull.setLocation(); // Set protected field directly, since no adapter. b.storeField(superType, property.getName(), propertyType); diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java index ee31b6c..4805ee2 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java @@ -502,8 +502,7 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (!mainProperty.isPrimaryKeyMember()) { errorMessages.add - ("Property \"" + propertyName + - "\" must have a PrimaryKey annotation"); + ("Property \"" + propertyName + "\" must be a primary key member"); } } while (rs.next()); } finally { @@ -516,7 +515,7 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (mainProperty.isPrimaryKeyMember()) { errorMessages.add - ("Property \"" + propertyName + "\" cannot have a PrimaryKey annotation"); + ("Property \"" + propertyName + "\" cannot be a primary key member"); } } } @@ -621,7 +620,7 @@ public class JDBCStorableIntrospector extends StorableIntrospector { /** * Figures out how to best access the given property, or returns null if - * not supported. An adapter is not be applied. + * not supported. An adapter is not applied. * * @return null if not supported */ @@ -649,6 +648,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == boolean.class) { actualClass = boolean.class; suffix = "Boolean"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -658,6 +660,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == byte.class) { actualClass = byte.class; suffix = "Byte"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -667,6 +672,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == short.class) { actualClass = short.class; suffix = "Short"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -676,6 +684,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == int.class) { actualClass = int.class; suffix = "Int"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -685,6 +696,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == long.class) { actualClass = long.class; suffix = "Long"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -694,6 +708,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == float.class) { actualClass = float.class; suffix = "Float"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -704,6 +721,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == double.class) { actualClass = double.class; suffix = "Double"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -745,6 +765,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { } else { return null; } + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -756,6 +779,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == String.class) { actualClass = String.class; suffix = "String"; + } else if (desiredClass == char.class && columnSize == 1) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -768,6 +794,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == Date.class || desiredClass == java.sql.Date.class) { actualClass = java.sql.Timestamp.class; suffix = "Timestamp"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -777,6 +806,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == Date.class || desiredClass == java.sql.Time.class) { actualClass = java.sql.Time.class; suffix = "Time"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } @@ -786,6 +818,9 @@ public class JDBCStorableIntrospector extends StorableIntrospector { if (desiredClass == Date.class || desiredClass == java.sql.Timestamp.class) { actualClass = java.sql.Timestamp.class; suffix = "Timestamp"; + } else if (desiredClass == String.class) { + actualClass = String.class; + suffix = "String"; } else { return null; } -- cgit v1.2.3