Author: vyemialyanchyk
Date: 2010-03-19 14:06:20 -0400 (Fri, 19 Mar 2010)
New Revision: 20944
Added:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubFactory.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/CollectionPropertySource.java
Removed:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigStubFactory.java
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtils.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/LoadConsoleCFGCompletionProposal.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/.classpath
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/SessionStub.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HbmExportExceptionTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-6070 - update
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/.classpath
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/.classpath 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/.classpath 2010-03-19
18:06:20 UTC (rev 20944)
@@ -28,7 +28,7 @@
<classpathentry exported="true" kind="lib"
path="lib/hibernate/hibernate-jmx.jar"
sourcepath="D:/Temp/_hibernate/hibernate-jmx-3.3.2.GA-sources.jar "/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/commons-collections-3.1.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/slf4j-api-1.5.8.jar"
sourcepath="D:/Temp/_hibernate/slf4j-api-1.5.8-sources.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/hibernate/cglib-2.2.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/hibernate/cglib-2.2.jar"
sourcepath="D:/Temp/_hibernate/cglib-src-2.2.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-commons-annotations.jar"
sourcepath="D:/Temp/_hibernate/hibernate-commons-annotations-3.1.0.GA-sources.jar
"/>
<classpathentry exported="true" kind="lib"
path="lib/annotations/ejb3-persistence.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/c3p0-0.9.1.jar"/>
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -22,60 +22,33 @@
package org.hibernate.console;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
-import org.dom4j.DocumentException;
-import org.dom4j.Node;
-import org.dom4j.io.DOMWriter;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ProfileManager;
-import org.eclipse.osgi.util.NLS;
import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
import org.hibernate.cfg.Environment;
-import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.Settings;
import org.hibernate.console.execution.DefaultExecutionContext;
import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.execution.ExecutionContextHolder;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
-import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
-import org.hibernate.console.stubs.ConfigStubFactory;
+import org.hibernate.console.stubs.ConfigurationStubFactory;
import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.console.stubs.SessionStub;
import org.hibernate.console.stubs.SessionStubFactory;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.resolver.DialectFactory;
-import org.hibernate.tool.ide.completion.HQLCodeAssist;
import org.hibernate.tool.ide.completion.IHQLCodeAssist;
-import org.hibernate.util.ConfigHelper;
-import org.hibernate.util.ReflectHelper;
-import org.hibernate.util.StringHelper;
-import org.hibernate.util.XMLHelper;
-import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
public class ConsoleConfiguration implements ExecutionContextHolder {
@@ -98,7 +71,10 @@
}
public Object execute(Command c) {
- return executionContext.execute(c);
+ if (executionContext != null) {
+ return executionContext.execute(c);
+ }
+ return null;
}
/**
@@ -108,15 +84,12 @@
public void reset() {
// reseting state
closeSessionFactory();
- if (executionContext != null) {
- executionContext.execute(new ExecutionContext.Command() {
-
- public Object execute() {
- configStub.cleanUp();
- return null;
- }
- });
- }
+ execute(new ExecutionContext.Command() {
+ public Object execute() {
+ configStub.cleanUp();
+ return null;
+ }
+ });
configStub = null;
cleanUpClassLoader();
fireConfigurationReset();
@@ -150,7 +123,7 @@
executionContext = new DefaultExecutionContext(getName(), classLoader);
ConfigurationStub result = (ConfigurationStub) executionContext.execute(new
ExecutionContext.Command() {
public Object execute() {
- ConfigStubFactory csf = new ConfigStubFactory(prefs);
+ ConfigurationStubFactory csf = new ConfigurationStubFactory(prefs);
return csf.createConfiguration(cfg, includeMappings);
}
});
@@ -169,7 +142,7 @@
if (profile == null) {
return null;
}
- ConfigStubFactory.refreshProfile(profile);
+ ConfigurationStubFactory.refreshProfile(profile);
//
Properties cpProperties = profile.getProperties(profile.getProviderId());
String driverJarPath = cpProperties.getProperty("jarList"); //$NON-NLS-1$
@@ -249,6 +222,7 @@
}
protected ClassLoader getParentClassLoader() {
+ //return Thread.currentThread().getContextClassLoader().getParent();
return Thread.currentThread().getContextClassLoader();
}
public ConfigurationStub getConfiguration() {
@@ -300,7 +274,7 @@
public QueryPage executeHQLQuery(final String hql, final QueryInputModel model) {
- return (QueryPage) executionContext.execute(new ExecutionContext.Command() {
+ return (QueryPage)execute(new ExecutionContext.Command() {
public Object execute() {
SessionStub sessionStub = getSessionStubFactory().openSession();
@@ -316,7 +290,7 @@
}
public QueryPage executeBSHQuery(final String queryString, final QueryInputModel model)
{
- return (QueryPage) executionContext.execute(new ExecutionContext.Command() {
+ return (QueryPage)execute(new ExecutionContext.Command() {
public Object execute() {
SessionStub sessionStub = getSessionStubFactory().openSession();
@@ -380,8 +354,8 @@
public String generateSQL(final String query) {
String res = ""; //$NON-NLS-1$
- if (sessionStubFactory != null && executionContext != null) {
- res = (String)executionContext.execute(new ExecutionContext.Command() {
+ if (sessionStubFactory != null) {
+ res = (String)execute(new ExecutionContext.Command() {
public Object execute() {
return sessionStubFactory.generateSQL(query);
}
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.console.stubs;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.eclipse.ui.views.properties.IPropertyDescriptor;
-import org.eclipse.ui.views.properties.IPropertySource;
-import org.eclipse.ui.views.properties.PropertyDescriptor;
-
-public class CollectionPropertySource implements IPropertySource {
-
- private Collection<?> collection;
-
- IPropertyDescriptor[] descriptors = null;
-
- Map<Object, Object> values = new WeakHashMap<Object, Object>();
-
- public CollectionPropertySource(Collection<?> propertyValue) {
- collection = propertyValue;
- }
-
- public Object getEditableValue() {
- return null;
- }
-
- public IPropertyDescriptor[] getPropertyDescriptors() {
- if (descriptors == null) {
- PropertyDescriptor[] properties = new PropertyDescriptor[collection.size()];
- for (int i = 0; i < properties.length; i++) {
- properties[i] = new PropertyDescriptor(Integer.valueOf(i), "#" + i);
//$NON-NLS-1$
- }
- descriptors = properties;
- }
- return descriptors;
- }
-
- public Object getPropertyValue(Object id) {
- Object value = values.get(id);
- if (value == null) {
- Integer i = (Integer) id;
- Iterator<?> iterator = collection.iterator();
- int base = 0;
-
- while (iterator.hasNext()) {
-
- value = iterator.next();
-
- if (base == i.intValue()) {
- values.put(id, value);
- return value;
- } else {
- value = null;
- }
- base++;
- }
- }
-
- return value;
- }
-
- public boolean isPropertySet(Object id) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void resetPropertyValue(Object id) {
- // TODO Auto-generated method stub
-
- }
-
- public void setPropertyValue(Object id, Object value) {
-
- }
-
-}
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigStubFactory.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigStubFactory.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigStubFactory.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -1,414 +0,0 @@
-package org.hibernate.console.stubs;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.dom4j.DocumentException;
-import org.dom4j.Node;
-import org.dom4j.io.DOMWriter;
-import org.eclipse.datatools.connectivity.IConnectionProfile;
-import org.eclipse.datatools.connectivity.ProfileManager;
-import org.eclipse.osgi.util.NLS;
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.cfg.JDBCMetaDataConfiguration;
-import org.hibernate.cfg.NamingStrategy;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.ConsoleMessages;
-import org.hibernate.console.HibernateConsoleRuntimeException;
-import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
-import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.resolver.DialectFactory;
-import org.hibernate.util.ConfigHelper;
-import org.hibernate.util.ReflectHelper;
-import org.hibernate.util.StringHelper;
-import org.hibernate.util.XMLHelper;
-import org.w3c.dom.Document;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-
-public class ConfigStubFactory {
-
- private ConsoleConfigurationPreferences prefs = null;
-
- public ConfigStubFactory(ConsoleConfigurationPreferences prefs) {
- this.prefs = prefs;
- }
-
- public ConfigurationStub createConfiguration() {
- ConfigurationStub res = new ConfigurationStub(new Configuration());
- return res;
- }
-
- public ConfigurationStubJDBCMetaData createConfigurationJDBCMetaData() {
- ConfigurationStubJDBCMetaData res = new ConfigurationStubJDBCMetaData(new
JDBCMetaDataConfiguration());
- return res;
- }
-
- public ConfigurationStub createConfiguration(ConfigurationStub cfg, boolean
includeMappings) {
- Configuration localCfg = cfg == null ? null : cfg.getConfiguration();
- Properties properties = prefs.getProperties();
- if (properties != null) {
- // to fix: JBIDE-5839 - setup this property: false is default value
- // to make hibernate tools diff hibernate versions compatible
- if (properties.getProperty("hibernate.search.autoregister_listeners") ==
null) { //$NON-NLS-1$
- properties.setProperty("hibernate.search.autoregister_listeners",
"false"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- // in case the transaction manager is empty then we need to inject a faketm since
- // hibernate will still try and instantiate it.
- String str =
properties.getProperty("hibernate.transaction.manager_lookup_class");
//$NON-NLS-1$
- if (str != null && StringHelper.isEmpty(str)) {
- properties
- .setProperty(
- "hibernate.transaction.manager_lookup_class",
"org.hibernate.console.FakeTransactionManagerLookup"); //$NON-NLS-1$
//$NON-NLS-2$
- // properties.setProperty( "hibernate.transaction.factory_class",
"");
- }
- }
- if (localCfg == null) {
- localCfg = buildConfiguration(properties, includeMappings);
- } else {
- // Properties origProperties = cfg.getProperties();
- // origProperties.putAll(properties);
- // cfg.setProperties(origProperties);
- // TODO: this is actually only for jdbc reveng...
- // localCfg = configureStandardConfiguration( includeMappings, localCfg, properties
);
- }
- // non-running databases + i havent been needed until now...
- // TODO: jpa configuration ?
- if (includeMappings) {
- File[] mappingFiles = prefs.getMappingFiles();
- for (int i = 0; i < mappingFiles.length; i++) {
- File hbm = mappingFiles[i];
- localCfg = localCfg.addFile(hbm);
- }
- }
- // TODO: HBX-
- localCfg.setProperty("hibernate.temp.use_jdbc_metadata_defaults",
"false"); //$NON-NLS-1$//$NON-NLS-2$
- localCfg.setProperty(Environment.HBM2DDL_AUTO, "false"); //$NON-NLS-1$
- ConfigurationStub res = new ConfigurationStub(localCfg);
- // here both setProperties and configxml have had their chance to tell which
databasedriver
- // is needed.
- res.registerFakeDriver(localCfg.getProperty(Environment.DRIVER));
- // autoConfigureDialect(localCfg); Disabled for now since it causes very looong
timeouts for
- return res;
- }
-
- @SuppressWarnings("unchecked")
- private Configuration buildAnnotationConfiguration() throws ClassNotFoundException,
- InstantiationException, IllegalAccessException {
- Class<Configuration> clazz = ReflectHelper
- .classForName("org.hibernate.cfg.AnnotationConfiguration"); //$NON-NLS-1$
- Configuration newInstance = clazz.newInstance();
- return newInstance;
- }
-
- private Configuration buildJPAConfiguration(String persistenceUnit, Properties
properties,
- String entityResolver, boolean includeMappings) {
- if (StringHelper.isEmpty(persistenceUnit)) {
- persistenceUnit = null;
- }
- try {
- Map<Object, Object> overrides = new HashMap<Object, Object>();
- if (properties != null) {
- overrides.putAll(properties);
- }
- if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
- overrides.put("hibernate.ejb.naming_strategy", prefs.getNamingStrategy());
//$NON-NLS-1$
- }
- if (StringHelper.isNotEmpty(prefs.getDialectName())) {
- overrides.put("hibernate.dialect", prefs.getDialectName()); //$NON-NLS-1$
- }
- if (!includeMappings) {
- overrides.put("hibernate.archive.autodetection", "none");
//$NON-NLS-1$//$NON-NLS-2$
- }
- Class<?> clazz = ReflectHelper.classForName(
- "org.hibernate.ejb.Ejb3Configuration", ConsoleConfiguration.class);
//$NON-NLS-1$
- Object ejb3cfg = clazz.newInstance();
-
- if (StringHelper.isNotEmpty(entityResolver)) {
- Class<?> resolver = ReflectHelper.classForName(entityResolver,
this.getClass());
- Object object = resolver.newInstance();
- Method method = clazz.getMethod(
- "setEntityResolver", new Class[] { EntityResolver.class });//$NON-NLS-1$
- method.invoke(ejb3cfg, new Object[] { object });
- }
-
- Method method = clazz.getMethod("configure", new Class[] { String.class,
Map.class }); //$NON-NLS-1$
- if (method.invoke(ejb3cfg, new Object[] { persistenceUnit, overrides }) == null) {
- String out = NLS.bind(
- ConsoleMessages.ConsoleConfiguration_persistence_unit_not_found,
- persistenceUnit);
- throw new HibernateConsoleRuntimeException(out);
- }
-
- method = clazz.getMethod("getHibernateConfiguration", new
Class[0]);//$NON-NLS-1$
- Configuration invoke = (Configuration) method.invoke(ejb3cfg, (Object[]) null);
- invoke = configureConnectionProfile(invoke);
-
- return invoke;
- } catch (HibernateConsoleRuntimeException he) {
- throw he;
- } catch (Exception e) {
- throw new HibernateConsoleRuntimeException(
- ConsoleMessages.ConsoleConfiguration_could_not_create_jpa_based_configuration,
- e);
- }
- }
-
- private Configuration buildConfiguration(Properties properties, boolean includeMappings)
{
- Configuration localCfg = null;
- if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) {
- try {
- localCfg = buildAnnotationConfiguration();
- localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
- } catch (HibernateConsoleRuntimeException he) {
- throw he;
- } catch (Exception e) {
- throw new HibernateConsoleRuntimeException(
- ConsoleMessages.ConsoleConfiguration_could_not_load_annotationconfiguration,
- e);
- }
- } else if (prefs.getConfigurationMode().equals(ConfigurationMode.JPA)) {
- try {
- localCfg = buildJPAConfiguration(prefs.getPersistenceUnitName(), properties, prefs
- .getEntityResolverName(), includeMappings);
- } catch (HibernateConsoleRuntimeException he) {
- throw he;
- } catch (Exception e) {
- throw new HibernateConsoleRuntimeException(
- ConsoleMessages.ConsoleConfiguration_could_not_load_jpa_configuration, e);
- }
- } else {
- localCfg = new Configuration();
- localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
- }
- return localCfg;
- }
-
- private Configuration configureStandardConfiguration(final boolean includeMappings,
- Configuration localCfg, Properties properties) {
- if (properties != null) {
- localCfg = localCfg.setProperties(properties);
- }
- EntityResolver entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER;
- if (StringHelper.isNotEmpty(prefs.getEntityResolverName())) {
- try {
- entityResolver = (EntityResolver) ReflectHelper.classForName(
- prefs.getEntityResolverName()).newInstance();
- } catch (Exception c) {
- throw new HibernateConsoleRuntimeException(
- ConsoleMessages.ConsoleConfiguration_could_not_configure_entity_resolver
- + prefs.getEntityResolverName(), c);
- }
- }
- localCfg.setEntityResolver(entityResolver);
- if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
- try {
- NamingStrategy ns = (NamingStrategy) ReflectHelper.classForName(
- prefs.getNamingStrategy()).newInstance();
- localCfg.setNamingStrategy(ns);
- } catch (Exception c) {
- throw new HibernateConsoleRuntimeException(
- ConsoleMessages.ConsoleConfiguration_could_not_configure_naming_strategy
- + prefs.getNamingStrategy(), c);
- }
- }
- localCfg = loadConfigurationXML(localCfg, includeMappings, entityResolver);
- localCfg = configureConnectionProfile(localCfg);
-
- // replace dialect if it is set in preferences
- if (StringHelper.isNotEmpty(prefs.getDialectName())) {
- localCfg.setProperty("hibernate.dialect", prefs.getDialectName());
//$NON-NLS-1$
- }
-
- return localCfg;
- }
-
- @SuppressWarnings("unchecked")
- private Configuration loadConfigurationXML(Configuration localCfg, boolean
includeMappings,
- EntityResolver entityResolver) {
- File configXMLFile = prefs.getConfigXMLFile();
- if (!includeMappings) {
- org.dom4j.Document doc;
- XMLHelper xmlHelper = new XMLHelper();
- InputStream stream = null;
- String resourceName = "<unknown>"; //$NON-NLS-1$
- if (configXMLFile != null) {
- resourceName = configXMLFile.toString();
- try {
- stream = new FileInputStream(configXMLFile);
- } catch (FileNotFoundException e1) {
- throw new HibernateConsoleRuntimeException(
- ConsoleMessages.ConsoleConfiguration_could_not_access + configXMLFile,
- e1);
- }
- } else {
- resourceName = "/hibernate.cfg.xml"; //$NON-NLS-1$
- if (checkHibernateResoureExistence(resourceName)) {
- stream = ConfigHelper.getResourceAsStream(resourceName); // simulate
hibernate's
- // default look up
- } else {
- return localCfg;
- }
- }
-
- try {
- List<Throwable> errors = new ArrayList<Throwable>();
-
- doc = xmlHelper.createSAXReader(resourceName, errors, entityResolver).read(
- new InputSource(stream));
- if (errors.size() != 0) {
- throw new MappingException(
- ConsoleMessages.ConsoleConfiguration_invalid_configuration, errors
- .get(0));
- }
-
- List<Node> list = doc.getRootElement()
- .element("session-factory").elements("mapping"); //$NON-NLS-1$
//$NON-NLS-2$
- for (Node element : list) {
- element.getParent().remove(element);
- }
-
- DOMWriter dw = new DOMWriter();
- Document document = dw.write(doc);
- return localCfg.configure(document);
-
- } catch (DocumentException e) {
- throw new HibernateException(
- ConsoleMessages.ConsoleConfiguration_could_not_parse_configuration
- + resourceName, e);
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException ioe) {
- // log.warn( "could not close input stream for: " + resourceName, ioe );
- }
- }
- } else {
- if (configXMLFile != null) {
- return localCfg.configure(configXMLFile);
- } else {
- Configuration resultCfg = localCfg;
- if (checkHibernateResoureExistence("/hibernate.cfg.xml")) { //$NON-NLS-1$
- resultCfg = localCfg.configure();
- }
- return resultCfg;
- }
- }
- }
-
- private boolean checkHibernateResoureExistence(String resource) {
- InputStream is = null;
- try {
- is = ConfigHelper.getResourceAsStream(resource);
- } catch (HibernateException e) {
- // just ignore
- } finally {
- try {
- if (is != null)
- is.close();
- } catch (IOException e) {
- // ignore
- }
- }
- return (is != null);
- }
-
- private Configuration configureConnectionProfile(Configuration localCfg) {
- String connectionProfile = prefs.getConnectionProfileName();
- if (connectionProfile == null) {
- return localCfg;
- }
- IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(
- connectionProfile);
- if (profile != null) {
- refreshProfile(profile);
- //
- final Properties invokeProperties = localCfg.getProperties();
- // set this property to null!
- invokeProperties.remove(Environment.DATASOURCE);
- localCfg.setProperties(invokeProperties);
- Properties cpProperties = profile.getProperties(profile.getProviderId());
- // seems we should not setup dialect here
- // String dialect =
- //
"org.hibernate.dialect.HSQLDialect";//cpProperties.getProperty("org.eclipse.datatools.connectivity.db.driverClass");
- // invoke.setProperty(Environment.DIALECT, dialect);
- String driver = cpProperties
- .getProperty("org.eclipse.datatools.connectivity.db.driverClass");
//$NON-NLS-1$
- localCfg.setProperty(Environment.DRIVER, driver);
- // TODO:
- @SuppressWarnings("unused")
- String driverJarPath = cpProperties.getProperty("jarList"); //$NON-NLS-1$
- String url =
cpProperties.getProperty("org.eclipse.datatools.connectivity.db.URL");
//$NON-NLS-1$
- // url += "/";// +
- //
cpProperties.getProperty("org.eclipse.datatools.connectivity.db.databaseName");
- localCfg.setProperty(Environment.URL, url);
- String user = cpProperties
- .getProperty("org.eclipse.datatools.connectivity.db.username");
//$NON-NLS-1$
- if (null != user && user.length() > 0) {
- localCfg.setProperty(Environment.USER, user);
- }
- String pass = cpProperties
- .getProperty("org.eclipse.datatools.connectivity.db.password");
//$NON-NLS-1$
- if (null != pass && pass.length() > 0) {
- localCfg.setProperty(Environment.PASS, pass);
- }
- } else {
- String out = NLS.bind(
- ConsoleMessages.ConsoleConfiguration_connection_profile_not_found,
- connectionProfile);
- throw new HibernateConsoleRuntimeException(out);
- }
- return localCfg;
- }
-
- @SuppressWarnings("unused")
- private void autoConfigureDialect(Configuration localCfg) {
- if (localCfg.getProperty(Environment.DIALECT) == null) {
- String url = localCfg.getProperty(Environment.URL);
- String user = localCfg.getProperty(Environment.USER);
- String pass = localCfg.getProperty(Environment.PASS);
- Connection connection = null;
- try {
- connection = DriverManager.getConnection(url, user, pass);
- // SQL Dialect:
- Dialect dialect = DialectFactory.buildDialect(localCfg.getProperties(), connection);
- localCfg.setProperty(Environment.DIALECT, dialect.toString());
- } catch (SQLException e) {
- // can't determine dialect
- }
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- // ignore
- }
- }
- }
- }
-
- public static void refreshProfile(IConnectionProfile profile) {
- // refresh profile (refresh jpa connection):
- // get fresh information about current db structure and update error markers
- if (profile.getConnectionState() == IConnectionProfile.CONNECTED_STATE) {
- profile.disconnect(null);
- }
- profile.connect(null);
- }
-}
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubFactory.java
(from rev 20919,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigStubFactory.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubFactory.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubFactory.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -0,0 +1,415 @@
+package org.hibernate.console.stubs;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.dom4j.DocumentException;
+import org.dom4j.Node;
+import org.dom4j.io.DOMWriter;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.HibernateException;
+import org.hibernate.MappingException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
+import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.resolver.DialectFactory;
+import org.hibernate.util.ConfigHelper;
+import org.hibernate.util.ReflectHelper;
+import org.hibernate.util.StringHelper;
+import org.hibernate.util.XMLHelper;
+import org.w3c.dom.Document;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+
+public class ConfigurationStubFactory {
+
+ private ConsoleConfigurationPreferences prefs = null;
+
+ public ConfigurationStubFactory(ConsoleConfigurationPreferences prefs) {
+ this.prefs = prefs;
+ }
+
+ public ConfigurationStub createConfiguration() {
+ ConfigurationStub res = new ConfigurationStub(new Configuration());
+ return res;
+ }
+
+ public ConfigurationStubJDBCMetaData createConfigurationJDBCMetaData() {
+ ConfigurationStubJDBCMetaData res = new ConfigurationStubJDBCMetaData(new
JDBCMetaDataConfiguration());
+ return res;
+ }
+
+ public ConfigurationStub createConfiguration(ConfigurationStub cfg, boolean
includeMappings) {
+ Configuration localCfg = cfg == null ? null : cfg.getConfiguration();
+ Properties properties = prefs.getProperties();
+ if (properties != null) {
+ // to fix: JBIDE-5839 - setup this property: false is default value
+ // to make hibernate tools diff hibernate versions compatible
+ if (properties.getProperty("hibernate.search.autoregister_listeners") ==
null) { //$NON-NLS-1$
+ properties.setProperty("hibernate.search.autoregister_listeners",
"false"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ // in case the transaction manager is empty then we need to inject a faketm since
+ // hibernate will still try and instantiate it.
+ String str =
properties.getProperty("hibernate.transaction.manager_lookup_class");
//$NON-NLS-1$
+ if (str != null && StringHelper.isEmpty(str)) {
+ properties
+ .setProperty(
+ "hibernate.transaction.manager_lookup_class",
"org.hibernate.console.FakeTransactionManagerLookup"); //$NON-NLS-1$
//$NON-NLS-2$
+ // properties.setProperty( "hibernate.transaction.factory_class",
"");
+ }
+ }
+ if (localCfg == null) {
+ localCfg = buildConfiguration(properties, includeMappings);
+ } else {
+ // Properties origProperties = cfg.getProperties();
+ // origProperties.putAll(properties);
+ // cfg.setProperties(origProperties);
+ // TODO: this is actually only for jdbc reveng...
+ // localCfg = configureStandardConfiguration( includeMappings, localCfg, properties
);
+ }
+ // non-running databases + i havent been needed until now...
+ // TODO: jpa configuration ?
+ if (includeMappings) {
+ File[] mappingFiles = prefs.getMappingFiles();
+ for (int i = 0; i < mappingFiles.length; i++) {
+ File hbm = mappingFiles[i];
+ localCfg = localCfg.addFile(hbm);
+ }
+ }
+ // TODO: HBX-
+ localCfg.setProperty("hibernate.temp.use_jdbc_metadata_defaults",
"false"); //$NON-NLS-1$//$NON-NLS-2$
+ localCfg.setProperty(Environment.HBM2DDL_AUTO, "false"); //$NON-NLS-1$
+ ConfigurationStub res = new ConfigurationStub(localCfg);
+ // here both setProperties and configxml have had their chance to tell which
databasedriver
+ // is needed.
+ res.registerFakeDriver(localCfg.getProperty(Environment.DRIVER));
+ // autoConfigureDialect(localCfg); Disabled for now since it causes very looong
timeouts for
+ return res;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Configuration buildAnnotationConfiguration() throws ClassNotFoundException,
+ InstantiationException, IllegalAccessException {
+ Class<Configuration> clazz = ReflectHelper
+ .classForName("org.hibernate.cfg.AnnotationConfiguration"); //$NON-NLS-1$
+ Configuration newInstance = clazz.newInstance();
+ return newInstance;
+ }
+
+ private Configuration buildJPAConfiguration(String persistenceUnit, Properties
properties,
+ String entityResolver, boolean includeMappings) {
+ if (StringHelper.isEmpty(persistenceUnit)) {
+ persistenceUnit = null;
+ }
+ try {
+ Map<Object, Object> overrides = new HashMap<Object, Object>();
+ if (properties != null) {
+ overrides.putAll(properties);
+ }
+ if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
+ overrides.put("hibernate.ejb.naming_strategy", prefs.getNamingStrategy());
//$NON-NLS-1$
+ }
+ if (StringHelper.isNotEmpty(prefs.getDialectName())) {
+ overrides.put("hibernate.dialect", prefs.getDialectName()); //$NON-NLS-1$
+ }
+ if (!includeMappings) {
+ overrides.put("hibernate.archive.autodetection", "none");
//$NON-NLS-1$//$NON-NLS-2$
+ }
+ Class<?> clazz = ReflectHelper.classForName(
+ "org.hibernate.ejb.Ejb3Configuration", ConsoleConfiguration.class);
//$NON-NLS-1$
+ Object ejb3cfg = clazz.newInstance();
+
+ if (StringHelper.isNotEmpty(entityResolver)) {
+ Class<?> resolver = ReflectHelper.classForName(entityResolver,
this.getClass());
+ Object object = resolver.newInstance();
+ Method method = clazz.getMethod(
+ "setEntityResolver", new Class[] { EntityResolver.class });//$NON-NLS-1$
+ method.invoke(ejb3cfg, new Object[] { object });
+ }
+
+ Method method = clazz.getMethod("configure", new Class[] { String.class,
Map.class }); //$NON-NLS-1$
+ if (method.invoke(ejb3cfg, new Object[] { persistenceUnit, overrides }) == null) {
+ String out = NLS.bind(
+ ConsoleMessages.ConsoleConfiguration_persistence_unit_not_found,
+ persistenceUnit);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+
+ method = clazz.getMethod("getHibernateConfiguration", new
Class[0]);//$NON-NLS-1$
+ Object obj = method.invoke(ejb3cfg, (Object[]) null);
+ Configuration invoke = (Configuration)obj;
+ invoke = configureConnectionProfile(invoke);
+
+ return invoke;
+ } catch (HibernateConsoleRuntimeException he) {
+ throw he;
+ } catch (Exception e) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_create_jpa_based_configuration,
+ e);
+ }
+ }
+
+ private Configuration buildConfiguration(Properties properties, boolean includeMappings)
{
+ Configuration localCfg = null;
+ if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) {
+ try {
+ localCfg = buildAnnotationConfiguration();
+ localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
+ } catch (HibernateConsoleRuntimeException he) {
+ throw he;
+ } catch (Exception e) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_load_annotationconfiguration,
+ e);
+ }
+ } else if (prefs.getConfigurationMode().equals(ConfigurationMode.JPA)) {
+ try {
+ localCfg = buildJPAConfiguration(prefs.getPersistenceUnitName(), properties, prefs
+ .getEntityResolverName(), includeMappings);
+ } catch (HibernateConsoleRuntimeException he) {
+ throw he;
+ } catch (Exception e) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_load_jpa_configuration, e);
+ }
+ } else {
+ localCfg = new Configuration();
+ localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
+ }
+ return localCfg;
+ }
+
+ private Configuration configureStandardConfiguration(final boolean includeMappings,
+ Configuration localCfg, Properties properties) {
+ if (properties != null) {
+ localCfg = localCfg.setProperties(properties);
+ }
+ EntityResolver entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER;
+ if (StringHelper.isNotEmpty(prefs.getEntityResolverName())) {
+ try {
+ entityResolver = (EntityResolver) ReflectHelper.classForName(
+ prefs.getEntityResolverName()).newInstance();
+ } catch (Exception c) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_configure_entity_resolver
+ + prefs.getEntityResolverName(), c);
+ }
+ }
+ localCfg.setEntityResolver(entityResolver);
+ if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
+ try {
+ NamingStrategy ns = (NamingStrategy) ReflectHelper.classForName(
+ prefs.getNamingStrategy()).newInstance();
+ localCfg.setNamingStrategy(ns);
+ } catch (Exception c) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_configure_naming_strategy
+ + prefs.getNamingStrategy(), c);
+ }
+ }
+ localCfg = loadConfigurationXML(localCfg, includeMappings, entityResolver);
+ localCfg = configureConnectionProfile(localCfg);
+
+ // replace dialect if it is set in preferences
+ if (StringHelper.isNotEmpty(prefs.getDialectName())) {
+ localCfg.setProperty("hibernate.dialect", prefs.getDialectName());
//$NON-NLS-1$
+ }
+
+ return localCfg;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Configuration loadConfigurationXML(Configuration localCfg, boolean
includeMappings,
+ EntityResolver entityResolver) {
+ File configXMLFile = prefs.getConfigXMLFile();
+ if (!includeMappings) {
+ org.dom4j.Document doc;
+ XMLHelper xmlHelper = new XMLHelper();
+ InputStream stream = null;
+ String resourceName = "<unknown>"; //$NON-NLS-1$
+ if (configXMLFile != null) {
+ resourceName = configXMLFile.toString();
+ try {
+ stream = new FileInputStream(configXMLFile);
+ } catch (FileNotFoundException e1) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_access + configXMLFile,
+ e1);
+ }
+ } else {
+ resourceName = "/hibernate.cfg.xml"; //$NON-NLS-1$
+ if (checkHibernateResoureExistence(resourceName)) {
+ stream = ConfigHelper.getResourceAsStream(resourceName); // simulate
hibernate's
+ // default look up
+ } else {
+ return localCfg;
+ }
+ }
+
+ try {
+ List<Throwable> errors = new ArrayList<Throwable>();
+
+ doc = xmlHelper.createSAXReader(resourceName, errors, entityResolver).read(
+ new InputSource(stream));
+ if (errors.size() != 0) {
+ throw new MappingException(
+ ConsoleMessages.ConsoleConfiguration_invalid_configuration, errors
+ .get(0));
+ }
+
+ List<Node> list = doc.getRootElement()
+ .element("session-factory").elements("mapping"); //$NON-NLS-1$
//$NON-NLS-2$
+ for (Node element : list) {
+ element.getParent().remove(element);
+ }
+
+ DOMWriter dw = new DOMWriter();
+ Document document = dw.write(doc);
+ return localCfg.configure(document);
+
+ } catch (DocumentException e) {
+ throw new HibernateException(
+ ConsoleMessages.ConsoleConfiguration_could_not_parse_configuration
+ + resourceName, e);
+ } finally {
+ try {
+ if (stream != null)
+ stream.close();
+ } catch (IOException ioe) {
+ // log.warn( "could not close input stream for: " + resourceName, ioe );
+ }
+ }
+ } else {
+ if (configXMLFile != null) {
+ return localCfg.configure(configXMLFile);
+ } else {
+ Configuration resultCfg = localCfg;
+ if (checkHibernateResoureExistence("/hibernate.cfg.xml")) { //$NON-NLS-1$
+ resultCfg = localCfg.configure();
+ }
+ return resultCfg;
+ }
+ }
+ }
+
+ private boolean checkHibernateResoureExistence(String resource) {
+ InputStream is = null;
+ try {
+ is = ConfigHelper.getResourceAsStream(resource);
+ } catch (HibernateException e) {
+ // just ignore
+ } finally {
+ try {
+ if (is != null)
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return (is != null);
+ }
+
+ private Configuration configureConnectionProfile(Configuration localCfg) {
+ String connectionProfile = prefs.getConnectionProfileName();
+ if (connectionProfile == null) {
+ return localCfg;
+ }
+ IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(
+ connectionProfile);
+ if (profile != null) {
+ refreshProfile(profile);
+ //
+ final Properties invokeProperties = localCfg.getProperties();
+ // set this property to null!
+ invokeProperties.remove(Environment.DATASOURCE);
+ localCfg.setProperties(invokeProperties);
+ Properties cpProperties = profile.getProperties(profile.getProviderId());
+ // seems we should not setup dialect here
+ // String dialect =
+ //
"org.hibernate.dialect.HSQLDialect";//cpProperties.getProperty("org.eclipse.datatools.connectivity.db.driverClass");
+ // invoke.setProperty(Environment.DIALECT, dialect);
+ String driver = cpProperties
+ .getProperty("org.eclipse.datatools.connectivity.db.driverClass");
//$NON-NLS-1$
+ localCfg.setProperty(Environment.DRIVER, driver);
+ // TODO:
+ @SuppressWarnings("unused")
+ String driverJarPath = cpProperties.getProperty("jarList"); //$NON-NLS-1$
+ String url =
cpProperties.getProperty("org.eclipse.datatools.connectivity.db.URL");
//$NON-NLS-1$
+ // url += "/";// +
+ //
cpProperties.getProperty("org.eclipse.datatools.connectivity.db.databaseName");
+ localCfg.setProperty(Environment.URL, url);
+ String user = cpProperties
+ .getProperty("org.eclipse.datatools.connectivity.db.username");
//$NON-NLS-1$
+ if (null != user && user.length() > 0) {
+ localCfg.setProperty(Environment.USER, user);
+ }
+ String pass = cpProperties
+ .getProperty("org.eclipse.datatools.connectivity.db.password");
//$NON-NLS-1$
+ if (null != pass && pass.length() > 0) {
+ localCfg.setProperty(Environment.PASS, pass);
+ }
+ } else {
+ String out = NLS.bind(
+ ConsoleMessages.ConsoleConfiguration_connection_profile_not_found,
+ connectionProfile);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ return localCfg;
+ }
+
+ @SuppressWarnings("unused")
+ private void autoConfigureDialect(Configuration localCfg) {
+ if (localCfg.getProperty(Environment.DIALECT) == null) {
+ String url = localCfg.getProperty(Environment.URL);
+ String user = localCfg.getProperty(Environment.USER);
+ String pass = localCfg.getProperty(Environment.PASS);
+ Connection connection = null;
+ try {
+ connection = DriverManager.getConnection(url, user, pass);
+ // SQL Dialect:
+ Dialect dialect = DialectFactory.buildDialect(localCfg.getProperties(), connection);
+ localCfg.setProperty(Environment.DIALECT, dialect.toString());
+ } catch (SQLException e) {
+ // can't determine dialect
+ }
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ public static void refreshProfile(IConnectionProfile profile) {
+ // refresh profile (refresh jpa connection):
+ // get fresh information about current db structure and update error markers
+ if (profile.getConnectionState() == IConnectionProfile.CONNECTED_STATE) {
+ profile.disconnect(null);
+ }
+ profile.connect(null);
+ }
+}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/SessionStub.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/SessionStub.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/SessionStub.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -21,6 +21,7 @@
import org.hibernate.console.QueryInputModel;
import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.util.CollectionPropertySource;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata;
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/CollectionPropertySource.java
(from rev 20919,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/CollectionPropertySource.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/CollectionPropertySource.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.console.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+public class CollectionPropertySource implements IPropertySource {
+
+ private Collection<?> collection;
+
+ IPropertyDescriptor[] descriptors = null;
+
+ Map<Object, Object> values = new WeakHashMap<Object, Object>();
+
+ public CollectionPropertySource(Collection<?> propertyValue) {
+ collection = propertyValue;
+ }
+
+ public Object getEditableValue() {
+ return null;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if (descriptors == null) {
+ PropertyDescriptor[] properties = new PropertyDescriptor[collection.size()];
+ for (int i = 0; i < properties.length; i++) {
+ properties[i] = new PropertyDescriptor(Integer.valueOf(i), "#" + i);
//$NON-NLS-1$
+ }
+ descriptors = properties;
+ }
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ Object value = values.get(id);
+ if (value == null) {
+ Integer i = (Integer) id;
+ Iterator<?> iterator = collection.iterator();
+ int base = 0;
+
+ while (iterator.hasNext()) {
+
+ value = iterator.next();
+
+ if (base == i.intValue()) {
+ values.put(id, value);
+ return value;
+ } else {
+ value = null;
+ }
+ base++;
+ }
+ }
+
+ return value;
+ }
+
+ public boolean isPropertySet(Object id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void resetPropertyValue(Object id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+
+ }
+
+}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtils.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtils.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtils.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -535,7 +535,7 @@
return file;
}
final ConsoleConfiguration cc2 = consoleConfig;
- List<String> documentPaths =
(List<String>)consoleConfig.getExecutionContext().execute(new
ExecutionContext.Command() {
+ List<String> documentPaths = (List<String>)consoleConfig.execute(new
ExecutionContext.Command() {
public Object execute() {
return OpenMappingUtilsEjb3.enumDocuments(cc2);
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -26,7 +26,6 @@
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ImageConstants;
import org.hibernate.console.KnownConfigurations;
-import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.utils.EclipseImages;
@@ -38,15 +37,7 @@
//String sfError = null;
if(ccfg.getConfiguration()==null) {
ccfg.build();
- ccfg.execute( new ExecutionContext.Command() {
-
- public Object execute() {
- if(ccfg.hasConfiguration()) {
- ccfg.getConfiguration().buildMappings();
- }
- return ccfg;
- }
- } );
+ ccfg.buildMappings();
}
/*if(ccfg.getSessionFactory()==null) { // initialize later?
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -104,7 +104,7 @@
protected void readDatabaseSchema(final IProgressMonitor monitor, final
DefaultDatabaseCollector db, ConsoleConfiguration consoleConfiguration, final
ReverseEngineeringStrategy strategy) {
final ConfigurationStub configuration = consoleConfiguration.buildWith(null, false);
- consoleConfiguration.getExecutionContext().execute(new ExecutionContext.Command() {
+ consoleConfiguration.execute(new ExecutionContext.Command() {
public Object execute() {
Settings settings = configuration.buildSettings();
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -148,7 +148,6 @@
final ConsoleConfiguration cfg0 = cfg;
SessionStub sessionStub = (SessionStub)cfg.execute(new Command() {
public Object execute() {
- // vitali TODO: openSession should be executed in context - all other no!
SessionStub sessionStub = cfg0.getSessionStubFactory().openSession();
return sessionStub;
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -422,18 +422,18 @@
if (queryPage == null || !getPinToOneResTab()) {
queryPage = cfg.executeHQLQuery(getQueryString(),
getQueryInputModel().getCopyForQuery());
} else {
+ KnownConfigurations.getInstance().getQueryPageModel().remove(queryPage);
final ConsoleConfiguration cfg0 = cfg;
- cfg.execute(new Command() {
+ SessionStub sessionStub = (SessionStub)cfg.execute(new Command() {
public Object execute() {
- KnownConfigurations.getInstance().getQueryPageModel().remove(queryPage);
SessionStub sessionStub = cfg0.getSessionStubFactory().openSession();
- queryPage.setModel(getQueryInputModel().getCopyForQuery());
- queryPage.setQueryString(getQueryString());
- queryPage.setSessionStub(sessionStub);
- KnownConfigurations.getInstance().getQueryPageModel().add(queryPage);
- return null;
+ return sessionStub;
}
});
+ queryPage.setModel(getQueryInputModel().getCopyForQuery());
+ queryPage.setQueryString(getQueryString());
+ queryPage.setSessionStub(sessionStub);
+ KnownConfigurations.getInstance().getQueryPageModel().add(queryPage);
}
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/LoadConsoleCFGCompletionProposal.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/LoadConsoleCFGCompletionProposal.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/LoadConsoleCFGCompletionProposal.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -18,7 +18,6 @@
import org.hibernate.HibernateException;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ImageConstants;
-import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.EclipseImages;
@@ -43,15 +42,7 @@
if(consoleConfiguration.getConfiguration()==null) {
try {
consoleConfiguration.build();
- consoleConfiguration.execute( new ExecutionContext.Command() {
-
- public Object execute() {
- if(consoleConfiguration.hasConfiguration()) {
- consoleConfiguration.getConfiguration().buildMappings();
- }
- return consoleConfiguration;
- }
- } );
+ consoleConfiguration.buildMappings();
} catch (HibernateException he) {
HibernateConsolePlugin.getDefault().showError(HibernateConsolePlugin.getShell(),
HibernateConsoleMessages.LoadConsoleCFGCompletionProposal_could_not_load_configuration +
' ' + consoleConfiguration.getName(), he);
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -59,7 +59,6 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.text.edits.TextEdit;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.JDBCMetaDataConfiguration;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.OverrideRepository;
import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
@@ -68,7 +67,7 @@
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.execution.ExecutionContext.Command;
-import org.hibernate.console.stubs.ConfigStubFactory;
+import org.hibernate.console.stubs.ConfigurationStubFactory;
import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.console.stubs.ConfigurationStubJDBCMetaData;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
@@ -274,7 +273,7 @@
}
// vitali: TODO: use execution context
- ConfigStubFactory configStubFactory = new ConfigStubFactory(null);
+ ConfigurationStubFactory configStubFactory = new ConfigurationStubFactory(null);
final ConfigurationStubJDBCMetaData cfg =
configStubFactory.createConfigurationJDBCMetaData();
Properties properties = configuration.getProperties();
cfg.setProperties( properties );
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -41,7 +41,7 @@
import org.eclipse.jdt.core.dom.WildcardType;
import org.hibernate.FetchMode;
import org.hibernate.cfg.Mappings;
-import org.hibernate.console.stubs.ConfigStubFactory;
+import org.hibernate.console.stubs.ConfigurationStubFactory;
import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector;
@@ -147,7 +147,7 @@
// vitali: TODO: should get ConsoleConfig in association with JavaProject
// and create Configuration in execution context of it!
- ConfigStubFactory configStubFactory = new ConfigStubFactory(null);
+ ConfigurationStubFactory configStubFactory = new ConfigurationStubFactory(null);
ConfigurationStub config = configStubFactory.createConfiguration();
Mappings mappings = config.createMappings();
Collection<PersistentClass> classesCollection = createHierarhyStructure(project,
processor.getRootClasses());
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HbmExportExceptionTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HbmExportExceptionTest.java 2010-03-19
17:49:46 UTC (rev 20943)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HbmExportExceptionTest.java 2010-03-19
18:06:20 UTC (rev 20944)
@@ -27,7 +27,6 @@
import org.eclipse.osgi.util.NLS;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
-import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.test.ConsoleTestMessages;
import org.hibernate.eclipse.console.test.project.ConfigurableTestProject;
@@ -75,15 +74,7 @@
consCFG.reset();
consCFG.build();
assertTrue(consCFG.hasConfiguration());
- consCFG.execute( new ExecutionContext.Command() {
-
- public Object execute() {
- if(consCFG.hasConfiguration()) {
- consCFG.getConfiguration().buildMappings();
- }
- return consCFG;
- }
- } );
+ consCFG.buildMappings();
ConfigurationStub config = consCFG.getConfiguration();
//delete old hbm files