Author: dgeraskov
Date: 2008-12-17 09:19:09 -0500 (Wed, 17 Dec 2008)
New Revision: 12640
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3361
Added new choice '[JPA Project Configured Connection]'.
Validation checks that project is jpa project and that connection profile specified for
it.
Console configuration uses current cp on the build time.
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF 2008-12-17
13:05:33 UTC (rev 12639)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF 2008-12-17
14:19:09 UTC (rev 12640)
@@ -74,5 +74,7 @@
org.eclipse.core.filesystem,
org.eclipse.core.variables,
org.eclipse.datatools.connectivity.ui,
- org.eclipse.datatools.connectivity
+ org.eclipse.datatools.connectivity,
+ org.eclipse.jpt.core,
+ org.eclipse.jpt.db
Eclipse-LazyStart: true
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java 2008-12-17
13:05:33 UTC (rev 12639)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java 2008-12-17
14:19:09 UTC (rev 12640)
@@ -10,6 +10,7 @@
import java.util.List;
import java.util.Properties;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -18,6 +19,9 @@
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jpt.core.JpaDataSource;
+import org.eclipse.jpt.core.JpaProject;
import org.eclipse.osgi.util.NLS;
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
@@ -128,6 +132,20 @@
}
public String getConnectionProfileName() {
+ if
(Boolean.parseBoolean(getAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE,
null))){
+ String projName = getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
null);
+ if (projName != null){
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
+ if (project != null){
+ JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
+ if (jpaProject != null) {
+ JpaDataSource ds = jpaProject.getDataSource();
+ if (ds != null)
+ return ds.getConnectionProfileName();
+ }
+ }
+ }
+ }
return getAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
null);
}
@@ -167,8 +185,9 @@
public String getDialectName() {
String dialect = getAttribute( IConsoleConfigurationLaunchConstants.DIALECT, null );
// determine dialect when connection profile is used
- if (dialect == null && getConnectionProfileName() != null) {
- IConnectionProfile profile =
ProfileManager.getInstance().getProfileByName(getConnectionProfileName());
+ if (dialect == null && getConnectionProfileName() != null &&
getConnectionProfileName() != null) {
+ IConnectionProfile profile =
ProfileManager.getInstance().getProfileByName(getConnectionProfileName());
+ if (profile == null) return null;
String driver =
profile.getProperties(profile.getProviderId()).getProperty("org.eclipse.datatools.connectivity.db.driverClass");
dialect = new DriverClassHelpers().getDialect(driver);
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2008-12-17
13:05:33 UTC (rev 12639)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2008-12-17
14:19:09 UTC (rev 12640)
@@ -456,6 +456,9 @@
public static String ConsoleConfigurationMainTab_type;
public static String ConsoleConfigurationMainTab_use_existing;
public static String ConsoleConfigurationMainTab_wizard_page;
+ public static String ConsoleConfigurationMainTab_project_must_be_jpa;
+ public static String ConsoleConfigurationMainTab_cp_not_specified;
+ public static String ConsoleConfigurationMainTab_project_must_be_set;
public static String ConsoleConfigurationMappingsTab_add_hbm_xml_file;
public static String ConsoleConfigurationMappingsTab_add_hibernate_mapping_file;
public static String ConsoleConfigurationMappingsTab_additional_mapping_files;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2008-12-17
13:05:33 UTC (rev 12639)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2008-12-17
14:19:09 UTC (rev 12640)
@@ -448,6 +448,9 @@
ConsoleConfigurationMainTab_type=Type:
ConsoleConfigurationMainTab_use_existing=Use &existing...
ConsoleConfigurationMainTab_wizard_page=wizardPage
+ConsoleConfigurationMainTab_project_must_be_jpa=Project ''{0}'' must be a
JPA project
+ConsoleConfigurationMainTab_cp_not_specified=Connection profile for project
''{0}'' not specified
+ConsoleConfigurationMainTab_project_must_be_set=Project must be set to JPA project
ConsoleConfigurationMappingsTab_add_hbm_xml_file=Add hbm.xml file
ConsoleConfigurationMappingsTab_add_hibernate_mapping_file=Add a Hibernate Mapping file
ConsoleConfigurationMappingsTab_additional_mapping_files=Additonal mapping files (not
listed in cfg.xml)
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java 2008-12-17
13:05:33 UTC (rev 12639)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java 2008-12-17
14:19:09 UTC (rev 12640)
@@ -55,8 +55,12 @@
protected ComboViewer comboControl;
protected Button buttonNew;
protected Button buttonEdit;
+
+ static final String NO_CONNECTIN_NAME = "[Hibernate configured connection]";
+ static final String JPA_CONNECTIN_NAME = "[JPA Project Configured
Connection]";
- static final protected ConnectionWrapper NO_CONNECTION_PLACEHOLDER = new
ConnectionWrapper("",null);
+ static final protected ConnectionWrapper NO_CONNECTION_PLACEHOLDER = new
ConnectionWrapper(NO_CONNECTIN_NAME, null);
+ static final protected ConnectionWrapper JPA_CONNECTION_PLACEHOLDER = new
ConnectionWrapper(JPA_CONNECTIN_NAME, null);
private static class ConnectionWrapper {
@@ -250,11 +254,7 @@
@Override
public String getText(Object element) {
ConnectionWrapper cw = (ConnectionWrapper) element;
- if(cw.getProfile()==null) {
- return "[Hibernate configured connection]";
- } else {
- return cw.getProfile().getName();
- }
+ return cw.getId();
}
});
@@ -324,9 +324,6 @@
private String getSelectedId() {
ConnectionWrapper cw = getSelectedConnection();
- if (cw == null) {
- cw = NO_CONNECTION_PLACEHOLDER;
- }
return cw.getId();
}
@@ -337,6 +334,7 @@
IConnectionProfile[] profiles = ProfileManager.getInstance()
.getProfilesByCategory("org.eclipse.datatools.connectivity.db.category");
//$NON-NLS-1$
List<ConnectionWrapper> names = new ArrayList<ConnectionWrapper>();
+ names.add(JPA_CONNECTION_PLACEHOLDER);
names.add(NO_CONNECTION_PLACEHOLDER);
for (IConnectionProfile connectionProfile : profiles) {
names.add(new ConnectionWrapper(connectionProfile.getName(), connectionProfile));
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2008-12-17
13:05:33 UTC (rev 12639)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2008-12-17
14:19:09 UTC (rev 12640)
@@ -21,6 +21,8 @@
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jpt.core.JpaDataSource;
+import org.eclipse.jpt.core.JpaProject;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -168,7 +170,14 @@
configuration.setAttribute(IConsoleConfigurationLaunchConstants.PROPERTY_FILE,
nonEmptyTrimOrNull(propertyFileText));
configuration.setAttribute(IConsoleConfigurationLaunchConstants.CFG_XML_FILE,
nonEmptyTrimOrNull(configurationFileText));
configuration.setAttribute(IConsoleConfigurationLaunchConstants.PERSISTENCE_UNIT_NAME,
nonEmptyTrimOrNull(persistenceUnitNameText));
- configuration.setAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
nonEmptyTrimOrNull(connectionProfileCtrl.getSelectedConnectionName()));
+ String cpName = nonEmptyTrimOrNull(connectionProfileCtrl.getSelectedConnectionName());
+ if (ConnectionProfileCtrl.JPA_CONNECTIN_NAME.equals(cpName)){
+ configuration.setAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE,
Boolean.toString(true));
+ configuration.removeAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME);
+ } else {
+ configuration.setAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
cpName);
+ configuration.removeAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE);
+ }
}
public void initializeFrom(ILaunchConfiguration configuration) {
@@ -184,7 +193,10 @@
configurationFileText.setText( configuration.getAttribute(
IConsoleConfigurationLaunchConstants.CFG_XML_FILE, "" )); //$NON-NLS-1$
persistenceUnitNameText.setText( configuration.getAttribute(
IConsoleConfigurationLaunchConstants.PERSISTENCE_UNIT_NAME, "" ));
//$NON-NLS-1$
- connectionProfileCtrl.selectValue(configuration.getAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
"")); //$NON-NLS-1$
+ if
(Boolean.parseBoolean(configuration.getAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE,
Boolean.toString(false)))){
+ connectionProfileCtrl.selectValue(ConnectionProfileCtrl.JPA_CONNECTIN_NAME);
+ } else
+ connectionProfileCtrl.selectValue(configuration.getAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
"")); //$NON-NLS-1$
}
catch (CoreException e) {
HibernateConsolePlugin.getDefault().log( e );
@@ -364,6 +376,7 @@
confbutton.setEnabled(!configurationFileWillBeCreated && !modeJPA);
persistenceUnitNameText.setEnabled(modeJPA);
+ String cpName = nonEmptyTrimOrNull(connectionProfileCtrl.getSelectedConnectionName());
if(getProjectName()!=null && StringHelper.isNotEmpty(getProjectName().trim()))
{
Path projectPath = new Path(getProjectName());
@@ -377,7 +390,33 @@
setErrorMessage(out);
return false;
}
+
+ if (ConnectionProfileCtrl.JPA_CONNECTIN_NAME.equals(cpName)){
+ JpaProject jpaProject = (JpaProject) findJavaProject.getAdapter(JpaProject.class);
+ if (jpaProject == null){
+ setErrorMessage(NLS.bind(HibernateConsoleMessages.ConsoleConfigurationMainTab_project_must_be_jpa,
getProjectName()));
+ return false;
+ }
+ JpaDataSource ds = jpaProject.getDataSource();
+ if (ds == null || "".equals(ds.getConnectionProfileName())){
+ setErrorMessage(NLS.bind(HibernateConsoleMessages.ConsoleConfigurationMainTab_cp_not_specified,
getProjectName()));
+ return false;
+ }
+ }
+ } else {//check if jpa project connection selected
+ if (ConnectionProfileCtrl.JPA_CONNECTIN_NAME.equals(cpName)){
+ setErrorMessage(HibernateConsoleMessages.ConsoleConfigurationMainTab_project_must_be_set);
+ return false;
+ }
}
+
+ if (ConnectionProfileCtrl.JPA_CONNECTIN_NAME.equals(cpName)){
+ if (!jpaMode.getSelection()){
+ String out = NLS.bind("{0} mode must be used for jpa project configured
connection", jpaMode.getText());
+ setErrorMessage(out);
+ return false;
+ }
+ }
/* TODO: warn about implicit behavior of loading /hibernate.cfg.xml,
/hibernate.properties and /META-INF/persistence.xml
* if (propertyFilename.length() == 0 && configurationFilename.trim().length()
== 0) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java 2008-12-17
13:05:33 UTC (rev 12639)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/IConsoleConfigurationLaunchConstants.java 2008-12-17
14:19:09 UTC (rev 12640)
@@ -13,6 +13,7 @@
public static final String PERSISTENCE_UNIT_NAME = ID +
".PERSISTENCE_UNIT_NAME"; //$NON-NLS-1$
public static final String CONFIGURATION_FACTORY = ID +
".CONFIGURATION_FACTORY"; //$NON-NLS-1$
public static final String CONNECTION_PROFILE_NAME = ID +
".CONNECTION_PROFILE_NAME"; //$NON-NLS-1$
+ public static final String USE_JPA_PROJECT_PROFILE = ID +
".USE_JPA_PROJECT_PROFILE"; //$NON-NLS-1$
public static final String FILE_MAPPINGS = ID + ".FILE_MAPPINGS";
//$NON-NLS-1$
public static final String PROJECT_NAME =
IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME;