Author: vyemialyanchyk
Date: 2010-03-18 16:04:29 -0400 (Thu, 18 Mar 2010)
New Revision: 20916
Added:
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/ConfigurationStub.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubJDBCMetaData.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.settings/
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.settings/org.eclipse.hyades.test.tools.core.prefs
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
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/OpenMappingUtilsEjb3.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationWorkbenchAdapter.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/graph/EntityGraphView.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/graph/model/ConfigurationViewAdapter.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.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.console/src/org/hibernate/eclipse/nature/HibernateNature.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.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.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.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/stubs/SessionStubFactory.java
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/OpenMappingDiagramTest.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/hbmexporter/HbmExporterTest.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-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -52,7 +52,6 @@
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.NamingStrategy;
import org.hibernate.cfg.Settings;
@@ -62,10 +61,14 @@
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.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;
@@ -79,12 +82,12 @@
private ExecutionContext executionContext;
private ConsoleConfigClassLoader classLoader = null;
- private Map<String, FakeDelegatingDriver> fakeDrivers = new HashMap<String,
FakeDelegatingDriver>();
-
/* TODO: move this out to the actual users of the configuraiton/sf ? */
- private Configuration configuration;
+ private ConfigurationStub configStub;
private SessionStubFactory sessionStubFactory;
+ private ConsoleConfigurationPreferences prefs = null;
+
/** Unique name for this configuration */
public String getName() {
return prefs.getName();
@@ -98,35 +101,23 @@
return executionContext.execute(c);
}
-
- public ConsoleConfigurationPreferences prefs = null;
-
-
/**
* Reset so a new configuration or sessionfactory is needed.
*
*/
public void reset() {
// reseting state
- configuration = null;
closeSessionFactory();
if (executionContext != null) {
executionContext.execute(new ExecutionContext.Command() {
public Object execute() {
- Iterator<FakeDelegatingDriver> it = fakeDrivers.values().iterator();
- while (it.hasNext()) {
- try {
- DriverManager.deregisterDriver(it.next());
- } catch (SQLException e) {
- // ignore
- }
- }
+ configStub.cleanUp();
return null;
}
});
}
- fakeDrivers.clear();
+ configStub = null;
cleanUpClassLoader();
fireConfigurationReset();
executionContext = null;
@@ -144,78 +135,28 @@
}
public void build() {
- configuration = buildWith(null, true);
+ configStub = buildWith(null, true);
fireConfigurationBuilt();
}
- private Configuration buildJPAConfiguration(String persistenceUnit, Properties
properties, String entityResolver, boolean includeMappings) {
- if(StringHelper.isEmpty( persistenceUnit )) {
- persistenceUnit = null;
+ /**
+ * @return
+ *
+ */
+ public ConfigurationStub buildWith(final ConfigurationStub cfg, final boolean
includeMappings) {
+ if (classLoader == null) {
+ classLoader = createClassLoader();
}
- try {
- Map<Object,Object> overrides = new HashMap<Object,Object>();
- if(properties!=null) {
- overrides.putAll( properties );
+ executionContext = new DefaultExecutionContext(getName(), classLoader);
+ ConfigurationStub result = (ConfigurationStub) executionContext.execute(new
ExecutionContext.Command() {
+ public Object execute() {
+ ConfigStubFactory csf = new ConfigStubFactory(prefs);
+ return csf.createConfiguration(cfg, includeMappings);
}
- 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);
- }
+ });
+ return result;
}
- @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;
- }
-
- protected 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);
- }
-
/*
* try get a path to the sql driver jar file from DTP connection profile
*/
@@ -228,7 +169,7 @@
if (profile == null) {
return null;
}
- refreshProfile(profile);
+ ConfigStubFactory.refreshProfile(profile);
//
Properties cpProperties = profile.getProperties(profile.getProviderId());
String driverJarPath = cpProperties.getProperty("jarList"); //$NON-NLS-1$
@@ -307,242 +248,17 @@
return classLoader;
}
- /**
- * @return
- *
- */
- public Configuration buildWith(final Configuration cfg, final boolean includeMappings)
{
- if (classLoader == null) {
- classLoader = createClassLoader();
- }
- executionContext = new DefaultExecutionContext(getName(), classLoader);
-
- Configuration result = (Configuration) executionContext.execute(new
ExecutionContext.Command() {
-
- public Object execute() {
- Configuration localCfg = cfg;
-
- 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
);
- }
-
- // here both setProperties and configxml have had their chance to tell which
databasedriver is needed.
- registerFakeDriver(localCfg.getProperty(Environment.DRIVER) );
- //autoConfigureDialect(localCfg); Disabled for now since it causes very looong
timeouts for 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$
-
- return localCfg;
- }
-
- 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
- }
- }
- }
- }
-
- });
-
-
- return result;
- }
-
- @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;
- }
- }
- }
-
- protected 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);
- }
-
- /**
- * DriverManager checks what classloader a class is loaded from thus
- * we register a FakeDriver that we know is loaded "properly" which delegates
all it class
- * to the real driver.
- *
- * By doing so we can convince DriverManager that we can use any dynamically loaded
driver.
- *
- * @param driverClassName
- */
- @SuppressWarnings("unchecked")
- private void registerFakeDriver(String driverClassName) {
-
- if(driverClassName!=null) {
- try {
- Class<Driver> driverClass = ReflectHelper.classForName(driverClassName);
- if(!fakeDrivers.containsKey(driverClassName) ) { // To avoid "double
registration"
- FakeDelegatingDriver fakeDelegatingDriver = new FakeDelegatingDriver(
driverClass.newInstance() );
- DriverManager.registerDriver(fakeDelegatingDriver);
- fakeDrivers.put(driverClassName,fakeDelegatingDriver);
- }
- }
- catch (ClassNotFoundException e) {
- String out =
NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
- throw new HibernateConsoleRuntimeException(out, e);
- }
- catch (InstantiationException e) {
- String out =
NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
- throw new HibernateConsoleRuntimeException(out, e);
- }
- catch (IllegalAccessException e) {
- String out =
NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
- throw new HibernateConsoleRuntimeException(out, e);
- }
- catch (SQLException e) {
- String out =
NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
- throw new HibernateConsoleRuntimeException(out, e);
- }
- }
- }
protected ClassLoader getParentClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
- public Configuration getConfiguration() {
- return configuration;
+ public ConfigurationStub getConfiguration() {
+ return configStub;
}
/**
* @return
*/
public boolean hasConfiguration() {
- return configuration!=null;
+ return configStub != null;
}
public void buildSessionFactory() {
@@ -551,7 +267,7 @@
if (sessionStubFactory != null) {
throw new
HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_factory_not_closed_before_build_new_factory);
}
- sessionStubFactory = new SessionStubFactory(executionContext, getConfiguration());
+ sessionStubFactory = new SessionStubFactory(executionContext, configStub);
fireFactoryBuilt();
return null;
}
@@ -726,7 +442,7 @@
}
}
- public Settings getSettings(final Configuration cfg) {
+ public Settings getSettings(final ConfigurationStub cfg) {
return (Settings) execute(new Command() {
public Object execute() {
@@ -736,109 +452,54 @@
});
}
- // TODO: delegate to some extension point
- 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( getPreferences().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;
+ public Settings getSettings2() {
+ ConfigurationStub cfg = buildWith(null, false);
+ Settings settings = getSettings(cfg);
+ return settings;
}
- private Configuration configureStandardConfiguration(final boolean includeMappings,
Configuration localCfg, Properties properties) {
- if(properties!=null) {
- localCfg = localCfg.setProperties(properties);
+ public EntityResolver getEntityResolver() {
+ if (configStub == null) {
+ build();
+ buildSessionFactory();
}
- 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);
+ return configStub.getEntityResolver();
+ }
- 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);
+ public IHQLCodeAssist getHQLCodeAssist() {
+ if (configStub == null) {
+ try{
+ build();
+ buildMappings();
+ } catch (HibernateException e){
+// String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
+ throw e;
+ //HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
}
}
-
- 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;
+ return configStub.getHQLCodeAssist();
}
-
- 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:
- 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);
+
+ public void buildMappings() {
+ execute(new ExecutionContext.Command() {
+ public Object execute() {
+ if (configStub != null) {
+ configStub.buildMappings();
+ }
+ return null;
}
- 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("unchecked")
+ public Iterator<Throwable> doSchemaExport() {
+ return (Iterator<Throwable>)execute(new ExecutionContext.Command() {
+ public Object execute() {
+ if (configStub != null) {
+ return configStub.doSchemaExport();
+ }
+ return null;
+ }
+ } );
+ }
}
\ No newline at end of file
Added:
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
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigStubFactory.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -0,0 +1,414 @@
+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);
+ }
+}
Added:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStub.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStub.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStub.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -0,0 +1,193 @@
+package org.hibernate.console.stubs;
+
+import java.io.File;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Mappings;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.cfg.Settings;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.FakeDelegatingDriver;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.engine.Mapping;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+import org.hibernate.tool.hbm2x.pojo.POJOClass;
+import org.hibernate.tool.ide.completion.HQLCodeAssist;
+import org.hibernate.tool.ide.completion.IHQLCodeAssist;
+import org.hibernate.util.ReflectHelper;
+import org.xml.sax.EntityResolver;
+
+public class ConfigurationStub {
+
+ private Map<String, FakeDelegatingDriver> fakeDrivers = new HashMap<String,
FakeDelegatingDriver>();
+
+ // configuration != null - by default
+ protected Configuration configuration;
+
+ protected ConfigurationStub(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ protected Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void cleanUp() {
+ Iterator<FakeDelegatingDriver> it = fakeDrivers.values().iterator();
+ while (it.hasNext()) {
+ try {
+ DriverManager.deregisterDriver(it.next());
+ } catch (SQLException e) {
+ // ignore
+ }
+ }
+ fakeDrivers.clear();
+ }
+
+ public void buildMappings() {
+ configuration.buildMappings();
+ }
+
+ // TODO: temporary should be protected and/or SettingsStub?
+ public Settings buildSettings() {
+ return configuration.buildSettings();
+ }
+
+ protected SessionFactory buildSessionFactory() {
+ return configuration.buildSessionFactory();
+ }
+
+ public EntityResolver getEntityResolver() {
+ return configuration.getEntityResolver();
+ }
+
+ public IHQLCodeAssist getHQLCodeAssist() {
+ return new HQLCodeAssist(configuration);
+ }
+
+ // TODO: temporary should be protected and/or NamingStrategyStub?
+ public NamingStrategy getNamingStrategy() {
+ return configuration.getNamingStrategy();
+ }
+
+ // TODO: temporary?
+ @SuppressWarnings("unchecked")
+ public Iterator getClassMappings() {
+ return configuration.getClassMappings();
+ }
+
+ // TODO: temporary should be protected and/or PersistentClassStub?
+ public PersistentClass getClassMapping(String entityName) {
+ return configuration.getClassMapping(entityName);
+ }
+
+ // TODO: temporary should be protected and/or MappingsStub?
+ public Mappings createMappings() {
+ return configuration.createMappings();
+ }
+
+ // TODO: temporary should be protected and/or MappingsStub?
+ public Mapping buildMapping() {
+ return configuration.buildMapping();
+ }
+
+ public static interface IExporterNewOutputDir {
+ File getNewOutputDir(POJOClass element, File outputdir4FileNew);
+ }
+
+ public HibernateMappingExporter createHibernateMappingExporter(File folder2Gen, final
IExporterNewOutputDir enod) {
+ return new HibernateMappingExporter(configuration, folder2Gen) {
+ @SuppressWarnings("unchecked")
+ protected void exportPOJO(Map additionalContext, POJOClass element) {
+ File outputdir4FileOld = getOutputDirectory();
+ File outputdir4FileNew = enod.getNewOutputDir(element, outputdir4FileOld);
+ if (!outputdir4FileNew.exists()) {
+ outputdir4FileNew.mkdirs();
+ }
+ setOutputDirectory(outputdir4FileNew);
+ super.exportPOJO(additionalContext, element);
+ setOutputDirectory(outputdir4FileOld);
+ }
+ };
+ }
+
+ @SuppressWarnings("unchecked")
+ public Iterator<Throwable> doSchemaExport() {
+ SchemaExport export = new SchemaExport(configuration);
+ export.create(false, true);
+ if (!export.getExceptions().isEmpty()) {
+ return (Iterator<Throwable>)export.getExceptions().iterator();
+ }
+ return null;
+ }
+
+ public void updateExporter(Exporter exporter) {
+ exporter.setConfiguration(configuration);
+ }
+
+ public Properties getProperties() {
+ return configuration.getProperties();
+ }
+
+ public String getProperty(String propertyName) {
+ return configuration.getProperty(propertyName);
+ }
+
+ /**
+ * DriverManager checks what classloader a class is loaded from thus we register a
FakeDriver
+ * that we know is loaded "properly" which delegates all it class to the real
driver. By doing
+ * so we can convince DriverManager that we can use any dynamically loaded driver.
+ *
+ * @param driverClassName
+ */
+ @SuppressWarnings("unchecked")
+ protected void registerFakeDriver(String driverClassName) {
+ if (driverClassName != null) {
+ try {
+ Class<Driver> driverClass = ReflectHelper.classForName(driverClassName);
+ if (!fakeDrivers.containsKey(driverClassName)) { // To avoid "double
registration"
+ FakeDelegatingDriver fakeDelegatingDriver = new FakeDelegatingDriver(
+ driverClass.newInstance());
+ DriverManager.registerDriver(fakeDelegatingDriver);
+ fakeDrivers.put(driverClassName, fakeDelegatingDriver);
+ }
+ } catch (ClassNotFoundException e) {
+ String out = NLS
+ .bind(
+ ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
+ driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ } catch (InstantiationException e) {
+ String out = NLS
+ .bind(
+ ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
+ driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ } catch (IllegalAccessException e) {
+ String out = NLS
+ .bind(
+ ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
+ driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ } catch (SQLException e) {
+ String out = NLS
+ .bind(
+ ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
+ driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ }
+ }
+ }
+}
Added:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubJDBCMetaData.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubJDBCMetaData.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/ConfigurationStubJDBCMetaData.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -0,0 +1,33 @@
+package org.hibernate.console.stubs;
+
+import java.util.Properties;
+
+import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
+
+public class ConfigurationStubJDBCMetaData extends ConfigurationStub {
+
+ protected JDBCMetaDataConfiguration jdbcMetaDataConfiguration;
+
+ protected ConfigurationStubJDBCMetaData(JDBCMetaDataConfiguration configuration) {
+ super(configuration);
+ jdbcMetaDataConfiguration = configuration;
+ }
+
+ public void setProperties(Properties properties) {
+ jdbcMetaDataConfiguration.setProperties(properties);
+ }
+
+ public void setPreferBasicCompositeIds(boolean flag) {
+ jdbcMetaDataConfiguration.setPreferBasicCompositeIds(flag);
+ }
+
+ public void setReverseEngineeringStrategy(ReverseEngineeringStrategy
reverseEngineeringStrategy) {
+ jdbcMetaDataConfiguration.setReverseEngineeringStrategy(reverseEngineeringStrategy);
+ }
+
+ public void readFromJDBC() {
+ jdbcMetaDataConfiguration.readFromJDBC();
+ }
+
+}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/SessionStubFactory.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/SessionStubFactory.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/SessionStubFactory.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -8,7 +8,6 @@
import java.util.Map;
import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.util.ELTransformer;
@@ -25,9 +24,9 @@
protected ExecutionContext executionContext;
protected SessionFactory sessionFactory;
- public SessionStubFactory(ExecutionContext executionContext, Configuration cfg) {
+ public SessionStubFactory(ExecutionContext executionContext, ConfigurationStub
configStub) {
this.executionContext = executionContext;
- sessionFactory = cfg.buildSessionFactory();
+ sessionFactory = configStub.buildSessionFactory();
}
public boolean isSessionFactoryCreated() {
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -15,8 +15,8 @@
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.launch.HibernateLaunchConstants;
import org.hibernate.eclipse.launch.PathHelper;
@@ -166,7 +166,7 @@
* @param collector
* @throws CoreException in case of resolve variables issues.
*/
- public Exporter createConfiguredExporter(Configuration cfg, String
defaultOutputDirectory,
+ public Exporter createConfiguredExporter(ConfigurationStub cfg, String
defaultOutputDirectory,
String customTemplatePath, Properties globalProperties, Set<String>
outputDirectories, ArtifactCollector collector) throws CoreException {
Exporter exporter = getExporterDefinition().createExporterInstance();
@@ -199,7 +199,7 @@
exporter.setOutputDirectory(new File(loc));
}
- exporter.setConfiguration(cfg);
+ cfg.updateExporter(exporter);
List<String> templatePathList = new ArrayList<String>();
if(props.containsKey("template_path")) { //$NON-NLS-1$
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-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtils.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -146,7 +146,7 @@
if (configXMLFile == null) {
return true;
}
- EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
+ EntityResolver entityResolver = consoleConfig.getEntityResolver();
Document doc = getDocument(configXMLFile, entityResolver);
return getElements(doc, HIBERNATE_TAG_MAPPING, HIBERNATE_TAG_CLASS,
getPersistentClassName(rootClass)).hasNext();
}
@@ -185,7 +185,7 @@
* @return
*/
public static boolean rootClassInFile(ConsoleConfiguration consoleConfig, IFile file,
RootClass rootClass) {
- EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
+ EntityResolver entityResolver = consoleConfig.getEntityResolver();
Document doc = getDocument(file.getLocation().toFile(), entityResolver);
final String clName = getPersistentClassName(rootClass);
final String clNameUnq = StringHelper.unqualify(clName);
@@ -219,7 +219,7 @@
* @return
*/
public static boolean subclassInFile(ConsoleConfiguration consoleConfig, IFile file,
Subclass subclass) {
- EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
+ EntityResolver entityResolver = consoleConfig.getEntityResolver();
Document doc = getDocument(file.getLocation().toFile(), entityResolver);
final String clName = getPersistentClassName(subclass);
final String clNameUnq = StringHelper.unqualify(clName);
@@ -243,7 +243,7 @@
*/
@SuppressWarnings("unchecked")
public static boolean tableInFile(ConsoleConfiguration consoleConfig, IFile file, Table
table) {
- EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
+ EntityResolver entityResolver = consoleConfig.getEntityResolver();
Document doc = getDocument(file.getLocation().toFile(), entityResolver);
Iterator<Element> classes = getElements(doc, HIBERNATE_TAG_CLASS);
boolean res = false;
@@ -449,11 +449,7 @@
return file;
}
java.io.File configXMLFile = consoleConfig.getConfigXMLFile();
- if (!consoleConfig.hasConfiguration()) {
- consoleConfig.build();
- consoleConfig.buildSessionFactory();
- }
- EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
+ EntityResolver entityResolver = consoleConfig.getEntityResolver();
Document doc = getDocument(configXMLFile, entityResolver);
if (doc == null) {
return file;
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtilsEjb3.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtilsEjb3.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/OpenMappingUtilsEjb3.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -73,7 +73,7 @@
try {
metadataFiles = PersistenceXmlLoader.deploy(
url, CollectionHelper.EMPTY_MAP,
- consoleConfiguration.getConfiguration().getEntityResolver(),
+ consoleConfiguration.getEntityResolver(),
PersistenceUnitTransactionType.RESOURCE_LOCAL);
} catch (Exception e1) {
//ignore
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -67,39 +67,30 @@
Object node = i.next();
if ( node instanceof ConsoleConfiguration ) {
final ConsoleConfiguration config = (ConsoleConfiguration) node;
- config.execute( new Command() {
- @SuppressWarnings("unchecked")
- public Object execute() {
- String out =
NLS.bind(HibernateConsoleMessages.SchemaExportAction_sure_run_schemaexport,
config.getName());
- if ( config.getConfiguration() != null
- && MessageDialog.openConfirm( viewer.getControl().getShell(),
- HibernateConsoleMessages.SchemaExportAction_run_schemaexport,
- out ) ) {
- SchemaExport export = new SchemaExport( config
- .getConfiguration() );
- export.create( false, true );
- if ( !export.getExceptions().isEmpty() ) {
- Iterator<Throwable> iterator = export.getExceptions().iterator();
- int cnt = 1;
- while ( iterator.hasNext() ) {
- Throwable element = iterator.next();
- String outStr =
NLS.bind(HibernateConsoleMessages.SchemaExportAction_errornum_while_performing_schemaexport,
cnt++);
- HibernateConsolePlugin.getDefault().logErrorMessage(outStr, element );
- }
- HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(),
- NLS.bind(HibernateConsoleMessages.SchemaExportAction_error_while_performing_schemaexport,
cnt - 1),
- (Throwable)null );
+ if (config.getConfiguration() != null) {
+ String out =
NLS.bind(HibernateConsoleMessages.SchemaExportAction_sure_run_schemaexport,
config.getName());
+ if (MessageDialog.openConfirm(viewer.getControl().getShell(),
+ HibernateConsoleMessages.SchemaExportAction_run_schemaexport,
+ out)) {
+ Iterator<Throwable> res = config.doSchemaExport();
+ if (res.hasNext()) {
+ int cnt = 1;
+ while (res.hasNext()) {
+ Throwable element = res.next();
+ String outStr =
NLS.bind(HibernateConsoleMessages.SchemaExportAction_errornum_while_performing_schemaexport,
cnt++);
+ HibernateConsolePlugin.getDefault().logErrorMessage(outStr, element );
}
+ HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(),
+ NLS.bind(HibernateConsoleMessages.SchemaExportAction_error_while_performing_schemaexport,
cnt - 1),
+ (Throwable)null);
}
- return null;
}
- } );
+ }
viewer.refresh( node ); // todo: should we do it here or should
// the view just react to config being
// build ?
}
- }
- catch (HibernateException he) {
+ } catch (HibernateException he) {
HibernateConsolePlugin.getDefault().showError(
viewer.getControl().getShell(),
HibernateConsoleMessages.SchemaExportAction_exception_running_schemaexport, he );
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -30,10 +30,10 @@
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.IPropertySource2;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.node.BaseNode;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.PrimaryKey;
@@ -51,7 +51,7 @@
Map<Class<?>, IDeferredWorkbenchAdapter> map = new
HashMap<Class<?>, IDeferredWorkbenchAdapter>();
map.put(ConsoleConfiguration.class, new ConsoleConfigurationWorkbenchAdapter());
- map.put(Configuration.class, new ConfigurationWorkbenchAdapter());
+ map.put(ConfigurationStub.class, new ConfigurationWorkbenchAdapter());
map.put(KnownConfigurations.class, new KnownConfigurationsWorkbenchAdapter());
map.put(PersistentClass.class, new PersistentClassWorkbenchAdapter());
map.put(Property.class, new PropertyWorkbenchAdapter());
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationWorkbenchAdapter.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationWorkbenchAdapter.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationWorkbenchAdapter.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -25,9 +25,9 @@
import java.util.Iterator;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ImageConstants;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.utils.EclipseImages;
import org.hibernate.mapping.PersistentClass;
@@ -36,7 +36,7 @@
@SuppressWarnings("unchecked")
public Object[] getChildren(Object o) {
- Configuration cfg = (Configuration) o;
+ ConfigurationStub cfg = (ConfigurationStub) o;
Iterator<? extends PersistentClass> classMappings = cfg.getClassMappings();
return toArray(classMappings, PersistentClass.class, new
Comparator<PersistentClass>() {
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-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -23,11 +23,11 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.cfg.Configuration;
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;
@@ -59,10 +59,10 @@
}*/
- Configuration configuration = ccfg.getConfiguration();
+ ConfigurationStub configStub = ccfg.getConfiguration();
Object o1;
- if(configuration!=null) {
- o1 = configuration;
+ if (configStub != null) {
+ o1 = configStub;
} else {
o1 =
HibernateConsoleMessages.ConsoleConfigurationWorkbenchAdapter_empty_configuration;
}
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-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -32,7 +32,6 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCReaderFactory;
import org.hibernate.cfg.Settings;
import org.hibernate.cfg.reveng.DefaultDatabaseCollector;
@@ -42,6 +41,7 @@
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ImageConstants;
import org.hibernate.console.execution.ExecutionContext;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.EclipseImages;
@@ -102,7 +102,7 @@
}
protected void readDatabaseSchema(final IProgressMonitor monitor, final
DefaultDatabaseCollector db, ConsoleConfiguration consoleConfiguration, final
ReverseEngineeringStrategy strategy) {
- final Configuration configuration = consoleConfiguration.buildWith(null, false);
+ final ConfigurationStub configuration = consoleConfiguration.buildWith(null, false);
consoleConfiguration.getExecutionContext().execute(new ExecutionContext.Command() {
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-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -58,12 +58,11 @@
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.QueryPage;
-import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.console.stubs.SessionStub;
import org.hibernate.eclipse.console.AbstractQueryEditor;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
@@ -145,18 +144,19 @@
if (queryPage == null || !getPinToOneResTab()) {
queryPage = cfg.executeBSHQuery(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);
+ // vitali TODO: openSession should be executed in context - all other no!
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);
}
}
@@ -179,14 +179,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 e) {
String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
@@ -194,7 +187,7 @@
}
Set<String> imports = new HashSet<String>();
- Configuration configuration = consoleConfiguration.getConfiguration();
+ ConfigurationStub configuration = consoleConfiguration.getConfiguration();
if(configuration!=null) {
Iterator<PersistentClass> classMappings = configuration.getClassMappings();
while ( classMappings.hasNext() ) {
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/graph/EntityGraphView.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/graph/EntityGraphView.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/graph/EntityGraphView.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -23,7 +23,7 @@
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.hibernate.cfg.Configuration;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.ConsolePreferencesConstants;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.views.KnownConfigurationsView;
@@ -49,8 +49,8 @@
protected void selectionChanged(IStructuredSelection ss) {
Object o = ss.getFirstElement();
- if (o instanceof Configuration) {
- viewer.setContents(new ConfigurationViewAdapter((Configuration) o));
+ if (o instanceof ConfigurationStub) {
+ viewer.setContents(new ConfigurationViewAdapter((ConfigurationStub) o));
boolean b =
HibernateConsolePlugin.getDefault().getPluginPreferences().getBoolean(ConsolePreferencesConstants.ENTITY_MODEL_LAYOUT);
((ConfigurationEditPart)viewer.getContents()).setManualLayoutActive(b);
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/graph/model/ConfigurationViewAdapter.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/graph/model/ConfigurationViewAdapter.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/graph/model/ConfigurationViewAdapter.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -28,18 +28,18 @@
import java.util.Map;
import java.util.Observable;
-import org.hibernate.cfg.Configuration;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.mapping.PersistentClass;
public class ConfigurationViewAdapter extends Observable {
- private final Configuration cfg;
+ private final ConfigurationStub cfg;
private Map<String, PersistentClassViewAdapter> persistentClasses; // key: name,
value: PersistentClassViewAdapter
private List<TableViewAdapter> selectedTables;
//private final Map sourceAssociations; // key: name, value: List of
AssociationViewAdapter
//private final Map targetAssociations; // key: name, value: List of
AssociationViewAdapter
- public ConfigurationViewAdapter(Configuration cfg) {
+ public ConfigurationViewAdapter(ConfigurationStub cfg) {
this.cfg = cfg;
//sourceAssociations = new HashMap();
@@ -73,7 +73,7 @@
return selectedTables;
}
- public Configuration getConfiguration() {
+ public ConfigurationStub getConfiguration() {
return cfg;
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -34,11 +34,7 @@
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.osgi.util.NLS;
-import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.QueryEditor;
@@ -93,7 +89,7 @@
return result;
}
- ICompletionProposal[] computeProposals(IDocument doc, int lineStart, final int
currentOffset, final ConsoleConfiguration consoleConfiguration) {
+ ICompletionProposal[] computeProposals(IDocument doc, int lineStart, final int
currentOffset, final ConsoleConfiguration consoleConfig) {
ICompletionProposal[] result = null;
errorMessage = null;
if (doc != null && currentOffset >= 0) {
@@ -114,26 +110,12 @@
errorMessage =
HibernateConsoleMessages.HQLCompletionProcessor_could_not_get_document_contents;
return result;
}
-
- if(consoleConfiguration != null &&
consoleConfiguration.getConfiguration()==null) {
- try{
- consoleConfiguration.build();
- consoleConfiguration.execute( new ExecutionContext.Command() {
- public Object execute() {
- if(consoleConfiguration.hasConfiguration()) {
- consoleConfiguration.getConfiguration().buildMappings();
- }
- return consoleConfiguration;
- }
- });
- } catch (HibernateException e){
- String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
- HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
- }
+ IHQLCodeAssist hqlEval = null;
+ if (consoleConfig != null) {
+ hqlEval = consoleConfig.getHQLCodeAssist();
+ } else {
+ hqlEval = new HQLCodeAssist(null);
}
-
- Configuration configuration =
consoleConfiguration!=null?consoleConfiguration.getConfiguration():null;
- IHQLCodeAssist hqlEval = new HQLCodeAssist(configuration);
EclipseHQLCompletionRequestor eclipseHQLCompletionCollector = new
EclipseHQLCompletionRequestor();
hqlEval.codeComplete(doc.get(), currentOffset, eclipseHQLCompletionCollector);
proposalList.addAll(eclipseHQLCompletionCollector.getCompletionProposals());
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-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -59,7 +59,6 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.text.edits.TextEdit;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCMetaDataConfiguration;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.OverrideRepository;
@@ -69,6 +68,9 @@
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.ConfigurationStub;
+import org.hibernate.console.stubs.ConfigurationStubJDBCMetaData;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.model.impl.ExporterFactory;
@@ -211,7 +213,7 @@
if (attributes.isReverseEngineer()) {
monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
}
- final Configuration cfg = buildConfiguration(attributes, cc,
ResourcesPlugin.getWorkspace().getRoot());
+ final ConfigurationStub cfg = buildConfiguration(attributes, cc,
ResourcesPlugin.getWorkspace().getRoot());
monitor.worked(1);
@@ -257,21 +259,23 @@
}
- private Configuration buildConfiguration(final ExporterAttributes attributes,
ConsoleConfiguration cc, IWorkspaceRoot root) {
+ private ConfigurationStub buildConfiguration(final ExporterAttributes attributes,
ConsoleConfiguration cc, IWorkspaceRoot root) {
final boolean reveng = attributes.isReverseEngineer();
final String reverseEngineeringStrategy = attributes.getRevengStrategy();
final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
final IResource revengres = PathHelper.findMember( root,
attributes.getRevengSettings());
if(reveng) {
- Configuration configuration = null;
+ ConfigurationStub configuration = null;
if(cc.hasConfiguration()) {
configuration = cc.getConfiguration();
} else {
configuration = cc.buildWith( null, false );
}
- final JDBCMetaDataConfiguration cfg = new JDBCMetaDataConfiguration();
+ // vitali: TODO: use execution context
+ ConfigStubFactory configStubFactory = new ConfigStubFactory(null);
+ final ConfigurationStubJDBCMetaData cfg =
configStubFactory.createConfigurationJDBCMetaData();
Properties properties = configuration.getProperties();
cfg.setProperties( properties );
cc.buildWith(cfg,false);
@@ -319,15 +323,8 @@
return cfg;
} else {
cc.build();
- final Configuration configuration = cc.getConfiguration();
-
- cc.execute(new Command() {
- public Object execute() {
-
- configuration.buildMappings();
- return configuration;
- }
- });
+ cc.buildMappings();
+ final ConfigurationStub configuration = cc.getConfiguration();
return configuration;
}
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/nature/HibernateNature.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/nature/HibernateNature.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/nature/HibernateNature.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -41,12 +41,12 @@
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCMetaDataConfiguration;
import org.hibernate.cfg.reveng.TableIdentifier;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.builder.HibernateBuilder;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
@@ -150,7 +150,7 @@
@SuppressWarnings("unchecked")
protected IStatus run(IProgressMonitor monitor) {
- Configuration cfg = ccfg.buildWith(null, false);
+ ConfigurationStub cfg = ccfg.buildWith(null, false);
final JDBCMetaDataConfiguration jcfg = new JDBCMetaDataConfiguration();
jcfg.setProperties(cfg.getProperties());
monitor.beginTask(HibernateConsoleMessages.HibernateNature_reading_database_metadata,
IProgressMonitor.UNKNOWN);
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLJavaCompletionProposalComputer.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -34,13 +34,11 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.hqleditor.EclipseHQLCompletionRequestor;
import org.hibernate.eclipse.hqleditor.HQLCompletionProcessor;
import org.hibernate.eclipse.nature.HibernateNature;
-import org.hibernate.tool.ide.completion.HQLCodeAssist;
import org.hibernate.tool.ide.completion.IHQLCodeAssist;
public class HQLJavaCompletionProposalComputer implements IJavaCompletionProposalComputer
{
@@ -76,22 +74,18 @@
JavaContentAssistInvocationContext ctx = (JavaContentAssistInvocationContext)context;
try {
- ConsoleConfiguration consoleConfiguration = getConfiguration( ctx.getProject() );
- if(consoleConfiguration!=null) {
- Configuration configuration = consoleConfiguration.getConfiguration();
-
- IHQLCodeAssist hqlEval = new HQLCodeAssist(configuration);
-
- String query = ""; //$NON-NLS-1$
- int stringStart = getStringStart( ctx.getDocument(), ctx.getInvocationOffset() );
- int stringEnd = getStringEnd( ctx.getDocument(), ctx.getInvocationOffset() );
- query = ctx.getDocument().get(stringStart, stringEnd-stringStart );
- EclipseHQLCompletionRequestor eclipseHQLCompletionCollector = new
EclipseHQLCompletionRequestor(stringStart);
- hqlEval.codeComplete(query, ctx.getInvocationOffset()-stringStart,
eclipseHQLCompletionCollector);
- errorMessage = eclipseHQLCompletionCollector.getLastErrorMessage();
-
- proposals = eclipseHQLCompletionCollector.getCompletionProposals();
- }
+ ConsoleConfiguration consoleConfig = getConfiguration( ctx.getProject() );
+ if (consoleConfig != null) {
+ IHQLCodeAssist hqlEval = consoleConfig.getHQLCodeAssist();
+ String query = ""; //$NON-NLS-1$
+ int stringStart = getStringStart( ctx.getDocument(), ctx.getInvocationOffset() );
+ int stringEnd = getStringEnd( ctx.getDocument(), ctx.getInvocationOffset() );
+ query = ctx.getDocument().get(stringStart, stringEnd-stringStart );
+ EclipseHQLCompletionRequestor eclipseHQLCompletionCollector = new
EclipseHQLCompletionRequestor(stringStart);
+ hqlEval.codeComplete(query, ctx.getInvocationOffset()-stringStart,
eclipseHQLCompletionCollector);
+ errorMessage = eclipseHQLCompletionCollector.getLastErrorMessage();
+ proposals = eclipseHQLCompletionCollector.getCompletionProposals();
+ }
} catch(RuntimeException re) {
HibernateConsolePlugin.getDefault().logErrorMessage(
JdtUiMessages.HQLJavaCompletionProposalComputer_errormessage, re );
}
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-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -40,8 +40,9 @@
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.WildcardType;
import org.hibernate.FetchMode;
-import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Mappings;
+import org.hibernate.console.stubs.ConfigStubFactory;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
@@ -88,8 +89,8 @@
*
* @return different configuration for different projects
*/
- public Map<IJavaProject, Configuration> createConfigurations(int processDepth){
- Map<IJavaProject, Configuration> configs = new HashMap<IJavaProject,
Configuration>();
+ public Map<IJavaProject, ConfigurationStub> createConfigurations(int
processDepth){
+ Map<IJavaProject, ConfigurationStub> configs = new HashMap<IJavaProject,
ConfigurationStub>();
if (selectionCU.size() == 0) {
return configs;
}
@@ -129,9 +130,7 @@
return configs;
}
- protected Configuration createConfiguration(IJavaProject project, Map<String,
EntityInfo> entities) {
- Configuration config = new Configuration();
-
+ protected ConfigurationStub createConfiguration(IJavaProject project, Map<String,
EntityInfo> entities) {
ProcessEntityInfo processor = new ProcessEntityInfo();
processor.setEntities(entities);
@@ -146,6 +145,10 @@
}
}
+ // vitali: TODO: should get ConsoleConfig in association with JavaProject
+ // and create Configuration in execution context of it!
+ ConfigStubFactory configStubFactory = new ConfigStubFactory(null);
+ ConfigurationStub config = configStubFactory.createConfiguration();
Mappings mappings = config.createMappings();
Collection<PersistentClass> classesCollection = createHierarhyStructure(project,
processor.getRootClasses());
for (PersistentClass persistentClass : classesCollection) {
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -61,8 +61,8 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
import org.eclipse.ui.ide.IDE;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ImageConstants;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.EclipseImages;
@@ -239,80 +239,67 @@
}
this.selection = new StructuredSelection(filteredElements.toArray());
}
-
- protected class HibernateMappingExporter2 extends HibernateMappingExporter {
- protected IJavaProject proj;
- public HibernateMappingExporter2(IJavaProject proj, Configuration cfg, File outputdir)
{
- super(cfg, outputdir);
- this.proj = proj;
- }
- /**
- * redefine base exportPOJO to setup right output dir in case
- * of several source folders
- */
- @SuppressWarnings("unchecked")
- @Override
- protected void exportPOJO(Map additionalContext, POJOClass element) {
- File outputdir4FileOld = getOutputDirectory();
- File outputdir4FileNew = outputdir4FileOld;
- String fullyQualifiedName = element.getQualifiedDeclarationName();
- ICompilationUnit icu = Utils.findCompilationUnit(proj, fullyQualifiedName);
- if (icu != null) {
- IResource resource = null;
- try {
- resource = icu.getCorrespondingResource();
- } catch (JavaModelException e) {
- //ignore
- }
- String[] aFQName = fullyQualifiedName.split("\\."); //$NON-NLS-1$
- int n = aFQName.length - 1;
- for ( ; n >= 0 && resource != null; n--) {
- if (n == 0 && aFQName[n].length() == 0) {
- // handle the (default package) case
- break;
- }
- resource = resource.getParent();
- }
- if (resource != null) {
- final IPath projPath = proj.getResource().getLocation();
- IPath place2Gen = previewPage.getRootPlace2Gen().append(proj.getElementName());
- //
- IPath tmpPath = resource.getLocation();
- tmpPath = tmpPath.makeRelativeTo(projPath);
- place2Gen = place2Gen.append(tmpPath);
- outputdir4FileNew = place2Gen.toFile();
- }
- }
- if (!outputdir4FileNew.exists()) {
- outputdir4FileNew.mkdirs();
- }
- setOutputDirectory(outputdir4FileNew);
- super.exportPOJO(additionalContext, element);
- setOutputDirectory(outputdir4FileOld);
- }
- }
protected Map<IJavaProject, IPath> getPlaces2Gen() {
updateCompilationUnits();
- Map<IJavaProject, Configuration> configs = createConfigurations();
+ Map<IJavaProject, ConfigurationStub> configs = createConfigurations();
Map<IJavaProject, IPath> places2Gen = new HashMap<IJavaProject, IPath>();
- for (Entry<IJavaProject, Configuration> entry : configs.entrySet()) {
- Configuration config = entry.getValue();
+ for (Entry<IJavaProject, ConfigurationStub> entry : configs.entrySet()) {
+ ConfigurationStub config = entry.getValue();
HibernateMappingGlobalSettings hmgs = new HibernateMappingGlobalSettings();
hmgs.setDefaultAccess("field"); //$NON-NLS-1$
//final IPath projPath = entry.getKey().getProject().getLocation();
- IPath place2Gen =
previewPage.getRootPlace2Gen().append(entry.getKey().getElementName());
- places2Gen.put(entry.getKey(), place2Gen);
+ IPath place2GenRoot =
previewPage.getRootPlace2Gen().append(entry.getKey().getElementName());
+ places2Gen.put(entry.getKey(), place2GenRoot);
- File folder2Gen = new File(place2Gen.toOSString());
+ File folder2Gen = new File(place2GenRoot.toOSString());
FileUtils.delete(folder2Gen); // cleanup folder before gen info
if (!folder2Gen.exists()) {
folder2Gen.mkdirs();
}
- HibernateMappingExporter2 hce = new HibernateMappingExporter2(
- entry.getKey(), config, folder2Gen);
+
+ final IJavaProject proj = entry.getKey();
+ ConfigurationStub.IExporterNewOutputDir nod = new
ConfigurationStub.IExporterNewOutputDir() {
+ /**
+ * redefine base exportPOJO to setup right output dir in case
+ * of several source folders
+ */
+ public File getNewOutputDir(POJOClass element, File outputdir4FileNew) {
+ String fullyQualifiedName = element.getQualifiedDeclarationName();
+ ICompilationUnit icu = Utils.findCompilationUnit(proj, fullyQualifiedName);
+ if (icu != null) {
+ IResource resource = null;
+ try {
+ resource = icu.getCorrespondingResource();
+ } catch (JavaModelException e) {
+ //ignore
+ }
+ String[] aFQName = fullyQualifiedName.split("\\."); //$NON-NLS-1$
+ int n = aFQName.length - 1;
+ for ( ; n >= 0 && resource != null; n--) {
+ if (n == 0 && aFQName[n].length() == 0) {
+ // handle the (default package) case
+ break;
+ }
+ resource = resource.getParent();
+ }
+ if (resource != null) {
+ final IPath projPath = proj.getResource().getLocation();
+ IPath place2Gen = previewPage.getRootPlace2Gen().append(proj.getElementName());
+ //
+ IPath tmpPath = resource.getLocation();
+ tmpPath = tmpPath.makeRelativeTo(projPath);
+ place2Gen = place2Gen.append(tmpPath);
+ outputdir4FileNew = place2Gen.toFile();
+ }
+ }
+ return outputdir4FileNew;
+ }
+ };
+ HibernateMappingExporter hce = config.createHibernateMappingExporter(folder2Gen,
nod);
+
hce.setGlobalSettings(hmgs);
//hce.setForEach("entity");
//hce.setFilePattern(file.getName());
@@ -536,9 +523,9 @@
}
- protected Map<IJavaProject, Configuration> createConfigurations() {
+ protected Map<IJavaProject, ConfigurationStub> createConfigurations() {
ConfigurationActor actor = new ConfigurationActor(selectionCU);
- Map<IJavaProject, Configuration> configs =
actor.createConfigurations(processDepth);
+ Map<IJavaProject, ConfigurationStub> configs =
actor.createConfigurations(processDepth);
return configs;
}
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-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HbmExportExceptionTest.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -25,10 +25,10 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.cfg.Configuration;
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;
import org.hibernate.eclipse.console.test.utils.ConsoleConfigUtils;
@@ -36,6 +36,7 @@
import org.hibernate.tool.hbm2x.ExporterException;
import org.hibernate.tool.hbm2x.HibernateMappingExporter;
import org.hibernate.tool.hbm2x.HibernateMappingGlobalSettings;
+import org.hibernate.tool.hbm2x.pojo.POJOClass;
/**
* @author Dmitry Geraskov
@@ -83,7 +84,7 @@
return consCFG;
}
} );
- Configuration config = consCFG.getConfiguration();
+ ConfigurationStub config = consCFG.getConfiguration();
//delete old hbm files
assertNotNull( testPackage );
@@ -101,10 +102,13 @@
HibernateMappingGlobalSettings hmgs = new HibernateMappingGlobalSettings();
+ ConfigurationStub.IExporterNewOutputDir nod = new
ConfigurationStub.IExporterNewOutputDir() {
+ public File getNewOutputDir(POJOClass element, File outputdir4FileNew) {
+ return outputdir4FileNew;
+ }
+ };
+ HibernateMappingExporter hce = config.createHibernateMappingExporter(getSrcFolder(),
nod);
- HibernateMappingExporter hce = new HibernateMappingExporter(config,
- getSrcFolder());
-
hce.setGlobalSettings(hmgs);
try {
hce.start();
@@ -120,15 +124,7 @@
consCFG.build();
assertTrue(consCFG.hasConfiguration());
- consCFG.execute( new ExecutionContext.Command() {
-
- public Object execute() {
- if(consCFG.hasConfiguration()) {
- consCFG.getConfiguration().buildMappings();
- }
- return consCFG;
- }
- } );
+ consCFG.buildMappings();
config = consCFG.getConfiguration();
} catch (CoreException e) {
String out =
NLS.bind(ConsoleTestMessages.UpdateConfigurationTest_error_customising_file_for_package,
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -21,9 +21,9 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.hibernate.InvalidMappingException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.test.ConsoleTestMessages;
import org.hibernate.eclipse.console.test.utils.Utils;
import org.hibernate.eclipse.console.workbench.ConfigurationWorkbenchAdapter;
@@ -68,7 +68,7 @@
Object[] persClasses = null;
try {
configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
- assertTrue(configs[0] instanceof Configuration);
+ assertTrue(configs[0] instanceof ConfigurationStub);
persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
} catch (InvalidMappingException ex){
String out =
NLS.bind(ConsoleTestMessages.OpenMappingDiagramTest_mapping_diagrams_for_package_cannot_be_opened,
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -24,9 +24,9 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.hibernate.InvalidMappingException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.actions.OpenMappingAction;
import org.hibernate.eclipse.console.test.ConsoleTestMessages;
import org.hibernate.eclipse.console.test.utils.Utils;
@@ -75,7 +75,7 @@
Object[] props = null;
try {
configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
- assertTrue(configs[0] instanceof Configuration);
+ assertTrue(configs[0] instanceof ConfigurationStub);
persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
} catch (InvalidMappingException ex){
String out =
NLS.bind(ConsoleTestMessages.OpenMappingFileTest_mapping_files_for_package_cannot_be_opened,
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -24,9 +24,9 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.hibernate.InvalidMappingException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.actions.OpenSourceAction;
import org.hibernate.eclipse.console.test.ConsoleTestMessages;
import org.hibernate.eclipse.console.test.utils.Utils;
@@ -77,7 +77,7 @@
Object[] fields = null;
try {
configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
- assertTrue(configs[0] instanceof Configuration);
+ assertTrue(configs[0] instanceof ConfigurationStub);
persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
} catch (InvalidMappingException ex) {
String out =
NLS.bind(ConsoleTestMessages.OpenSourceFileTest_source_files_for_package_cannot_be_opened,
Added:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.settings/org.eclipse.hyades.test.tools.core.prefs
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.settings/org.eclipse.hyades.test.tools.core.prefs
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.settings/org.eclipse.hyades.test.tools.core.prefs 2010-03-18
20:04:29 UTC (rev 20916)
@@ -0,0 +1,3 @@
+#Tue Feb 02 14:06:59 EET 2010
+defaultJUnitTestSuiteFactory=org.eclipse.hyades.test.plugin.junit.testSuite
+eclipse.preferences.version=1
Modified:
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/hbmexporter/HbmExporterTest.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/hbmexporter/HbmExporterTest.java 2010-03-18
19:52:20 UTC (rev 20915)
+++
branches/hibernatetools-multiversion/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/hbmexporter/HbmExporterTest.java 2010-03-18
20:04:29 UTC (rev 20916)
@@ -20,7 +20,7 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.cfg.Configuration;
+import org.hibernate.console.stubs.ConfigurationStub;
import org.hibernate.eclipse.console.test.ConsoleTestMessages;
import org.hibernate.eclipse.console.test.project.TestProject;
import org.hibernate.eclipse.console.test.utils.FilesTransfer;
@@ -75,7 +75,7 @@
* Fails if configuration is null.
* @return
*/
- protected Configuration getConfigurationFor(String... cuNames){
+ protected ConfigurationStub getConfigurationFor(String... cuNames){
Set<ICompilationUnit> selectionCU = new HashSet<ICompilationUnit>();
for (int i = 0; i < cuNames.length; i++) {
ICompilationUnit icu = Utils.findCompilationUnit(project.getIJavaProject(),
@@ -84,21 +84,21 @@
selectionCU.add(icu);
}
ConfigurationActor actor = new ConfigurationActor(selectionCU);
- Map<IJavaProject, Configuration> configurations =
actor.createConfigurations(Integer.MAX_VALUE);
+ Map<IJavaProject, ConfigurationStub> configurations =
actor.createConfigurations(Integer.MAX_VALUE);
assertEquals(1, configurations.size());
- Configuration config = configurations.get(project.getIJavaProject());
+ ConfigurationStub config = configurations.get(project.getIJavaProject());
assertNotNull(config);
return config;
}
- protected void checkClassesMaped(Configuration config, String... classesNames){
+ protected void checkClassesMaped(ConfigurationStub config, String... classesNames){
for (int i = 0; i < classesNames.length; i++) {
assertNotNull(config.getClassMapping(classesNames[i]));
}
}
public void testId(){
- Configuration config = getConfigurationFor("pack.A"); //$NON-NLS-1$
+ ConfigurationStub config = getConfigurationFor("pack.A"); //$NON-NLS-1$
checkClassesMaped(config, "pack.A", "pack.B"); //$NON-NLS-1$
//$NON-NLS-2$
PersistentClass a = config.getClassMapping("pack.A"); //$NON-NLS-1$
PersistentClass b = config.getClassMapping("pack.B"); //$NON-NLS-1$
@@ -112,7 +112,7 @@
}
public void testProperty(){
- Configuration config = getConfigurationFor("pack.A"); //$NON-NLS-1$
+ ConfigurationStub config = getConfigurationFor("pack.A"); //$NON-NLS-1$
checkClassesMaped(config, "pack.A", "pack.B"); //$NON-NLS-1$
//$NON-NLS-2$
PersistentClass a = config.getClassMapping("pack.A"); //$NON-NLS-1$
@@ -125,7 +125,7 @@
}
public void testArray(){
- Configuration config = getConfigurationFor("pack.A"); //$NON-NLS-1$
+ ConfigurationStub config = getConfigurationFor("pack.A"); //$NON-NLS-1$
checkClassesMaped(config, "pack.A", "pack.B"); //$NON-NLS-1$
//$NON-NLS-2$
PersistentClass a = config.getClassMapping("pack.A"); //$NON-NLS-1$
PersistentClass b = config.getClassMapping("pack.B"); //$NON-NLS-1$
@@ -151,7 +151,7 @@
}
public void testList(){
- Configuration config = getConfigurationFor("pack.A"); //$NON-NLS-1$
+ ConfigurationStub config = getConfigurationFor("pack.A"); //$NON-NLS-1$
checkClassesMaped(config, "pack.A", "pack.B"); //$NON-NLS-1$
//$NON-NLS-2$
PersistentClass a = config.getClassMapping("pack.A"); //$NON-NLS-1$
PersistentClass b = config.getClassMapping("pack.B"); //$NON-NLS-1$
@@ -169,7 +169,7 @@
}
public void testSet(){
- Configuration config = getConfigurationFor("pack.A"); //$NON-NLS-1$
+ ConfigurationStub config = getConfigurationFor("pack.A"); //$NON-NLS-1$
checkClassesMaped(config, "pack.A", "pack.B"); //$NON-NLS-1$
//$NON-NLS-2$
PersistentClass a = config.getClassMapping("pack.A"); //$NON-NLS-1$
PersistentClass b = config.getClassMapping("pack.B"); //$NON-NLS-1$
@@ -186,7 +186,7 @@
}
public void testMap(){
- Configuration config = getConfigurationFor("pack.A"); //$NON-NLS-1$
+ ConfigurationStub config = getConfigurationFor("pack.A"); //$NON-NLS-1$
checkClassesMaped(config, "pack.A", "pack.B"); //$NON-NLS-1$
//$NON-NLS-2$
PersistentClass a = config.getClassMapping("pack.A"); //$NON-NLS-1$
PersistentClass b = config.getClassMapping("pack.B"); //$NON-NLS-1$