Author: vyemialyanchyk
Date: 2010-04-01 14:30:51 -0400 (Thu, 01 Apr 2010)
New Revision: 21209
Added:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionFactoryStub.java
Removed:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionStubFactory.java
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseConsoleConfigurationPreferences.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/ConsoleConfigurationWizardPage.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java
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/preferences/AbstractConsoleConfigurationPreferences.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/StandAloneConsoleConfigurationPreferences.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/preferences/ConsoleConfigurationPreferences.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStub.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubJDBCMetaData.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/DialectStub.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/EnvironmentStub.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/KnownConfigurationsTest.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateErrorsTest2.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-6070 - update
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-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -47,7 +47,7 @@
import org.hibernate.mediator.stubs.HibernateConsoleRuntimeException;
import org.hibernate.mediator.stubs.IHQLCodeAssistStub;
import org.hibernate.mediator.stubs.SessionStub;
-import org.hibernate.mediator.stubs.SessionStubFactory;
+import org.hibernate.mediator.stubs.SessionFactoryStub;
import org.hibernate.mediator.stubs.SettingsStub;
import org.xml.sax.EntityResolver;
@@ -58,7 +58,7 @@
/* TODO: move this out to the actual users of the configuraiton/sf ? */
private ConfigurationStub configStub;
- private SessionStubFactory sessionStubFactory;
+ private SessionFactoryStub sessionStubFactory;
private ConsoleConfigurationPreferences prefs = null;
@@ -225,11 +225,11 @@
}
protected ClassLoader getParentClassLoader() {
+ boolean useClassPathHibernateLibs = prefs.getUseClassPathHibernateLibs();
+ if (useClassPathHibernateLibs) {
+ return ClassLoader.getSystemClassLoader();
+ }
return ConfigurationStub.class.getClassLoader();
- //return this.getClass().getClassLoader();
- //return ClassLoader.getSystemClassLoader();
- //return Thread.currentThread().getContextClassLoader().getParent().getParent();
- //return Thread.currentThread().getContextClassLoader();
}
public ConfigurationStub getConfiguration() {
return configStub;
@@ -247,14 +247,14 @@
if (sessionStubFactory != null) {
throw new
HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_factory_not_closed_before_build_new_factory,
null);
}
- sessionStubFactory = new SessionStubFactory(configStub);
+ sessionStubFactory = configStub.buildSessionFactory();
fireFactoryBuilt();
return null;
}
});
}
- public SessionStubFactory getSessionStubFactory() {
+ public SessionFactoryStub getSessionStubFactory() {
return sessionStubFactory;
}
@@ -335,7 +335,7 @@
}
}
- private void fireFactoryClosing(SessionStubFactory ssf) {
+ private void fireFactoryClosing(SessionFactoryStub ssf) {
for (ConsoleConfigurationListener view : consoleCfgListeners) {
view.sessionFactoryClosing(this);
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/AbstractConsoleConfigurationPreferences.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/AbstractConsoleConfigurationPreferences.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/AbstractConsoleConfigurationPreferences.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -52,13 +52,15 @@
protected String entityResolverName = null;
private boolean useProjectClasspath;
private ConfigurationMode configurationMode;
+ private boolean useClassPathHibernateLibs;
private String persistenceUnitName;
private String namingStrategy;
private String connectionProfile;
private String dialectName;
- public AbstractConsoleConfigurationPreferences(String name, ConfigurationMode
configurationMode,
+ public AbstractConsoleConfigurationPreferences(String name,
+ ConfigurationMode configurationMode, boolean useClassPathHibernateLibs,
String projectName, boolean useProjectclassPath, String entityResolver,
String persistenceUnitName, String namingStrategy,
String connectionProfile, String dialectName) {
@@ -66,6 +68,7 @@
this.persistenceUnitName = persistenceUnitName;
this.namingStrategy = namingStrategy;
this.configurationMode = configurationMode;
+ this.useClassPathHibernateLibs = useClassPathHibernateLibs;
entityResolverName = entityResolver;
this.projectName = projectName;
this.useProjectClasspath = useProjectclassPath;
@@ -81,6 +84,10 @@
return configurationMode;
}
+ public boolean getUseClassPathHibernateLibs() {
+ return useClassPathHibernateLibs;
+ }
+
public String getPersistenceUnitName() {
return persistenceUnitName;
}
@@ -133,13 +140,17 @@
/** generic xml dumper that just dumps the toString representation of the paramters
* @param useAnnotations */
- protected static void writeStateTo(Node node, String name, String entityResolver,
ConfigurationMode configurationMode, String projectName, boolean useProjectClasspath,
Object cfgFile, Object propertyFilename, Object[] mappings, Object[] customClasspath) {
+ protected static void writeStateTo(Node node, String name, String entityResolver,
+ ConfigurationMode configurationMode, boolean useClassPathHibernateLibs,
+ String projectName, boolean useProjectClasspath, Object cfgFile,
+ Object propertyFilename, Object[] mappings, Object[] customClasspath) {
Document doc = node.getOwnerDocument();
Element n = createElementWithAttribute(doc, CONFIGURATION_TAG, NAME_ATTRIB, name);
/*if(useAnnotations) {
n.setAttribute(ANNOTATIONS_ATTRIB, "true");
}*/
n.setAttribute(CONFIGURATION_MODE_ATTRIB, configurationMode.toString());
+ n.setAttribute(USE_CLASSPATH_HIBERNATE_LIBS_ATTRIB,
Boolean.toString(useClassPathHibernateLibs));
if(StringHelper.isNotEmpty(entityResolver)) {
n.setAttribute(ENTITYRESOLVER_ATTRIB, entityResolver);
@@ -227,6 +238,8 @@
attribute = node.getAttribute(CONFIGURATION_MODE_ATTRIB);
configurationMode = ConfigurationMode.parse( attribute );
}
+ attribute = node.getAttribute(USE_CLASSPATH_HIBERNATE_LIBS_ATTRIB);
+ useClassPathHibernateLibs = Boolean.parseBoolean(attribute);
attribute = node.getAttribute( PROJECT_ATTRIB );
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/StandAloneConsoleConfigurationPreferences.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/StandAloneConsoleConfigurationPreferences.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/StandAloneConsoleConfigurationPreferences.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -46,7 +46,7 @@
private File[] customClasspath;
public StandAloneConsoleConfigurationPreferences(String name, File xmlconfig, File
propertiesFile, File[] mappingFiles, File[] customClasspath) {
- super(name, ConfigurationMode.CORE, null, false, null, null, null, null, null);
+ super(name, ConfigurationMode.CORE, false, null, false, null, null, null, null, null);
this.cfgFile = xmlconfig;
this.propertyFilename = propertiesFile;
this.mappings = mappingFiles;
@@ -91,7 +91,7 @@
}
public void writeStateTo(Element node) {
- writeStateTo(node, getName(), getEntityResolverName(), getConfigurationMode(), null,
false, cfgFile, propertyFilename, mappings, customClasspath);
+ writeStateTo(node, getName(), getEntityResolverName(), getConfigurationMode(),
getUseClassPathHibernateLibs(), null, false, cfgFile, propertyFilename, mappings,
customClasspath);
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseConsoleConfigurationPreferences.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseConsoleConfigurationPreferences.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseConsoleConfigurationPreferences.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -59,11 +59,14 @@
private IPath[] customClasspath = new IPath[0];
public EclipseConsoleConfigurationPreferences(String configName,
- ConfigurationMode cmode, String projectName, boolean useProjectClasspath,
+ ConfigurationMode cmode, boolean useClassPathHibernateLibs,
+ String projectName, boolean useProjectClasspath,
String entityResolver, IPath cfgFile, IPath propertyFilename,
IPath[] mappings, IPath[] classpaths, String persistenceUnitName, String
namingStrategy,
String connectionProfile, String dialectName) {
- super(configName, cmode, projectName, useProjectClasspath, entityResolver,
persistenceUnitName, namingStrategy, connectionProfile, dialectName);
+ super(configName, cmode, useClassPathHibernateLibs, projectName,
+ useProjectClasspath, entityResolver, persistenceUnitName,
+ namingStrategy, connectionProfile, dialectName);
this.cfgFile = cfgFile;
this.propertyFilename = propertyFilename;
this.mappings = mappings;
@@ -168,7 +171,7 @@
}
public void writeStateTo(Element node) {
- writeStateTo(node, getName(), getEntityResolverName(), getConfigurationMode(),
getProjectName(), useProjectClasspath(), cfgFile, propertyFilename, mappings,
customClasspath);
+ writeStateTo(node, getName(), getEntityResolverName(), getConfigurationMode(),
getUseClassPathHibernateLibs(), getProjectName(), useProjectClasspath(), cfgFile,
propertyFilename, mappings, customClasspath);
}
protected void setConfigFile(String cfgFile) {
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -89,6 +89,10 @@
public ConfigurationMode getConfigurationMode() {
return ConfigurationMode.parse( getAttribute(
IConsoleConfigurationLaunchConstants.CONFIGURATION_FACTORY, "" ) );
//$NON-NLS-1$
}
+
+ public boolean getUseClassPathHibernateLibs() {
+ return
Boolean.parseBoolean(getAttribute(IConsoleConfigurationLaunchConstants.USE_CLASSPATH_HIBERNATE_LIBS,
"false")); //$NON-NLS-1$
+ }
public URL[] getCustomClassPathURLS() {
try {
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/ConsoleConfigurationWizardPage.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/ConsoleConfigurationWizardPage.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/ConsoleConfigurationWizardPage.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -567,6 +567,7 @@
if (flagFileWillBeCreated) {
setPathAttribute(currentLaunchConfig,
IConsoleConfigurationLaunchConstants.CFG_XML_FILE, configFullPath);
setStrAttribute(currentLaunchConfig,
IConsoleConfigurationLaunchConstants.CONFIGURATION_FACTORY,
ConfigurationMode.CORE.toString());
+ setStrAttribute(currentLaunchConfig,
IConsoleConfigurationLaunchConstants.USE_CLASSPATH_HIBERNATE_LIBS,
Boolean.toString(false));
ConsoleConfigurationMainTab ccmt = null;
ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
for (int i = 0; i < tabs.length; i++) {
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -37,6 +37,7 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
@@ -60,6 +61,7 @@
private Button coreMode;
private Button jpaMode;
private Button annotationsMode;
+ private Button useLibs;
private Button confbutton;
private Button persistenceUnitNameButton;
@@ -119,6 +121,11 @@
jpaMode = new Button(group, SWT.RADIO);
jpaMode.setText(HibernateConsoleMessages.ConsoleConfigurationMainTab_jpa);
jpaMode.addSelectionListener( getChangeListener() );
+ Label label = new Label(group, SWT.SEPARATOR | SWT.HORIZONTAL);
+ label.setVisible(false);
+ useLibs = new Button(group, SWT.CHECK);
+ useLibs.setText("Use classpath Hibernate jars");
+ useLibs.addSelectionListener( getChangeListener() );
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
group.setLayoutData( gd );
@@ -170,6 +177,7 @@
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
String projectName = nonEmptyTrimOrNull( projectNameText );
configuration.setAttribute(IConsoleConfigurationLaunchConstants.CONFIGURATION_FACTORY,
getConfigurationMode().toString());
+ configuration.setAttribute(IConsoleConfigurationLaunchConstants.USE_CLASSPATH_HIBERNATE_LIBS,
Boolean.toString(getUseLibs()));
configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
projectName);
if (projectName != null){
configuration.setAttribute(LaunchConfiguration.ATTR_MAPPED_RESOURCE_PATHS,
@@ -202,6 +210,8 @@
coreMode.setSelection( cm.equals( ConfigurationMode.CORE ) );
annotationsMode.setSelection( cm.equals( ConfigurationMode.ANNOTATIONS ) );
jpaMode.setSelection( cm.equals( ConfigurationMode.JPA ) );
+
+ useLibs.setSelection(Boolean.parseBoolean(configuration.getAttribute(
IConsoleConfigurationLaunchConstants.USE_CLASSPATH_HIBERNATE_LIBS, "false" )));
//$NON-NLS-1$
projectNameText.setText( configuration.getAttribute(
IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "" ) ); //$NON-NLS-1$
propertyFileText.setText( configuration.getAttribute(
IConsoleConfigurationLaunchConstants.PROPERTY_FILE, "" ) ); //$NON-NLS-1$
@@ -498,6 +508,10 @@
}
}
+ private boolean getUseLibs() {
+ return useLibs.getSelection();
+ }
+
String getProjectName() {
return projectNameText.getText();
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -12,6 +12,7 @@
public static final String CFG_XML_FILE = ID + ".CFG_XML_FILE"; //$NON-NLS-1$
public static final String PERSISTENCE_UNIT_NAME = ID +
".PERSISTENCE_UNIT_NAME"; //$NON-NLS-1$
public static final String CONFIGURATION_FACTORY = ID +
".CONFIGURATION_FACTORY"; //$NON-NLS-1$
+ public static final String USE_CLASSPATH_HIBERNATE_LIBS = ID +
".USE_CLASSPATH_HIBERNATE_LIBS"; //$NON-NLS-1$
public static final String CONNECTION_PROFILE_NAME = ID +
".CONNECTION_PROFILE_NAME"; //$NON-NLS-1$
public static final String USE_JPA_PROJECT_PROFILE = ID +
".USE_JPA_PROJECT_PROFILE"; //$NON-NLS-1$
public static final String FILE_MAPPINGS = ID + ".FILE_MAPPINGS";
//$NON-NLS-1$
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/preferences/ConsoleConfigurationPreferences.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/preferences/ConsoleConfigurationPreferences.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/preferences/ConsoleConfigurationPreferences.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -48,6 +48,7 @@
static final String ANNOTATIONS_ATTRIB = "annotations"; //$NON-NLS-1$
static final String ENTITYRESOLVER_ATTRIB = "entityresolver"; //$NON-NLS-1$
static final String CONFIGURATION_MODE_ATTRIB = "configuration-factory";
//$NON-NLS-1$
+ static final String USE_CLASSPATH_HIBERNATE_LIBS_ATTRIB =
"use-classpath-hibernate-libs"; //$NON-NLS-1$
// TODO: we should move this to some classhandler
static public class ConfigurationMode implements Serializable {
@@ -97,6 +98,8 @@
public abstract ConfigurationMode getConfigurationMode();
+ public abstract boolean getUseClassPathHibernateLibs();
+
public abstract String getName();
/**
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStub.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStub.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStub.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -11,7 +11,6 @@
import java.util.Properties;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mediator.Messages;
@@ -19,6 +18,7 @@
import org.hibernate.mediator.stubs.util.ReflectHelper;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.ide.completion.HQLCodeAssist;
+import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
public class ConfigurationStub {
@@ -28,15 +28,16 @@
// configuration != null - by default
protected Configuration configuration;
- protected ConfigurationStub(Configuration configuration) {
+ protected ConfigurationStub(Object configuration) {
if (configuration == null) {
throw new HibernateConsoleRuntimeException(Messages.Stub_create_null_stub_prohibit);
}
- this.configuration = configuration;
+ this.configuration = (Configuration)configuration;
}
- protected Configuration getConfiguration() {
- return configuration;
+ public static ConfigurationStub newInstance() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
+ Class<?> clazz =
ReflectHelper.classForName("org.hibernate.cfg.Configuration"); //$NON-NLS-1$
+ return new ConfigurationStub(clazz.newInstance());
}
public void cleanUp() {
@@ -63,8 +64,8 @@
return new SettingsStub(obj);
}
- protected SessionFactory buildSessionFactory() {
- return configuration.buildSessionFactory();
+ public SessionFactoryStub buildSessionFactory() {
+ return new SessionFactoryStub(configuration.buildSessionFactory());
}
public EntityResolver getEntityResolver() {
@@ -204,4 +205,41 @@
}
}
}
+
+ public ConfigurationStub setProperties(Properties properties) {
+ Configuration tmp = configuration.setProperties(properties);
+ return (tmp == configuration ? this : new ConfigurationStub(tmp));
+ }
+
+ public void setProperty(String propertyName, String value) {
+ configuration.setProperty(propertyName, value);
+ }
+
+ public ConfigurationStub configure(Document document) {
+ Configuration tmp = configuration.configure(document);
+ return (tmp == configuration ? this : new ConfigurationStub(tmp));
+ }
+
+ public ConfigurationStub configure() {
+ Configuration tmp = configuration.configure();
+ return (tmp == configuration ? this : new ConfigurationStub(tmp));
+ }
+
+ public ConfigurationStub configure(File configFile) {
+ Configuration tmp = configuration.configure(configFile);
+ return (tmp == configuration ? this : new ConfigurationStub(tmp));
+ }
+
+ public void setEntityResolver(EntityResolver entityResolver) {
+ configuration.setEntityResolver(entityResolver);
+ }
+
+ public void setNamingStrategy(NamingStrategyStub ns) {
+ configuration.setNamingStrategy(ns.namingStrategy);
+ }
+
+ public ConfigurationStub addFile(File xmlFile) {
+ Configuration tmp = configuration.addFile(xmlFile);
+ return (tmp == configuration ? this : new ConfigurationStub(tmp));
+ }
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -21,14 +21,6 @@
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.dialect.Dialect;
-import org.hibernate.dialect.resolver.DialectFactory;
import org.hibernate.mediator.Messages;
import org.hibernate.mediator.preferences.ConsoleConfigurationPreferences;
import
org.hibernate.mediator.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
@@ -52,17 +44,22 @@
}
public ConfigurationStub createConfiguration() {
- ConfigurationStub res = new ConfigurationStub(new Configuration());
- return res;
+ try {
+ return ConfigurationStub.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new HibernateConsoleRuntimeException(e);
+ } catch (InstantiationException e) {
+ throw new HibernateConsoleRuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new HibernateConsoleRuntimeException(e);
+ }
}
public ConfigurationStubJDBCMetaData createConfigurationJDBCMetaData() {
- ConfigurationStubJDBCMetaData res = new ConfigurationStubJDBCMetaData(new
JDBCMetaDataConfiguration());
- return res;
+ return ConfigurationStubJDBCMetaData.newInstance();
}
- public ConfigurationStub createConfiguration(ConfigurationStub cfg, boolean
includeMappings) {
- Configuration localCfg = cfg == null ? null : cfg.getConfiguration();
+ public ConfigurationStub createConfiguration(ConfigurationStub localCfg, boolean
includeMappings) {
Properties properties = prefs.getProperties();
if (properties != null) {
// to fix: JBIDE-5839 - setup this property: false is default value
@@ -81,7 +78,15 @@
}
}
if (localCfg == null) {
- localCfg = buildConfiguration(properties, includeMappings);
+ try {
+ localCfg = buildConfiguration(properties, includeMappings);
+ } catch (ClassNotFoundException e) {
+ throw new HibernateConsoleRuntimeException(e);
+ } catch (InstantiationException e) {
+ throw new HibernateConsoleRuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new HibernateConsoleRuntimeException(e);
+ }
} else {
// Properties origProperties = cfg.getProperties();
// origProperties.putAll(properties);
@@ -100,24 +105,22 @@
}
// 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);
+ localCfg.setProperty(EnvironmentStub.HBM2DDL_AUTO, "false"); //$NON-NLS-1$
// here both setProperties and configxml have had their chance to tell which
databasedriver
// is needed.
- res.registerFakeDriver(localCfg.getProperty(Environment.DRIVER));
+ localCfg.registerFakeDriver(localCfg.getProperty(EnvironmentStub.DRIVER));
// autoConfigureDialect(localCfg); Disabled for now since it causes very looong
timeouts for
- return res;
+ return localCfg;
}
- private Configuration buildAnnotationConfiguration() throws ClassNotFoundException,
+ private ConfigurationStub buildAnnotationConfiguration() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
Class<?> clazz = ReflectHelper
- .classForName("org.hibernate.cfg.AnnotationConfiguration",
Configuration.class); //$NON-NLS-1$
- Configuration annotationConfig = (Configuration)clazz.newInstance();
- return annotationConfig;
+ .classForName("org.hibernate.cfg.AnnotationConfiguration"); //$NON-NLS-1$
+ return new ConfigurationStub(clazz.newInstance());
}
- private Configuration buildJPAConfiguration(String persistenceUnit, Properties
properties,
+ private ConfigurationStub buildJPAConfiguration(String persistenceUnit, Properties
properties,
String entityResolver, boolean includeMappings) {
if (StringHelper.isEmpty(persistenceUnit)) {
persistenceUnit = null;
@@ -137,11 +140,11 @@
overrides.put("hibernate.archive.autodetection", "none");
//$NON-NLS-1$//$NON-NLS-2$
}
Class<?> clazz = ReflectHelper.classForName(
- "org.hibernate.ejb.Ejb3Configuration", Configuration.class);
//$NON-NLS-1$
+ "org.hibernate.ejb.Ejb3Configuration"); //$NON-NLS-1$
Object ejb3cfg = clazz.newInstance();
if (StringHelper.isNotEmpty(entityResolver)) {
- Class<?> resolver = ReflectHelper.classForName(entityResolver,
this.getClass());
+ Class<?> resolver = ReflectHelper.classForName(entityResolver);
Object object = resolver.newInstance();
Method method = clazz.getMethod(
"setEntityResolver", new Class[] { EntityResolver.class });//$NON-NLS-1$
@@ -158,7 +161,7 @@
method = clazz.getMethod("getHibernateConfiguration", new
Class[0]);//$NON-NLS-1$
Object obj = method.invoke(ejb3cfg, (Object[]) null);
- Configuration invoke = (Configuration)obj;
+ ConfigurationStub invoke = new ConfigurationStub(obj);
invoke = configureConnectionProfile(invoke);
return invoke;
@@ -171,8 +174,8 @@
}
}
- private Configuration buildConfiguration(Properties properties, boolean includeMappings)
{
- Configuration localCfg = null;
+ private ConfigurationStub buildConfiguration(Properties properties, boolean
includeMappings) throws ClassNotFoundException, InstantiationException,
IllegalAccessException {
+ ConfigurationStub localCfg = null;
if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) {
try {
localCfg = buildAnnotationConfiguration();
@@ -195,14 +198,14 @@
Messages.ConsoleConfiguration_could_not_load_jpa_configuration, e);
}
} else {
- localCfg = new Configuration();
+ localCfg = ConfigurationStub.newInstance();
localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
}
return localCfg;
}
- private Configuration configureStandardConfiguration(final boolean includeMappings,
- Configuration localCfg, Properties properties) {
+ private ConfigurationStub configureStandardConfiguration(final boolean includeMappings,
+ ConfigurationStub localCfg, Properties properties) {
if (properties != null) {
localCfg = localCfg.setProperties(properties);
}
@@ -220,8 +223,8 @@
localCfg.setEntityResolver(entityResolver);
if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
try {
- NamingStrategy ns = (NamingStrategy) ReflectHelper.classForName(
- prefs.getNamingStrategy()).newInstance();
+ NamingStrategyStub ns = new NamingStrategyStub(ReflectHelper.classForName(
+ prefs.getNamingStrategy()).newInstance());
localCfg.setNamingStrategy(ns);
} catch (Exception c) {
throw new HibernateConsoleRuntimeException(
@@ -241,7 +244,7 @@
}
@SuppressWarnings("unchecked")
- private Configuration loadConfigurationXML(Configuration localCfg, boolean
includeMappings,
+ private ConfigurationStub loadConfigurationXML(ConfigurationStub localCfg, boolean
includeMappings,
EntityResolver entityResolver) {
File configXMLFile = prefs.getConfigXMLFile();
if (!includeMappings) {
@@ -274,7 +277,7 @@
doc = xmlHelper.createSAXReader(resourceName, errors, entityResolver).read(
new InputSource(stream));
if (errors.size() != 0) {
- throw new MappingException(
+ throw new HibernateConsoleRuntimeException(
Messages.ConsoleConfiguration_invalid_configuration, errors
.get(0));
}
@@ -290,7 +293,7 @@
return localCfg.configure(document);
} catch (DocumentException e) {
- throw new HibernateException(
+ throw new HibernateConsoleRuntimeException(
Messages.ConsoleConfiguration_could_not_parse_configuration
+ resourceName, e);
} finally {
@@ -305,7 +308,7 @@
if (configXMLFile != null) {
return localCfg.configure(configXMLFile);
} else {
- Configuration resultCfg = localCfg;
+ ConfigurationStub resultCfg = localCfg;
if (checkHibernateResoureExistence("/hibernate.cfg.xml")) { //$NON-NLS-1$
resultCfg = localCfg.configure();
}
@@ -318,8 +321,13 @@
InputStream is = null;
try {
is = ConfigHelper.getResourceAsStream(resource);
- } catch (HibernateException e) {
- // just ignore
+ } catch (RuntimeException he) {
+ // TODO: RuntimeException ? - find correct solution
+ if (he.getClass().getName().contains("HibernateException")) { //$NON-NLS-1$
+ // just ignore
+ } else {
+ throw he;
+ }
} finally {
try {
if (is != null)
@@ -331,7 +339,7 @@
return (is != null);
}
- private Configuration configureConnectionProfile(Configuration localCfg) {
+ private ConfigurationStub configureConnectionProfile(ConfigurationStub localCfg) {
String connectionProfile = prefs.getConnectionProfileName();
if (connectionProfile == null) {
return localCfg;
@@ -343,7 +351,7 @@
//
final Properties invokeProperties = localCfg.getProperties();
// set this property to null!
- invokeProperties.remove(Environment.DATASOURCE);
+ invokeProperties.remove(EnvironmentStub.DATASOURCE);
localCfg.setProperties(invokeProperties);
Properties cpProperties = profile.getProperties(profile.getProviderId());
// seems we should not setup dialect here
@@ -352,23 +360,23 @@
// invoke.setProperty(Environment.DIALECT, dialect);
String driver = cpProperties
.getProperty("org.eclipse.datatools.connectivity.db.driverClass");
//$NON-NLS-1$
- localCfg.setProperty(Environment.DRIVER, driver);
+ localCfg.setProperty(EnvironmentStub.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);
+ localCfg.setProperty(EnvironmentStub.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);
+ localCfg.setProperty(EnvironmentStub.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);
+ localCfg.setProperty(EnvironmentStub.PASS, pass);
}
} else {
String out = NLS.bind(
@@ -380,17 +388,17 @@
}
@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);
+ private void autoConfigureDialect(ConfigurationStub localCfg) {
+ if (localCfg.getProperty(EnvironmentStub.DIALECT) == null) {
+ String url = localCfg.getProperty(EnvironmentStub.URL);
+ String user = localCfg.getProperty(EnvironmentStub.USER);
+ String pass = localCfg.getProperty(EnvironmentStub.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());
+ DialectStub dialect = DialectStub.newInstance(localCfg.getProperties(), connection);
+ localCfg.setProperty(EnvironmentStub.DIALECT, dialect.toString());
} catch (SQLException e) {
// can't determine dialect
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubJDBCMetaData.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubJDBCMetaData.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubJDBCMetaData.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -18,9 +18,14 @@
}
jdbcMetaDataConfiguration = configuration;
}
+
+ public static ConfigurationStubJDBCMetaData newInstance() {
+ return new ConfigurationStubJDBCMetaData(new JDBCMetaDataConfiguration());
+ }
- public void setProperties(Properties properties) {
- jdbcMetaDataConfiguration.setProperties(properties);
+ public ConfigurationStubJDBCMetaData setProperties(Properties properties) {
+ JDBCMetaDataConfiguration tmp =
(JDBCMetaDataConfiguration)jdbcMetaDataConfiguration.setProperties(properties);
+ return (tmp == jdbcMetaDataConfiguration ? this : new
ConfigurationStubJDBCMetaData(tmp));
}
public void setPreferBasicCompositeIds(boolean flag) {
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/DialectStub.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/DialectStub.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/DialectStub.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -1,6 +1,10 @@
package org.hibernate.mediator.stubs;
+import java.sql.Connection;
+import java.util.Properties;
+
import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.resolver.DialectFactory;
import org.hibernate.mediator.Messages;
public class DialectStub {
@@ -16,4 +20,12 @@
public static DialectStub newInstance(final String dialectName) throws
InstantiationException, IllegalAccessException, ClassNotFoundException {
return new DialectStub(Class.forName(dialectName).newInstance());
}
+
+ public static DialectStub newInstance(Properties properties, Connection connection) {
+ return new DialectStub(DialectFactory.buildDialect(properties, connection));
+ }
+
+ public String toString() {
+ return dialect.toString();
+ }
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/EnvironmentStub.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/EnvironmentStub.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/EnvironmentStub.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -17,6 +17,8 @@
public static final String SESSION_FACTORY_NAME = Environment.SESSION_FACTORY_NAME;
public static final String URL = Environment.URL;
public static final String USER = Environment.USER;
+ public static final String HBM2DDL_AUTO = Environment.HBM2DDL_AUTO;
+ public static final String DATASOURCE = Environment.DATASOURCE;
@SuppressWarnings("unchecked")
public static String[] extractHibernateProperties() {
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionFactoryStub.java
(from rev 21117,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionStubFactory.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionFactoryStub.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionFactoryStub.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -0,0 +1,167 @@
+package org.hibernate.mediator.stubs;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.engine.query.HQLQueryPlan;
+import org.hibernate.hql.QueryTranslator;
+import org.hibernate.impl.SessionFactoryImpl;
+import org.hibernate.mediator.Messages;
+import org.hibernate.mediator.util.ELTransformer;
+import org.hibernate.mediator.util.QLFormatHelper;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.metadata.CollectionMetadata;
+import org.hibernate.type.Type;
+
+public class SessionFactoryStub {
+
+ protected SessionFactory sessionFactory;
+
+ protected SessionFactoryStub(Object sessionFactory) {
+ if (sessionFactory == null) {
+ throw new HibernateConsoleRuntimeException(Messages.Stub_create_null_stub_prohibit);
+ }
+ this.sessionFactory = (SessionFactory)sessionFactory;
+ }
+
+ public boolean isSessionFactoryCreated() {
+ return sessionFactory != null;
+ }
+
+ public SessionStub openSession() {
+ if (sessionFactory != null) {
+ return new SessionStub(sessionFactory.openSession());
+ }
+ return null;
+ }
+
+ public void close() {
+ if (sessionFactory != null) {
+ sessionFactory.close();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<String> getClasses() {
+ List<String> res = Collections.emptyList();
+ if (sessionFactory != null) {
+ res = new ArrayList<String>();
+ res.addAll(sessionFactory.getAllClassMetadata().keySet());
+ }
+ return res;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<String, ClassMetadataStub> getClassMetaData() {
+ if (sessionFactory == null) {
+ return new HashMap<String, ClassMetadataStub>();
+ }
+ Map<String, ClassMetadata> allClassMetadata =
sessionFactory.getAllClassMetadata();
+ Iterator<Map.Entry<String, ClassMetadata>> it =
allClassMetadata.entrySet().iterator();
+ Map<String, ClassMetadataStub> res = new HashMap<String,
ClassMetadataStub>();
+ while (it.hasNext()) {
+ Map.Entry<String, ClassMetadata> entry = it.next();
+ res.put(entry.getKey(), new ClassMetadataStub(entry.getValue()));
+ }
+ return res;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<String, CollectionMetadataStub> getCollectionMetaData() {
+ if (sessionFactory == null) {
+ return new HashMap<String, CollectionMetadataStub>();
+ }
+ Map<String, CollectionMetadata> allClassMetadata =
sessionFactory.getAllCollectionMetadata();
+ Iterator<Map.Entry<String, CollectionMetadata>> it =
allClassMetadata.entrySet().iterator();
+ Map<String, CollectionMetadataStub> res = new HashMap<String,
CollectionMetadataStub>();
+ while (it.hasNext()) {
+ Map.Entry<String, CollectionMetadata> entry = it.next();
+ res.put(entry.getKey(), new CollectionMetadataStub(entry.getValue()));
+ }
+ return res;
+ }
+
+ /**
+ * Given a ConsoleConfiguration and a query this method validates the query through
hibernate if
+ * a sessionfactory is available.
+ *
+ * @param query
+ * @param allowEL
+ * if true, EL syntax will be replaced as a named variable
+ */
+ public void checkQuery(String query, boolean allowEL) {
+ if (sessionFactory != null) {
+ if (allowEL) {
+ query = ELTransformer.removeEL(query);
+ }
+ new HQLQueryPlan(query, false, Collections.EMPTY_MAP,
+ (SessionFactoryImpl) sessionFactory);
+ }
+ }
+
+ public String generateSQL(String query) {
+ try {
+ SessionFactoryImpl sfimpl = (SessionFactoryImpl) sessionFactory; // hack - to get to
the
+ // actual queries..
+ StringBuffer str = new StringBuffer(256);
+ HQLQueryPlan plan = new HQLQueryPlan(query, false, Collections.EMPTY_MAP, sfimpl);
+
+ QueryTranslator[] translators = plan.getTranslators();
+ for (int i = 0; i < translators.length; i++) {
+ QueryTranslator translator = translators[i];
+ if (translator.isManipulationStatement()) {
+ str.append(Messages.DynamicSQLPreviewView_manipulation_of + i
+ + ":"); //$NON-NLS-1$
+ Iterator<?> iterator = translator.getQuerySpaces().iterator();
+ while (iterator.hasNext()) {
+ Object qspace = iterator.next();
+ str.append(qspace);
+ if (iterator.hasNext()) {
+ str.append(", ");} //$NON-NLS-1$
+ }
+
+ } else {
+ Type[] returnTypes = translator.getReturnTypes();
+ str.append(i + ": "); //$NON-NLS-1$
+ for (int j = 0; j < returnTypes.length; j++) {
+ Type returnType = returnTypes[j];
+ str.append(returnType.getName());
+ if (j < returnTypes.length - 1) {
+ str.append(", ");} //$NON-NLS-1$
+ }
+ }
+ str.append("\n-----------------\n"); //$NON-NLS-1$
+ Iterator<?> sqls = translator.collectSqlStrings().iterator();
+ while (sqls.hasNext()) {
+ String sql = (String) sqls.next();
+ str.append(QLFormatHelper.formatForScreen(sql));
+ str.append("\n\n"); //$NON-NLS-1$
+ }
+ }
+ return str.toString();
+ } catch (Throwable t) {
+ // StringWriter sw = new StringWriter();
+ StringBuffer msgs = new StringBuffer();
+
+ Throwable cause = t;
+ while (cause != null) {
+ msgs.append(t);
+ if (cause.getCause() == cause) {
+ cause = null;
+ } else {
+ cause = cause.getCause();
+ if (cause != null)
+ msgs.append(Messages.DynamicSQLPreviewView_caused_by);
+ }
+ }
+ // t.printStackTrace(new PrintWriter(sw));
+ // return sw.getBuffer().toString();
+ return msgs.toString();
+ }
+ }
+}
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionStubFactory.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionStubFactory.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/SessionStubFactory.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -1,164 +0,0 @@
-package org.hibernate.mediator.stubs;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.engine.query.HQLQueryPlan;
-import org.hibernate.hql.QueryTranslator;
-import org.hibernate.impl.SessionFactoryImpl;
-import org.hibernate.mediator.Messages;
-import org.hibernate.mediator.util.ELTransformer;
-import org.hibernate.mediator.util.QLFormatHelper;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.metadata.CollectionMetadata;
-import org.hibernate.type.Type;
-
-public class SessionStubFactory {
-
- protected SessionFactory sessionFactory;
-
- public SessionStubFactory(ConfigurationStub configStub) {
- sessionFactory = configStub.buildSessionFactory();
- }
-
- public boolean isSessionFactoryCreated() {
- return sessionFactory != null;
- }
-
- public SessionStub openSession() {
- if (sessionFactory != null) {
- return new SessionStub(sessionFactory.openSession());
- }
- return null;
- }
-
- public void close() {
- if (sessionFactory != null) {
- sessionFactory.close();
- }
- }
-
- @SuppressWarnings("unchecked")
- public List<String> getClasses() {
- List<String> res = Collections.emptyList();
- if (sessionFactory != null) {
- res = new ArrayList<String>();
- res.addAll(sessionFactory.getAllClassMetadata().keySet());
- }
- return res;
- }
-
- @SuppressWarnings("unchecked")
- public Map<String, ClassMetadataStub> getClassMetaData() {
- if (sessionFactory == null) {
- return new HashMap<String, ClassMetadataStub>();
- }
- Map<String, ClassMetadata> allClassMetadata =
sessionFactory.getAllClassMetadata();
- Iterator<Map.Entry<String, ClassMetadata>> it =
allClassMetadata.entrySet().iterator();
- Map<String, ClassMetadataStub> res = new HashMap<String,
ClassMetadataStub>();
- while (it.hasNext()) {
- Map.Entry<String, ClassMetadata> entry = it.next();
- res.put(entry.getKey(), new ClassMetadataStub(entry.getValue()));
- }
- return res;
- }
-
- @SuppressWarnings("unchecked")
- public Map<String, CollectionMetadataStub> getCollectionMetaData() {
- if (sessionFactory == null) {
- return new HashMap<String, CollectionMetadataStub>();
- }
- Map<String, CollectionMetadata> allClassMetadata =
sessionFactory.getAllCollectionMetadata();
- Iterator<Map.Entry<String, CollectionMetadata>> it =
allClassMetadata.entrySet().iterator();
- Map<String, CollectionMetadataStub> res = new HashMap<String,
CollectionMetadataStub>();
- while (it.hasNext()) {
- Map.Entry<String, CollectionMetadata> entry = it.next();
- res.put(entry.getKey(), new CollectionMetadataStub(entry.getValue()));
- }
- return res;
- }
-
- /**
- * Given a ConsoleConfiguration and a query this method validates the query through
hibernate if
- * a sessionfactory is available.
- *
- * @param query
- * @param allowEL
- * if true, EL syntax will be replaced as a named variable
- */
- public void checkQuery(String query, boolean allowEL) {
- if (sessionFactory != null) {
- if (allowEL) {
- query = ELTransformer.removeEL(query);
- }
- new HQLQueryPlan(query, false, Collections.EMPTY_MAP,
- (SessionFactoryImpl) sessionFactory);
- }
- }
-
- public String generateSQL(String query) {
- try {
- SessionFactoryImpl sfimpl = (SessionFactoryImpl) sessionFactory; // hack - to get to
the
- // actual queries..
- StringBuffer str = new StringBuffer(256);
- HQLQueryPlan plan = new HQLQueryPlan(query, false, Collections.EMPTY_MAP, sfimpl);
-
- QueryTranslator[] translators = plan.getTranslators();
- for (int i = 0; i < translators.length; i++) {
- QueryTranslator translator = translators[i];
- if (translator.isManipulationStatement()) {
- str.append(Messages.DynamicSQLPreviewView_manipulation_of + i
- + ":"); //$NON-NLS-1$
- Iterator<?> iterator = translator.getQuerySpaces().iterator();
- while (iterator.hasNext()) {
- Object qspace = iterator.next();
- str.append(qspace);
- if (iterator.hasNext()) {
- str.append(", ");} //$NON-NLS-1$
- }
-
- } else {
- Type[] returnTypes = translator.getReturnTypes();
- str.append(i + ": "); //$NON-NLS-1$
- for (int j = 0; j < returnTypes.length; j++) {
- Type returnType = returnTypes[j];
- str.append(returnType.getName());
- if (j < returnTypes.length - 1) {
- str.append(", ");} //$NON-NLS-1$
- }
- }
- str.append("\n-----------------\n"); //$NON-NLS-1$
- Iterator<?> sqls = translator.collectSqlStrings().iterator();
- while (sqls.hasNext()) {
- String sql = (String) sqls.next();
- str.append(QLFormatHelper.formatForScreen(sql));
- str.append("\n\n"); //$NON-NLS-1$
- }
- }
- return str.toString();
- } catch (Throwable t) {
- // StringWriter sw = new StringWriter();
- StringBuffer msgs = new StringBuffer();
-
- Throwable cause = t;
- while (cause != null) {
- msgs.append(t);
- if (cause.getCause() == cause) {
- cause = null;
- } else {
- cause = cause.getCause();
- if (cause != null)
- msgs.append(Messages.DynamicSQLPreviewView_caused_by);
- }
- }
- // t.printStackTrace(new PrintWriter(sw));
- // return sw.getBuffer().toString();
- return msgs.toString();
- }
- }
-}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -283,8 +283,8 @@
String dialect = determineDialect();
String ccName =
launchManager.generateUniqueLaunchConfigurationNameFrom(HibernateConsoleMessages.AddConfigurationAction_hibernate);
ConsoleConfigurationPreferences prefs = new
EclipseConsoleConfigurationPreferences(ccName,
- ConfigurationMode.JPA, jpaProject.getName(), true,
- null, null, null,
+ ConfigurationMode.JPA, false,
+ jpaProject.getName(), true, null, null, null,
new IPath[0], new IPath[0], null, null,
getConnectionProfileName(), dialect);
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -98,6 +98,10 @@
return ConfigurationMode.CORE;
}
+ public boolean getUseClassPathHibernateLibs() {
+ return false;
+ }
+
public String getNamingStrategy() {
// TODO Auto-generated method stub
return null;
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/KnownConfigurationsTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/KnownConfigurationsTest.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/KnownConfigurationsTest.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -114,6 +114,10 @@
return null;
}
+ public boolean getUseClassPathHibernateLibs() {
+ return false;
+ }
+
public String getNamingStrategy() {
// TODO Auto-generated method stub
return null;
@@ -193,6 +197,10 @@
return null;
}
+ public boolean getUseClassPathHibernateLibs() {
+ return false;
+ }
+
public String getNamingStrategy() {
// TODO Auto-generated method stub
return null;
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -114,7 +114,7 @@
String prjName = getProject().getIProject().getName();
EclipseConsoleConfigurationPreferences preferences = new
EclipseConsoleConfigurationPreferences(prjName,
- ConfigurationMode.JPA, prjName, true, null, null, null, new IPath[0], new IPath[0],
null, null, null, null);
+ ConfigurationMode.JPA, false, prjName, true, null, null, null, new IPath[0], new
IPath[0], null, null, null, null);
ccfg = KnownConfigurations.getInstance().addConfiguration(new
EclipseConsoleConfiguration(preferences), false);
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateErrorsTest2.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateErrorsTest2.java 2010-04-01
18:30:27 UTC (rev 21208)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateErrorsTest2.java 2010-04-01
18:30:51 UTC (rev 21209)
@@ -117,7 +117,7 @@
String prjName = getProject().getIProject().getName();
EclipseConsoleConfigurationPreferences preferences = new
EclipseConsoleConfigurationPreferences(prjName,
- ConfigurationMode.JPA, prjName, true, null, null, null, new IPath[0], new IPath[0],
null, null, null, null);
+ ConfigurationMode.JPA, false, prjName, true, null, null, null, new IPath[0], new
IPath[0], null, null, null, null);
ccfg = KnownConfigurations.getInstance().addConfiguration(new
EclipseConsoleConfiguration(preferences), false);