Author: dgeraskov
Date: 2008-07-28 08:39:48 -0400 (Mon, 28 Jul 2008)
New Revision: 9351
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizard.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizard.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2344
https://jira.jboss.org/jira/browse/JBIDE-2345
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF 2008-07-28
12:26:26 UTC (rev 9350)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/META-INF/MANIFEST.MF 2008-07-28
12:39:48 UTC (rev 9351)
@@ -20,7 +20,9 @@
org.eclipse.jdt.core;bundle-version="3.4.0",
org.eclipse.jpt.db;bundle-version="1.1.1",
org.eclipse.jdt.ui;bundle-version="3.4.0",
- org.eclipse.jpt.db.ui;bundle-version="1.0.1"
+ org.eclipse.jpt.db.ui;bundle-version="1.0.1",
+ org.eclipse.datatools.connectivity;bundle-version="1.1.0",
+ org.eclipse.jdt.launching;bundle-version="3.4.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: Hibernate Team
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java 2008-07-28
12:26:26 UTC (rev 9350)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernatePlatformUI.java 2008-07-28
12:39:48 UTC (rev 9351)
@@ -54,30 +54,7 @@
GenerateEntitiesWizard wizard = new GenerateEntitiesWizard(project, selection);
WizardDialog dialog = new WizardDialog(null, wizard);
- dialog.create();
- /*int returnCode = */dialog.open();
- /*if (returnCode == Window.OK) {
- ILaunchConfigurationWorkingCopy wc = createDefaultLaunchConfig(project.getName());
- if (wc != null) {
- // SHOULD PRESENT THE CONFIGURATION!!!
- //unknown - ccname, outputdir, packagename
- wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
project.getName());
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR, project.getName() +
"\\src"); //$NON-NLS-1$
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,
"package_name");
- wc.setAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS, true);
- wc.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY, true);
- wc.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING, true);
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5, true);
- wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
-
- wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + '.' + exporter_id +
".extension_id",
- HibernateLaunchConstants.ATTR_PREFIX + "hbm2java"); //$NON-NLS-1$
//$NON-NLS-2$
- runLaunchConfiguration(wc);
- }
- } */
+ dialog.open();
}
@Override
@@ -85,27 +62,7 @@
GenerateDdlWizard wizard = new GenerateDdlWizard(project, selection);
WizardDialog dialog = new WizardDialog(null, wizard);
- dialog.create();
- /*int returnCode = */dialog.open();
- /*if (returnCode == Window.OK) {
- ILaunchConfigurationWorkingCopy wc = createDefaultLaunchConfig(project.getName());
- if (wc != null) {
- // Main
- //unknown - ccname, outputdir, filename
- wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
project.getName());
- wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR, project.getName() +
"\\src"); //$NON-NLS-1$
-
- Map<String, String> prop = new HashMap<String, String>();
- prop.put("outputFileName", "schema.ddl");
- //prop.put("outputdir", project.getName() + "\\src");
- prop.put("format", "true");
- prop.put("scriptToConsole", "false");
-
- wc.setAttribute(full_exporter_id + ".properties", prop);
- wc.setAttribute(full_exporter_id + ".extension_id",
HibernateLaunchConstants.ATTR_PREFIX + "hbm2ddl"); //$NON-NLS-1$ //$NON-NLS-2$
- runLaunchConfiguration(wc);
- }
- }*/
+ dialog.open();
}
public static ILaunchConfigurationWorkingCopy createDefaultLaunchConfig(String
projectName) {
@@ -128,12 +85,4 @@
return wc;
}
-
- public static void runLaunchConfiguration(ILaunchConfiguration configuration) {
- try {
- DebugPlugin.getDefault().getLaunchManager().addLaunch(configuration.launch(ILaunchManager.RUN_MODE,
null));
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizard.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizard.java 2008-07-28
12:26:26 UTC (rev 9350)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizard.java 2008-07-28
12:39:48 UTC (rev 9351)
@@ -13,7 +13,10 @@
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
@@ -21,6 +24,7 @@
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.ui.internal.JptUiMessages;
+import org.hibernate.console.KnownConfigurations;
import org.hibernate.eclipse.launch.HibernateLaunchConstants;
import org.jboss.tools.hibernate.jpt.ui.internal.platform.HibernatePlatformUI;
@@ -60,9 +64,8 @@
String projectName = jpaProject.getName();
ILaunchConfigurationWorkingCopy wc =
HibernatePlatformUI.createDefaultLaunchConfig(projectName);
if (wc != null) {
- // Main
- //unknown - ccname, outputdir, filename
- wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
initPage.getConfigurationName());
+ String concoleConfigurationName = initPage.getConfigurationName();
+ wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
concoleConfigurationName);
wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR, page2.getOutputDir());
//$NON-NLS-1$
Map<String, String> prop = new HashMap<String, String>();
@@ -73,7 +76,15 @@
wc.setAttribute(HibernatePlatformUI.full_exporter_id + ".properties",
prop);
wc.setAttribute(HibernatePlatformUI.full_exporter_id + ".extension_id",
HibernateLaunchConstants.ATTR_PREFIX + "hbm2ddl"); //$NON-NLS-1$ //$NON-NLS-2$
- HibernatePlatformUI.runLaunchConfiguration(wc);
+ try {
+ wc.launch(ILaunchManager.RUN_MODE, null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } finally{
+ if (initPage.isTemporaryConfiguration()){
+ KnownConfigurations.getInstance().removeConfiguration(KnownConfigurations.getInstance().find(concoleConfigurationName),
false);
+ }
+ }
}
return true;
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizard.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizard.java 2008-07-28
12:26:26 UTC (rev 9350)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizard.java 2008-07-28
12:39:48 UTC (rev 9351)
@@ -13,7 +13,9 @@
import java.util.Collection;
import java.util.Collections;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
@@ -28,6 +30,7 @@
import org.eclipse.jpt.ui.internal.JptUiMessages;
import org.eclipse.jpt.ui.internal.wizards.DatabaseReconnectWizardPage;
import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.hibernate.console.KnownConfigurations;
import org.hibernate.eclipse.launch.HibernateLaunchConstants;
import org.jboss.tools.hibernate.jpt.ui.internal.platform.HibernatePlatformUI;
@@ -67,8 +70,8 @@
ILaunchConfigurationWorkingCopy wc =
HibernatePlatformUI.createDefaultLaunchConfig(projectName);
if (wc != null) {
// SHOULD PRESENT THE CONFIGURATION!!!
- //unknown - ccname, outputdir, packagename
- wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
initPage.getConfigurationName());
+ String concoleConfigurationName = initPage.getConfigurationName();
+ wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
concoleConfigurationName);
wc.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR, page2.getOutputDir());
//$NON-NLS-1$
@@ -79,10 +82,20 @@
wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5, true);
wc.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
+ wc.setAttribute("hibernate.dialect",
"org.hibernate.dialect.PostgreSQLDialect");
+ wc.setAttribute("hibernate.temp.use_jdbc_metadata_defaults", true);
wc.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + '.' +
HibernatePlatformUI.exporter_id + ".extension_id",
HibernateLaunchConstants.ATTR_PREFIX + "hbm2java"); //$NON-NLS-1$
//$NON-NLS-2$
- HibernatePlatformUI.runLaunchConfiguration(wc);
+ try {
+ wc.launch(ILaunchManager.RUN_MODE, null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } finally{
+ if (initPage.isTemporaryConfiguration()){
+ KnownConfigurations.getInstance().removeConfiguration(KnownConfigurations.getInstance().find(concoleConfigurationName),
false);
+ }
+ }
}
return true;
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2008-07-28
12:26:26 UTC (rev 9350)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2008-07-28
12:39:48 UTC (rev 9351)
@@ -10,15 +10,29 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.ui.wizard;
+import java.io.File;
+import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.db.JptDbPlugin;
@@ -35,10 +49,16 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
+import org.hibernate.cfg.Environment;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
+import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.launch.ICodeGenerationLaunchConstants;
+import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
import org.hibernate.util.StringHelper;
+import org.w3c.dom.Element;
/**
* @author Dmitry Geraskov
@@ -206,10 +226,89 @@
}
public String getConfigurationName() {
- return consoleConfigurationName.getText();
+ if (selectMethod.getSelection())
+ return consoleConfigurationName.getText();
+ return createConsoleConfiguration();
}
public String getConnectionProfileName() {
return connectionProfileName.getText();
}
+
+ private String createConsoleConfiguration(){
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+
+ ILaunchConfigurationType launchConfigurationType =
launchManager.getLaunchConfigurationType(
ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID );
+ String launchName =
launchManager.generateUniqueLaunchConfigurationNameFrom(HibernateConsoleMessages.AddConfigurationAction_hibernate);
+ //ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(
launchConfigurationType );
+ ILaunchConfigurationWorkingCopy wc = null;
+ try {
+ wc = launchConfigurationType.newInstance(null, launchName);
+
+ wc.setAttributes(getProperties());
+
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.CONFIGURATION_FACTORY,
ConfigurationMode.JPA.toString());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
nonEmptyTrimOrNull( jpaProject.getName() ));
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true );
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS, (List)null);
+ wc.setAttribute("hibernate.temp.use_jdbc_metadata_defaults", true);
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.USE_CONNECT_PROFILE_SETTINGS,
true);
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.CONNECT_PROFILE_NAME,
getConnectionProfileName());
+ wc.doSave();
+ return wc.getName();
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+
+ /**
+ * @param name
+ * @return
+ */
+ private String nonEmptyTrimOrNull(String name) {
+ if(StringHelper.isEmpty( name )) {
+ return null;
+ } else {
+ return name.trim();
+ }
+ }
+
+ private Properties getProperties(){
+ Properties prop = new Properties();
+ IConnectionProfile profile =
ProfileManager.getInstance().getProfileByName(getConnectionProfileName());
+ if (null != profile) {
+ Properties cpProperties = profile.getProperties(profile.getProviderId());
+ Map<String, String> keyMaps = new HashMap<String, String>();
+ keyMaps.put(Environment.DRIVER,
"org.eclipse.datatools.connectivity.db.driverClass");
+ keyMaps.put(Environment.URL,
"org.eclipse.datatools.connectivity.db.URL");
+ keyMaps.put(Environment.USER,
"org.eclipse.datatools.connectivity.db.username");
+ keyMaps.put(Environment.PASS,
"org.eclipse.datatools.connectivity.db.password");
+ keyMaps.put(Environment.DEFAULT_CATALOG,
"org.eclipse.datatools.connectivity.db.databaseName");
+ copyProperties(cpProperties, prop, keyMaps);
+ }
+ return prop;
+ }
+
+ /**
+ *
+ * @param source
+ * @param dest
+ * @param map - key is the key in <code>dest</code> map, value is the key in
<code>source</code> map.
+ */
+ private void copyProperties(Properties source, Properties dest, Map<String,
String> map){
+ for (Map.Entry<String, String> entry : map.entrySet()) {
+ putIfNotNull(dest, entry.getKey(), (String) source.get(entry.getValue()));
+ }
+ }
+
+ private void putIfNotNull(Properties prop, String key, String value){
+ if (StringHelper.isNotEmpty(value)) prop.put(key, value);
+ }
+
+ public boolean isTemporaryConfiguration(){
+ return !selectMethod.getSelection();
+ }
}