Author: vyemialyanchyk
Date: 2010-10-15 13:39:37 -0400 (Fri, 15 Oct 2010)
New Revision: 25885
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
Log:
https://jira.jboss.org/browse/JBIDE-7278 - fixed
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java 2010-10-15
17:24:37 UTC (rev 25884)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java 2010-10-15
17:39:37 UTC (rev 25885)
@@ -78,7 +78,9 @@
rootName = ConfigurationXMLStrings.CONFIGURATION;
}
Element root = DocumentFactory.getInstance().createElement(rootName);
- String tmp = file2Str(prefs.getConfigXMLFile());
+ final ConsoleConfiguration cc2ExtractConfigXMLFile = new ConsoleConfiguration(prefs);
+ final File configXMLFile = cc2ExtractConfigXMLFile.getConfigXMLFile();
+ String tmp = file2Str(configXMLFile);
tmp = makePathRelative(tmp, pathPlace2Generate, pathWorkspacePath);
updateAttr(root, tmp, ConfigurationXMLStrings.CONFIGURATIONFILE);
tmp = file2Str(prefs.getPropertyFile());
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-10-15
17:24:37 UTC (rev 25884)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-10-15
17:39:37 UTC (rev 25885)
@@ -77,10 +77,14 @@
* Reset so a new configuration or sessionfactory is needed.
*
*/
- public void reset() {
+ public boolean reset() {
+ boolean res = false;
// reseting state
- configuration = null;
- closeSessionFactory();
+ if (configuration != null) {
+ configuration = null;
+ res = true;
+ }
+ res = res || closeSessionFactory();
if (executionContext != null) {
executionContext.execute(new Command() {
public Object execute() {
@@ -96,30 +100,68 @@
}
});
}
- fakeDrivers.clear();
- cleanUpClassLoader();
- fireConfigurationReset();
+ if (fakeDrivers.size() > 0) {
+ fakeDrivers.clear();
+ res = true;
+ }
+ res = res || cleanUpClassLoader();
+ if (res) {
+ fireConfigurationReset();
+ }
executionContext = null;
+ return res;
}
- public void cleanUpClassLoader() {
+ protected boolean cleanUpClassLoader() {
+ boolean res = false;
ClassLoader classLoaderTmp = classLoader;
while (classLoaderTmp != null) {
if (classLoaderTmp instanceof ConsoleConfigClassLoader) {
((ConsoleConfigClassLoader)classLoaderTmp).close();
+ res = true;
}
classLoaderTmp = classLoaderTmp.getParent();
}
- classLoader = null;
+ if (classLoader != null) {
+ classLoader = null;
+ res = true;
+ }
+ return res;
}
+
+ /**
+ * Create class loader - so it uses the original urls list from preferences.
+ */
+ protected void reinitClassLoader() {
+ boolean recreateFlag = true;
+ final URL[] customClassPathURLs =
PreferencesClassPathUtils.getCustomClassPathURLs(prefs);
+ if (classLoader != null) {
+ // check -> do not recreate class loader in case if urls list is the same
+ final URL[] oldURLS = classLoader.getURLs();
+ if (customClassPathURLs.length == oldURLS.length) {
+ int i = 0;
+ for (; i < oldURLS.length; i++) {
+ if (!customClassPathURLs[i].sameFile(oldURLS[i])) {
+ break;
+ }
+ }
+ if (i == oldURLS.length) {
+ recreateFlag = false;
+ }
+ }
+ }
+ if (recreateFlag) {
+ reset();
+ classLoader = createClassLoader(customClassPathURLs);
+ }
+ }
public void build() {
configuration = buildWith(null, true);
fireConfigurationBuilt();
}
- protected ConsoleConfigClassLoader createClassLoader() {
- final URL[] customClassPathURLs =
PreferencesClassPathUtils.getCustomClassPathURLs(prefs);
+ protected ConsoleConfigClassLoader createClassLoader(final URL[] customClassPathURLs) {
ConsoleConfigClassLoader classLoader = AccessController.doPrivileged(new
PrivilegedAction<ConsoleConfigClassLoader>() {
public ConsoleConfigClassLoader run() {
return new ConsoleConfigClassLoader(customClassPathURLs, getParentClassLoader()) {
@@ -157,9 +199,7 @@
*
*/
public Configuration buildWith(final Configuration cfg, final boolean includeMappings)
{
- if (classLoader == null) {
- classLoader = createClassLoader();
- }
+ reinitClassLoader();
executionContext = new DefaultExecutionContext(getName(), classLoader);
Configuration result = (Configuration)execute(new Command() {
public Object execute() {
@@ -295,8 +335,12 @@
if (prefs != null) {
configXMLFile = prefs.getConfigXMLFile();
}
- if (configXMLFile == null && classLoader != null) {
- URL url = classLoader.findResource("hibernate.cfg.xml"); //$NON-NLS-1$
+ if (configXMLFile == null) {
+ URL url = null;
+ reinitClassLoader();
+ if (classLoader != null) {
+ url = classLoader.findResource("hibernate.cfg.xml"); //$NON-NLS-1$
+ }
if (url != null) {
URI uri = null;
try {
@@ -330,12 +374,15 @@
return executionContext;
}
- public void closeSessionFactory() {
+ public boolean closeSessionFactory() {
+ boolean res = false;
if (sessionFactory != null) {
fireFactoryClosing(sessionFactory);
sessionFactory.close();
sessionFactory = null;
+ res = true;
}
+ return res;
}
public Settings getSettings(final Configuration cfg) {
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java 2010-10-15
17:24:37 UTC (rev 25884)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java 2010-10-15
17:39:37 UTC (rev 25885)
@@ -85,12 +85,11 @@
}
public URL[] getCustomClassPathURLS() {
- URL[] urls = new URL[4];
+ URL[] urls = new URL[3];
try {
urls[0] = new File("ejb3-persistence.jar").toURL(); //$NON-NLS-1$
urls[1] = new File("hibernate3.jar").toURL(); //$NON-NLS-1$
urls[2] = new File("hsqldb.jar").toURL(); //$NON-NLS-1$
- urls[3] = null;
} catch (IOException e) {
}
return urls;