[286797] problems with MS SQL Server/Sybase "catalogs"
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java
index 23d50e8..dafa62f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java
@@ -394,6 +394,8 @@
}
else if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, this.getDefaultSchemaName());
+ this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG);
+ this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG);
}
else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG);
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java
index 9de6b76..d42d994 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java
@@ -54,6 +54,17 @@
}
/**
+ * SQL Server will use the user-requested database; if that database is not
+ * found, it will default to 'master'.
+ */
+ @Override
+ void addDefaultCatalogIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) {
+ identifiers.add(database.getName());
+ identifiers.add(MASTER_CATALOG_IDENTIFIER);
+ }
+ private static final String MASTER_CATALOG_IDENTIFIER = "master"; //$NON-NLS-1$
+
+ /**
* The default schema on SQL Server for any database (catalog) is 'dbo'.
*/
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java
index 8dcfcba..a28a9b5 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java
@@ -58,6 +58,17 @@
}
/**
+ * Sybase will use the user-requested database; if that database is not
+ * found, it will default to 'master'.
+ */
+ @Override
+ void addDefaultCatalogIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) {
+ identifiers.add(database.getName());
+ identifiers.add(MASTER_CATALOG_IDENTIFIER);
+ }
+ private static final String MASTER_CATALOG_IDENTIFIER = "master"; //$NON-NLS-1$
+
+ /**
* The typical default schema on Sybase for any database (catalog) is
* 'dbo'.
*
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java
index 4b459e9..a735eac 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseSchemaWizardPage.java
@@ -240,6 +240,10 @@
return DatabaseSchemaWizardPage.this.jpaProject.getDefaultDbSchema();
}
+ private SchemaContainer getDefaultSchemaContainer() {
+ return DatabaseSchemaWizardPage.this.jpaProject.getDefaultDbSchemaContainer();
+ }
+
/**
* called at start-up and when the selected connection profile changes
*/
@@ -278,7 +282,7 @@
}
private Iterator<String> getSchemata() {
- SchemaContainer sc = DatabaseSchemaWizardPage.this.jpaProject.getDefaultDbSchemaContainer();
+ SchemaContainer sc = this.getDefaultSchemaContainer();
return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers();
}
@@ -286,7 +290,7 @@
void selectedSchemaChanged() {
Schema old = this.selectedSchema;
- this.selectedSchema = this.getJpaProjectConnectionProfile().getDatabase().getSchemaForIdentifier(this.schemaComboBox.getText());
+ this.selectedSchema = this.getDefaultSchemaContainer().getSchemaNamed(this.schemaComboBox.getText());
if (this.selectedSchema != old) {
DatabaseSchemaWizardPage.this.fireSchemaChanged(this.selectedSchema);
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java
index 8a030c1..3f4dd5c 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/DatabaseGroup.java
@@ -25,15 +25,16 @@
import org.eclipse.jpt.db.ConnectionAdapter;
import org.eclipse.jpt.db.ConnectionListener;
import org.eclipse.jpt.db.ConnectionProfile;
-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.CommonImages;
import org.eclipse.jpt.ui.JptUiPlugin;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
+import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -169,13 +170,8 @@
* called at start-up and when the selected connection profile changes
*/
private Schema getDefaultSchema() {
- try{
return (this.selectedConnectionProfile == this.getJpaProjectConnectionProfile()) ?
jpaProject.getDefaultDbSchema() : null;
- }catch(Exception e ){
- e.printStackTrace();
- }
- return null;
}
/**
@@ -213,7 +209,7 @@
*/
private void updateSchemaComboBox() {
this.schemaComboBox.removeAll();
- for (Iterator<String> stream = this.getSchemata(); stream.hasNext(); ) {
+ for (Iterator<String> stream = this.schemaNames(); stream.hasNext(); ) {
this.schemaComboBox.add(stream.next());
}
// the current schema *should* be in the current connection profile
@@ -222,15 +218,20 @@
}
}
- private Iterator<String> getSchemata() {
- ConnectionProfile profile = this.getSelectedConnectionProfile();
- if( profile == null )
- return EmptyIterator.<String>instance() ;
- Database db = profile.getDatabase();
- if ( db == null)
- return EmptyIterator.<String>instance() ;
- Iterator<String> ret = db.sortedSchemaIdentifiers();
- return ret;
+ private Iterator<String> schemaNames() {
+ SchemaContainer sc = this.jpaProject.getDefaultDbSchemaContainer();
+ // use schema *names* since the combo-box is read-only
+ return (sc != null) ? this.sortedSchemaNames(sc) : EmptyIterator.<String>instance();
+ }
+
+ private Iterator<String> sortedSchemaNames(SchemaContainer sc) {
+ // the schemata are already sorted
+ return new TransformationIterator<Schema, String>(sc.schemata()) {
+ @Override
+ protected String transform(Schema next) {
+ return next.getName();
+ }
+ };
}
/**
@@ -279,7 +280,7 @@
void selectedSchemaChanged() {
Schema old = this.selectedSchema;
- this.selectedSchema = this.selectedConnectionProfile.getDatabase().getSchemaForIdentifier(this.schemaComboBox.getText());
+ this.selectedSchema = this.jpaProject.getDefaultDbSchemaContainer().getSchemaNamed(this.schemaComboBox.getText());
if (this.selectedSchema != old) {
fireSchemaChanged(this.selectedSchema);
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java
index a08a9d3..3d419c2 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/gen/TablesSelectorWizardPage.java
@@ -217,7 +217,8 @@
doStatusUpdate();
return;
}
- jpaProject.setUserOverrideDefaultSchema(schema.getName());
+ // store the *identifier* in the JPA project, since it gets put in Java annotations
+ jpaProject.setUserOverrideDefaultSchema(schema.getIdentifier());
setSchema( schema );
updateTablesSelector(schema);
doStatusUpdate();