Skip to content

Commit

Permalink
[connection]完善数据库驱动类加载器
Browse files Browse the repository at this point in the history
  • Loading branch information
datageartech committed Mar 11, 2020
1 parent a9b0294 commit 2038439
Showing 1 changed file with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ public URL getResource(String name)
URL url = findResource(name);

// 对于独立的驱动程序类加载器,不应该代理至父类加载器
// if (url == null)
// {
// ClassLoader parent = getParentClassLoader();
//
// if (LOGGER.isDebugEnabled())
// LOGGER.debug("delegate parent class loader for getting resource URL for [" + name + "]");
//
// return parent.getResource(name);
// }
// if (url == null)
// {
// ClassLoader parent = getParentClassLoader();
//
// if (LOGGER.isDebugEnabled())
// LOGGER.debug("delegate parent class loader for getting resource URL
// for [" + name + "]");
//
// return parent.getResource(name);
// }

if (LOGGER.isDebugEnabled())
LOGGER.debug("getResource [" + url + "] for [" + name + "] in path [" + getPath() + "]");
Expand All @@ -111,15 +112,16 @@ public Enumeration<URL> getResources(String name) throws IOException
Enumeration<URL> urls = findResources(name);

// 对于独立的驱动程序类加载器,不应该代理至父类加载器
// if (urls == null || urls.hasMoreElements())
// {
// ClassLoader parent = getParentClassLoader();
//
// if (LOGGER.isDebugEnabled())
// LOGGER.debug("delegate parent class loader for getting resource URLs for [" + name + "]");
//
// return parent.getResources(name);
// }
// if (urls == null || urls.hasMoreElements())
// {
// ClassLoader parent = getParentClassLoader();
//
// if (LOGGER.isDebugEnabled())
// LOGGER.debug("delegate parent class loader for getting resource URLs
// for [" + name + "]");
//
// return parent.getResources(name);
// }

if (LOGGER.isDebugEnabled())
LOGGER.debug("getResources for [" + name + "] in path [" + getPath() + "]");
Expand All @@ -133,15 +135,16 @@ public InputStream getResourceAsStream(String name)
URL url = findResource(name);

// 对于独立的驱动程序类加载器,不应该代理至父类加载器
// if (url == null)
// {
// ClassLoader parent = getParentClassLoader();
//
// if (LOGGER.isDebugEnabled())
// LOGGER.debug("delegate parent class loader for getting resource as stream for [" + name + "]");
//
// return parent.getResourceAsStream(name);
// }
// if (url == null)
// {
// ClassLoader parent = getParentClassLoader();
//
// if (LOGGER.isDebugEnabled())
// LOGGER.debug("delegate parent class loader for getting resource as
// stream for [" + name + "]");
//
// return parent.getResourceAsStream(name);
// }

if (url == null)
return null;
Expand Down Expand Up @@ -190,10 +193,10 @@ protected synchronized Class<?> loadClass(String name, boolean resolve)
{
clazz = findClass(name);
}
catch(ClassNotFoundException e)
catch (ClassNotFoundException e)
{
}
catch(ClassFormatError e)
catch (ClassFormatError e)
{
// 类加载出错(比如版本不兼容),则抛出
throw e;
Expand All @@ -214,7 +217,7 @@ protected synchronized Class<?> loadClass(String name, boolean resolve)
{
bytes = IOUtil.getBytes(in);
}
catch(IOException e)
catch (IOException e)
{
throw new ClassNotFoundException(name, e);
}
Expand All @@ -237,6 +240,9 @@ protected synchronized Class<?> loadClass(String name, boolean resolve)
clazz = Class.forName(name, false, parent);
}

if (clazz == null)
throw new ClassNotFoundException(name);

if (resolve)
resolveClass(clazz);

Expand Down Expand Up @@ -267,7 +273,7 @@ protected boolean isJDKStandardClassName(String name)
protected boolean isJDKExtClassName(String name)
{
return (name.startsWith("sun.") || name.startsWith("org.ietf.") || name.startsWith("org.omg.")
|| name.startsWith("org.w3c.") || name.startsWith("org.xml."));
|| name.startsWith("org.w3c.") || name.startsWith("org.xml.") || name.startsWith("jdk."));
}

/**
Expand Down

0 comments on commit 2038439

Please sign in to comment.