summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2012-04-25 16:30:32 +0000
committerBrian S. O'Neill <bronee@gmail.com>2012-04-25 16:30:32 +0000
commitbbb9c4d99701a5f6035060e680d3f2c774f53212 (patch)
treea9f5ab44c2778fe7b13a7938ea3321d463d34f52 /src/main/java/com
parent8a4d3f53fba552a5eddafc619729ba4560d48c58 (diff)
Infer type names for data sources that don't report the type properly.
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java48
1 files changed, 48 insertions, 0 deletions
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 9e9134f..924b045 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java
@@ -77,6 +77,7 @@ import com.amazon.carbonado.util.SoftValuedCache;
* @author Adam D Bradley
* @author Tobias Holgers
* @author Archit Shivaprakash
+ * @author Matt Carlson
*/
public class JDBCStorableIntrospector extends StorableIntrospector {
// Maps compound keys to softly referenced JDBCStorableInfo objects.
@@ -598,6 +599,20 @@ public class JDBCStorableIntrospector extends StorableIntrospector {
return info;
}
+ // Dynamically typed data sources (e.g. SQLite3) always report
+ // dataType as java.sql.Types.VARCHAR. Infer the dataType from the
+ // dataTypeName and try again.
+ if (dataType == java.sql.Types.VARCHAR) {
+ Integer dataTypeMapping = typeNameToDataTypeMapping.get(dataTypeName.toUpperCase());
+ if (dataTypeMapping != null) {
+ info = getAccessInfo
+ (property.getType(), dataTypeMapping, dataTypeName, columnSize, decimalDigits);
+ if (info != null) {
+ return info;
+ }
+ }
+ }
+
// See if an appropriate adapter exists.
StorablePropertyAdapter adapter = property.getAdapter();
if (adapter != null) {
@@ -948,6 +963,39 @@ public class JDBCStorableIntrospector extends StorableIntrospector {
return str == null ? null : str.intern();
}
+ private static final Map<String, Integer> typeNameToDataTypeMapping;
+ static {
+ // Mapping taken from the following:
+ // http://docs.oracle.com/javase/6/docs/technotes/guides/jdbc/getstart/mapping.html
+ Map<String, Integer> aMap = new HashMap<String, Integer>();
+ aMap.put("CHAR", java.sql.Types.CHAR);
+ aMap.put("VARCHAR", java.sql.Types.VARCHAR);
+ aMap.put("LONGVARCHAR", java.sql.Types.LONGVARCHAR);
+ aMap.put("NUMERIC", java.sql.Types.NUMERIC);
+ aMap.put("DECIMAL", java.sql.Types.DECIMAL);
+ aMap.put("BIT", java.sql.Types.BIT);
+ aMap.put("TINYINT", java.sql.Types.TINYINT);
+ aMap.put("SMALLINT", java.sql.Types.SMALLINT);
+ aMap.put("INTEGER", java.sql.Types.INTEGER);
+ aMap.put("BIGINT", java.sql.Types.BIGINT);
+ aMap.put("REAL", java.sql.Types.REAL);
+ aMap.put("FLOAT", java.sql.Types.FLOAT);
+ aMap.put("DOUBLE", java.sql.Types.DOUBLE);
+ aMap.put("BINARY", java.sql.Types.BINARY);
+ aMap.put("VARBINARY", java.sql.Types.VARBINARY);
+ aMap.put("LONGVARBINARY", java.sql.Types.LONGVARBINARY);
+ aMap.put("DATE", java.sql.Types.DATE);
+ aMap.put("TIME", java.sql.Types.TIME);
+ aMap.put("TIMESTAMP", java.sql.Types.TIMESTAMP);
+ aMap.put("CLOB", java.sql.Types.CLOB);
+ aMap.put("BLOB", java.sql.Types.BLOB);
+ aMap.put("ARRAY", java.sql.Types.ARRAY);
+ aMap.put("DISTINCT", java.sql.Types.DISTINCT);
+ aMap.put("STRUCT", java.sql.Types.STRUCT);
+ aMap.put("REF", java.sql.Types.REF);
+ typeNameToDataTypeMapping = Collections.unmodifiableMap(aMap);
+ }
+
private static class ColumnInfo {
final String columnName;
final int dataType;