### Eclipse Workspace Patch 1.0 #P org.eclipse.jpt.ui Index: src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java,v retrieving revision 1.30 diff -u -r1.30 JpaProjectPropertiesPage.java --- src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java 21 May 2009 14:44:28 -0000 1.30 +++ src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java 26 May 2009 13:39:09 -0000 @@ -50,6 +50,7 @@ import org.eclipse.jpt.db.Database; import org.eclipse.jpt.db.JptDbPlugin; import org.eclipse.jpt.db.Schema; +import org.eclipse.jpt.db.SchemaContainer; import org.eclipse.jpt.db.ui.internal.DTPUiTools; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.JptUiMessages; @@ -271,15 +272,15 @@ } }; } - + protected BufferedWritablePropertyValueModel initializeOverrideDefaultCatalogModel() { OverrideDefaultCatalogModel model = new OverrideDefaultCatalogModel(this.jpaProjectHolder); - BufferedWritablePropertyValueModel modelBuffer = - new BufferedWritablePropertyValueModel(model, this.trigger); model.addPropertyChangeListener(PropertyValueModel.VALUE, this.overrideDefaultCatalogListener); - modelBuffer.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); - return modelBuffer; - + + BufferedWritablePropertyValueModel bufferedModel = new BufferedWritablePropertyValueModel(model, this.trigger); + bufferedModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); + + return bufferedModel; } protected BufferedWritablePropertyValueModel initializeDefaultCatalogModel() { @@ -338,7 +339,7 @@ new CombinedDefaultSchemaModel( this.defaultSchemaModel, this.overrideDefaultSchemaModel, - new DefaultDefaultSchemaModel(this.connectionProfileModel)); + new DefaultDefaultSchemaModel(this.defaultCatalogModel, this.connectionProfileModel)); model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); return model; } @@ -346,7 +347,7 @@ protected ListValueModel initializeSchemaChoicesModel() { Collection cvms = new ArrayList(); cvms.add(new PropertyCollectionValueModelAdapter(this.defaultSchemaModel)); - cvms.add(new SchemaChoicesModel(this.connectionProfileModel)); + cvms.add(new SchemaChoicesModel(this.defaultCatalogModel, this.connectionProfileModel)); return new SortedListValueModelAdapter( new CompositeCollectionValueModel(cvms) { @Override @@ -1057,15 +1058,14 @@ } - // ************ Catalog ************ - private static class OverrideDefaultCatalogModel - extends BasePropertyAspectAdapter + private abstract static class OverrideDefaultModel + extends BasePropertyAspectAdapter { // the superclass "value" is the *cached* value private Boolean actualValue; - - - private OverrideDefaultCatalogModel(PropertyValueModel jpaProjectHolder) { + + + OverrideDefaultModel(PropertyValueModel jpaProjectHolder) { super(jpaProjectHolder); } @@ -1074,14 +1074,14 @@ @Override public Boolean getValue() { - Boolean value = super.getValue(); - return (value == null) ? Boolean.FALSE : value; + Boolean v = super.getValue(); + return (v == null) ? Boolean.FALSE : v; } @Override public void setValue_(Boolean newValue) { this.actualValue = newValue; - valueChanged(); + this.valueChanged(); } @@ -1089,14 +1089,16 @@ @Override protected void engageSubject_() { + // we need to build 'actualValue' *before* calling 'super' + // because 'super' calls back here to #buildValue_() this.actualValue = this.buildActualValue_(); super.engageSubject_(); } @Override protected void disengageSubject_() { - this.actualValue = null; super.disengageSubject_(); + this.actualValue = null; } @@ -1108,7 +1110,28 @@ } protected Boolean buildActualValue_() { - return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultCatalog()); + return Boolean.valueOf(this.subjectHasUserOverrideDefault()); + } + + protected boolean subjectHasUserOverrideDefault() { + return ! StringTools.stringIsEmpty(this.getSubjectUserOverrideDefault()); + } + + protected abstract String getSubjectUserOverrideDefault(); + } + + + // ************ Catalog ************ + private static class OverrideDefaultCatalogModel + extends OverrideDefaultModel + { + OverrideDefaultCatalogModel(PropertyValueModel jpaProjectHolder) { + super(jpaProjectHolder); + } + + @Override + protected String getSubjectUserOverrideDefault() { + return this.subject.getUserOverrideDefaultCatalog(); } } @@ -1116,7 +1139,7 @@ private static class DefaultCatalogModel extends PropertyAspectAdapter { - private DefaultCatalogModel(PropertyValueModel jpaProjectModel) { + DefaultCatalogModel(PropertyValueModel jpaProjectModel) { super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY); } @@ -1136,57 +1159,54 @@ return this.subject.getUserOverrideDefaultCatalog(); } } - - private static class DefaultDefaultCatalogModel - extends BasePropertyAspectAdapter + + private abstract static class ConnectionProfilePropertyAspectAdapter + extends BasePropertyAspectAdapter { private ConnectionListener connectionListener; - - - private DefaultDefaultCatalogModel( - PropertyValueModel connectionProfileModel) { + + ConnectionProfilePropertyAspectAdapter(PropertyValueModel connectionProfileModel) { super(connectionProfileModel); - this.connectionListener = buildConnectionListener(); + this.connectionListener = this.buildConnectionListener(); } - - - // ************ initialization ***************************************** - + + // the connection opening is probably the only thing that will happen... private ConnectionListener buildConnectionListener() { return new ConnectionAdapter() { @Override public void opened(ConnectionProfile profile) { - if (profile.equals(DefaultDefaultCatalogModel.this.subject)) { - valueChanged(); - } - } - @Override - public void catalogChanged(ConnectionProfile profile, Catalog catalog) { - if (profile.equals(DefaultDefaultCatalogModel.this.subject)) { - valueChanged(); - } + ConnectionProfilePropertyAspectAdapter.this.profileOpened(profile); } }; } - - - // ************ AspectAdapter impl ************************************* - + + void profileOpened(ConnectionProfile profile) { + if (profile.equals(this.subject)) { + this.valueChanged(); + } + } + @Override protected void engageSubject_() { - this.subject.addConnectionListener(this.connectionListener); super.engageSubject_(); + this.subject.addConnectionListener(this.connectionListener); } - + @Override protected void disengageSubject_() { this.subject.removeConnectionListener(this.connectionListener); super.disengageSubject_(); } - - - // ************ internal *********************************************** - + + } + + private static class DefaultDefaultCatalogModel + extends ConnectionProfilePropertyAspectAdapter + { + DefaultDefaultCatalogModel(PropertyValueModel connectionProfileModel) { + super(connectionProfileModel); + } + @Override protected String buildValue_() { Database db = this.subject.getDatabase(); @@ -1209,13 +1229,13 @@ private PropertyValueModel defaultDefaultCatalogModel; - private CombinedDefaultCatalogModel( + CombinedDefaultCatalogModel( WritablePropertyValueModel defaultCatalogModel, PropertyValueModel overrideDefaultCatalogModel, PropertyValueModel defaultDefaultCatalogModel) { super( - new CompositeListValueModel( - CollectionTools.list( + new CompositeListValueModel,Object>( + CollectionTools.>list( new PropertyListValueModelAdapter(defaultCatalogModel), new PropertyListValueModelAdapter(overrideDefaultCatalogModel), new PropertyListValueModelAdapter(defaultDefaultCatalogModel) @@ -1233,9 +1253,7 @@ if (this.overrideDefaultCatalogModel.getValue()) { return this.defaultCatalogModel.getValue(); } - else { - return this.defaultDefaultCatalogModel.getValue(); - } + return this.defaultDefaultCatalogModel.getValue(); } @@ -1250,114 +1268,72 @@ } - private static class CatalogChoicesModel - extends BaseCollectionAspectAdapter + private static class ConnectionProfileCollectionAspectAdapter + extends BaseCollectionAspectAdapter { private ConnectionListener connectionListener; - - - private CatalogChoicesModel(PropertyValueModel subjectHolder) { + + ConnectionProfileCollectionAspectAdapter(PropertyValueModel subjectHolder) { super(subjectHolder); - this.connectionListener = buildConnectionListener(); + this.connectionListener = this.buildConnectionListener(); } - - - // ************ initialization ***************************************** - + + // the connection opening is probably the only thing that will happen... private ConnectionListener buildConnectionListener() { return new ConnectionAdapter() { @Override public void opened(ConnectionProfile profile) { - if (profile.equals(CatalogChoicesModel.this.subject)) { - collectionChanged(); - } - } - @Override - public void catalogChanged(ConnectionProfile profile, Catalog catalog) { - if (profile.equals(CatalogChoicesModel.this.subject)) { - collectionChanged(); - } + ConnectionProfileCollectionAspectAdapter.this.profileOpened(profile); } }; } - - - // ************ AspectAdapter impl ************************************* - + + void profileOpened(ConnectionProfile profile) { + if (profile.equals(this.subject)) { + this.collectionChanged(); + } + } + @Override protected void engageSubject_() { this.subject.addConnectionListener(this.connectionListener); } - + @Override protected void disengageSubject_() { this.subject.removeConnectionListener(this.connectionListener); } - - - // ************ internal *********************************************** - + + } + + private static class CatalogChoicesModel + extends ConnectionProfileCollectionAspectAdapter + { + CatalogChoicesModel(PropertyValueModel subjectHolder) { + super(subjectHolder); + } + @Override protected Iterator iterator_() { - return (this.subject.getDatabase() == null) ? + Database db = this.subject.getDatabase(); + return ((db == null) || ( ! db.supportsCatalogs())) ? EmptyIterator.instance() : - this.subject.getDatabase().sortedCatalogIdentifiers(); + db.sortedCatalogIdentifiers(); } } // ************ Schema ************ private static class OverrideDefaultSchemaModel - extends BasePropertyAspectAdapter + extends OverrideDefaultModel { - // the superclass "value" is the *cached* value - private Boolean actualValue; - - - private OverrideDefaultSchemaModel(PropertyValueModel jpaProjectHolder) { + OverrideDefaultSchemaModel(PropertyValueModel jpaProjectHolder) { super(jpaProjectHolder); } - - - // ************ WritablePropertyValueModel impl ************************ - - @Override - public Boolean getValue() { - Boolean value = super.getValue(); - return (value == null) ? Boolean.FALSE : value; - } - - @Override - public void setValue_(Boolean newValue) { - this.actualValue = newValue; - valueChanged(); - } - - - // ************ AspectAdapter impl ************************************* - - @Override - protected void engageSubject_() { - this.actualValue = this.buildActualValue_(); - super.engageSubject_(); - } - - @Override - protected void disengageSubject_() { - this.actualValue = null; - super.disengageSubject_(); - } - - - // ************ internal *********************************************** - + @Override - protected Boolean buildValue_() { - return this.actualValue; - } - - protected Boolean buildActualValue_() { - return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultSchema()); + public String getSubjectUserOverrideDefault() { + return this.subject.getUserOverrideDefaultSchema(); } } @@ -1365,7 +1341,7 @@ private static class DefaultSchemaModel extends PropertyAspectAdapter { - private DefaultSchemaModel(PropertyValueModel jpaProjectModel) { + DefaultSchemaModel(PropertyValueModel jpaProjectModel) { super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY); } @@ -1388,64 +1364,76 @@ private static class DefaultDefaultSchemaModel - extends BasePropertyAspectAdapter + extends ConnectionProfilePropertyAspectAdapter { - private ConnectionListener connectionListener; - - - private DefaultDefaultSchemaModel( + private final PropertyValueModel defaultCatalogModel; + private final PropertyChangeListener catalogListener; + + DefaultDefaultSchemaModel(PropertyValueModel defaultCatalogModel, PropertyValueModel connectionProfileModel) { super(connectionProfileModel); - this.connectionListener = buildConnectionListener(); + this.defaultCatalogModel = defaultCatalogModel; + this.catalogListener = this.buildCatalogListener(); } - - - // ************ initialization ***************************************** - - private ConnectionListener buildConnectionListener() { - return new ConnectionAdapter() { - @Override - public void opened(ConnectionProfile profile) { - if (profile.equals(DefaultDefaultSchemaModel.this.subject)) { - valueChanged(); - } - } - @Override - public void schemaChanged(ConnectionProfile profile, Schema schema) { - if (profile.equals(DefaultDefaultSchemaModel.this.subject)) { - valueChanged(); - } + + private PropertyChangeListener buildCatalogListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + DefaultDefaultSchemaModel.this.valueChanged(); } }; } - - - // ************ AspectAdapter impl ************************************* - + @Override protected void engageSubject_() { - this.subject.addConnectionListener(this.connectionListener); + // call 'super' last? + this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); super.engageSubject_(); } @Override protected void disengageSubject_() { - this.subject.removeConnectionListener(this.connectionListener); super.disengageSubject_(); + this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); } - - - // ************ internal *********************************************** - + @Override protected String buildValue_() { - Database db = this.subject.getDatabase(); - if (db == null) { - return null; - } - Schema schema = db.getDefaultSchema(); + Schema schema = this.getDefaultSchema(); return (schema == null) ? null : schema.getIdentifier(); } + + private Schema getDefaultSchema() { + SchemaContainer sc = this.getSchemaContainer(); + return (sc == null) ? null : sc.getDefaultSchema(); + } + + private SchemaContainer getSchemaContainer() { + return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); + } + + private boolean databaseSupportsCatalogs() { + Database db = this.getDatabase(); + return (db != null) && db.supportsCatalogs(); + } + + private Catalog getCatalog() { + String name = this.defaultCatalogModel.getValue(); + return (name == null) ? null : this.getCatalog(name); + } + + /** + * pre-condition: 'name' is not null + */ + private Catalog getCatalog(String name) { + Database db = this.getDatabase(); + return (db == null) ? null : db.getCatalogForIdentifier(name); + } + + private Database getDatabase() { + return this.subject.getDatabase(); + } + } @@ -1460,7 +1448,7 @@ private PropertyValueModel defaultDefaultSchemaModel; - private CombinedDefaultSchemaModel( + CombinedDefaultSchemaModel( WritablePropertyValueModel defaultSchemaModel, PropertyValueModel overrideDefaultSchemaModel, PropertyValueModel defaultDefaultSchemaModel) { @@ -1484,9 +1472,7 @@ if (this.overrideDefaultSchemaModel.getValue()) { return this.defaultSchemaModel.getValue(); } - else { - return this.defaultDefaultSchemaModel.getValue(); - } + return this.defaultDefaultSchemaModel.getValue(); } @@ -1502,58 +1488,71 @@ private static class SchemaChoicesModel - extends BaseCollectionAspectAdapter + extends ConnectionProfileCollectionAspectAdapter { - private ConnectionListener connectionListener; - - - private SchemaChoicesModel(PropertyValueModel subjectHolder) { + private final PropertyValueModel defaultCatalogModel; + private final PropertyChangeListener catalogListener; + + SchemaChoicesModel(PropertyValueModel defaultCatalogModel, + PropertyValueModel subjectHolder) { super(subjectHolder); - this.connectionListener = buildConnectionListener(); + this.defaultCatalogModel = defaultCatalogModel; + this.catalogListener = this.buildCatalogListener(); } - - - // ************ initialization ***************************************** - - private ConnectionListener buildConnectionListener() { - return new ConnectionAdapter() { - @Override - public void opened(ConnectionProfile profile) { - if (profile.equals(SchemaChoicesModel.this.subject)) { - collectionChanged(); - } - } - @Override - public void schemaChanged(ConnectionProfile profile, Schema schema) { - if (profile.equals(SchemaChoicesModel.this.subject)) { - collectionChanged(); - } + + private PropertyChangeListener buildCatalogListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + collectionChanged(); } }; } - - - // ************ AspectAdapter impl ************************************* - + @Override protected void engageSubject_() { - this.subject.addConnectionListener(this.connectionListener); + // call 'super' last? + this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); + super.engageSubject_(); } - + @Override protected void disengageSubject_() { - this.subject.removeConnectionListener(this.connectionListener); + super.disengageSubject_(); + this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); } - - - // ************ internal *********************************************** - + @Override protected Iterator iterator_() { - return (this.subject.getDatabase() == null) ? - EmptyIterator.instance() : - this.subject.getDatabase().sortedSchemaIdentifiers(); + SchemaContainer sc = this.getSchemaContainer(); + return (sc == null) ? EmptyIterator.instance() : sc.sortedSchemaIdentifiers(); + } + + private SchemaContainer getSchemaContainer() { + return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); + } + + private boolean databaseSupportsCatalogs() { + Database db = this.getDatabase(); + return (db != null) && db.supportsCatalogs(); + } + + private Catalog getCatalog() { + String name = this.defaultCatalogModel.getValue(); + return (name == null) ? null : this.getCatalog(name); + } + + /** + * pre-condition: 'name' is not null + */ + private Catalog getCatalog(String name) { + Database db = this.getDatabase(); + return (db == null) ? null : db.getCatalogForIdentifier(name); + } + + private Database getDatabase() { + return this.subject.getDatabase(); } + } #P org.eclipse.jpt.core Index: src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java,v retrieving revision 1.33 diff -u -r1.33 JpaFacetDataModelProvider.java --- src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java 11 Mar 2009 00:22:00 -0000 1.33 +++ src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java 26 May 2009 13:39:10 -0000 @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.facet; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -29,11 +28,9 @@ import org.eclipse.jpt.db.DatabaseFinder; import org.eclipse.jpt.db.JptDbPlugin; import org.eclipse.jpt.db.Schema; +import org.eclipse.jpt.db.SchemaContainer; import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener; import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; import org.eclipse.osgi.util.NLS; @@ -41,21 +38,23 @@ import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; -public class JpaFacetDataModelProvider extends FacetInstallDataModelProvider +public class JpaFacetDataModelProvider + extends FacetInstallDataModelProvider implements JpaFacetDataModelProperties { - private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; + private LibraryInstallDelegate defaultLibraryProvider; - private static final String RUNTIME_NONE = - WTPCommonPlugin.getResourceString(WTPCommonMessages.RUNTIME_NONE, null); + /** cache the connection profile - change it whenever the user selects a different name */ + private ConnectionProfile connectionProfile; + + private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; + private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED); @@ -63,29 +62,19 @@ buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED); private static final IStatus USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS = - buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED); + buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED); private static final IStatus USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS = buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED); - private static final IStatus RUNTIME_NOT_SPECIFIED_STATUS = - buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_NOT_SPECIFIED); - - private static final IStatus RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS = - buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30); - - - private LibraryInstallDelegate defaultLibraryProvider; - - + /** * required default constructor */ public JpaFacetDataModelProvider() { super(); } - - + @Override public Set getPropertyNames() { @SuppressWarnings("unchecked") Set propertyNames = super.getPropertyNames(); @@ -105,24 +94,94 @@ propertyNames.add(CREATE_ORM_XML); return propertyNames; } + + + // ********** properties ********** + + private String getPlatformId() { + return (String) this.getProperty(PLATFORM_ID); + } + + private String getConnectionName() { + return (String) this.getProperty(CONNECTION); + } + + private boolean userWantsToAddDbDriverJarsToClasspath() { + return this.getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); + } + + private String getDriverName() { + return (String) this.getProperty(DB_DRIVER_NAME); + } + + private boolean userWantsToOverrideDefaultCatalog() { + return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); + } + private String getUserOverrideDefaultCatalog() { + return (String) this.getProperty(USER_OVERRIDE_DEFAULT_CATALOG); + } + + private boolean userWantsToOverrideDefaultSchema() { + return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); + } + + private String getUserOverrideDefaultSchema() { + return (String) this.getProperty(USER_OVERRIDE_DEFAULT_SCHEMA); + } + + private boolean discoverAnnotatedClasses() { + return this.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES); + } + + private IFacetedProjectWorkingCopy getFacetedProjectWorkingCopy() { + return (IFacetedProjectWorkingCopy) this.getProperty(FACETED_PROJECT_WORKING_COPY); + } + + private IProjectFacetVersion getProjectFacetVersion() { + return (IProjectFacetVersion) this.getProperty(FACET_VERSION); + } + + private IRuntime getRuntime() { + return (IRuntime) this.getProperty(RUNTIME); + } + + private LibraryInstallDelegate getLibraryInstallDelegate() { + return (LibraryInstallDelegate) this.getProperty(LIBRARY_PROVIDER_DELEGATE); + } + + + // ********** enabled ********** + @Override public boolean isPropertyEnabled(String propertyName) { - if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); - } - if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); - } if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { - return getConnectionProfile() != null; + return (this.getConnectionProfile() != null); } if (propertyName.equals(DB_DRIVER_NAME)) { - return getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); + return this.userWantsToAddDbDriverJarsToClasspath(); } + + if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { + return this.connectionIsActive() && this.databaseSupportsCatalogs(); + } + if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { + return this.userWantsToOverrideDefaultCatalog(); + } + + if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { + return this.connectionIsActive(); + } + if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { + return this.userWantsToOverrideDefaultSchema(); + } + return super.isPropertyEnabled(propertyName); } - + + + // ********** defaults ********** + @Override public Object getDefaultProperty(String propertyName) { if (propertyName.equals(RUNTIME)) { @@ -135,37 +194,37 @@ return JptCorePlugin.getDefaultJpaPlatformId(); } if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { - return getDefaultLibraryProvider(); + return this.getDefaultLibraryProvider(); } if (propertyName.equals(CONNECTION)) { return null; } if (propertyName.equals(CONNECTION_ACTIVE)) { - return Boolean.valueOf(connectionIsActive()); + return Boolean.valueOf(this.connectionIsActive()); } if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { return Boolean.FALSE; } if (propertyName.equals(DB_DRIVER_NAME)) { - return getDefaultDriverName(); + return this.getDefaultDriverName(); } if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { return Boolean.FALSE; } if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return getDefaultCatalogName(); + return this.getDefaultCatalogName(); } if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { return Boolean.FALSE; } if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return getDefaultSchemaName(); + return this.getDefaultSchemaName(); } if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { - return Boolean.valueOf(this.runtimeSupportsEjb30(this.runtime())); + return Boolean.valueOf(this.runtimeSupportsEjb30()); } if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { - return Boolean.valueOf( ! getBooleanProperty(DISCOVER_ANNOTATED_CLASSES)); + return Boolean.valueOf( ! this.discoverAnnotatedClasses()); } if (propertyName.equals(CREATE_ORM_XML)) { return Boolean.TRUE; @@ -173,63 +232,80 @@ return super.getDefaultProperty(propertyName); } - - private String getDefaultDriverName() { - ConnectionProfile cp = this.getConnectionProfile(); - if (cp == null) { - return null; + + private LibraryInstallDelegate getDefaultLibraryProvider() { + // delegate itself changes, not the instance of delegate + if (this.defaultLibraryProvider == null) { + this.defaultLibraryProvider = this.buildDefaultLibraryProvider(); } - return cp.getDriverName(); + return defaultLibraryProvider; } - - private String getDefaultCatalogName() { - ConnectionProfile cp = this.getConnectionProfile(); - if (cp == null) { + + private LibraryInstallDelegate buildDefaultLibraryProvider() { + IFacetedProjectWorkingCopy fpjwc = this.getFacetedProjectWorkingCopy(); + if (fpjwc == null) { return null; } - Database db = cp.getDatabase(); - if (db == null) { + IProjectFacetVersion pfv = this.getProjectFacetVersion(); + if (pfv == null) { return null; } - Catalog catalog = db.getDefaultCatalog(); + LibraryInstallDelegate lp = new LibraryInstallDelegate(fpjwc, pfv, this.buildEnablementVariables()); + lp.addListener(this.buildLibraryProviderListener()); + return lp; + } + + private Map buildEnablementVariables() { + Map enablementVariables = new HashMap(); + enablementVariables.put(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, this.getPlatformId()); + return enablementVariables; + } + + private IPropertyChangeListener buildLibraryProviderListener() { + return new IPropertyChangeListener() { + public void propertyChanged(String property, Object oldValue, Object newValue ) { + JpaFacetDataModelProvider.this.getDataModel().notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG); + } + }; + } + + private String getDefaultDriverName() { + ConnectionProfile cp = this.getConnectionProfile(); + return (cp == null) ? null : cp.getDriverName(); + } + + private String getDefaultCatalogName() { + Catalog catalog = this.getDefaultCatalog(); return (catalog == null) ? null : catalog.getIdentifier(); } + private Catalog getDefaultCatalog() { + Database db = this.getDatabase(); + return (db == null) ? null : db.getDefaultCatalog(); + } + private String getDefaultSchemaName() { - ConnectionProfile cp = this.getConnectionProfile(); - if (cp == null) { - return null; - } - Database db = cp.getDatabase(); - if (db == null) { - return null; - } - Schema schema = db.getDefaultSchema(); + Schema schema = this.getDefaultSchema(); return (schema == null) ? null : schema.getIdentifier(); } - private LibraryInstallDelegate getDefaultLibraryProvider() { - // delegate itself changes, not the instance of delegate - if (defaultLibraryProvider == null) { - IFacetedProjectWorkingCopy fpjwc = (IFacetedProjectWorkingCopy) getProperty(FACETED_PROJECT_WORKING_COPY); - IProjectFacetVersion fv = (IProjectFacetVersion) getProperty(FACET_VERSION); - if (fpjwc != null && fv != null ) { - Map enablementVariables = new HashMap(); - enablementVariables.put( - JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, - getPlatformId()); - defaultLibraryProvider = new LibraryInstallDelegate(fpjwc, fv, enablementVariables); - defaultLibraryProvider.addListener( - new IPropertyChangeListener() { - public void propertyChanged(final String property, final Object oldValue, final Object newValue ) { - JpaFacetDataModelProvider.this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG); - } - }); - } - } - return defaultLibraryProvider; + private Schema getDefaultSchema() { + SchemaContainer sc = this.getSchemaContainer(); + return (sc == null) ? null : sc.getDefaultSchema(); } - + + private boolean runtimeSupportsEjb30() { + IRuntime runtime = this.getRuntime(); + return (runtime != null) && runtime.supports(this.getEJB30()); + } + + private IProjectFacetVersion getEJB30() { + return ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ + } + + + // ********** synchronize data model ********** + @Override public boolean propertySet(String propertyName, Object propertyValue) { boolean ok = super.propertySet(propertyName, propertyValue); @@ -237,11 +313,11 @@ if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) { //no-op } - if( propertyName.equals(FACET_VERSION)){ + else if (propertyName.equals(FACET_VERSION)) { this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG); } - if (propertyName.equals(RUNTIME)) { - LibraryInstallDelegate lid = getLibraryInstallDelegate(); + else if (propertyName.equals(RUNTIME)) { + LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); if (lid != null) { // may be null while model is being built up // ... or in tests @@ -250,321 +326,364 @@ this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); } - if (propertyName.equals(PLATFORM_ID)) { - LibraryInstallDelegate lid = getLibraryInstallDelegate(); + else if (propertyName.equals(PLATFORM_ID)) { + LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); if (lid != null) { // may be null while model is being built up // ... or in tests - lid.setEnablementContextVariable( - JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, - (String) propertyValue); + lid.setEnablementContextVariable(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, propertyValue); } } - if (propertyName.equals(CONNECTION)) { - this.model.notifyPropertyChange(CONNECTION, IDataModel.VALID_VALUES_CHG); - this.model.setBooleanProperty(CONNECTION_ACTIVE, connectionIsActive()); + else if (propertyName.equals(CONNECTION)) { + this.setBooleanProperty(CONNECTION_ACTIVE, this.connectionIsActive()); + + // db driver + if (propertyValue == null) { // connection set to '' + this.setBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, false); + } + this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG); this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG); this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG); + + // catalog + if ((propertyValue == null) || ! this.databaseSupportsCatalogs()) { // connection set to '' or "non-catalog" database + this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); + } + this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); + + // schema + if (propertyValue == null) { // connection set to '' + this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); + } + this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); } - if (propertyName.equals(CONNECTION_ACTIVE)) { + else if (propertyName.equals(CONNECTION_ACTIVE)) { + // catalog + if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive + this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); + } + this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); + + // schema + if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive + this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); + } + this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); - this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG); - this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); } - if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { + else if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); - if (! ((Boolean) propertyValue).booleanValue()) { - this.model.setProperty(DB_DRIVER_NAME, null); + if (this.propertyValueIsFalse(propertyValue)) { + this.setProperty(DB_DRIVER_NAME, null); } } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { + else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); - if (! ((Boolean) propertyValue).booleanValue()) { - this.model.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); + if (this.propertyValueIsFalse(propertyValue)) { + this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); } } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { + else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); - if (! ((Boolean) propertyValue).booleanValue()) { - this.model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); + if (this.propertyValueIsFalse(propertyValue)) { + this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); } } -// if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) { -// this.model.setBooleanProperty(USE_USER_JPA_LIBRARY, ! ((Boolean) propertyValue).booleanValue()); -// } -// if (propertyName.equals(USE_USER_JPA_LIBRARY)) { -// this.model.setBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION, ! ((Boolean) propertyValue).booleanValue()); -// this.model.notifyPropertyChange(JPA_LIBRARY, IDataModel.ENABLE_CHG); -// } - if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { - this.model.setBooleanProperty(LIST_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); + else if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { + this.setBooleanProperty(LIST_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); } - if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { - this.model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); + else if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { + this.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); } return ok; } - private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; + private boolean propertyValueIsFalse(Object propertyValue) { + return ! this.propertyValueIsTrue(propertyValue); + } + + private boolean propertyValueIsTrue(Object propertyValue) { + return ((Boolean) propertyValue).booleanValue(); + } + + + // ********** property descriptors ********** @Override public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { if (propertyName.equals(PLATFORM_ID)) { - return CollectionTools.sort( - CollectionTools.array( - new TransformationIterator( - JpaPlatformRegistry.instance().jpaPlatformIds()) { - @Override - protected DataModelPropertyDescriptor transform(String platformId) { - return platformIdPropertyDescriptor(platformId); - } - }, - EMPTY_DMPD_ARRAY), - new Comparator() { - public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { - return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); - }; - }); + return this.buildValidPlatformDescriptors(); } + if (propertyName.equals(CONNECTION)) { - return CollectionTools.array( - new TransformationIterator( - new CompositeIterator(null, connectionNames())) { - @Override - protected DataModelPropertyDescriptor transform(String next) { - return connectionPropertyDescriptor(next); - } - }, - EMPTY_DMPD_ARRAY); + return this.buildValidConnectionDescriptors(); } + if (propertyName.equals(DB_DRIVER_NAME)) { - return CollectionTools.array( - new TransformationIterator(driverNames()) { - @Override - protected DataModelPropertyDescriptor transform(String next) { - return new DataModelPropertyDescriptor(next); - } - }, - EMPTY_DMPD_ARRAY); + return this.buildValidDriverDescriptors(); } + if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return CollectionTools.array( - new TransformationIterator(catalogNames()) { - @Override - protected DataModelPropertyDescriptor transform(String next) { - return new DataModelPropertyDescriptor(next); - } - }, - EMPTY_DMPD_ARRAY); + return this.buildValidCatalogDescriptors(); } + if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return CollectionTools.array( - new TransformationIterator(schemaNames()) { - @Override - protected DataModelPropertyDescriptor transform(String next) { - return new DataModelPropertyDescriptor(next); - } - }, - EMPTY_DMPD_ARRAY); + return this.buildValidSchemaDescriptors(); } return super.getValidPropertyDescriptors(propertyName); } - + + private DataModelPropertyDescriptor[] buildValidPlatformDescriptors() { + List platformIDs = CollectionTools.list(JpaPlatformRegistry.instance().jpaPlatformIds()); + DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[platformIDs.size()]; + for (int i = 0; i < descriptors.length; i++) { + descriptors[i] = this.buildPlatformIdDescriptor(platformIDs.get(i)); + } + return CollectionTools.sort(descriptors, this.buildDescriptorComparator()); + } + + /** + * sort the descriptors by 'description' (as opposed to 'value') + */ + private Comparator buildDescriptorComparator() { + return new Comparator() { + public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { + return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); + } + }; + } + + private DataModelPropertyDescriptor[] buildValidConnectionDescriptors() { + List connectionNames = this.buildValidConnectionNames(); + DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[connectionNames.size()]; + for (int i = 0; i < descriptors.length; i++) { + descriptors[i] = this.buildConnectionDescriptor(connectionNames.get(i)); + } + return descriptors; + } + + /** + * put a null entry at the top of the list (for ) + */ + private List buildValidConnectionNames() { + List connectionNames = CollectionTools.sort(CollectionTools.list(this.connectionProfileNames())); + connectionNames.add(0, null); + return connectionNames; + } + + private DataModelPropertyDescriptor[] buildValidDriverDescriptors() { + return new DataModelPropertyDescriptor[] { new DataModelPropertyDescriptor(this.getDriverName()) }; + } + + private DataModelPropertyDescriptor[] buildValidCatalogDescriptors() { + Database db = this.getDatabase(); + return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidCatalogNames(db)); + } + + /** + * pre-condition: 'db' is not null + */ + private List buildValidCatalogNames(Database db) { + return this.buildValidStrings(db.sortedCatalogIdentifiers(), this.getDefaultCatalogName()); + } + + private DataModelPropertyDescriptor[] buildValidSchemaDescriptors() { + Database db = this.getDatabase(); + return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidSchemaNames()); + } + + private List buildValidSchemaNames() { + return this.buildValidStrings(this.schemaNames(), this.getDefaultSchemaName()); + } + + private Iterator schemaNames() { + SchemaContainer sc = this.getSchemaContainer(); + return (sc == null) ? EmptyIterator.instance() : sc.sortedSchemaIdentifiers(); + } + + /** + * put an entry for the default at the top of the list + */ + private List buildValidStrings(Iterator stream, String defaultString) { + List strings = CollectionTools.list(stream); + if ((defaultString != null) && ! strings.contains(defaultString)) { + strings.add(0, defaultString); + } + return strings; + } + + private DataModelPropertyDescriptor[] buildDescriptors(List strings) { + DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[strings.size()]; + for (int i = 0; i < descriptors.length; i++) { + descriptors[i] = new DataModelPropertyDescriptor(strings.get(i)); + } + return descriptors; + } + + private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; + + /** + * platform and connection have 'description's (in addition to 'value's) + */ @Override public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { if (propertyName.equals(PLATFORM_ID)) { - return platformIdPropertyDescriptor(getStringProperty(PLATFORM_ID)); + return this.buildPlatformIdDescriptor(this.getPlatformId()); } if (propertyName.equals(CONNECTION)) { - return connectionPropertyDescriptor(getStringProperty(CONNECTION)); + return this.buildConnectionDescriptor(this.getConnectionName()); } return super.getPropertyDescriptor(propertyName); } - - DataModelPropertyDescriptor platformIdPropertyDescriptor(String platformId) { - return new DataModelPropertyDescriptor( - platformId, JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId)); + + DataModelPropertyDescriptor buildPlatformIdDescriptor(String platformId) { + return new DataModelPropertyDescriptor(platformId, this.getPlatformLabel(platformId)); } - - DataModelPropertyDescriptor connectionPropertyDescriptor(String connection) { - return StringTools.stringIsEmpty(connection) ? - new DataModelPropertyDescriptor(null, JptCoreMessages.NONE) - : - new DataModelPropertyDescriptor(connection); + + private String getPlatformLabel(String platformId) { + return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId); } - @Override - public IStatus validate(String name) { - if (name.equals(PLATFORM_ID)) { - return this.validatePlatformId(this.getStringProperty(name)); - } - if (name.equals(LIBRARY_PROVIDER_DELEGATE)) { - LibraryInstallDelegate delegate = (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE); - return delegate.validate(); - } - if (name.equals(CONNECTION)) { - return this.validateConnectionName(this.getStringProperty(name)); - } - if (name.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) - || name.equals(DB_DRIVER_NAME)) { - return this.validateDbDriverName(); - } - if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) - || name.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return this.validateUserOverrideDefaultCatalog(); - } - if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) - || name.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return this.validateUserOverrideDefaultSchema(); - } - if (name.equals(DISCOVER_ANNOTATED_CLASSES)) { - return this.validatePersistentClassManagement(this.getBooleanProperty(name)); - } - - return super.validate(name); + private DataModelPropertyDescriptor buildConnectionDescriptor(String connectionName) { + String description = (connectionName == null) ? JptCoreMessages.NONE : null; + return new DataModelPropertyDescriptor(connectionName, description); } - private IRuntime runtime() { - return (IRuntime) this.getProperty(RUNTIME); + + // ********** database ********** + + private SchemaContainer getSchemaContainer() { + return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); } - private boolean runtimeSupportsEjb30(IRuntime runtime) { - IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ - return (runtime == null) ? false : runtime.supports(ejb30); + private Catalog getCatalog() { + String name = this.getUserOverrideDefaultCatalog(); + return (name == null) ? null : this.getCatalog(name); } - - private String getPlatformId() { - return this.getStringProperty(PLATFORM_ID); + + /** + * pre-condition: 'name' is not null + */ + private Catalog getCatalog(String name) { + Database db = this.getDatabase(); + return (db == null) ? null : db.getCatalogForIdentifier(name); + } + + private boolean databaseSupportsCatalogs() { + Database db = this.getDatabase(); + return (db != null) && db.supportsCatalogs(); } - private LibraryInstallDelegate getLibraryInstallDelegate() { - return (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE); + private Database getDatabase() { + ConnectionProfile cp = this.getConnectionProfile(); + return (cp == null) ? null : cp.getDatabase(); } - private String getConnectionName() { - return this.getStringProperty(CONNECTION); + private boolean connectionIsActive() { + ConnectionProfile cp = this.getConnectionProfile(); + return (cp != null) && cp.isActive(); } - + private ConnectionProfile getConnectionProfile() { - return this.buildConnectionProfile(this.getConnectionName()); + String name = this.getConnectionName(); + return (name == null) ? null : this.getConnectionProfile(name); } - private ConnectionProfileFactory getConnectionProfileFactory() { - // we don't have a JPA project yet, so go to the db plug-in directly to get the factory - return JptDbPlugin.instance().getConnectionProfileFactory(); + /** + * pre-condition: 'name' is not null + */ + private ConnectionProfile getConnectionProfile(String name) { + if (this.cachedConnectionProfileIsStale(name)) { + this.connectionProfile = this.buildConnectionProfile(name); + } + return this.connectionProfile; } - private ConnectionProfile buildConnectionProfile(String name) { - return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); + private boolean cachedConnectionProfileIsStale(String name) { + return (this.connectionProfile == null) || ! this.connectionProfile.getName().equals(name); } - private boolean connectionIsActive() { - return this.connectionIsActive(this.getConnectionName()); + private ConnectionProfile buildConnectionProfile(String name) { + return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); } - private boolean connectionIsActive(String connectionName) { - ConnectionProfile cp = this.buildConnectionProfile(connectionName); - return (cp != null) && cp.isActive(); + private Iterator connectionProfileNames() { + return this.getConnectionProfileFactory().connectionProfileNames(); } - private Iterator connectionNames() { - String setValue = getStringProperty(CONNECTION); - - List connectionNames = CollectionTools.sort(CollectionTools.list( - this.getConnectionProfileFactory().connectionProfileNames())); - - if (! StringTools.stringIsEmpty(setValue) && ! connectionNames.contains(setValue)) { - return new CompositeIterator(setValue, connectionNames.iterator()); - } - return connectionNames.iterator(); + private ConnectionProfileFactory getConnectionProfileFactory() { + // we don't have a JPA project yet, so go to the db plug-in directly to get the factory + return JptDbPlugin.instance().getConnectionProfileFactory(); } - - private List buildSortedCatalogNames() { - ConnectionProfile cp = this.getConnectionProfile(); - if (cp == null) { - return Collections.emptyList(); + + + // ********** validation ********** + + @Override + public IStatus validate(String propertyName) { + if (propertyName.equals(PLATFORM_ID)) { + return this.validatePlatformId(); } - Database db = cp.getDatabase(); - if (db == null) { - return Collections.emptyList(); + if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { + return this.getLibraryInstallDelegate().validate(); } - return CollectionTools.list(db.sortedCatalogIdentifiers()); - } - - private Iterator catalogNames() { - String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG); - List catalogNames = this.buildSortedCatalogNames(); - - if (StringTools.stringIsEmpty(setValue) || catalogNames.contains(setValue)) { - return catalogNames.iterator(); + if (propertyName.equals(CONNECTION)) { + return this.validateConnection(); } - return new CompositeIterator(setValue, catalogNames.iterator()); - } - - private List buildSortedSchemaNames() { - ConnectionProfile cp = this.getConnectionProfile(); - if (cp == null) { - return Collections.emptyList(); + if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) + || propertyName.equals(DB_DRIVER_NAME)) { + return this.validateDbDriverName(); } - Database db = cp.getDatabase(); - if (db == null) { - return Collections.emptyList(); + if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) + || propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { + return this.validateUserOverrideDefaultCatalog(); } - return CollectionTools.list(db.sortedSchemaIdentifiers()); // use identifiers? names seem OK since combo-box is read-only? - } - - private Iterator schemaNames() { - String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA); - List schemaNames = this.buildSortedSchemaNames(); - - if (StringTools.stringIsEmpty(setValue) || schemaNames.contains(setValue)) { - return schemaNames.iterator(); + if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) + || propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { + return this.validateUserOverrideDefaultSchema(); + } + if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { + return this.validatePersistentClassManagement(); } - return new CompositeIterator(setValue, schemaNames.iterator()); - } - - private Iterator driverNames() { - String setValue = getStringProperty(DB_DRIVER_NAME); - return new CompositeIterator(setValue, EmptyIterator. instance()); + return super.validate(propertyName); } - - // ********** validation ********** - - private IStatus validatePlatformId(String platformId) { - return StringTools.stringIsEmpty(platformId) ? - PLATFORM_NOT_SPECIFIED_STATUS - : - OK_STATUS; + private IStatus validatePlatformId() { + return (this.getPlatformId() == null) ? PLATFORM_NOT_SPECIFIED_STATUS : OK_STATUS; } - private IStatus validateConnectionName(String connectionName) { - if (StringTools.stringIsEmpty(connectionName)) { - return OK_STATUS; - } - ConnectionProfile connectionProfile = getConnectionProfile(); - if (connectionProfile == null) { - return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); + private IStatus validateConnection() { + String connectionName = this.getConnectionName(); + return (connectionName == null) ? OK_STATUS : this.validateNonNullConnection(connectionName); + } + private IStatus validateNonNullConnection(String connectionName) { + ConnectionProfile cp = this.getConnectionProfile(connectionName); + if (cp == null) { + return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); } - if (! connectionProfile.isActive()) { + if ( ! cp.isActive()) { return CONNECTION_NOT_CONNECTED_STATUS; } return OK_STATUS; } + private IStatus validateDbDriverName() { + return OK_STATUS; + } + private IStatus validateUserOverrideDefaultCatalog() { - if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { - if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG))) { + if (this.userWantsToOverrideDefaultCatalog()) { + if (this.getUserOverrideDefaultCatalog() == null) { return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS; } } @@ -572,23 +691,20 @@ } private IStatus validateUserOverrideDefaultSchema() { - if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA))) { + if (this.userWantsToOverrideDefaultSchema()) { + if (this.getUserOverrideDefaultSchema() == null) { return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; } } return OK_STATUS; } - private IStatus validatePersistentClassManagement(boolean discoverAnnotatedClasses) { + private IStatus validatePersistentClassManagement() { + @SuppressWarnings("unused") boolean discoverAnnotatedClasses = this.discoverAnnotatedClasses(); // TODO warning if "discovery" is used, but no runtime specified ?? return OK_STATUS; } - private IStatus validateDbDriverName() { - return OK_STATUS; - } - // ********** static methods ********** @@ -596,9 +712,9 @@ return buildStatus(IStatus.INFO, message); } - private static IStatus buildWarningStatus(String message) { - return buildStatus(IStatus.WARNING, message); - } +// private static IStatus buildWarningStatus(String message) { +// return buildStatus(IStatus.WARNING, message); +// } private static IStatus buildErrorStatus(String message) { return buildStatus(IStatus.ERROR, message); @@ -607,4 +723,5 @@ private static IStatus buildStatus(int severity, String message) { return new Status(severity, JptCorePlugin.PLUGIN_ID, message); } + } Index: src/org/eclipse/jpt/core/internal/GenericJpaModel.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java,v retrieving revision 1.22 diff -u -r1.22 GenericJpaModel.java --- src/org/eclipse/jpt/core/internal/GenericJpaModel.java 18 May 2009 21:07:30 -0000 1.22 +++ src/org/eclipse/jpt/core/internal/GenericJpaModel.java 26 May 2009 13:39:10 -0000 @@ -131,6 +131,7 @@ config.setProject(project); config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); + config.setUserOverrideDefaultCatalogName(JptCorePlugin.getUserOverrideDefaultCatalogName(project)); config.setUserOverrideDefaultSchemaName(JptCorePlugin.getUserOverrideDefaultSchemaName(project)); config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project)); return config;