HHH-9136 - DatabaseMetadata: NPE hides exception in finally block

- Protection against NPE in finally block
- Little formatting fixes
This commit is contained in:
msulima 2014-04-20 14:12:20 +02:00 committed by Brett Meyer
parent f693f5c320
commit ee8f26a4be

View File

@ -54,7 +54,7 @@
*/
public class DatabaseMetadata {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, DatabaseMetaData.class.getName());
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, DatabaseMetaData.class.getName());
private final Map tables = new HashMap();
private final Set sequences = new HashSet();
@ -149,7 +149,9 @@ else if ( (isQuoted && meta.storesLowerCaseQuotedIdentifiers())
}
finally {
rs.close();
if ( rs != null ) {
rs.close();
}
}
}
catch (SQLException sqlException) {
@ -180,10 +182,13 @@ private void initSequences(Connection connection, Dialect dialect) throws SQLExc
}
}
finally {
rs.close();
statement.close();
if ( rs != null ) {
rs.close();
}
if ( statement != null ) {
statement.close();
}
}
}
}
}
@ -196,30 +201,30 @@ public boolean isSequence(Object key) {
return false;
}
public boolean isTable(Object key) throws HibernateException {
if(key instanceof String) {
public boolean isTable(Object key) throws HibernateException {
if(key instanceof String) {
Table tbl = new Table((String)key);
if ( getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null ) {
return true;
} else {
String[] strings = StringHelper.split(".", (String) key);
if(strings.length==3) {
return true;
} else {
String[] strings = StringHelper.split(".", (String) key);
if(strings.length==3) {
tbl = new Table(strings[2]);
tbl.setCatalog(strings[0]);
tbl.setSchema(strings[1]);
return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null;
} else if (strings.length==2) {
} else if (strings.length==2) {
tbl = new Table(strings[1]);
tbl.setSchema(strings[0]);
return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null;
}
}
}
return false;
}
}
}
}
return false;
}
@Override
public String toString() {
public String toString() {
return "DatabaseMetadata" + tables.keySet().toString() + sequences.toString();
}
}