Skip to content

Commit

Permalink
TEIID-4209 adding additional handling of getShort
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed May 24, 2016
1 parent 5f830ab commit 79add1b
Showing 1 changed file with 23 additions and 2 deletions.
Expand Up @@ -492,7 +492,7 @@ private void getPrimaryKeys(MetadataFactory metadataFactory,
String pkName = null;
while (pks.next()) {
String columnName = pks.getString(4);
short seqNum = pks.getShort(5);
short seqNum = safeGetShort(pks, 5);
if (keyColumns == null) {
keyColumns = new TreeMap<Short, String>();
}
Expand All @@ -510,6 +510,27 @@ private void getPrimaryKeys(MetadataFactory metadataFactory,
pks.close();
}
}

/**
* some sources, such as PI, don't consistently support getShort
* @param rs
* @param pos
* @return
* @throws SQLException
*/
private short safeGetShort(ResultSet rs, int pos) throws SQLException {
short val;
try {
val = rs.getShort(pos);
} catch (SQLException e) {
int valInt = rs.getInt(pos);
if (valInt > Short.MAX_VALUE) {
throw new SQLException("invalid short value " + valInt); //$NON-NLS-1$
}
val = (short)valInt;
}
return val;
}

private class FKInfo {
TableInfo pkTable;
Expand All @@ -526,7 +547,7 @@ private void getForeignKeys(MetadataFactory metadataFactory,
HashMap<String, FKInfo> allKeys = new HashMap<String, FKInfo>();
while (fks.next()) {
String columnName = fks.getString(8);
short seqNum = fks.getShort(9);
short seqNum = safeGetShort(fks, 9);
String pkColumnName = fks.getString(4);

String fkName = fks.getString(12);
Expand Down

0 comments on commit 79add1b

Please sign in to comment.