use of org.hibernate.console.ConsoleConfigClassLoader in project jbosstools-hibernate by jbosstools.
the class HibernateExtension method cleanUpClassLoader.
protected boolean cleanUpClassLoader() {
boolean resetted = false;
if (executionContext != null) {
executionContext.execute(new Command() {
public Object execute() {
Iterator<FakeDelegatingDriver> it = fakeDrivers.values().iterator();
while (it.hasNext()) {
try {
DriverManager.deregisterDriver(it.next());
} catch (SQLException e) {
// ignore
}
}
return null;
}
});
}
if (fakeDrivers.size() > 0) {
fakeDrivers.clear();
resetted = true;
}
ClassLoader classLoaderTmp = classLoader;
while (classLoaderTmp != null) {
if (classLoaderTmp instanceof ConsoleConfigClassLoader) {
((ConsoleConfigClassLoader) classLoaderTmp).close();
resetted = true;
}
classLoaderTmp = classLoaderTmp.getParent();
}
if (classLoader != null) {
classLoader = null;
resetted = true;
}
return resetted;
}
use of org.hibernate.console.ConsoleConfigClassLoader in project jbosstools-hibernate by jbosstools.
the class DriverDeleteTest method createJarClassLoader.
private ConsoleConfigClassLoader createJarClassLoader() {
final URL[] customClassPathURLs = getCustomClassPathURLs();
ConsoleConfigClassLoader urlClassLoader = AccessController.doPrivileged(new PrivilegedAction<ConsoleConfigClassLoader>() {
public ConsoleConfigClassLoader run() {
return new ConsoleConfigClassLoader(customClassPathURLs, getParentClassLoader()) {
public InputStream getResourceAsStream(String name) {
InputStream is = super.getResourceAsStream(name);
return is;
}
public URL findResource(final String name) {
URL res = super.findResource(name);
return res;
}
public Enumeration<URL> findResources(final String name) throws IOException {
Enumeration<URL> res = super.findResources(name);
return res;
}
protected Class<?> findClass(String name) throws ClassNotFoundException {
Class<?> res = null;
try {
res = super.findClass(name);
} catch (ClassNotFoundException cnfe) {
throw cnfe;
}
return res;
}
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class<?> res = null;
try {
res = super.loadClass(name, resolve);
} catch (ClassNotFoundException cnfe) {
throw cnfe;
}
return res;
}
public Class<?> loadClass(String name) throws ClassNotFoundException {
Class<?> res = null;
try {
res = super.loadClass(name);
} catch (ClassNotFoundException cnfe) {
throw cnfe;
}
return res;
}
};
}
});
return urlClassLoader;
}
use of org.hibernate.console.ConsoleConfigClassLoader in project jbosstools-hibernate by jbosstools.
the class ConsoleConfigurationUtils method getClassLoader.
public static ClassLoader getClassLoader(ConsoleConfiguration cc) {
try {
Field loaderField = cc.getClass().getDeclaredField("classLoader");
loaderField.setAccessible(true);
return (ConsoleConfigClassLoader) loaderField.get(cc);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) {
return null;
}
}
use of org.hibernate.console.ConsoleConfigClassLoader in project jbosstools-hibernate by jbosstools.
the class DriverDeleteTest method initExecutionContext.
private void initExecutionContext() {
final ConsoleConfigClassLoader urlClassLoader = createJarClassLoader();
DefaultExecutionContext dec = new DefaultExecutionContext(testName.getMethodName(), urlClassLoader);
ExecutionContext.Command command = new ExecutionContext.Command() {
public Object execute() {
try {
Class<?> driverClass = null;
driverClass = (Class<?>) ReflectHelper.classForName(DRIVER_TEST_CLASS);
Driver driver2 = (Driver) driverClass.newInstance();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
driverClass = (Class<?>) contextClassLoader.loadClass(DRIVER_TEST_CLASS);
}
java.util.Properties info = new java.util.Properties();
info.put("user", CONNECTION_USERNAME);
info.put("password", CONNECTION_PASSWORD);
try {
Connection connection = driver2.connect(CONNECTION_URL, info);
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
};
dec.execute(command);
command = null;
dec = null;
urlClassLoader.close();
}
Aggregations