From e82efda6a2f6571bf14a0c43412e33b00143123b Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 10 May 2008 22:51:21 +0000 Subject: Use quoted table name identifier if required and supported. --- .../repo/jdbc/JDBCStorableIntrospector.java | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src') 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 98235cb..b81837e 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java @@ -118,6 +118,11 @@ public class JDBCStorableIntrospector extends StorableIntrospector { try { try { jInfo = examine(mainInfo, con, catalog, schema, resolver); + if (!jInfo.isSupported() && resolver != null && + resolver.resolve(mainInfo, con, catalog, schema)) + { + jInfo = examine(mainInfo, con, catalog, schema, resolver); + } } catch (SupportException e) { if (resolver != null && resolver.resolve(mainInfo, con, catalog, schema)) { jInfo = examine(mainInfo, con, catalog, schema, resolver); @@ -159,7 +164,7 @@ public class JDBCStorableIntrospector extends StorableIntrospector { SchemaResolver resolver) throws SQLException, SupportException { - DatabaseMetaData meta = con.getMetaData(); + final DatabaseMetaData meta = con.getMetaData(); final String databaseProductName = meta.getDatabaseProductName(); final String userName = meta.getUserName(); @@ -491,10 +496,40 @@ public class JDBCStorableIntrospector extends StorableIntrospector { // IndexInfo is empty, as querying for it tends to cause a table analyze to run. IndexInfo[] indexInfo = new IndexInfo[0]; + if (needsQuotes(tableName)) { + String quote = meta.getIdentifierQuoteString(); + if (quote != null && !quote.equals(" ")) { + tableName = quote + tableName + quote; + qualifiedTableName = quote + qualifiedTableName + quote; + } + } + return new JInfo (mainInfo, catalog, schema, tableName, qualifiedTableName, indexInfo, jProperties); } + private static boolean needsQuotes(String str) { + if (str == null) { + return false; + } + if (str.length() == 0) { + return true; + } + char c = str.charAt(0); + if (!(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_')) { + return true; + } + for (int i=str.length(); --i>=0; ) { + c = str.charAt(i); + if (!(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_' || + c >= '0' && c <= '9')) + { + return true; + } + } + return false; + } + private static boolean matchesKey(Collection keyProps, StorableKey declaredKey) { if (keyProps.size() != declaredKey.getProperties().size()) { return false; -- cgit v1.2.3