General defensiveness about the bootstrap ClassLoader (i.e. null ClassLoader)
Issue: SPR-11721
(cherry picked from commit 59cef3c)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.jdbc.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
import javax.sql.rowset.RowSetFactory;
|
||||
import javax.sql.rowset.RowSetProvider;
|
||||
@@ -26,6 +25,7 @@ import javax.sql.rowset.RowSetProvider;
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link ResultSetExtractor} implementation that returns a Spring {@link SqlRowSet}
|
||||
@@ -134,12 +134,14 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet
|
||||
*/
|
||||
private static class SunCachedRowSetFactory implements CachedRowSetFactory {
|
||||
|
||||
private static final Class<?> IMPLEMENTATION_CLASS;
|
||||
private static final Class<?> implementationClass;
|
||||
|
||||
static {
|
||||
try {
|
||||
IMPLEMENTATION_CLASS = Class.forName("com.sun.rowset.CachedRowSetImpl");
|
||||
implementationClass = ClassUtils.forName("com.sun.rowset.CachedRowSetImpl",
|
||||
SqlRowSetResultSetExtractor.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
@@ -147,12 +149,9 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet
|
||||
@Override
|
||||
public CachedRowSet createCachedRowSet() throws SQLException {
|
||||
try {
|
||||
return (CachedRowSet) IMPLEMENTATION_CLASS.newInstance();
|
||||
return (CachedRowSet) implementationClass.newInstance();
|
||||
}
|
||||
catch (InstantiationException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,9 +56,10 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
|
||||
lookupDefaultSchema(databaseMetaData);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultSchema() {
|
||||
if (defaultSchema != null) {
|
||||
if (this.defaultSchema != null) {
|
||||
return defaultSchema;
|
||||
}
|
||||
return super.getDefaultSchema();
|
||||
@@ -81,7 +82,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
|
||||
}
|
||||
boolean isOracleCon;
|
||||
try {
|
||||
Class<?> oracleConClass = getClass().getClassLoader().loadClass("oracle.jdbc.OracleConnection");
|
||||
Class<?> oracleConClass = con.getClass().getClassLoader().loadClass("oracle.jdbc.OracleConnection");
|
||||
isOracleCon = oracleConClass.isInstance(con);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
@@ -107,7 +108,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
|
||||
ReflectionUtils.makeAccessible(getIncludeSynonyms);
|
||||
originalValueForIncludeSynonyms = (Boolean) getIncludeSynonyms.invoke(con);
|
||||
|
||||
setIncludeSynonyms = con.getClass().getMethod("setIncludeSynonyms", new Class<?>[] {boolean.class});
|
||||
setIncludeSynonyms = con.getClass().getMethod("setIncludeSynonyms", boolean.class);
|
||||
ReflectionUtils.makeAccessible(setIncludeSynonyms);
|
||||
setIncludeSynonyms.invoke(con, Boolean.TRUE);
|
||||
}
|
||||
@@ -126,8 +127,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
|
||||
}
|
||||
|
||||
/*
|
||||
* Oracle implementation for detecting current schema
|
||||
*
|
||||
* Oracle-based implementation for detecting the current schema.
|
||||
* @param databaseMetaData
|
||||
*/
|
||||
private void lookupDefaultSchema(DatabaseMetaData databaseMetaData) {
|
||||
@@ -144,7 +144,9 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
|
||||
cstmt.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user