From 3963e826926e19ec83947f0b4db2fe631c4933d7 Mon Sep 17 00:00:00 2001 From: Michael Dick Date: Mon, 14 Jun 2010 17:52:29 +0000 Subject: [PATCH] OPENJPA-1641: Try JDBC standard column names as well as Sybase specific ones git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@954567 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/sql/SybaseDictionary.java | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java index 6e9d55440..11ed12367 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java @@ -323,6 +323,35 @@ public class SybaseDictionary return ConcreteClassGenerator.newInstance(sybaseConnectionImpl, conn); } + + /** + * Helper method obtains a string value from a given column in a ResultSet. Strings provided are column names, + * jdbcName will be tried first if an SQLException occurs we'll try the sybase name. + */ + protected String getStringFromResultSet(ResultSet rs, String jdbcName, String sybaseName) throws SQLException { + try { + return rs.getString(jdbcName); + } + catch(SQLException sqle) { + // if the generic JDBC identifier isn't found an SQLException will be thrown + // try the Sybase specific id + return rs.getString(sybaseName); + } + } + /** + * Helper method obtains a boolean value from a given column in a ResultSet. Strings provided are column names, + * jdbcName will be tried first if an SQLException occurs we'll try the sybase name. + */ + protected boolean getBooleanFromResultSet(ResultSet rs, String jdbcName, String sybaseName) throws SQLException { + try { + return rs.getBoolean(jdbcName); + } + catch(SQLException sqle) { + // if the generic JDBC identifier isn't found an SQLException will be thrown + // try the Sybase specific id + return rs.getBoolean(sybaseName); + } + } /** * Create a new primary key from the information in the schema metadata. @@ -330,10 +359,14 @@ public class SybaseDictionary protected PrimaryKey newPrimaryKey(ResultSet pkMeta) throws SQLException { PrimaryKey pk = new PrimaryKey(); - pk.setSchemaIdentifier(fromDBName(pkMeta.getString("table_owner"), DBIdentifierType.SCHEMA)); - pk.setTableIdentifier(fromDBName(pkMeta.getString("table_name"), DBIdentifierType.TABLE)); - pk.setColumnIdentifier(fromDBName(pkMeta.getString("column_name"), DBIdentifierType.COLUMN)); - pk.setIdentifier(fromDBName(pkMeta.getString("index_name"), DBIdentifierType.CONSTRAINT)); + pk.setSchemaIdentifier(fromDBName(getStringFromResultSet(pkMeta, "TABLE_SCHEM", "table_owner"), + DBIdentifierType.SCHEMA)); + pk.setTableIdentifier(fromDBName(getStringFromResultSet(pkMeta, "TABLE_NAME", "table_name"), + DBIdentifierType.TABLE)); + pk.setColumnIdentifier(fromDBName(getStringFromResultSet(pkMeta, "COLUMN_NAME", "column_name"), + DBIdentifierType.COLUMN)); + pk.setIdentifier(fromDBName(getStringFromResultSet(pkMeta, "PK_NAME", "index_name"), + DBIdentifierType.CONSTRAINT)); return pk; } @@ -343,11 +376,15 @@ public class SybaseDictionary protected Index newIndex(ResultSet idxMeta) throws SQLException { Index idx = new Index(); - idx.setSchemaIdentifier(fromDBName(idxMeta.getString("table_owner"), DBIdentifierType.SCHEMA)); - idx.setTableIdentifier(fromDBName(idxMeta.getString("table_name"), DBIdentifierType.TABLE)); - idx.setColumnIdentifier(fromDBName(idxMeta.getString("column_name"), DBIdentifierType.COLUMN)); - idx.setIdentifier(fromDBName(idxMeta.getString("index_name"), DBIdentifierType.INDEX)); - idx.setUnique(!idxMeta.getBoolean("non_unique")); + idx.setSchemaIdentifier(fromDBName(getStringFromResultSet(idxMeta, "TABLE_SCHEM", "table_owner"), + DBIdentifierType.SCHEMA)); + idx.setTableIdentifier(fromDBName(getStringFromResultSet(idxMeta, "TABLE_NAME", "table_name"), + DBIdentifierType.TABLE)); + idx.setColumnIdentifier(fromDBName(getStringFromResultSet(idxMeta, "COLUMN_NAME", "column_name"), + DBIdentifierType.COLUMN)); + idx.setIdentifier(fromDBName(getStringFromResultSet(idxMeta, "INDEX_NAME", "index_name"), + DBIdentifierType.INDEX)); + idx.setUnique(!getBooleanFromResultSet(idxMeta, "NON_UNIQUE", "non_unique")); return idx; }