diff options
author | bvosburgh | 2012-07-20 21:13:33 +0000 |
---|---|---|
committer | bvosburgh | 2012-07-20 21:13:33 +0000 |
commit | 33ce0e09289fb4089f5f2eb1063d1e41617694c0 (patch) | |
tree | e2354cf30fd6b1671e790e31477b4edb60a82a2c /jpa | |
parent | 088c089a4448cc59f173d06b0bc5b8fafb4c8349 (diff) | |
download | webtools.dali-33ce0e09289fb4089f5f2eb1063d1e41617694c0.tar.gz webtools.dali-33ce0e09289fb4089f5f2eb1063d1e41617694c0.tar.xz webtools.dali-33ce0e09289fb4089f5f2eb1063d1e41617694c0.zip |
[379458] fix listener leak
Diffstat (limited to 'jpa')
15 files changed, 303 insertions, 318 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseObject.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseObject.java index e20a54084b..21110a469b 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseObject.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseObject.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. + * Copyright (c) 2008, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,7 +10,9 @@ package org.eclipse.jpt.jpa.db; import java.util.Comparator; +import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.Transformer; +import org.eclipse.jpt.common.utility.internal.TransformerAdapter; import com.ibm.icu.text.Collator; /** @@ -63,40 +65,46 @@ public interface DatabaseObject { */ ConnectionProfile getConnectionProfile(); + /** + * Refresh the database object's state from the underlying database server, + * if appropriate. + */ + void refresh(); + /** * Sort by name. */ - Comparator<DatabaseObject> DEFAULT_COMPARATOR = - new Comparator<DatabaseObject>() { - public int compare(DatabaseObject dbObject1, DatabaseObject dbObject2) { - return Collator.getInstance().compare(dbObject1.getName(), dbObject2.getName()); - } - @Override - public String toString() { - return this.getClass().getEnclosingClass().getSimpleName() + ".DEFAULT_COMPARATOR"; //$NON-NLS-1$ - } - }; + Comparator<DatabaseObject> DEFAULT_COMPARATOR = new DefaultComparator(); + class DefaultComparator + implements Comparator<DatabaseObject> + { + public int compare(DatabaseObject dbObject1, DatabaseObject dbObject2) { + return Collator.getInstance().compare(dbObject1.getName(), dbObject2.getName()); + } + @Override + public String toString() { + return StringTools.buildToStringFor(this); + } + } - Transformer<DatabaseObject, String> NAME_TRANSFORMER = - new Transformer<DatabaseObject, String>() { - public String transform(DatabaseObject dbObject) { - return dbObject.getName(); - } - @Override - public String toString() { - return this.getClass().getEnclosingClass().getSimpleName() + ".NAME_TRANSFORMER"; //$NON-NLS-1$ - } - }; + Transformer<DatabaseObject, String> NAME_TRANSFORMER = new NameTransformer(); + class NameTransformer + extends TransformerAdapter<DatabaseObject, String> + { + @Override + public String transform(DatabaseObject dbObject) { + return dbObject.getName(); + } + } - Transformer<DatabaseObject, String> IDENTIFIER_TRANSFORMER = - new Transformer<DatabaseObject, String>() { - public String transform(DatabaseObject dbObject) { - return dbObject.getIdentifier(); - } - @Override - public String toString() { - return this.getClass().getEnclosingClass().getSimpleName() + ".IDENTIFIER_TRANSFORMER"; //$NON-NLS-1$ - } - }; + Transformer<DatabaseObject, String> IDENTIFIER_TRANSFORMER = new IdentifierTransformer(); + class IdentifierTransformer + extends TransformerAdapter<DatabaseObject, String> + { + @Override + public String transform(DatabaseObject dbObject) { + return dbObject.getIdentifier(); + } + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Schema.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Schema.java index 9ae336fe27..08405cec86 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Schema.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Schema.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. + * Copyright (c) 2008, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -95,8 +95,4 @@ public interface Schema * @see #getSortedSequenceIdentifiers() */ Sequence getSequenceForIdentifier(String identifier); - - // ********** sequences ********** - - void refresh(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPCatalogWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPCatalogWrapper.java index 8773036640..60271ff2e7 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPCatalogWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPCatalogWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. + * Copyright (c) 2007, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,37 +10,23 @@ package org.eclipse.jpt.jpa.db.internal; import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.jpt.jpa.db.Catalog; /** * Wrap a DTP Catalog */ final class DTPCatalogWrapper - extends DTPSchemaContainerWrapper<DTPDatabaseWrapper> + extends DTPSchemaContainerWrapper<DTPDatabaseWrapper, org.eclipse.datatools.modelbase.sql.schema.Catalog> implements Catalog { - /** the wrapped DTP catalog */ - private final org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog; - - - // ********** constructor ********** - DTPCatalogWrapper(DTPDatabaseWrapper database, org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) { - super(database); - this.dtpCatalog = dtpCatalog; + super(database, dtpCatalog); } // ********** DTPDatabaseObjectWrapper implementation ********** @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpCatalog; - } - - @Override synchronized void catalogObjectChanged() { super.catalogObjectChanged(); this.getConnectionProfile().catalogChanged(this); @@ -52,7 +38,7 @@ final class DTPCatalogWrapper @Override @SuppressWarnings("unchecked") List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemas() { - return this.dtpCatalog.getSchemas(); + return this.dtpObject.getSchemas(); } @Override @@ -80,17 +66,9 @@ final class DTPCatalogWrapper } - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpCatalog.getName(); - } - - // ********** internal methods ********** boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Catalog catalog) { - return this.dtpCatalog == catalog; + return this.dtpObject == catalog; } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPColumnWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPColumnWrapper.java index 4613cab63f..7bf497f931 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPColumnWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPColumnWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.db.internal; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.datatools.modelbase.dbdefinition.PredefinedDataTypeDefinition; import org.eclipse.datatools.modelbase.sql.datatypes.CharacterStringDataType; import org.eclipse.datatools.modelbase.sql.datatypes.DataType; @@ -23,32 +22,20 @@ import org.eclipse.jpt.common.utility.internal.SimpleJavaType; import org.eclipse.jpt.jpa.db.Column; /** - * Wrap a DTP Column + * Wrap a DTP Column */ final class DTPColumnWrapper - extends DTPDatabaseObjectWrapper<DTPTableWrapper> + extends DTPDatabaseObjectWrapper<DTPTableWrapper, org.eclipse.datatools.modelbase.sql.tables.Column> implements Column { - /** the wrapped DTP column */ - private final org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn; - - - // ********** constructor ********** - DTPColumnWrapper(DTPTableWrapper table, org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - super(table); - this.dtpColumn = dtpColumn; + super(table, dtpColumn); } // ********** DTPDatabaseObjectWrapper implementation ********** @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpColumn; - } - - @Override synchronized void catalogObjectChanged() { super.catalogObjectChanged(); this.getConnectionProfile().columnChanged(this); @@ -57,10 +44,6 @@ final class DTPColumnWrapper // ********** Column implementation ********** - public String getName() { - return this.dtpColumn.getName(); - } - public DTPTableWrapper getTable() { return this.parent; } @@ -74,45 +57,45 @@ final class DTPColumnWrapper } public boolean isPartOfUniqueConstraint() { - return this.dtpColumn.isPartOfUniqueConstraint(); + return this.dtpObject.isPartOfUniqueConstraint(); } public boolean isNullable() { - return this.dtpColumn.isNullable(); + return this.dtpObject.isNullable(); } public String getDataTypeName() { - DataType dataType = this.dtpColumn.getDataType(); + DataType dataType = this.dtpObject.getDataType(); return (dataType == null) ? null : dataType.getName(); } public boolean isNumeric() { - return this.dtpColumn.getDataType() instanceof NumericalDataType; + return this.dtpObject.getDataType() instanceof NumericalDataType; } public int getPrecision() { - DataType dataType = this.dtpColumn.getDataType(); + DataType dataType = this.dtpObject.getDataType(); return (dataType instanceof NumericalDataType) ? ((NumericalDataType) dataType).getPrecision() : -1; } public int getScale(){ - DataType dataType = this.dtpColumn.getDataType(); + DataType dataType = this.dtpObject.getDataType(); return (dataType instanceof ExactNumericDataType) ? ((ExactNumericDataType) dataType).getScale() : -1; } public int getLength() { - DataType dataType = this.dtpColumn.getDataType(); + DataType dataType = this.dtpObject.getDataType(); return (dataType instanceof CharacterStringDataType) ? ((CharacterStringDataType) dataType).getLength() : -1; } public boolean isLOB() { - DataType dataType = this.dtpColumn.getDataType(); + DataType dataType = this.dtpObject.getDataType(); return (dataType instanceof PredefinedDataType) ? primitiveTypeIsLob(((PredefinedDataType) dataType).getPrimitiveType()) : false; @@ -123,7 +106,7 @@ final class DTPColumnWrapper } public JavaType getJavaType() { - DataType dataType = this.dtpColumn.getDataType(); + DataType dataType = this.dtpObject.getDataType(); return (dataType instanceof PredefinedDataType) ? convertToJPAJavaType(this.getJavaType((PredefinedDataType) dataType)) : DEFAULT_JAVA_TYPE; @@ -151,7 +134,7 @@ final class DTPColumnWrapper // ********** internal methods ********** boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Column column) { - return this.dtpColumn == column; + return this.dtpObject == column; } @Override @@ -231,5 +214,4 @@ final class DTPColumnWrapper private static final JavaType BIG_DECIMAL_JAVA_TYPE = new SimpleJavaType(java.math.BigDecimal.class); private static final JavaType LONG_JAVA_TYPE = new SimpleJavaType(long.class); - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java index f07551a360..e5e19b170f 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java @@ -112,6 +112,12 @@ final class DTPConnectionProfileWrapper return this.database; } + public synchronized void refresh() { + if (this.database != null) { // don't trigger database creation + this.database.refresh(); + } + } + // ********** ConnectionProfile implementation ********** @@ -288,7 +294,11 @@ final class DTPConnectionProfileWrapper } private DTPDatabaseWrapper buildDatabase() { - return this.isInactive() ? null : new DTPDatabaseWrapper(this, this.buildDTPDatabase()); + return this.isInactive() ? null : this.buildDatabase_(); + } + + private DTPDatabaseWrapper buildDatabase_() { + return new DTPDatabaseWrapper(this, this.buildDTPDatabase()); } private org.eclipse.datatools.modelbase.sql.schema.Database buildDTPDatabase() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObjectWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObjectWrapper.java index d498e152f2..78d7a5fd61 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObjectWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObjectWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.db.internal; import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObjectListener; import org.eclipse.datatools.connectivity.sqm.core.rte.RefreshManager; +import org.eclipse.datatools.modelbase.sql.schema.SQLObject; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.jpa.db.DatabaseObject; import org.eclipse.jpt.jpa.db.internal.driver.DTPDriverAdapter; @@ -19,27 +20,32 @@ import org.eclipse.jpt.jpa.db.internal.driver.DTPDriverAdapter; /** * DTP Object Wrapper base class */ -abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> +abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject, S extends SQLObject> implements DTPDatabaseObject { /** we need a way to get to the connection profile */ final P parent; - /** listen for the "catalog object" being refreshed */ + /** the wrapped DTP SQL object */ + final S dtpObject; + + /** listen for the "catalog object" to be refreshed */ private final ICatalogObjectListener catalogObjectListener; // ********** constructor ********** - DTPDatabaseObjectWrapper(P parent) { + DTPDatabaseObjectWrapper(P parent, S dtpObject) { super(); this.parent = parent; - if (this.getConnectionProfile().isConnected()) { + this.dtpObject = dtpObject; + ICatalogObject catalogObject = this.getCatalogObject(); + if ((catalogObject != null) && this.getConnectionProfile().isConnected()) { // we only listen to "live" connections (as opposed to "off-line" connections); // and the model is rebuilt when the connection connects or disconnects this.catalogObjectListener = this.buildCatalogObjectListener(); if (this.getConnectionProfile().hasAnyListeners()) { - this.startListening(); + this.startListening(catalogObject); } } else { this.catalogObjectListener = null; @@ -49,6 +55,10 @@ abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> // ********** names vs. identifiers ********** + public String getName() { + return this.dtpObject.getName(); + } + /** * Examples:<ul> * <li>Oracle etc.<ul><code> @@ -71,7 +81,7 @@ abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> * </code></ul> * </ul> */ - public String getIdentifier(String defaultName) { + public final String getIdentifier(String defaultName) { return this.getDTPDriverAdapter().convertNameToIdentifier(this.getName(), defaultName); } @@ -107,10 +117,13 @@ abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> * </code></ul> * </ul> */ - public String getIdentifier() { + public final String getIdentifier() { return this.convertNameToIdentifier(this.getName()); } + /** + * @see DTPDatabaseWrapper#convertNameToIdentifier(String) + */ String convertNameToIdentifier(String name) { return this.getDTPDriverAdapter().convertNameToIdentifier(name); } @@ -119,20 +132,29 @@ abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> // ********** DTP database object listener ********** private ICatalogObjectListener buildCatalogObjectListener() { - return new ICatalogObjectListener() { - public void notifyChanged(ICatalogObject dmElement, int eventType) { - if (dmElement == DTPDatabaseObjectWrapper.this.getCatalogObject()) { - // 'eventType' doesn't seem to be very useful, so drop it - DTPDatabaseObjectWrapper.this.catalogObjectChanged(); - } - } - }; + return new CatalogObjectListener(); + } + + /* CU private */ class CatalogObjectListener + implements ICatalogObjectListener + { + public void notifyChanged(ICatalogObject dmElement, int eventType) { + // 'eventType' doesn't seem to be very useful, so drop it + DTPDatabaseObjectWrapper.this.catalogObjectChanged(); + } + @Override + public String toString() { + return StringTools.buildToStringFor(this); + } } /** - * Typically, return the wrapped DTP database object. + * Return the wrapped DTP database object if it is a DTP "catalog" object; + * otherwise, return <code>null</code>. */ - abstract ICatalogObject getCatalogObject(); + final ICatalogObject getCatalogObject() { + return (this.dtpObject instanceof ICatalogObject) ? (ICatalogObject) this.dtpObject : null; + } /** * Typically, a subclass will override this method to @@ -149,16 +171,35 @@ abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> */ abstract void clear(); - // this should only be called when the connection profile is "live" and has listeners + /** + * This should only be called when the connection profile is "live" and has + * listeners. + */ void startListening() { - this.checkListener(); - RefreshManager.getInstance().AddListener(this.getCatalogObject(), this.catalogObjectListener); + ICatalogObject catalogObject = this.getCatalogObject(); + if (catalogObject != null) { + this.checkListener(); + this.startListening(catalogObject); + } } - // this should only be called when the connection profile is "live" and has no listeners + /** + * Pre-conditions: catalog listener and object are both present + */ + private void startListening(ICatalogObject catalogObject) { + RefreshManager.getInstance().AddListener(catalogObject, this.catalogObjectListener); + } + + /** + * This should only be called when the connection profile is "live" and has + * no listeners. + */ void stopListening() { - this.checkListener(); - RefreshManager.getInstance().removeListener(this.getCatalogObject(), this.catalogObjectListener); + ICatalogObject catalogObject = this.getCatalogObject(); + if (catalogObject != null) { + this.checkListener(); + RefreshManager.getInstance().removeListener(catalogObject, this.catalogObjectListener); + } } /** @@ -175,14 +216,27 @@ abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> // ********** misc ********** - public DTPConnectionProfileWrapper getConnectionProfile() { + /** + * @see DTPConnectionProfileWrapper#getConnectionProfile() + */ + public final DTPConnectionProfileWrapper getConnectionProfile() { return this.parent.getConnectionProfile(); } + /** + * @see DTPDatabaseWrapper#getDatabase() + */ public DTPDatabaseWrapper getDatabase() { return this.parent.getDatabase(); } + public final void refresh() { + ICatalogObject catalogObject = this.getCatalogObject(); + if (catalogObject != null) { + catalogObject.refresh(); + } + } + DTPDriverAdapter getDTPDriverAdapter() { return this.getDatabase().getDTPDriverAdapter(); } @@ -190,7 +244,7 @@ abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> /** * Convenience method. */ - <T extends DatabaseObject> T selectDatabaseObjectNamed(Iterable<T> databaseObjects, String name) { + final <T extends DatabaseObject> T selectDatabaseObjectNamed(Iterable<T> databaseObjects, String name) { for (T databaseObject : databaseObjects) { if (databaseObject.getName().equals(name)) { return databaseObject; diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseWrapper.java index ed7d51577a..dd5b6ae191 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -11,9 +11,7 @@ package org.eclipse.jpt.jpa.db.internal; import java.util.Iterator; import java.util.List; - import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.CollectionTools; @@ -58,12 +56,9 @@ import org.eclipse.jpt.jpa.db.internal.driver.DTPDriverAdapterManager; * be case-insensitive). */ final class DTPDatabaseWrapper - extends DTPSchemaContainerWrapper<DTPConnectionProfileWrapper> + extends DTPSchemaContainerWrapper<DTPConnectionProfileWrapper, org.eclipse.datatools.modelbase.sql.schema.Database> implements Database { - /** the wrapped DTP database */ - private final org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase; - /** database-specific behavior */ private final DTPDriverAdapter dtpDriverAdapter; @@ -74,19 +69,13 @@ final class DTPDatabaseWrapper // ********** constructor ********** DTPDatabaseWrapper(DTPConnectionProfileWrapper connectionProfile, org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase) { - super(connectionProfile); - this.dtpDatabase = dtpDatabase; + super(connectionProfile, dtpDatabase); this.dtpDriverAdapter = DTPDriverAdapterManager.instance().buildAdapter(this.getVendorName(), this); } // ********** DTPDatabaseObjectWrapper implementation ********** - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpDatabase; - } - /* TODO * We might want to listen to the "virtual" catalog; but that's probably * not necessary since there is no easy way for the user to refresh it @@ -267,7 +256,10 @@ final class DTPDatabaseWrapper // ********** names vs. identifiers ********** - // override to make method public since it's in the Database interface + /** + * Override to make method public since it's in the {@link Database} + * interface. + */ @Override public String convertNameToIdentifier(String name) { return super.convertNameToIdentifier(name); @@ -277,19 +269,15 @@ final class DTPDatabaseWrapper // ********** misc ********** public org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase() { - return this.dtpDatabase; - } - - public String getName() { - return this.dtpDatabase.getName(); + return this.dtpObject; } public String getVendorName() { - return this.dtpDatabase.getVendor(); + return this.dtpObject.getVendor(); } public String getVersion() { - return this.dtpDatabase.getVersion(); + return this.dtpObject.getVersion(); } @Override @@ -303,7 +291,7 @@ final class DTPDatabaseWrapper // TODO add to interface? (so it can be used by AbstractDTPDriverAdapter) DatabaseDefinition getDTPDefinition() { - return RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(this.dtpDatabase); + return RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(this.dtpObject); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPForeignKeyWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPForeignKeyWrapper.java index 3a341c636f..b61d71da66 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPForeignKeyWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPForeignKeyWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -11,8 +11,6 @@ package org.eclipse.jpt.jpa.db.internal; import java.util.Arrays; import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.CollectionTools; import org.eclipse.jpt.common.utility.internal.StringTools; @@ -26,12 +24,9 @@ import org.eclipse.jpt.jpa.db.ForeignKey; * Wrap a DTP ForeignKey */ final class DTPForeignKeyWrapper - extends DTPDatabaseObjectWrapper<DTPTableWrapper> + extends DTPDatabaseObjectWrapper<DTPTableWrapper, org.eclipse.datatools.modelbase.sql.constraints.ForeignKey> implements ForeignKey { - /** the wrapped DTP foreign key */ - private final org.eclipse.datatools.modelbase.sql.constraints.ForeignKey dtpForeignKey; - /** lazy-initialized */ private DTPTableWrapper referencedTable; @@ -46,19 +41,13 @@ final class DTPForeignKeyWrapper // ********** constructor ********** DTPForeignKeyWrapper(DTPTableWrapper baseTable, org.eclipse.datatools.modelbase.sql.constraints.ForeignKey dtpForeignKey) { - super(baseTable); - this.dtpForeignKey = dtpForeignKey; + super(baseTable, dtpForeignKey); } // ********** DTPDatabaseObjectWrapper implementation ********** @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpForeignKey; - } - - @Override synchronized void catalogObjectChanged() { super.catalogObjectChanged(); this.getConnectionProfile().foreignKeyChanged(this); @@ -72,17 +61,13 @@ final class DTPForeignKeyWrapper // ********** ForeignKey implementation ********** - public String getName() { - return this.dtpForeignKey.getName(); - } - public DTPTableWrapper getBaseTable() { return this.parent; } public synchronized DTPTableWrapper getReferencedTable() { if (this.referencedTable == null) { - this.referencedTable = this.getBaseTable().getTable(this.dtpForeignKey.getUniqueConstraint().getBaseTable()); + this.referencedTable = this.getBaseTable().getTable(this.dtpObject.getUniqueConstraint().getBaseTable()); } return this.referencedTable; } @@ -143,13 +128,13 @@ final class DTPForeignKeyWrapper // minimize scope of suppressed warnings @SuppressWarnings("unchecked") private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPBaseColumns() { - return this.dtpForeignKey.getMembers(); + return this.dtpObject.getMembers(); } // minimize scope of suppressed warnings @SuppressWarnings("unchecked") private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPReferenceColumns() { - return this.dtpForeignKey.getUniqueConstraint().getMembers(); + return this.dtpObject.getUniqueConstraint().getMembers(); } public int getColumnPairsSize() { @@ -290,7 +275,7 @@ final class DTPForeignKeyWrapper // ********** internal methods ********** boolean wraps(org.eclipse.datatools.modelbase.sql.constraints.ForeignKey foreignKey) { - return this.dtpForeignKey == foreignKey; + return this.dtpObject == foreignKey; } @Override @@ -333,5 +318,4 @@ final class DTPForeignKeyWrapper } } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaContainerWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaContainerWrapper.java index 46d0f6a4c8..39c9147702 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaContainerWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaContainerWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,7 +10,7 @@ package org.eclipse.jpt.jpa.db.internal; import java.util.List; - +import org.eclipse.datatools.modelbase.sql.schema.SQLObject; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.CollectionTools; import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; @@ -22,8 +22,8 @@ import org.eclipse.jpt.jpa.db.SchemaContainer; /** * Coalesce behavior for a schema container (i.e. database or catalog). */ -abstract class DTPSchemaContainerWrapper<P extends DTPDatabaseObject> - extends DTPDatabaseObjectWrapper<P> +abstract class DTPSchemaContainerWrapper<P extends DTPDatabaseObject, S extends SQLObject> + extends DTPDatabaseObjectWrapper<P, S> implements SchemaContainer { /** lazy-initialized */ @@ -32,8 +32,8 @@ abstract class DTPSchemaContainerWrapper<P extends DTPDatabaseObject> // ********** constructor ********** - DTPSchemaContainerWrapper(P parent) { - super(parent); + DTPSchemaContainerWrapper(P parent, S dtpObject) { + super(parent, dtpObject); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaWrapper.java index ddc7040902..347175ae0e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -11,10 +11,8 @@ package org.eclipse.jpt.jpa.db.internal; import java.util.ArrayList; import java.util.List; - import org.eclipse.core.runtime.IProduct; import org.eclipse.core.runtime.Platform; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.datatools.modelbase.sql.tables.SQLTablesPackage; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; @@ -28,12 +26,9 @@ import org.eclipse.jpt.jpa.db.Table; * Wrap a DTP Schema */ final class DTPSchemaWrapper - extends DTPDatabaseObjectWrapper<DTPSchemaContainerWrapper<?>> + extends DTPDatabaseObjectWrapper<DTPSchemaContainerWrapper<?, ?>, org.eclipse.datatools.modelbase.sql.schema.Schema> implements Schema { - /** the wrapped DTP schema */ - private final org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema; - /** lazy-initialized */ private DTPTableWrapper[] tables; @@ -49,20 +44,14 @@ final class DTPSchemaWrapper // ********** constructor ********** - DTPSchemaWrapper(DTPSchemaContainerWrapper<?> container, org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - super(container); - this.dtpSchema = dtpSchema; + DTPSchemaWrapper(DTPSchemaContainerWrapper<?, ?> container, org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { + super(container, dtpSchema); } // ********** DTPDatabaseObjectWrapper implementation ********** @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpSchema; - } - - @Override synchronized void catalogObjectChanged() { super.catalogObjectChanged(); this.getConnectionProfile().schemaChanged(this); @@ -71,11 +60,7 @@ final class DTPSchemaWrapper // ********** Schema implementation ********** - public String getName() { - return this.dtpSchema.getName(); - } - - public DTPSchemaContainerWrapper<?> getContainer() { + public DTPSchemaContainerWrapper<?, ?> getContainer() { return this.parent; } @@ -113,7 +98,7 @@ final class DTPSchemaWrapper // minimize scope of suppressed warnings @SuppressWarnings("unchecked") private List<org.eclipse.datatools.modelbase.sql.tables.Table> getDTPTables_() { - return this.dtpSchema.getTables(); + return this.dtpObject.getTables(); } private boolean hack() { @@ -208,7 +193,7 @@ final class DTPSchemaWrapper // minimize scope of suppressed warnings @SuppressWarnings("unchecked") private List<org.eclipse.datatools.modelbase.sql.schema.Sequence> getDTPSequences() { - return this.dtpSchema.getSequences(); + return this.dtpObject.getSequences(); } public int getSequencesSize() { @@ -228,17 +213,11 @@ final class DTPSchemaWrapper return this.getDTPDriverAdapter().selectSequenceForIdentifier(this.getSequences(), identifier); } - // ***** refresh - - public void refresh() { - - this.getCatalogObject().refresh(); - } // ********** internal methods ********** boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Schema schema) { - return this.dtpSchema == schema; + return this.dtpObject == schema; } /** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSequenceWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSequenceWrapper.java index 49114e051d..6535838fcb 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSequenceWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSequenceWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,36 +9,23 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.db.internal; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.jpt.jpa.db.Sequence; /** - * Wrap a DTP Sequence + * Wrap a DTP Sequence */ final class DTPSequenceWrapper - extends DTPDatabaseObjectWrapper<DTPSchemaWrapper> + extends DTPDatabaseObjectWrapper<DTPSchemaWrapper, org.eclipse.datatools.modelbase.sql.schema.Sequence> implements Sequence { - /** the wrapped DTP sequence */ - private final org.eclipse.datatools.modelbase.sql.schema.Sequence dtpSequence; - - - // ********** constructor ********** - DTPSequenceWrapper(DTPSchemaWrapper schema, org.eclipse.datatools.modelbase.sql.schema.Sequence dtpSequence) { - super(schema); - this.dtpSequence = dtpSequence; + super(schema, dtpSequence); } // ********** DTPDatabaseObjectWrapper implementation ********** @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpSequence; - } - - @Override synchronized void catalogObjectChanged() { super.catalogObjectChanged(); this.getConnectionProfile().sequenceChanged(this); @@ -47,10 +34,6 @@ final class DTPSequenceWrapper // ********** Sequence implementation ********** - public String getName() { - return this.dtpSequence.getName(); - } - public DTPSchemaWrapper getSchema() { return this.parent; } @@ -59,12 +42,11 @@ final class DTPSequenceWrapper // ********** internal methods ********** boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Sequence sequence) { - return this.dtpSequence == sequence; + return this.dtpObject == sequence; } @Override void clear() { // no state to clear } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPTableWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPTableWrapper.java index a7a58c595f..1801370078 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPTableWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPTableWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,8 +10,6 @@ package org.eclipse.jpt.jpa.db.internal; import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.datatools.modelbase.sql.constraints.PrimaryKey; import org.eclipse.datatools.modelbase.sql.tables.BaseTable; import org.eclipse.jpt.common.utility.internal.ArrayTools; @@ -23,15 +21,12 @@ import org.eclipse.jpt.jpa.db.ForeignKey; import org.eclipse.jpt.jpa.db.Table; /** - * Wrap a DTP Table + * Wrap a DTP Table */ final class DTPTableWrapper - extends DTPDatabaseObjectWrapper<DTPSchemaWrapper> + extends DTPDatabaseObjectWrapper<DTPSchemaWrapper, org.eclipse.datatools.modelbase.sql.tables.Table> implements Table { - /** the wrapped DTP table */ - private final org.eclipse.datatools.modelbase.sql.tables.Table dtpTable; - /** lazy-initialized */ private DTPColumnWrapper[] columns; @@ -49,8 +44,7 @@ final class DTPTableWrapper // ********** constructor ********** DTPTableWrapper(DTPSchemaWrapper schema, org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - super(schema); - this.dtpTable = dtpTable; + super(schema, dtpTable); } @@ -83,7 +77,7 @@ final class DTPTableWrapper // minimize scope of suppressed warnings @SuppressWarnings("unchecked") private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPColumns() { - return this.dtpTable.getColumns(); + return this.dtpObject.getColumns(); } public int getColumnsSize() { @@ -148,10 +142,10 @@ final class DTPTableWrapper } private DTPColumnWrapper[] buildPrimaryKeyColumnArray() { - if ( ! (this.dtpTable instanceof BaseTable)) { + if ( ! (this.dtpObject instanceof BaseTable)) { return EMPTY_COLUMNS; } - PrimaryKey pk = ((BaseTable) this.dtpTable).getPrimaryKey(); + PrimaryKey pk = ((BaseTable) this.dtpObject).getPrimaryKey(); if (pk == null) { // no PK was defined return EMPTY_COLUMNS; @@ -193,7 +187,7 @@ final class DTPTableWrapper } private DTPForeignKeyWrapper[] buildForeignKeyArray() { - if ( ! (this.dtpTable instanceof BaseTable)) { + if ( ! (this.dtpObject instanceof BaseTable)) { return EMPTY_FOREIGN_KEYS; } List<org.eclipse.datatools.modelbase.sql.constraints.ForeignKey> dtpForeignKeys = this.getDTPForeignKeys(); @@ -206,7 +200,7 @@ final class DTPTableWrapper @SuppressWarnings("unchecked") private List<org.eclipse.datatools.modelbase.sql.constraints.ForeignKey> getDTPForeignKeys() { - return ((BaseTable) this.dtpTable).getForeignKeys(); + return ((BaseTable) this.dtpObject).getForeignKeys(); } public int getForeignKeysSize() { @@ -301,15 +295,6 @@ final class DTPTableWrapper return this.parent; } - public String getName() { - return this.dtpTable.getName(); - } - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpTable; - } - @Override synchronized void catalogObjectChanged() { super.catalogObjectChanged(); @@ -317,7 +302,7 @@ final class DTPTableWrapper } boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Table table) { - return this.dtpTable == table; + return this.dtpObject == table; } /** diff --git a/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/DTPPlatformTests.java b/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/DTPPlatformTests.java index 6cb7b60962..f4ab0aaf7e 100644 --- a/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/DTPPlatformTests.java +++ b/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/DTPPlatformTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -21,15 +21,17 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; +import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Vector; import junit.framework.TestCase; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.datatools.connectivity.ConnectionProfileException; import org.eclipse.datatools.connectivity.IConnectionProfile; import org.eclipse.datatools.connectivity.ProfileManager; @@ -40,6 +42,8 @@ import org.eclipse.datatools.connectivity.drivers.XMLFileManager; import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; import org.eclipse.datatools.connectivity.internal.ConnectivityPlugin; import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; +import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObjectListener; +import org.eclipse.datatools.connectivity.sqm.core.rte.RefreshManager; import org.eclipse.jpt.common.utility.IndentingPrintWriter; import org.eclipse.jpt.common.utility.internal.CollectionTools; import org.eclipse.jpt.common.utility.internal.ReflectionTools; @@ -53,13 +57,13 @@ import org.eclipse.jpt.jpa.db.ConnectionProfileFactory; import org.eclipse.jpt.jpa.db.ConnectionProfileListener; import org.eclipse.jpt.jpa.db.Database; import org.eclipse.jpt.jpa.db.DatabaseIdentifierAdapter; +import org.eclipse.jpt.jpa.db.DatabaseObject; import org.eclipse.jpt.jpa.db.ForeignKey; -import org.eclipse.jpt.jpa.db.JptJpaDbPlugin; import org.eclipse.jpt.jpa.db.Schema; import org.eclipse.jpt.jpa.db.SchemaContainer; import org.eclipse.jpt.jpa.db.Sequence; import org.eclipse.jpt.jpa.db.Table; -import org.eclipse.jpt.jpa.db.tests.internal.JptJpaDbTestsPlugin; +import org.eclipse.jpt.jpa.db.tests.internal.plugin.JptJpaDbTestsPlugin; /** * Base class for testing DTP wrappers on various databases. @@ -122,9 +126,40 @@ public abstract class DTPPlatformTests extends TestCase { this.connectionProfile = null; this.platformProperties = null; + this.checkForListenerLeak(); + super.tearDown(); } + /** + * See bug 379458 + */ + protected void checkForListenerLeak() { + for (Map.Entry<ICatalogObject, Vector<ICatalogObjectListener>> entry : this.getDTPRefreshListeners().entrySet()) { + checkForListenerLeak(entry.getValue()); + } + checkForListenerLeak(this.getDTPGlobalRefreshListeners()); + } + + protected void checkForListenerLeak(Vector<ICatalogObjectListener> listeners) { + String pkg = DatabaseObject.class.getPackage().getName(); + for (ICatalogObjectListener listener : listeners) { + if (listener.getClass().getName().startsWith(pkg)) { + fail("listener leak: " + listener); + } + } + } + + @SuppressWarnings("unchecked") + protected Hashtable<ICatalogObject, Vector<ICatalogObjectListener>> getDTPRefreshListeners() { + return (Hashtable<ICatalogObject, Vector<ICatalogObjectListener>>) ReflectionTools.getFieldValue(RefreshManager.getInstance(), "listeners"); + } + + @SuppressWarnings("unchecked") + protected Vector<ICatalogObjectListener> getDTPGlobalRefreshListeners() { + return (Vector<ICatalogObjectListener>) ReflectionTools.getFieldValue(RefreshManager.getInstance(), "globalListeners"); + } + // ***** platform properties file private Properties loadPlatformProperties() throws IOException { Properties p = new Properties(); @@ -133,11 +168,7 @@ public abstract class DTPPlatformTests extends TestCase { } private URL buildPlatformPropertiesFileURL() { - return Platform.getBundle(this.getTestPluginBundleID()).getEntry(this.getPlatformPropertiesFilePath()); - } - - private String getTestPluginBundleID() { - return JptJpaDbTestsPlugin.BUNDLE_ID; + return JptJpaDbTestsPlugin.instance().getBundle().getEntry(this.getPlatformPropertiesFilePath()); } private String getPlatformPropertiesFilePath() { @@ -551,7 +582,7 @@ public abstract class DTPPlatformTests extends TestCase { // ********** convenience methods ********** protected ConnectionProfileFactory getConnectionProfileFactory() { - return JptJpaDbPlugin.getConnectionProfileFactory(); + return (ConnectionProfileFactory) ResourcesPlugin.getWorkspace().getAdapter(ConnectionProfileFactory.class); } protected ConnectionProfile getConnectionProfile() { @@ -618,11 +649,15 @@ public abstract class DTPPlatformTests extends TestCase { } protected org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase() { - return getDTPDatabase(this.connectionProfile.getDatabase()); + return this.extractDTPDatabase(this.connectionProfile.getDatabase()); + } + + protected org.eclipse.datatools.modelbase.sql.schema.Database extractDTPDatabase(Database database) { + return (org.eclipse.datatools.modelbase.sql.schema.Database) this.extractDTPObject(database); } - protected static org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase(Database database) { - return (org.eclipse.datatools.modelbase.sql.schema.Database) ReflectionTools.getFieldValue(database, "dtpDatabase"); + protected Object extractDTPObject(DatabaseObject databaseObject) { + return ReflectionTools.getFieldValue(databaseObject, "dtpObject"); } @SuppressWarnings("unchecked") @@ -635,19 +670,19 @@ public abstract class DTPPlatformTests extends TestCase { } protected org.eclipse.datatools.modelbase.sql.schema.Catalog getDTPCatalogNamed(String name) { - return getDTPCatalog(this.getDatabase().getCatalogNamed(name)); + return extractDTPCatalog(this.getDatabase().getCatalogNamed(name)); } - protected static org.eclipse.datatools.modelbase.sql.schema.Catalog getDTPCatalog(Catalog catalog) { - return (org.eclipse.datatools.modelbase.sql.schema.Catalog) ReflectionTools.getFieldValue(catalog, "dtpCatalog"); + protected org.eclipse.datatools.modelbase.sql.schema.Catalog extractDTPCatalog(Catalog catalog) { + return (org.eclipse.datatools.modelbase.sql.schema.Catalog) this.extractDTPObject(catalog); } protected org.eclipse.datatools.modelbase.sql.schema.Schema getDTPSchemaNamed(String name) { - return getDTPSchema(this.getDatabase().getSchemaNamed(name)); + return extractDTPSchema(this.getDatabase().getSchemaNamed(name)); } - protected static org.eclipse.datatools.modelbase.sql.schema.Schema getDTPSchema(Schema schema) { - return (org.eclipse.datatools.modelbase.sql.schema.Schema) ReflectionTools.getFieldValue(schema, "dtpSchema"); + protected org.eclipse.datatools.modelbase.sql.schema.Schema extractDTPSchema(Schema schema) { + return (org.eclipse.datatools.modelbase.sql.schema.Schema) this.extractDTPObject(schema); } diff --git a/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/MySQLTests.java b/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/MySQLTests.java index e35b7e7fca..c01bbf3960 100644 --- a/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/MySQLTests.java +++ b/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/MySQLTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. + * Copyright (c) 2007, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -146,7 +146,7 @@ public class MySQLTests extends DTPPlatformTests { // the MySQL database does NOT refresh - see bug 279721... ((ICatalogObject) this.getDTPDatabase()).refresh(); // ...refresh the single schema instead - ((ICatalogObject) getDTPSchema(this.getDefaultSchema())).refresh(); + ((ICatalogObject) extractDTPSchema(this.getDefaultSchema())).refresh(); Schema schema = this.getDefaultSchema(); @@ -281,7 +281,7 @@ public class MySQLTests extends DTPPlatformTests { // the MySQL database does NOT refresh - see bug 279721... ((ICatalogObject) this.getDTPDatabase()).refresh(); // ...refresh the single schema instead - ((ICatalogObject) getDTPSchema(this.getDefaultSchema())).refresh(); + ((ICatalogObject) extractDTPSchema(this.getDefaultSchema())).refresh(); Schema schema = this.getDefaultSchema(); @@ -311,7 +311,11 @@ public class MySQLTests extends DTPPlatformTests { // the underscore is a wild character on MySQL, so we need to escape it ArrayList<HashMap<String, Object>> rows = this.execute("show variables like 'lower\\_case\\_table\\_names'"); Map<String, Object> row = rows.get(0); - return Integer.valueOf((String) row.get("Value")).intValue(); + String value = (String) row.get("Value"); // Windows? + if (value == null) { + value = (String) row.get("VARIABLE_VALUE"); // MySQL 5.1.62 on Ubuntu 10.04 LTS Lucid Lynx + } + return Integer.valueOf(value).intValue(); } /** @@ -333,7 +337,7 @@ public class MySQLTests extends DTPPlatformTests { // the MySQL database does NOT refresh - see bug 279721... ((ICatalogObject) this.getDTPDatabase()).refresh(); // ...refresh the single schema instead - ((ICatalogObject) getDTPSchema(this.getDefaultSchema())).refresh(); + ((ICatalogObject) extractDTPSchema(this.getDefaultSchema())).refresh(); Table table = this.getDefaultSchema().getTableNamed("test"); assertNotNull(table.getColumnNamed("id")); @@ -348,7 +352,7 @@ public class MySQLTests extends DTPPlatformTests { // the MySQL database does NOT refresh - see bug 279721... ((ICatalogObject) this.getDTPDatabase()).refresh(); // ...refresh the single schema instead - ((ICatalogObject) getDTPSchema(this.getDefaultSchema())).refresh(); + ((ICatalogObject) extractDTPSchema(this.getDefaultSchema())).refresh(); table = this.getDefaultSchema().getTableNamed("test"); assertNotNull(table.getColumnNamed("ID")); @@ -363,7 +367,7 @@ public class MySQLTests extends DTPPlatformTests { // the MySQL database does NOT refresh - see bug 279721... ((ICatalogObject) this.getDTPDatabase()).refresh(); // ...refresh the single schema instead - ((ICatalogObject) getDTPSchema(this.getDefaultSchema())).refresh(); + ((ICatalogObject) extractDTPSchema(this.getDefaultSchema())).refresh(); table = this.getDefaultSchema().getTableNamed("test"); assertNotNull(table.getColumnNamed("Id")); @@ -378,7 +382,7 @@ public class MySQLTests extends DTPPlatformTests { // the MySQL database does NOT refresh - see bug 279721... ((ICatalogObject) this.getDTPDatabase()).refresh(); // ...refresh the single schema instead - ((ICatalogObject) getDTPSchema(this.getDefaultSchema())).refresh(); + ((ICatalogObject) extractDTPSchema(this.getDefaultSchema())).refresh(); table = this.getDefaultSchema().getTableNamed("test"); assertNotNull(table.getColumnNamed("Id")); diff --git a/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/PostgreSQLTests.java b/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/PostgreSQLTests.java index 6e501a7942..88ff73b8e5 100644 --- a/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/PostgreSQLTests.java +++ b/jpa/tests/org.eclipse.jpt.jpa.db.tests/src/org/eclipse/jpt/jpa/db/tests/internal/platforms/PostgreSQLTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. + * Copyright (c) 2007, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -13,6 +13,7 @@ import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; import org.eclipse.jpt.jpa.db.Column; import org.eclipse.jpt.jpa.db.ForeignKey; import org.eclipse.jpt.jpa.db.Schema; +import org.eclipse.jpt.jpa.db.Sequence; import org.eclipse.jpt.jpa.db.Table; @SuppressWarnings("nls") @@ -444,43 +445,42 @@ public class PostgreSQLTests extends DTPPlatformTests { } } -// see 241578/241557 -// public void testSequence() throws Exception { -// this.connectionProfile.connect(); -// TestConnectionListener listener = new TestConnectionListener(); -// this.connectionProfile.addConnectionListener(listener); -// -// this.dropSequence("SEQUENCE_TEST", "FOO"); -// this.dropSchema("SEQUENCE_TEST"); -// -// this.executeUpdate("CREATE SCHEMA SEQUENCE_TEST"); -// this.executeUpdate("SET search_path TO SEQUENCE_TEST"); -// -// this.executeUpdate(this.buildBarDDL()); -// this.executeUpdate("CREATE SEQUENCE FOO START 1"); -//// List<Object[]> list = this.execute("SELECT nextval('foo')"); -//// System.out.println(list); -// ((ICatalogObject) this.getDTPDatabase()).refresh(); -// -// Schema schema = this.getDefaultCatalog().getSchemaNamed("SEQUENCE_TEST"); -// Sequence sequence = schema.getSequenceNamed("FOO"); -// assertNotNull(sequence); -// assertEquals("foo_seq", sequence.getName()); -// -// this.dropSequence("SEQUENCE_TEST", "FOO"); -// this.dropSchema("SEQUENCE_TEST"); -// -// this.connectionProfile.removeConnectionListener(listener); -// this.connectionProfile.disconnect(); -// } -// -// private void dropSequence(String schemaName, String sequenceName) throws Exception { -// Schema schema= this.getDefaultCatalog().getSchemaNamed(schemaName); -// if (schema != null) { -// if (schema.getSequenceNamed(sequenceName) != null) { -// this.executeUpdate("DROP SEQUENCE " + schemaName + '.' + sequenceName); -// } -// } -// } -// + public void testSequence() throws Exception { + this.connectionProfile.connect(); + TestConnectionListener listener = new TestConnectionListener(); + this.connectionProfile.addConnectionListener(listener); + + this.dropSequence("SEQUENCE_TEST", "FOO"); + this.dropSchema("SEQUENCE_TEST"); + + this.executeUpdate("CREATE SCHEMA SEQUENCE_TEST"); + this.executeUpdate("SET search_path TO SEQUENCE_TEST"); + + this.executeUpdate(this.buildBarDDL()); + this.executeUpdate("CREATE SEQUENCE FOO START 1"); +// List<Object[]> list = this.execute("SELECT nextval('foo')"); +// System.out.println(list); + ((ICatalogObject) this.getDTPDatabase()).refresh(); + + Schema schema = this.getDefaultCatalog().getSchemaForIdentifier("SEQUENCE_TEST"); + Sequence sequence = schema.getSequenceForIdentifier("FOO"); + assertNotNull(sequence); + assertEquals("foo", sequence.getName()); + + this.dropSequence("SEQUENCE_TEST", "FOO"); + this.dropSchema("SEQUENCE_TEST"); + + this.connectionProfile.removeConnectionListener(listener); + this.connectionProfile.disconnect(); + } + + private void dropSequence(String schemaName, String sequenceName) throws Exception { + Schema schema= this.getDefaultCatalog().getSchemaNamed(schemaName); + if (schema != null) { + if (schema.getSequenceNamed(sequenceName) != null) { + this.executeUpdate("DROP SEQUENCE " + schemaName + '.' + sequenceName); + } + } + } + } |