diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt')
29 files changed, 0 insertions, 5199 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java deleted file mode 100644 index 5c6da7058d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Database catalog - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Catalog - extends SchemaContainer, Comparable<Catalog> -{ - // nothing yet -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java deleted file mode 100644 index b502f61ca6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.jpt.utility.JavaType; - -/** - * Database column - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Column - extends DatabaseObject, Comparable<Column> -{ - /** - * Return the column's table. - */ - Table getTable(); - - - // ********** constraints ********** - - /** - * Return whether the column is part of it's table's primary key. - */ - boolean isPartOfPrimaryKey(); - - /** - * Return whether the column is part of one of it's table's foreign keys. - */ - boolean isPartOfForeignKey(); - - /** - * Return whether the column is part of a unique constraint defined for its - * table. - */ - boolean isPartOfUniqueConstraint(); - - /** - * Return whether the column is nullable. - */ - boolean isNullable(); - - - // ********** data type ********** - - /** - * Return the name of the column's datatype. - */ - String getDataTypeName(); - - /** - * Return whether the column's type is numeric. - */ - boolean isNumeric(); - - /** - * Return the column's precision if it is a NumericalDataType; - * otherwise, return -1. - */ - public int getPrecision(); - - /** - * Return the column's scale if it is an ExactNumericDataType; - * otherwise, return -1. - */ - public int getScale(); - - /** - * If the column is a CharacterStringDataType, return its length; - * otherwise, return -1. - */ - public int getLength(); - - /** - * Return whether the column's datatype is a LOB type - * (i.e. BLOB, CLOB, or NCLOB). - */ - boolean isLOB(); - - - // ********** Java type ********** - - /** - * Return a Java type declaration that is reasonably - * similar to the column's data type. - */ - String getJavaTypeDeclaration(); - - /** - * Return a Java type that is reasonably - * similar to the column's data type. - */ - JavaType getJavaType(); - - /** - * Return a Java type declaration that is reasonably - * similar to the column's data type and suitable for use as a - * primary key field. - */ - String getPrimaryKeyJavaTypeDeclaration(); - - /** - * Return a Java type that is reasonably - * similar to the column's data type and suitable for use as a - * primary key field. - */ - JavaType getPrimaryKeyJavaType(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionAdapter.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionAdapter.java deleted file mode 100644 index 972848965c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionAdapter.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - - -/** - * An empty implementation of ConnectionListener. - * - * Provisional API: This class is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public class ConnectionAdapter implements ConnectionListener { - - public void aboutToClose(ConnectionProfile profile) { - // do nothing - } - - public void closed(ConnectionProfile profile) { - // do nothing - } - - public void databaseChanged(ConnectionProfile profile, Database database) { - // do nothing - } - - public void modified(ConnectionProfile profile) { - // do nothing - } - - public boolean okToClose(ConnectionProfile profile) { - return true; - } - - public void opened(ConnectionProfile profile) { - // do nothing - } - - public void catalogChanged(ConnectionProfile profile, Catalog catalog) { - // do nothing - } - - public void schemaChanged(ConnectionProfile profile, Schema schema) { - // do nothing - } - - public void sequenceChanged(ConnectionProfile profile, Sequence sequence) { - // do nothing - } - - public void tableChanged(ConnectionProfile profile, Table table) { - // do nothing - } - - public void columnChanged(ConnectionProfile profile, Column column) { - // do nothing - } - - public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java deleted file mode 100644 index 4f3b09bae8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.EventListener; - - -/** - * A ConnectionListener is notified of any changes to a connection. - * - * @see org.eclipse.datatools.connectivity.IManagedConnectionListener - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public interface ConnectionListener extends EventListener { - - public void opened(ConnectionProfile profile); - public void modified(ConnectionProfile profile); - public boolean okToClose(ConnectionProfile profile); - public void aboutToClose(ConnectionProfile profile); - public void closed(ConnectionProfile profile); - - public void databaseChanged(ConnectionProfile profile, Database database); - public void catalogChanged(ConnectionProfile profile, Catalog catalog); - public void schemaChanged(ConnectionProfile profile, Schema schema); - public void sequenceChanged(ConnectionProfile profile, Sequence sequence); - public void tableChanged(ConnectionProfile profile, Table table); - public void columnChanged(ConnectionProfile profile, Column column); - public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java deleted file mode 100644 index c15db7aa7f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; - -/** - * Database connection profile - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface ConnectionProfile - extends DatabaseObject, Comparable<ConnectionProfile> -{ - - // ********** properties ********** - - /** - * Return the connection profile's database. - * Return null if the connection profile is inactive. - */ - Database getDatabase(); - - /** - * Return ID of the provider managing the DTP profile. - */ - String getProviderID(); - - /** - * Return the connection profile's static ID. - */ - String getInstanceID(); - - /** - * Return the default database name. - */ - String getDatabaseName(); - - /** - * Return the database product name. - */ - String getDatabaseProduct(); - - /** - * Return the database vendor. - */ - String getDatabaseVendor(); - - /** - * Return the database version. - */ - String getDatabaseVersion(); - - /** - * Return the driver class name. - */ - String getDriverClassName(); - - /** - * Return the default connection URL. - */ - String getURL(); - - /** - * Return the default user name. - */ - String getUserName(); - - /** - * Return the default user password. - */ - String getUserPassword(); - - /** - * Return the ID of the associated Driver definition. - */ - String getDriverDefinitionID(); - - /** - * Return the jar list for the associated Driver as a - * comma-delimited string. - */ - String getDriverJarList(); - - /** - * Return the name of the associated Driver definition. - */ - String getDriverName(); - - // ********** connection ********** - - /** - * Return whether the profile is either connected to a live database - * session or working off-line (i.e. it has access to meta-data). - * @see isConnected() - * @see isWorkingOffline() - */ - boolean isActive(); - - /** - * Return whether the profile is neither connected to a live database - * session nor working off-line (i.e. it has access to meta-data). - * @see isActive() - */ - boolean isInactive(); - - /** - * Return whether the profile is connected to a live database session - * (i.e. the meta-data comes from the database), as opposed to working - * off-line. - * @see #isActive() - */ - boolean isConnected(); - - /** - * Return whether the profile is not connected to a live database session - * (i.e. the meta-data comes from the database), as opposed to working - * off-line. - * @see #isConnected() - */ - boolean isDisconnected(); - - /** - * Connect to the database. - * @see #disconnect() - */ - void connect(); - - /** - * Disconnect from the database. - * @see #connect() - */ - void disconnect(); - - - // ********** off-line support ********** - - /** - * Return whether the profile is working off-line (i.e. the meta-data - * comes from a local cache), as opposed to connected to a live - * database session. - * @see #isActive() - */ - boolean isWorkingOffline(); - - /** - * Return whether the connection factories associated with the - * connection profile's provider support working offline. - */ - boolean supportsWorkOfflineMode(); - - /** - * Save the state of the connection profile for working in an offline mode. - * If the connection profile does not support working in an offline mode, no - * exception is thrown and the method will return immediately. - */ - IStatus saveWorkOfflineData(); - - /** - * Return whether the connection profile supports working offline and data - * has been saved for working offline. - */ - boolean canWorkOffline(); - - /** - * Begin working off-line. - */ - IStatus workOffline(); - - - // ********** listeners ********** - - /** - * Add the specified connection listener to the connection profile. - */ - void addConnectionListener(ConnectionListener listener); - - /** - * Remove the specified connection listener from the connection profile. - */ - void removeConnectionListener(ConnectionListener listener); - - - // ********** constants ********** - - String CONNECTION_PROFILE_TYPE = "org.eclipse.datatools.connectivity.db.generic.connectionProfile"; //$NON-NLS-1$ - String DRIVER_DEFINITION_PROP_ID = "org.eclipse.datatools.connectivity.driverDefinitionID"; //$NON-NLS-1$ - String DRIVER_DEFINITION_TYPE_PROP_ID = "org.eclipse.datatools.connectivity.drivers.defnType"; //$NON-NLS-1$ - String DRIVER_JAR_LIST_PROP_ID = "jarList"; //$NON-NLS-1$ - String DATABASE_SAVE_PWD_PROP_ID = IJDBCDriverDefinitionConstants.PROP_PREFIX + "savePWD"; //$NON-NLS-1$ - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java deleted file mode 100644 index 648daa5bf6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * An empty implementation of ProfileListener. - * - * Provisional API: This class is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public class ConnectionProfileAdapter implements ConnectionProfileListener { - - public void connectionProfileAdded(String name) { - // do nothing - } - - public void connectionProfileRemoved(String name) { - // do nothing - } - - public void connectionProfileRenamed(String oldName, String newName) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileFactory.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileFactory.java deleted file mode 100644 index e44773953a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database connection profile factory - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface ConnectionProfileFactory { - - /** - * Return the names of the DTP connection profiles the factory can wrap with - * new connection profiles. - */ - Iterator<String> connectionProfileNames(); - - /** - * Build and return a connection profile that wraps the DTP connection - * profile with the specified name. - * Return null if there is no DTP connection profile with the specified - * name. - * Use the specified database finder to allow clients to control how - * database objects are found based on their names. - */ - ConnectionProfile buildConnectionProfile(String name, DatabaseFinder finder); - - /** - * Build and return a connection profile that wraps the DTP connection - * profile with the specified name. - * Return null if there is no DTP connection profile with the specified - * name. - * Clients should use this method when a JPA platform is unavailable - * (e.g. during project creation). The returned connection profile will - * not be able to search for database objects by any names other than - * those supplied by the factory (i.e. lookups cannot be performed with - * "identifiers"). - */ - ConnectionProfile buildConnectionProfile(String name); - - /** - * Add a listener that will be notified of changes to the DTP - * connection profiles. - */ - void addConnectionProfileListener(ConnectionProfileListener listener); - - /** - * Remove the specified listener. - */ - void removeConnectionProfileListener(ConnectionProfileListener listener); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java deleted file mode 100644 index f020c5505d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.EventListener; - -/** - * A ProfileListener is notified of any changes to the DTP connection profiles. - * - * @see org.eclipse.datatools.connectivity.IProfileListener - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public interface ConnectionProfileListener - extends EventListener -{ - - /** - * The specified profile has been added. - */ - public void connectionProfileAdded(String name); - - /** - * The specified profile has been removed. - */ - public void connectionProfileRemoved(String name); - - /** - * The specified profile has been renamed. - */ - public void connectionProfileRenamed(String oldName, String newName); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java deleted file mode 100644 index c101d40f59..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Database - extends SchemaContainer, Comparable<Database> -{ - - // ********** properties ********** - - /** - * Return the name of the database's vendor. - */ - String getVendorName(); - - /** - * Return the database's version. - */ - String getVersion(); - - - // ********** catalogs ********** - - /** - * Return whether the database supports catalogs. - */ - boolean supportsCatalogs(); - - /** - * Return the database's catalogs. - * @see #supportsCatalogs() - */ - Iterator<Catalog> catalogs(); - - /** - * Return the number of catalogs the database contains. - * @see #supportsCatalogs() - */ - int catalogsSize(); - - /** - * Return the catalog with specified name. The name must be an exact match - * of the catalog's name. - * @see #supportsCatalogs() - * @see #getCatalogForIdentifier(String) - */ - Catalog getCatalogNamed(String name); - - /** - * Return the database's catalog identifiers, sorted by name. - */ - Iterator<String> sortedCatalogIdentifiers(); - - /** - * Return the catalog for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #supportsCatalogs() - * @see #getCatalogNamed(String) - */ - Catalog getCatalogForIdentifier(String identifier); - - /** - * Return the database's "default" catalog. - * Return null if the database does not support catalogs. - * @see #supportsCatalogs() - */ - Catalog getDefaultCatalog(); - - - // ********** utility methods ********** - - /** - * Select and return from the specified list of database objects the - * database object identified by the specified identifier. - * The identifier should be an SQL identifier (i.e. delimited when - * non-"normal"). - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier); - - /** - * Convert the specified name to a database-appropriate SQL identifier. - */ - String convertNameToIdentifier(String name); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseFinder.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseFinder.java deleted file mode 100644 index e7806e7933..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseFinder.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * This interface allows clients of the Dali db package to plug in a custom - * strategy for comparing an identifier to the names of a collection of - * database objects. - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface DatabaseFinder { - - /** - * Select and return from the specified list of database objects the - * database object identified by the specified identifier. - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier, DefaultCallback defaultCallback); - - /** - * The platform-provided finder is passed a "default" callback that can be - * used if appropriate. - */ - interface DefaultCallback { - - /** - * Select and return from the specified list of database objects the - * database object identified by the specified identifier. - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier); - - } - - /** - * This finder searches for an exact match. - */ - final class Simple implements DatabaseFinder { - public static final DatabaseFinder INSTANCE = new Simple(); - public static DatabaseFinder instance() { - return INSTANCE; - } - // ensure single instance - private Simple() { - super(); - } - // search for an exact match on the name - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier, DefaultCallback defaultCallback) { - for (T databaseObject : databaseObjects) { - if (databaseObject.getName().equals(identifier)) { - return databaseObject; - } - } - return null; - } - @Override - public String toString() { - return "DatabaseFinder.Default"; //$NON-NLS-1$ - } - } - - /** - * This finder uses the passed in callback to search the list of database objects. - */ - final class Default implements DatabaseFinder { - public static final DatabaseFinder INSTANCE = new Default(); - public static DatabaseFinder instance() { - return INSTANCE; - } - // ensure single instance - private Default() { - super(); - } - // simply use the callback - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier, DefaultCallback defaultCallback) { - return defaultCallback.selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - @Override - public String toString() { - return "DatabaseFinder.Default"; //$NON-NLS-1$ - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseObject.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseObject.java deleted file mode 100644 index e9f755dbb0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseObject.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Common behavior to all database objects - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface DatabaseObject { - - /** - * Return the database object's name. - */ - String getName(); - - /** - * Return the database object's "identifier", which is the object's name - * modified so it can be used in an SQL statement (e.g. if the name contains - * special characters or is mixed case, it will be delimited, typically by - * double-quotes). - * Return null if the database object's identifier matches the specified - * "default name". - */ - String getIdentifier(String defaultName); - - /** - * Return the database object's "identifier", which is the object's name - * modified so it can be used in an SQL statement (e.g. if the name contains - * special characters or is mixed case, it will be delimited, typically by - * double-quotes). - */ - String getIdentifier(); - - /** - * Return the database object's database. - */ - Database getDatabase(); - - /** - * Return the database object's connection profile. - */ - ConnectionProfile getConnectionProfile(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java deleted file mode 100644 index 0406b42eba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database foreign key - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface ForeignKey - extends DatabaseObject, Comparable<ForeignKey> -{ - - // ********** tables ********** - - /** - * Return the foreign key's "base" table. - */ - Table getBaseTable(); - - /** - * Return the foreign key's "referenced" table. - */ - Table getReferencedTable(); - - - // ********** column pairs ********** - - /** - * Return the foreign key's column pairs. - */ - Iterator<ColumnPair> columnPairs(); - - /** - * Return the size of the foreign key's column pairs. - */ - int columnPairsSize(); - - /** - * Return the foreign key's single column pair. Throw an - * IllegalStateException if the foreign key has more than one column pair. - */ - ColumnPair getColumnPair(); - - /** - * Return the foreign key's "base" columns. - */ - Iterator<Column> baseColumns(); - - /** - * Return the foreign key's "base" columns that are not part of the base - * table's primary key. (The non-primary key base columns are not used to - * generate basic attributes during entity generation.) - */ - Iterator<Column> nonPrimaryKeyBaseColumns(); - - /** - * Return the foreign key's "referenced" columns. - */ - Iterator<Column> referencedColumns(); - - /** - * Return whether the foreign key references the primary key of the - * "referenced" table and that primary key has only a single column. - * This can be used when determining JPA defaults. - */ - boolean referencesSingleColumnPrimaryKey(); - - - // ********** JPA support ********** - - /** - * Return an appropriate name for an attribute that holds the entity - * mapped to the foreign key's "referenced" table. - */ - String getAttributeName(); - - /** - * If the name of the "base" column adheres to the JPA spec for a - * default mapping (i.e. it ends with an underscore followed by the name - * of the "referenced" column, and the "referenced" column is the single - * primary key column of the "referenced" table), return the corresponding - * default attribute name: - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * Return a null if it does not adhere to the JPA spec: - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.CUBICLE_ID) => null - * ForeignKey(EMP.CUBICLE => CUBICLE.ID) => null - */ - String getDefaultAttributeName(); - - /** - * Given the name of an attribute (field or property) that is mapped to the - * foreign key, - * build and return a string to be used as the value for the attribute's - * JoinColumn annotation's 'name' element. Return null if the attribute - * maps to the join column by default. - * Precondition: The foreign key consists of a single column pair whose - * referenced column is the single-column primary key of the foreign - * key's referenced table. - */ - String getJoinColumnAnnotationIdentifier(String attributeName); - - // ********** column pair interface ********** - - /** - * Pair up the foreign key's column pairs, matching each "base" column with - * the appropriate "referenced" column. - * @see #columnPairs() - */ - interface ColumnPair extends Comparable<ColumnPair> { - - /** - * Return the column pair's "base" column. - */ - Column getBaseColumn(); - - /** - * Return the column pair's "referenced" column. - */ - Column getReferencedColumn(); - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java deleted file mode 100644 index 346de5ba65..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.jpt.db.internal.DTPConnectionProfileFactory; -import org.osgi.framework.BundleContext; - -/** - * The JPT DB plug-in lifecycle implementation. - * Globally available connection profile factory. - * - * Provisional API: This class is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public class JptDbPlugin extends Plugin { - private DTPConnectionProfileFactory connectionProfileFactory; - - private static JptDbPlugin INSTANCE; // sorta-final - - /** - * Return the singleton JPT DB plug-in. - */ - public static JptDbPlugin instance() { - return INSTANCE; - } - - /** - * The constructor - */ - public JptDbPlugin() { - super(); - INSTANCE = this; - } - - /** - * This method is called upon plug-in activation - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - this.connectionProfileFactory = DTPConnectionProfileFactory.instance(); - this.connectionProfileFactory.start(); - } - - /** - * This method is called when the plug-in is stopped - */ - @Override - public void stop(BundleContext context) throws Exception { - this.connectionProfileFactory.stop(); - this.connectionProfileFactory = null; - INSTANCE = null; - super.stop(context); - } - - public ConnectionProfileFactory getConnectionProfileFactory() { - return this.connectionProfileFactory; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java deleted file mode 100644 index 984dfb537a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - - -/** - * Database schema - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Schema - extends DatabaseObject, Comparable<Schema> -{ - /** - * Return the schema's container; either a catalog or a database. - */ - SchemaContainer getContainer(); - - - // ********** tables ********** - - /** - * Return the schema's tables. - */ - Iterator<Table> tables(); - - /** - * Return the number of tables the schema contains. - */ - int tablesSize(); - - /** - * Return the table with specified name. The name must be an exact match - * of the table's name. - * @see #getTableForIdentifier(String) - */ - Table getTableNamed(String name); - - /** - * Return the schema's table identifiers, sorted by name. - */ - Iterator<String> sortedTableIdentifiers(); - - /** - * Return the table for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #getTableNamed(String) - */ - Table getTableForIdentifier(String identifier); - - - // ********** sequences ********** - - /** - * Return the schema's sequences. - */ - Iterator<Sequence> sequences(); - - /** - * Return the number of sequences the schema contains. - */ - int sequencesSize(); - - /** - * Return the sequence with specified name. The name must be an exact match - * of the sequence's name. - * @see #getSequenceForIdentifier(String) - */ - Sequence getSequenceNamed(String name); - - /** - * Return the schema's sequence identifers, sorted by name. - */ - Iterator<String> sortedSequenceIdentifiers(); - - /** - * Return the sequence for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #getSequenceNamed(String) - */ - Sequence getSequenceForIdentifier(String identifier); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java deleted file mode 100644 index 26372f4a03..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Schema "container" (i.e. Database or Catalog) - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface SchemaContainer - extends DatabaseObject -{ - - /** - * Return the container's schemata. - */ - Iterator<Schema> schemata(); - - /** - * Return the number of schemata in the container. - */ - int schemataSize(); - - /** - * Return the schema with specified name. The name must be an exact match - * of the schema's name. - * @see #schemaNames() - * @see #getSchemaForIdentifier(String) - */ - Schema getSchemaNamed(String name); - - /** - * Return the container's schema identifiers, sorted by name. - */ - Iterator<String> sortedSchemaIdentifiers(); - - /** - * Return the schema for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #schemaIdentifiers() - * @see #getSchemaNamed(String) - */ - Schema getSchemaForIdentifier(String identifier); - - /** - * Return the container's default schema, as defined by the database vendor. - * In most cases the default schema's name will match the user name. - */ - Schema getDefaultSchema(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java deleted file mode 100644 index f4ccaa78f9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Database sequence - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Sequence - extends DatabaseObject, Comparable<Sequence> -{ - - /** - * Return the sequence's schema. - */ - Schema getSchema(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java deleted file mode 100644 index ef4d334af0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database table - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Table - extends DatabaseObject, Comparable<Table> -{ - - /** - * Return the table's schema. - */ - Schema getSchema(); - - - // ********** columns ********** - - /** - * Return the table's columns. - */ - Iterator<Column> columns(); - - /** - * Return the number of columns the table contains. - */ - int columnsSize(); - - /** - * Return the column with specified name. The name must be an exact match - * of the column's name. - * @see #getColumnForIdentifier(String) - */ - Column getColumnNamed(String name); - - /** - * Return the table's column identifers, sorted by name. - */ - Iterator<String> sortedColumnIdentifiers(); - - /** - * Return the column for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #getColumnNamed(String) - */ - Column getColumnForIdentifier(String identifier); - - - // ********** primary key columns ********** - - /** - * Return the table's primary key columns. - */ - Iterator<Column> primaryKeyColumns(); - - /** - * Return the number of primary key columns the table contains. - */ - int primaryKeyColumnsSize(); - - /** - * Return the table's single primary key column. Throw an - * IllegalStateException if the table has more than one primary key column. - */ - Column getPrimaryKeyColumn(); - - - // ********** foreign keys ********** - - /** - * Return the table's foreign keys. - */ - Iterator<ForeignKey> foreignKeys(); - - /** - * Return the number of foreign keys the table contains. - */ - int foreignKeysSize(); - - - // ********** join table support ********** - - /** - * Return whether the table is possibly a "join" table - * (i.e. it contains only 2 foreign keys). Whether the table *actually* is - * a "join" table is determined by the semantics of the database design. - */ - boolean isPossibleJoinTable(); - - /** - * Assuming the table is a "join" table, return the foreign key to the - * "owning" table. - * @see #isPossibleJoinTable() - */ - ForeignKey getJoinTableOwningForeignKey(); - - /** - * Assuming the table is a "join" table, return the foreign key to the - * "non-owning" table. - * @see #isPossibleJoinTable() - */ - ForeignKey getJoinTableNonOwningForeignKey(); - - /** - * Assuming the table is a "join" table, return whether its name matches - * the JPA default (i.e. "OWNINGTABLE_NONOWNINGTABLE"). - * @see #isPossibleJoinTable() - */ - boolean joinTableNameIsDefault(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java deleted file mode 100644 index 29e4b09683..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.List; -import org.eclipse.jpt.db.Catalog; - -/** - * Wrap a DTP Catalog - */ -final class DTPCatalogWrapper - extends DTPSchemaContainerWrapper - 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, dtpCatalog); - this.dtpCatalog = dtpCatalog; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().catalogChanged(this); - } - - - // ********** DTPSchemaContainerWrapper implementation ********** - - @Override - @SuppressWarnings("unchecked") - List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemata() { - return this.dtpCatalog.getSchemas(); - } - - @Override - DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - return this.wraps(dtpSchema.getCatalog()) ? - this.getSchema_(dtpSchema) - : - this.getDatabase().getSchema(dtpSchema); - } - - @Override - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.wraps(dtpTable.getSchema().getCatalog()) ? - this.getTable_(dtpTable) - : - this.getDatabase().getTable(dtpTable); - } - - @Override - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.wraps(dtpColumn.getTable().getSchema().getCatalog()) ? - this.getColumn_(dtpColumn) - : - this.getDatabase().getColumn(dtpColumn); - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpCatalog.getName(); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Catalog catalog) { - return Collator.getInstance().compare(this.getName(), catalog.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Catalog catalog) { - return this.dtpCatalog == catalog; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java deleted file mode 100644 index 77608037ca..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java +++ /dev/null @@ -1,241 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import org.eclipse.datatools.modelbase.dbdefinition.PredefinedDataTypeDefinition; -import org.eclipse.datatools.modelbase.sql.datatypes.CharacterStringDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.DataType; -import org.eclipse.datatools.modelbase.sql.datatypes.ExactNumericDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.NumericalDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.PredefinedDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.PrimitiveType; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.utility.JavaType; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.SimpleJavaType; - -/** - * Wrap a DTP Column - */ -final class DTPColumnWrapper - extends DTPDatabaseObjectWrapper - 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, dtpColumn); - this.dtpColumn = dtpColumn; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().columnChanged(this); - } - - - // ********** Column implementation ********** - - public String getName() { - return this.dtpColumn.getName(); - } - - public DTPTableWrapper getTable() { - return (DTPTableWrapper) this.getParent(); - } - - public boolean isPartOfPrimaryKey() { - return this.getTable().primaryKeyColumnsContains(this); - } - - public boolean isPartOfForeignKey() { - return this.getTable().foreignKeyBaseColumnsContains(this); - } - - public boolean isPartOfUniqueConstraint() { - return this.dtpColumn.isPartOfUniqueConstraint(); - } - - public boolean isNullable() { - return this.dtpColumn.isNullable(); - } - - public String getDataTypeName() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType == null) ? null : dataType.getName(); - } - - public boolean isNumeric() { - return this.dtpColumn.getDataType() instanceof NumericalDataType; - } - - public int getPrecision() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof NumericalDataType) ? - ((NumericalDataType) dataType).getPrecision() - : - -1; - } - - public int getScale(){ - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof ExactNumericDataType) ? - ((ExactNumericDataType) dataType).getScale() - : - -1; - } - - public int getLength() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof CharacterStringDataType) ? - ((CharacterStringDataType) dataType).getLength() - : - -1; - } - - public boolean isLOB() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof PredefinedDataType) ? - primitiveTypeIsLob(((PredefinedDataType) dataType).getPrimitiveType()) - : - false; - } - - public String getJavaTypeDeclaration() { - return this.getJavaType().declaration(); - } - - public JavaType getJavaType() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof PredefinedDataType) ? - convertToJPAJavaType(this.getJavaType((PredefinedDataType) dataType)) - : - DEFAULT_JAVA_TYPE; - } - - public String getPrimaryKeyJavaTypeDeclaration() { - return this.getPrimaryKeyJavaType().declaration(); - } - - public JavaType getPrimaryKeyJavaType() { - return convertToJPAPrimaryKeyJavaType(this.getJavaType()); - } - - private JavaType getJavaType(PredefinedDataType dataType) { - // this is just a bit hacky: moving from a type declaration to a class name to a type declaration... - String dtpJavaClassName = this.getDefinition(dataType).getJavaClassName(); - return new SimpleJavaType(ClassTools.classNameForTypeDeclaration(dtpJavaClassName)); - } - - private PredefinedDataTypeDefinition getDefinition(PredefinedDataType dataType) { - return this.getDatabase().getDTPDefinition().getPredefinedDataTypeDefinition(dataType.getName()); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Column column) { - return Collator.getInstance().compare(this.getName(), column.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Column column) { - return this.dtpColumn == column; - } - - @Override - void clear() { - // no state to clear - } - - - // ********** static methods ********** - - /** - * The JDBC spec says JDBC drivers should be able to map BLOBs and CLOBs - * directly, but the JPA spec does not allow them. - */ - private static JavaType convertToJPAJavaType(JavaType javaType) { - if (javaType.equals(BLOB_JAVA_TYPE)) { - return BYTE_ARRAY_JAVA_TYPE; - } - if (javaType.equals(CLOB_JAVA_TYPE)) { - return STRING_JAVA_TYPE; - } - return javaType; - } - - /** - * The JPA spec [2.1.4] says only the following types are allowed in - * primary key fields: - * [variable] primitives - * [variable] primitive wrappers - * java.lang.String - * java.util.Date - * java.sql.Date - */ - private static JavaType convertToJPAPrimaryKeyJavaType(JavaType javaType) { - if (javaType.isVariablePrimitive() - || javaType.isVariablePrimitiveWrapper() - || javaType.equals(STRING_JAVA_TYPE) - || javaType.equals(UTIL_DATE_JAVA_TYPE) - || javaType.equals(SQL_DATE_JAVA_TYPE)) { - return javaType; - } - if (javaType.equals(BIG_DECIMAL_JAVA_TYPE)) { - return LONG_JAVA_TYPE; // ?? - } - if (javaType.equals(SQL_TIME_JAVA_TYPE)) { - return UTIL_DATE_JAVA_TYPE; // ??? - } - if (javaType.equals(SQL_TIMESTAMP_JAVA_TYPE)) { - return UTIL_DATE_JAVA_TYPE; // ??? - } - // all the other typical types are pretty much un-mappable - return String(?) - return STRING_JAVA_TYPE; - } - - private static boolean primitiveTypeIsLob(PrimitiveType primitiveType) { - return (primitiveType == PrimitiveType.BINARY_LARGE_OBJECT_LITERAL) - || (primitiveType == PrimitiveType.CHARACTER_LARGE_OBJECT_LITERAL) - || (primitiveType == PrimitiveType.NATIONAL_CHARACTER_LARGE_OBJECT_LITERAL); - } - - - // ***** some constants used when converting the column to a Java attribute - // TODO Object is the default? - private static final JavaType DEFAULT_JAVA_TYPE = new SimpleJavaType(java.lang.Object.class); - - private static final JavaType BLOB_JAVA_TYPE = new SimpleJavaType(java.sql.Blob.class); - private static final JavaType BYTE_ARRAY_JAVA_TYPE = new SimpleJavaType(byte[].class); - - private static final JavaType CLOB_JAVA_TYPE = new SimpleJavaType(java.sql.Clob.class); - private static final JavaType STRING_JAVA_TYPE = new SimpleJavaType(java.lang.String.class); - - private static final JavaType UTIL_DATE_JAVA_TYPE = new SimpleJavaType(java.util.Date.class); - private static final JavaType SQL_DATE_JAVA_TYPE = new SimpleJavaType(java.sql.Date.class); - private static final JavaType SQL_TIME_JAVA_TYPE = new SimpleJavaType(java.sql.Time.class); - private static final JavaType SQL_TIMESTAMP_JAVA_TYPE = new SimpleJavaType(java.sql.Timestamp.class); - - 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.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileFactory.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileFactory.java deleted file mode 100644 index 6e5df2860a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileFactory.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Iterator; - -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.IProfileListener1; -import org.eclipse.datatools.connectivity.ProfileManager; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.ConnectionProfileListener; -import org.eclipse.jpt.db.DatabaseFinder; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap the DTP ProfileManager in yet another singleton. - */ -public final class DTPConnectionProfileFactory - implements ConnectionProfileFactory -{ - private ProfileManager dtpProfileManager; - - private LocalProfileListener profileListener; - - - // ********** singleton ********** - - private static final DTPConnectionProfileFactory INSTANCE = new DTPConnectionProfileFactory(); - - public static DTPConnectionProfileFactory instance() { - return INSTANCE; - } - - /** - * 'private' to ensure singleton - */ - private DTPConnectionProfileFactory() { - super(); - } - - - // ********** lifecycle ********** - - /** - * called by plug-in - */ - public synchronized void start() { - this.dtpProfileManager = ProfileManager.getInstance(); - this.profileListener = new LocalProfileListener(); - this.dtpProfileManager.addProfileListener(this.profileListener); - } - - /** - * called by plug-in - */ - public synchronized void stop() { - this.dtpProfileManager.removeProfileListener(this.profileListener); - this.profileListener = null; - this.dtpProfileManager = null; - } - - - // ********** connection profiles ********** - - public ConnectionProfile buildConnectionProfile(String name, DatabaseFinder finder) { - for (IConnectionProfile dtpProfile : this.dtpProfileManager.getProfiles()) { - if (dtpProfile.getName().equals(name)) { - return new DTPConnectionProfileWrapper(dtpProfile, finder); - } - } - return null; - } - - public ConnectionProfile buildConnectionProfile(String name) { - return this.buildConnectionProfile(name, DatabaseFinder.Simple.instance()); - } - - public Iterator<String> connectionProfileNames() { - return new TransformationIterator<IConnectionProfile, String>(this.dtpConnectionProfiles()) { - @Override - protected String transform(IConnectionProfile dtpProfile) { - return dtpProfile.getName(); - } - }; - } - - private Iterator<IConnectionProfile> dtpConnectionProfiles() { - return new ArrayIterator<IConnectionProfile>(this.dtpProfileManager.getProfiles()); - } - - - // ********** listeners ********** - - public void addConnectionProfileListener(ConnectionProfileListener listener) { - this.profileListener.addConnectionProfileListener(listener); - } - - public void removeConnectionProfileListener(ConnectionProfileListener listener) { - this.profileListener.removeConnectionProfileListener(listener); - } - - - // ********** listener ********** - - /** - * Forward events to the factory's listeners. - */ - private class LocalProfileListener implements IProfileListener1 { - private ListenerList<ConnectionProfileListener> listenerList = new ListenerList<ConnectionProfileListener>(ConnectionProfileListener.class); - - LocalProfileListener() { - super(); - } - - void addConnectionProfileListener(ConnectionProfileListener listener) { - this.listenerList.add(listener); - } - - void removeConnectionProfileListener(ConnectionProfileListener listener) { - this.listenerList.remove(listener); - } - - // ********** IProfileListener implementation ********** - - public void profileAdded(IConnectionProfile dtpProfile) { - String name = dtpProfile.getName(); - for (ConnectionProfileListener listener : this.listenerList.getListeners()) { - listener.connectionProfileAdded(name); - } - } - - public void profileChanged(IConnectionProfile dtpProfile, String oldName, String oldDescription, Boolean oldAutoConnect) { - String newName = dtpProfile.getName(); - if ( ! newName.equals(oldName)) { - for (ConnectionProfileListener listener : this.listenerList.getListeners()) { - listener.connectionProfileRenamed(oldName, newName); - } - } - } - - public void profileChanged(IConnectionProfile dtpProfile) { - // this method shouldn't be called on IProfileListener1 - throw new UnsupportedOperationException(); - } - - public void profileDeleted(IConnectionProfile dtpProfile) { - String name = dtpProfile.getName(); - for (ConnectionProfileListener listener : this.listenerList.getListeners()) { - listener.connectionProfileRemoved(name); - } - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java deleted file mode 100644 index 3547a9867e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java +++ /dev/null @@ -1,543 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.datatools.connectivity.ConnectEvent; -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.IManagedConnection; -import org.eclipse.datatools.connectivity.IManagedConnectionOfflineListener; -import org.eclipse.datatools.connectivity.drivers.DriverManager; -import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; -import org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionInfo; -import org.eclipse.datatools.sqltools.core.DatabaseIdentifier; -import org.eclipse.datatools.sqltools.core.profile.ProfileUtil; -import org.eclipse.jpt.db.ConnectionListener; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.DatabaseFinder; -import org.eclipse.jpt.db.DatabaseObject; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Wrap a DTP ConnectionProfile - */ -final class DTPConnectionProfileWrapper - implements DTPDatabaseObject, ConnectionProfile -{ - // the wrapped DTP connection profile - private final IConnectionProfile dtpConnectionProfile; - - // finder supplied by the JPA platform (determines case-sensitivity, etc.) - private final DatabaseFinder finder; - - // callback passed to the finder - private final DatabaseFinder.DefaultCallback databaseFinderCallback; - - // the DTP managed connection we listen to - private final IManagedConnection dtpManagedConnection; - - // forward events from the DTP managed connection above; - // we listen and propagate events iff we have listeners ourselves - private final LocalConnectionListener connectionListener; - - // lazy-initialized, and deleted at disconnect - private DTPDatabaseWrapper database; - - - // ********** constants ********** - - private static final String LIVE_DTP_CONNECTION_TYPE = "java.sql.Connection"; //$NON-NLS-1$ - - private static final String OFFLINE_DTP_CONNECTION_TYPE = ConnectionInfo.class.getName(); - - private static final String DATABASE_PRODUCT_PROP_ID = "org.eclipse.datatools.connectivity.server.version"; //$NON-NLS-1$ - - - // ********** constructor ********** - - DTPConnectionProfileWrapper(IConnectionProfile dtpConnectionProfile, DatabaseFinder finder) { - super(); - this.dtpConnectionProfile = dtpConnectionProfile; - this.finder = finder; - this.databaseFinderCallback = new DatabaseFinderCallback(); - this.dtpManagedConnection = this.buildDTPManagedConnection(); - this.connectionListener = new LocalConnectionListener(); - // don't listen to the managed connection yet - } - - private IManagedConnection buildDTPManagedConnection() { - String connectionType = this.dtpConnectionProfile.supportsWorkOfflineMode() ? - OFFLINE_DTP_CONNECTION_TYPE : LIVE_DTP_CONNECTION_TYPE; - return this.dtpConnectionProfile.getManagedConnection(connectionType); - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpConnectionProfile.getName(); - } - - public String getIdentifier(String javaIdentifier) { - // connection profiles do not have "identifiers" - throw new UnsupportedOperationException(); - } - - public String getIdentifier() { - // connection profiles do not have "identifiers" - throw new UnsupportedOperationException(); - } - - - // ********** DTPDatabaseObject implementation ********** - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this; - } - - public synchronized DTPDatabaseWrapper getDatabase() { - if (this.database == null) { - this.database = this.buildDatabase(); - } - return this.database; - } - - - // ********** ConnectionProfile implementation ********** - - // ***** properties - public String getProviderID() { - return this.dtpConnectionProfile.getProviderId(); - } - - public String getInstanceID() { - return this.dtpConnectionProfile.getInstanceID(); - } - - public String getDatabaseName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_NAME_PROP_ID); - } - - public String getDatabaseProduct() { - return this.getProperty(DATABASE_PRODUCT_PROP_ID); - } - - public String getDatabaseVendor() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID); - } - - public String getDatabaseVersion() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID); - } - - public String getDriverClassName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DRIVER_CLASS_PROP_ID); - } - - public String getURL() { - return this.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID); - } - - public String getUserName() { - String userName = this.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID); - // 208946 handle username like "sys as sysdba" on Oracle - int index = userName.indexOf(' '); - return (index == -1) ? userName : userName.substring(0, index); - } - - public String getUserPassword() { - return this.getProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID); - } - - public String getDriverDefinitionID() { - return this.getProperty(DRIVER_DEFINITION_PROP_ID); - } - - public String getDriverJarList() { - return DriverManager.getInstance().getDriverInstanceByID(this.getDriverDefinitionID()).getJarList(); - } - - public String getDriverName() { - return DriverManager.getInstance().getDriverInstanceByID(this.getDriverDefinitionID()).getName(); - } - - // ***** connection - public boolean isActive() { - return this.isConnected() || this.isWorkingOffline(); - } - - public boolean isInactive() { - return ! this.isActive(); - } - - public boolean isConnected() { - return this.dtpManagedConnection.isConnected() - && ! this.dtpManagedConnection.isWorkingOffline(); - } - - public boolean isDisconnected() { - return ! this.isConnected(); - } - - public void connect() { - if (this.isDisconnected()) { - this.checkStatus(this.dtpConnectionProfile.connect()); - } - } - - public void disconnect() { - this.checkStatus(this.dtpConnectionProfile.disconnect()); - } - - // ***** off-line support - public boolean isWorkingOffline() { - return this.dtpManagedConnection.isWorkingOffline(); - } - - public boolean supportsWorkOfflineMode() { - return this.dtpConnectionProfile.supportsWorkOfflineMode(); - } - - public IStatus saveWorkOfflineData() { - return this.dtpConnectionProfile.saveWorkOfflineData(); - } - - public boolean canWorkOffline() { - return this.dtpConnectionProfile.canWorkOffline(); - } - - public IStatus workOffline() { - return this.dtpConnectionProfile.workOffline(); - } - - // ***** listeners - public synchronized void addConnectionListener(ConnectionListener listener) { - if (this.hasNoListeners()) { // first listener added - this.startListening(); - } - this.connectionListener.addConnectionListener(listener); - } - - private void startListening() { - this.dtpManagedConnection.addConnectionListener(this.connectionListener); - if (this.database != null) { // don't trigger database creation - if (this.isConnected()) { // DTP does not change when off-line - this.database.startListening(); - } - } - } - - public synchronized void removeConnectionListener(ConnectionListener listener) { - this.connectionListener.removeConnectionListener(listener); - if (this.hasNoListeners()) { // last listener removed - this.stopListening(); - } - } - - private void stopListening() { - if (this.database != null) { // don't trigger database creation - if (this.isConnected()) { // DTP does not change when off-line - this.database.stopListening(); - } - } - this.dtpManagedConnection.removeConnectionListener(this.connectionListener); - } - - boolean hasNoListeners() { - return this.connectionListener.hasNoListeners(); - } - - boolean hasAnyListeners() { - return this.connectionListener.hasAnyListeners(); - } - - - // ********** internal methods ********** - - private void checkStatus(IStatus status) { - if (status.isOK()) { - return; - } - if (status.isMultiStatus()) { - for (IStatus child : status.getChildren()) { - this.checkStatus(child); // recurse, looking for the first error - } - } - throw new RuntimeException(status.getMessage(), status.getException()); - } - - private DTPDatabaseWrapper buildDatabase() { - if (this.isInactive()) { - return null; - } - - if (this.isWorkingOffline()) { - ConnectionInfo connectionInfo = (ConnectionInfo) this.dtpManagedConnection.getConnection().getRawConnection(); - return new DTPDatabaseWrapper(this, connectionInfo.getSharedDatabase()); - } - - // TODO see DTP bug 202306 - // pass connect=true in to ProfileUtil.getDatabase() - // there is a bug mentioned in a comment: - // "during the profile connected event notification, - // IManagedConnection is connected while IConnectionProfile is not" - // so, some hackery here to handle hackery there - return new DTPDatabaseWrapper(this, ProfileUtil.getDatabase(new DatabaseIdentifier(this.getName(), this.getDatabaseName()), true)); - } - - synchronized void clearDatabase() { - if (this.database != null) { - if (this.isConnected()) { // DTP does not change when off-line - this.database.stopListening(); - } - this.database = null; - } - } - - /** - * This is called whenever we need to find a component by identifier - * (e.g. Table.getColumnForIdentifier(String)). We channel all the calls to here - * and then we delegate to the JPA platform-supplied "database finder". - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - return this.finder.selectDatabaseObjectForIdentifier(databaseObjects, identifier, this.databaseFinderCallback); - } - - /** - * The default "database finder" calls back to here so we can delegate to - * the database, which contains all the information necessary to properly - * match identifiers. - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier_(T[] databaseObjects, String identifier) { - // the database should not be null here - call its internal method - return this.database.selectDatabaseObjectForIdentifier_(databaseObjects, identifier); - } - - void databaseChanged(DTPDatabaseWrapper db) { - this.connectionListener.databaseChanged(db); - } - - void catalogChanged(DTPCatalogWrapper catalog) { - this.connectionListener.catalogChanged(catalog); - } - - void schemaChanged(DTPSchemaWrapper schema) { - this.connectionListener.schemaChanged(schema); - } - - void sequenceChanged(DTPSequenceWrapper sequence) { - this.connectionListener.sequenceChanged(sequence); - } - - void tableChanged(DTPTableWrapper table) { - this.connectionListener.tableChanged(table); - } - - void columnChanged(DTPColumnWrapper column) { - this.connectionListener.columnChanged(column); - } - - void foreignKeyChanged(DTPForeignKeyWrapper foreignKey) { - this.connectionListener.foreignKeyChanged(foreignKey); - } - - private String getProperty(String propertyName) { - return this.dtpConnectionProfile.getBaseProperties().getProperty(propertyName); - } - - - // ********** Comparable implementation ********** - - public int compareTo(ConnectionProfile connectionProfile) { - return Collator.getInstance().compare(this.getName(), connectionProfile.getName()); - } - - - // ********** overrides ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } - - - // ********** DTP connection listener ********** - - /** - * This listener translates and forwards IManagedConnectionListener and - * IManagedConnectionOfflineListener events to ConnectionListeners. - */ - class LocalConnectionListener implements IManagedConnectionOfflineListener { - private ListenerList<ConnectionListener> listenerList = new ListenerList<ConnectionListener>(ConnectionListener.class); - - LocalConnectionListener() { - super(); - } - - void addConnectionListener(ConnectionListener listener) { - this.listenerList.add(listener); - } - - void removeConnectionListener(ConnectionListener listener) { - this.listenerList.remove(listener); - } - - boolean hasNoListeners() { - return this.listenerList.isEmpty(); - } - - boolean hasAnyListeners() { - return ! this.listenerList.isEmpty(); - } - - - // ********** IManagedConnectionListener implementation ********** - - // off-line or inactive => live - public void opened(ConnectEvent event) { - // do not build the database here - it is built on-demand - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.opened(DTPConnectionProfileWrapper.this); - } - } - - /** - * This method is never called from the base DTP code. - * Perhaps DTP extenders call it.... - * @see ManagedConnection#fireModifiedEvent(Object) - * which is never called... - */ - public void modified(ConnectEvent event) { - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.modified(DTPConnectionProfileWrapper.this); - } - } - - public boolean okToClose(ConnectEvent event) { - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - if ( ! listener.okToClose(DTPConnectionProfileWrapper.this)) { - return false; - } - } - return true; - } - - public void aboutToClose(ConnectEvent event) { - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.aboutToClose(DTPConnectionProfileWrapper.this); - } - } - - // live or off-line => inactive - public void closed(ConnectEvent event) { - // clear the database - DTPConnectionProfileWrapper.this.clearDatabase(); - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.closed(DTPConnectionProfileWrapper.this); - } - } - - - // ********** IManagedConnectionOfflineListener implementation ********** - - // live => off-line - public boolean okToDetach(ConnectEvent event) { - // convert the event to an "ok to close" event; - // we are "closing" the live connection - return this.okToClose(event); - } - - // live => off-line - public void aboutToDetach(ConnectEvent event) { - // convert the event to a "close" event; - // we are "closing" the live connection - this.closed(event); - } - - // inactive or live => off-line - public void workingOffline(ConnectEvent event) { - // convert the event to an "open" event; - // we are "opening" the off-line connection - this.opened(event); - } - - // off-line => live - public void aboutToAttach(ConnectEvent event) { - // convert the event to an "close" event; - // we are "closing" the off-line connection - this.closed(event); - } - - - // ********** internal methods ********** - - void databaseChanged(DTPDatabaseWrapper db) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.databaseChanged(DTPConnectionProfileWrapper.this, db); - } - } - - void catalogChanged(DTPCatalogWrapper catalog) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.catalogChanged(DTPConnectionProfileWrapper.this, catalog); - } - } - - void schemaChanged(DTPSchemaWrapper schema) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.schemaChanged(DTPConnectionProfileWrapper.this, schema); - } - } - - void sequenceChanged(DTPSequenceWrapper sequence) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.sequenceChanged(DTPConnectionProfileWrapper.this, sequence); - } - } - - void tableChanged(DTPTableWrapper table) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.tableChanged(DTPConnectionProfileWrapper.this, table); - } - } - - void columnChanged(DTPColumnWrapper column) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.columnChanged(DTPConnectionProfileWrapper.this, column); - } - } - - void foreignKeyChanged(DTPForeignKeyWrapper foreignKey) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.foreignKeyChanged(DTPConnectionProfileWrapper.this, foreignKey); - } - } - - } - - - // ********** default DatabaseFinder ********** - - class DatabaseFinderCallback implements DatabaseFinder.DefaultCallback { - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - // call back to the internal method - return DTPConnectionProfileWrapper.this.selectDatabaseObjectForIdentifier_(databaseObjects, identifier); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObject.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObject.java deleted file mode 100644 index c976fe4b39..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObject.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.jpt.db.DatabaseObject; - -/** - * DTP database object - */ -public interface DTPDatabaseObject extends DatabaseObject { - - /** - * covariant override - */ - DTPConnectionProfileWrapper getConnectionProfile(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObjectWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObjectWrapper.java deleted file mode 100644 index a4cfae644c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObjectWrapper.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.jpt.db.DatabaseObject; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * DTP Catalog Object Wrapper base class - */ -abstract class DTPDatabaseObjectWrapper - implements DTPDatabaseObject -{ - // we need a way to get to the connection profile - private final DTPDatabaseObject parent; - - // listen for the "catalog object" being refreshed - private final ICatalogObjectListener catalogObjectListener; - - // listen for this DTP catalog object to refresh - final ICatalogObject catalogObject; - - - // ********** construction/initialization ********** - - DTPDatabaseObjectWrapper(DTPDatabaseObject parent, Object dtpObject) { - super(); - this.parent = parent; - if (this.getConnectionProfile().isConnected()) { - // we only listen to "live" connections (as opposed to "off-line" connections) - this.catalogObject = (ICatalogObject) dtpObject; - this.catalogObjectListener = this.buildCatalogObjectListener(); - if (this.getConnectionProfile().hasAnyListeners()) { - this.startListening(); - } - } else { - this.catalogObject = null; - this.catalogObjectListener = null; - } - } - - private ICatalogObjectListener buildCatalogObjectListener() { - return new ICatalogObjectListener() { - public void notifyChanged(ICatalogObject dmElement, int eventType) { - if (dmElement == DTPDatabaseObjectWrapper.this.catalogObject) { - // 'eventType' doesn't seem to be very useful, so drop it - DTPDatabaseObjectWrapper.this.catalogObjectChanged(); - } - } - }; - } - - // typically, notify the connection profile something has changed - void catalogObjectChanged() { - this.clear(); - } - - /** - * The DTP object has changed, clear the wrapper's state so it will be - * synchronized on-demand. - */ - abstract void clear(); - - - - // ********** queries ********** - - DTPDatabaseObject getParent() { - return this.parent; - } - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this.parent.getConnectionProfile(); - } - - public DTPDatabaseWrapper getDatabase() { - return this.getConnectionProfile().getDatabase(); - } - - /** - * This is called by whenever we need to find a component by identifier - * (e.g. Table.getColumnForIdentifier(String)). We channel all the calls to the - * connection profile, which then delegates to the JPA platform-supplied - * "database finder". - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - return this.getConnectionProfile().selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - - /** - * Convenience method. - */ - <T extends DatabaseObject> T selectDatabaseObjectNamed(T[] databaseObjects, String name) { - for (T dbObject : databaseObjects) { - if (dbObject.getName().equals(name)) { - return dbObject; - } - } - return null; - } - - /** - * Examples: - * Oracle etc. - * Table(FOO) vs. "Foo" => null - * Table(BAR) vs. "Foo" => "BAR" - * Table(Foo) vs. "Foo" => "\"Foo\"" - * Table(Bar) vs. "Foo" => "\"Bar\"" - * - * PostgreSQL etc. - * Table(foo) vs. "Foo" => null - * Table(bar) vs. "Foo" => "bar" - * Table(Foo) vs. "Foo" => "\"Foo\"" - * Table(Bar) vs. "Foo" => "\"Bar\"" - * - * SQL Server etc. - * Table(Foo) vs. "Foo" => null - * Table(foo) vs. "Foo" => "foo" - * Table(bar) vs. "Foo" => "bar" - * Table(Bar) vs. "Foo" => "Bar" - */ - public String getIdentifier(String defaultName) { - return this.getDatabase().convertNameToIdentifier(this.getName(), defaultName); - } - - /** - * Examples: - * Oracle etc. - * Table(FOO) => "FOO" - * Table(Foo) => "\"Foo\"" - * Table(foo) => "\"foo\"" - * Table(foo++) => "\"foo++\"" - * Table(f"o) => "\"f\"\"o++\"" (i.e. "f""o") - * - * PostgreSQL etc. - * Table(FOO) => "\"FOO\"" - * Table(Foo) => "\"Foo\"" - * Table(foo) => "foo" - * Table(foo++) => "\"foo++\"" - * Table(f"o) => "\"f\"\"o++\"" (i.e. "f""o") - * - * SQL Server etc. - * Table(FOO) => "FOO" - * Table(Foo) => "Foo" - * Table(foo) => "foo" - * Table(foo++) => "\"foo++\"" - * Table(f"o) => "\"f\"\"o++\"" (i.e. "f""o") - */ - public String getIdentifier() { - return this.getDatabase().convertNameToIdentifier(this.getName()); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } - - - // ********** listening to DTP database object ********** - - // this should only be called when the connection profile is "live" and has listeners - void startListening() { - this.checkListener(); - RefreshManager.getInstance().AddListener(this.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.catalogObject, this.catalogObjectListener); - } - - private void checkListener() { - if (this.catalogObjectListener == null) { - throw new IllegalStateException("the catalog listener is null"); //$NON-NLS-1$ - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java deleted file mode 100644 index 2c75aeae4e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java +++ /dev/null @@ -1,1191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition; -import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.DatabaseObject; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP Database. - * - * Catalogs vs. Schemata: - * Typically, if a DTP database does not support "catalogs", - * o.e.datatools.modelbase.sql.schema.Database#getCatalogs() will return a - * single catalog without a name (actually, it's an empty string). This catalog - * will contain all the database's schemata. We try to ignore this catalog and - * return the schemata from the database directly. (Note MySQL does not seem - * to be consistent with this pattern.) - * - * Note: - * We use "name" when dealing with the unmodified name of a database object - * as supplied by the database itself (i.e. it is not delimited and it is always - * case-sensitive). - * We use "identifier" when dealing with a string representation of a database - * object name (i.e. it may be delimited and, depending on the vendor, it may - * be case-insensitive). - */ -final class DTPDatabaseWrapper - extends DTPSchemaContainerWrapper - implements Database -{ - // the wrapped DTP database - private final org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase; - - // lazy-initialized, sorted - private DTPCatalogWrapper[] catalogs; - - // lazy-initialized - but it can be 'null' so we use a flag - private DTPCatalogWrapper defaultCatalog; - private boolean defaultCatalogCalculated = false; - - - private static final DTPCatalogWrapper[] EMPTY_CATALOGS = new DTPCatalogWrapper[0]; - - - // ********** constructor ********** - - DTPDatabaseWrapper(DTPConnectionProfileWrapper connectionProfile, org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase) { - super(connectionProfile, dtpDatabase); - this.dtpDatabase = dtpDatabase; - } - - - // ********** DTPWrapper implementation ********** - - /* TODO - * We might want to listen to the "virtual" catalog; but that's probably - * not necessary since there is not easy way for the user to refresh it - * (i.e. it is not displayed in the DTP UI). - */ - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().databaseChanged(this); - } - - @Override - public DTPDatabaseWrapper getDatabase() { - return this; - } - - - // ********** DTPSchemaContainerWrapper implementation ********** - - @Override - @SuppressWarnings("unchecked") - List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemata() { - List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs = this.getDTPCatalogs(); - // if there are no catalogs, the database must hold the schemata directly - if ((dtpCatalogs == null) || dtpCatalogs.isEmpty()) { - return this.dtpDatabase.getSchemas(); - } - org.eclipse.datatools.modelbase.sql.schema.Catalog virtualCatalog = getVirtualCatalog(dtpCatalogs); - return (virtualCatalog != null) ? virtualCatalog.getSchemas() : Collections.emptyList(); - } - - @Override - DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - return this.getSchema_(dtpSchema); - } - - @Override - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.getTable_(dtpTable); - } - - @Override - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getColumn_(dtpColumn); - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpDatabase.getName(); - } - - - // ********** Database implementation ********** - - public String getVendorName() { - return this.dtpDatabase.getVendor(); - } - - public String getVersion() { - return this.dtpDatabase.getVersion(); - } - - // override to make method public since it's in the Database interface - @Override - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - return super.selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - - // ***** catalogs - - public boolean supportsCatalogs() { - return supportsCatalogs(this.getDTPCatalogs()); - } - - private static boolean supportsCatalogs(List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs) { - // if there are no catalogs, they must not be supported - if ((dtpCatalogs == null) || dtpCatalogs.isEmpty()) { - return false; - } - - // if we only have a single catalog with an empty name, - // they are not really supported either... - return ! listContainsOnlyAVirtualCatalog(dtpCatalogs); - } - - /** - * pre-condition: 'dtpCatalogs' is not null - */ - private static boolean listContainsOnlyAVirtualCatalog(List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs) { - return getVirtualCatalog(dtpCatalogs) != null; - } - - /** - * pre-condition: 'dtpCatalogs' is not null - */ - private static org.eclipse.datatools.modelbase.sql.schema.Catalog getVirtualCatalog(List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs) { - if (dtpCatalogs.size() == 1) { - org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog = dtpCatalogs.get(0); - if (dtpCatalog.getName().equals("")) { //$NON-NLS-1$ - return dtpCatalog; - } - } - return null; - } - - public Iterator<Catalog> catalogs() { - return new ArrayIterator<Catalog>(this.getCatalogs()); - } - - private Iterator<DTPCatalogWrapper> catalogWrappers() { - return new ArrayIterator<DTPCatalogWrapper>(this.getCatalogs()); - } - - private synchronized DTPCatalogWrapper[] getCatalogs() { - if (this.catalogs == null) { - this.catalogs = this.buildCatalogs(); - } - return this.catalogs; - } - - private DTPCatalogWrapper[] buildCatalogs() { - List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs = this.getDTPCatalogs(); - if ( ! supportsCatalogs(dtpCatalogs)) { - return EMPTY_CATALOGS; - } - DTPCatalogWrapper[] result = new DTPCatalogWrapper[dtpCatalogs.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPCatalogWrapper(this, dtpCatalogs.get(i)); - } - return CollectionTools.sort(result); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.schema.Catalog> getDTPCatalogs() { - return this.dtpDatabase.getCatalogs(); - } - - public int catalogsSize() { - return this.getCatalogs().length; - } - - /** - * return the catalog for the specified DTP catalog - */ - DTPCatalogWrapper getCatalog(org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) { - for (DTPCatalogWrapper catalog : this.getCatalogs()) { - if (catalog.wraps(dtpCatalog)) { - return catalog; - } - } - throw new IllegalArgumentException("invalid DTP catalog: " + dtpCatalog); //$NON-NLS-1$ - } - - public DTPCatalogWrapper getCatalogNamed(String name) { - return this.selectDatabaseObjectNamed(this.getCatalogs(), name); - } - - public Iterator<String> sortedCatalogIdentifiers() { - // the catalogs are already sorted - return new TransformationIterator<DTPCatalogWrapper, String>(this.catalogWrappers()) { - @Override - protected String transform(DTPCatalogWrapper next) { - return next.getIdentifier(); - } - }; - } - - public DTPCatalogWrapper getCatalogForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getCatalogs(), identifier); - } - - public synchronized DTPCatalogWrapper getDefaultCatalog() { - if ( ! this.defaultCatalogCalculated) { - this.defaultCatalogCalculated = true; - this.defaultCatalog = this.buildDefaultCatalog(); - } - return this.defaultCatalog; - } - - private DTPCatalogWrapper buildDefaultCatalog() { - return this.supportsCatalogs() ? this.getVendor().getDefaultCatalog(this) : null; - } - - // ***** schemata - - @Override - synchronized DTPSchemaWrapper[] getSchemata() { - DTPCatalogWrapper cat = this.getDefaultCatalog(); - return (cat != null) ? cat.getSchemata() : super.getSchemata(); - } - - /** - * Return the specified schema container's default schema. - */ - DTPSchemaWrapper getDefaultSchema(DTPSchemaContainerWrapper schemaContainer) { - return this.getVendor().getDefaultSchema(schemaContainer); - } - - - // ********** names vs. identifiers ********** - - /** - * Convert the specified name to an identifier. Return null if the resulting - * identifier matches the specified default name. - */ - String convertNameToIdentifier(String name, String defaultName) { - return this.getVendor().convertNameToIdentifier(name, defaultName); - } - - /** - * Convert the specified name to an identifier. - */ - public String convertNameToIdentifier(String name) { - return this.getVendor().convertNameToIdentifier(name); - } - - /** - * Return the database object identified by the specified identifier. If - * the identifier is "delimited" (typically with double-quotes), it will be - * used without any folding. If the name is "normal" (i.e. not delimited), - * it will be folded to the appropriate case (typically uppercase). - * - * Since the database has the appropriate state to compare identifiers and - * names, the connection profile delegates to here when using the default - * "database finder". - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier_(T[] databaseObjects, String identifier) { - return this.selectDatabaseObjectNamed(databaseObjects, this.convertIdentifierToName(identifier)); - } - - /** - * Convert the specified identifier to a name. - */ - String convertIdentifierToName(String identifier) { - return this.getVendor().convertIdentifierToName(identifier); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Database database) { - return Collator.getInstance().compare(this.getName(), database.getName()); - } - - - // ********** internal methods ********** - - DatabaseDefinition getDTPDefinition() { - return RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(this.dtpDatabase); - } - - private Vendor getVendor() { - return getVendor(this.getVendorName()); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.catalogs != null) { - this.startCatalogs(); - } - super.startListening(); - } - - private void startCatalogs() { - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.catalogs != null) { - this.stopCatalogs(); - } - super.stopListening(); - } - - private void stopCatalogs() { - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.stopListening(); - } - } - - - // ********** clear ********** - - @Override - void clear() { - this.defaultCatalogCalculated = false; - this.defaultCatalog = null; - if (this.catalogs != null) { - this.clearCatalogs(); - } - super.clear(); - } - - private void clearCatalogs() { - this.stopCatalogs(); - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.clear(); - } - this.catalogs = null; - } - - - // ********** vendors ********** - - private static Vendor getVendor(String name) { - Vendor vendor = getVendors().get(name); - return (vendor != null) ? vendor : Default.INSTANCE; - } - - /** - * keyed by vendor name - */ - private static HashMap<String, Vendor> Vendors; - - private static synchronized HashMap<String, Vendor> getVendors() { - if (Vendors == null) { - Vendors = buildVendors(); - } - return Vendors; - } - - private static HashMap<String, Vendor> buildVendors() { - HashMap<String, Vendor> map = new HashMap<String, Vendor>(20); - putVendor(map, Derby.INSTANCE); - putVendor(map, HSQLDB.INSTANCE); - putVendor(map, DB2.UDB); - putVendor(map, DB2.UDB_I_SERIES); - putVendor(map, DB2.UDB_Z_SERIES); - putVendor(map, Informix.INSTANCE); - putVendor(map, SQLServer.INSTANCE); - putVendor(map, MySQL.INSTANCE); - putVendor(map, Oracle.INSTANCE); - putVendor(map, Postgres.INSTANCE); - putVendor(map, MaxDB.INSTANCE); - putVendor(map, Sybase.ASA); - putVendor(map, Sybase.ASE); - return map; - } - - private static void putVendor(HashMap<String, Vendor> map, Vendor vendor) { - String name = vendor.getName(); - if (map.put(name, vendor) != null) { - throw new IllegalArgumentException("Duplicate vendor: " + name); //$NON-NLS-1$ - } - } - - - // ********** vendor classes ********** - - /** - * Delegate vendor-specific behavior to implementations of this class" - * - default catalog and schema - * - converting names to identifiers and vice-versa - * - * Note: - * We use "name" when dealing with the unmodified name of a database object - * as supplied by the database itself (i.e. it is not delimited and it is always - * case-sensitive). - * We use "identifier" when dealing with a string representation of a database - * object name (i.e. it may be delimited and, depending on the vendor, it may - * be case-insensitive). - */ - private abstract static class Vendor { - - Vendor() { - super(); - } - - /** - * Return the vendor's name. This must match the name specified by the - * DTP connection profile. - */ - abstract String getName(); - - /** - * The SQL spec says a "normal" (non-delimited) identifier should be - * folded to uppercase; but some databases do otherwise (e.g. Sybase). - */ - Folder getFolder() { - return Folder.UPPER; - } - - - // ********** default catalog and schema ********** - - /** - * Return whether the vendor supports catalogs. - */ - abstract boolean supportsCatalogs(); - - DTPCatalogWrapper getDefaultCatalog(DTPDatabaseWrapper database) { - if ( ! this.supportsCatalogs()) { - throw new UnsupportedOperationException(); - } - return database.getCatalogForIdentifier(this.getDefaultCatalogIdentifier(database)); - } - - /** - * Typically, the name of the default catalog is the user name. - */ - String getDefaultCatalogIdentifier(DTPDatabaseWrapper database) { - if ( ! this.supportsCatalogs()) { - throw new UnsupportedOperationException(); - } - return database.getConnectionProfile().getUserName(); - } - - DTPSchemaWrapper getDefaultSchema(DTPSchemaContainerWrapper sc) { - return sc.getSchemaForIdentifier(this.getDefaultSchemaIdentifier(sc)); - } - - /** - * Typically, the name of the default schema is the user name. - */ - String getDefaultSchemaIdentifier(DTPSchemaContainerWrapper sc) { - return sc.getDatabase().getConnectionProfile().getUserName(); - } - - - // ********** name -> identifier ********** - - /** - * @see DTPDatabaseWrapper#convertNameToIdentifier(String, String) - */ - final String convertNameToIdentifier(String name, String defaultName) { - return this.nameRequiresDelimiters(name) ? this.delimitName(name) - : this.normalNamesMatch(name, defaultName) ? null : name; - } - - /** - * @see DTPDatabaseWrapper#convertNameToIdentifier(String) - */ - final String convertNameToIdentifier(String name) { - return this.nameRequiresDelimiters(name) ? this.delimitName(name) : name; - } - - /** - * Return whether the specified database object name must be delimited - * when used in an SQL statement. - * If the name has any "special" characters (as opposed to letters, - * digits, and other allowed characters [e.g. underscores]), it requires - * delimiters. - * If the name is mixed case and the database folds undelimited names - * (to either uppercase or lowercase), it requires delimiters. - */ - final boolean nameRequiresDelimiters(String name) { - return (name.length() == 0) // an empty string must be delimited(?) - || this.nameContainsAnySpecialCharacters(name) - || this.nameIsNotFolded(name); - } - - /** - * Return whether the specified name contains any "special" characters - * that require the name to be delimited. - * Pre-condition: the specified name is not empty - */ - final boolean nameContainsAnySpecialCharacters(String name) { - char[] string = name.toCharArray(); - if (this.characterIsSpecialNameStart(string[0])) { - return true; - } - for (int i = string.length; i-- > 1; ) { // note: stop at 1 - if (this.characterIsSpecialNamePart(string[i])) { - return true; - } - } - return false; - } - - /** - * Return whether the specified character is "special" for the first - * character of a name. - * Typically, databases are more restrictive about what characters can - * be used to *start* an identifier (as opposed to the characters - * allowed for the remainder of the identifier). - */ - final boolean characterIsSpecialNameStart(char c) { - return ! this.characterIsNormalNameStart(c); - } - - /** - * Return whether the specified character is "normal" for the first - * character of a name. - * The first character of an identifier can be: - * - a letter - * - any of the other, vendor-specific, "normal" start characters - */ - boolean characterIsNormalNameStart(char c) { - // all vendors allow a letter - return Character.isLetter(c) - || this.characterIsNormalNameStart_(c); - } - - private boolean characterIsNormalNameStart_(char c) { - return arrayContains(this.getNormalNameStartCharacters(), c); - } - - /** - * Return the "normal" characters, beyond letters, for the - * first character of a name. - * Return null if there are no additional characters. - */ - char[] getNormalNameStartCharacters() { - return null; - } - - /** - * Return whether the specified character is "special" for the second and - * subsequent characters of a name. - */ - final boolean characterIsSpecialNamePart(char c) { - return ! this.characterIsNormalNamePart(c); - } - - /** - * Return whether the specified character is "normal" for the second and - * subsequent characters of a name. - * The second and subsequent characters of a "normal" name can be: - * - a letter - * - a digit - * - any of the other, vendor-specific, "normal" start characters - * - any of the other, vendor-specific, "normal" part characters - */ - boolean characterIsNormalNamePart(char c) { - // all vendors allow a letter or digit - return Character.isLetterOrDigit(c) - || this.characterIsNormalNameStart_(c) - || this.characterIsNormalNamePart_(c); - } - - private boolean characterIsNormalNamePart_(char c) { - return arrayContains(this.getNormalNamePartCharacters(), c); - } - - /** - * Return the "normal" characters, beyond letters and digits and the - * "normal" first characters, for the second and subsequent characters - * of an identifier. Return null if there are no additional characters. - */ - char[] getNormalNamePartCharacters() { - return null; - } - - /** - * Return whether the specified name is not folded to the database's - * case, requiring it to be delimited. - */ - final boolean nameIsNotFolded(String name) { - return ! this.getFolder().stringIsFolded(name); - } - - /** - * Return whether the specified "normal" names match. - */ - final boolean normalNamesMatch(String name1, String name2) { - return this.normalIdentifiersAreCaseSensitive() ? - name1.equals(name2) - : - name1.equalsIgnoreCase(name2); - } - - /** - * Typically, "normal" identifiers are case-insensitive. - */ - final boolean normalIdentifiersAreCaseSensitive() { - return this.getFolder().isCaseSensitive(); - } - - /** - * Wrap the specified name in delimiters (typically double-quotes), - * converting it to an identifier. - */ - String delimitName(String name) { - return StringTools.quote(name); - } - - - // ********** identifier -> name ********** - - /** - * @see DTPDatabaseWrapper#selectDatabaseObjectForIdentifier_(DatabaseObject[], String) - */ - // not sure how to handle an empty string: - // both "" and "\"\"" are converted to "" ... - // convert "" to 'null' since empty strings must be delimited? - final String convertIdentifierToName(String identifier) { - return (identifier == null) ? null : - this.identifierIsDelimited(identifier) ? - StringTools.undelimit(identifier) - : - this.getFolder().fold(identifier); - } - - /** - * Return whether the specified identifier is "delimited". - * The SQL-92 spec says identifiers should be delimited by - * double-quotes; but some databases allow otherwise (e.g. Sybase). - */ - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsQuoted(identifier); - } - - - // ********** misc ********** - - @Override - public String toString() { - return this.getName(); - } - - /** - * static convenience method - array null check - */ - static boolean arrayContains(char[] array, char c) { - return (array != null) && CollectionTools.contains(array, c); - } - - /** - * Handle database-specific case-folding issues. - */ - enum Folder { - UPPER { - @Override String fold(String string) { return string.toUpperCase(); } - @Override boolean stringIsFolded(String string) { return StringTools.stringIsUppercase(string); } - @Override boolean isCaseSensitive() { return false; } - }, - LOWER { - @Override String fold(String string) { return string.toLowerCase(); } - @Override boolean stringIsFolded(String string) { return StringTools.stringIsLowercase(string); } - @Override boolean isCaseSensitive() { return false; } - }, - NONE { - @Override String fold(String string) { return string; } - @Override boolean stringIsFolded(String string) { return true; } - @Override boolean isCaseSensitive() { return true; } - }; - abstract String fold(String string); - abstract boolean stringIsFolded(String string); - abstract boolean isCaseSensitive(); - } - - } - - private static class Default extends Vendor { - static final Vendor INSTANCE = new Default(); - - private Default() { - super(); - } - - @Override - String getName() { - return "Default Vendor"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return true; // hmmm... ~bjv - } - - } - - private static class Derby extends Vendor { - static final Vendor INSTANCE = new Derby(); - - private Derby() { - super(); - } - - @Override - String getName() { - return "Derby"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return false; - } - - /** - * The default user name on Derby is "APP". - */ - @Override - String getDefaultSchemaIdentifier(DTPSchemaContainerWrapper sc) { - String user = super.getDefaultSchemaIdentifier(sc); - return ((user == null) || (user.length() == 0)) ? - DEFAULT_USER_NAME - : - user; - } - private static final String DEFAULT_USER_NAME = "APP"; //$NON-NLS-1$ - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '_' }; - - } - - private static class HSQLDB extends Vendor { - static final Vendor INSTANCE = new HSQLDB(); - - private HSQLDB() { - super(); - } - - @Override - String getName() { - return "HSQLDB"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return false; - } - - @Override - String getDefaultSchemaIdentifier(DTPSchemaContainerWrapper sc) { - return PUBLIC_SCHEMA_NAME; - } - private static final String PUBLIC_SCHEMA_NAME = "PUBLIC"; //$NON-NLS-1$ - - } - - private static class DB2 extends Vendor { - static final Vendor UDB_I_SERIES = new DB2("DB2 UDB iSeries"); //$NON-NLS-1$ - static final Vendor UDB = new DB2("DB2 UDB"); //$NON-NLS-1$ - static final Vendor UDB_Z_SERIES = new DB2("DB2 UDB zSeries"); //$NON-NLS-1$ - - private final String name; - - private DB2(String name) { - super(); - this.name = name; - } - - @Override - String getName() { - return this.name; - } - - @Override - boolean supportsCatalogs() { - return false; - } - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '_' }; - - } - - private static class Informix extends Vendor { - static final Vendor INSTANCE = new Informix(); - - private Informix() { - super(); - } - - @Override - String getName() { - return "Informix"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return false; - } - - @Override - Folder getFolder() { - return Folder.LOWER; - } - - @Override - char[] getNormalNameStartCharacters() { - return NORMAL_NAME_START_CHARACTERS; - } - private static final char[] NORMAL_NAME_START_CHARACTERS = new char[] { '_' }; - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '$' }; - - } - - private static class SQLServer extends Vendor { - static final Vendor INSTANCE = new SQLServer(); - - private SQLServer() { - super(); - } - - @Override - String getName() { - return "SQL Server"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return true; - } - - /** - * The default schema on SQL Server for any database (catalog) is 'dbo'. - */ - @Override - String getDefaultSchemaIdentifier(DTPSchemaContainerWrapper sc) { - return DEFAULT_SCHEMA_NAME; - } - private static final String DEFAULT_SCHEMA_NAME = "dbo"; //$NON-NLS-1$ - - /** - * By default, SQL Server identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - @Override - Folder getFolder() { - return Folder.NONE; - } - - @Override - char[] getNormalNameStartCharacters() { - return NORMAL_NAME_START_CHARACTERS; - } - private static final char[] NORMAL_NAME_START_CHARACTERS = new char[] { '_', '@', '#' }; - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '$' }; - - /** - * By default, SQL Server delimits identifiers with brackets ([]); but it - * can also be configured to use double-quotes. - */ - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsBracketed(identifier) - || super.identifierIsDelimited(identifier); - } - - } - - private static class MySQL extends Vendor { - static final Vendor INSTANCE = new MySQL(); - - private MySQL() { - super(); - } - - @Override - String getName() { - return "MySql"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return false; - } - - /** - * MySQL is a bit unusual, so we force exact matches. - * (e.g. MySQL folds database and table names to lowercase on Windows - * by default; but that default can be changed by the - * 'lower_case_table_names' system variable. This is because databases are - * stored as directories and tables are stored as files in the underlying - * O/S; and the case-sensitivity of the names is determined by the behavior - * of filenames on the O/S. Then, to complicate things, - * none of the other identifiers, like table and column names, are folded; - * but they are case-insensitive, unless delimited. See - * http://dev.mysql.com/doc/refman/6.0/en/identifier-case-sensitivity.html.) - */ - @Override - Folder getFolder() { - return Folder.NONE; - } - - /** - * The DTP model for MySQL has a database that contains no catalogs - * but directly holds a single schema with the same name as the database. - * Although you can qualify identifiers with a database name - * in MySQL, only the database specified at login seems to be available - * in the DTP model.... - * NB: In MySQL DDL, SCHEMA is a synonym for DATABASE; but the JDBC - * method DatabaseMetaData.getSchemas() returns an empty list, - * while getCatalogs() returns a list of the available databases. - * You can also use the JDBC method Connection.setCatalog(String) to - * set the default database. - */ - @Override - String getDefaultSchemaIdentifier(DTPSchemaContainerWrapper sc) { - return sc.getDatabase().getName(); // hmmm... ~bjv - } - - /** - * MySQL is the only vendor that allows a digit. - * Although, the name cannnot be *all* digits. - */ - @Override - boolean characterIsNormalNameStart(char c) { - return Character.isDigit(c) || super.characterIsNormalNameStart(c); - } - - @Override - char[] getNormalNameStartCharacters() { - return NORMAL_NAME_START_CHARACTERS; - } - private static final char[] NORMAL_NAME_START_CHARACTERS = new char[] { '_', '$' }; - - /** - * By default, MySQL delimits identifiers with backticks (`); but it - * can also be configured to use double-quotes. - */ - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsDelimited(identifier, BACKTICK) - || super.identifierIsDelimited(identifier); - } - private static final char BACKTICK = '`'; - - } - - private static class Oracle extends Vendor { - static final Vendor INSTANCE = new Oracle(); - - private Oracle() { - super(); - } - - @Override - String getName() { - return "Oracle"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return false; - } - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '_', '$', '#' }; - - } - - private static class Postgres extends Vendor { - static final Vendor INSTANCE = new Postgres(); - - private Postgres() { - super(); - } - - @Override - String getName() { - return "postgres"; //$NON-NLS-1$ - } - - @Override - Folder getFolder() { - return Folder.LOWER; - } - - @Override - boolean supportsCatalogs() { - return false; - } - - /** - * PostgreSQL has a "schema search path". The default is: - * "$user",public - * If "$user" is not found, return "public". - */ - @Override - DTPSchemaWrapper getDefaultSchema(DTPSchemaContainerWrapper sc) { - DTPSchemaWrapper userSchema = super.getDefaultSchema(sc); - return (userSchema != null) ? userSchema : sc.getSchemaNamed(PUBLIC_SCHEMA_NAME); - } - private static final String PUBLIC_SCHEMA_NAME = "public"; //$NON-NLS-1$ - - @Override - char[] getNormalNameStartCharacters() { - return NORMAL_NAME_START_CHARACTERS; - } - private static final char[] NORMAL_NAME_START_CHARACTERS = new char[] { '_' }; - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '$' }; - - } - - private static class MaxDB extends Vendor { - static final Vendor INSTANCE = new MaxDB(); - - private MaxDB() { - super(); - } - - @Override - String getName() { - return "MaxDB"; //$NON-NLS-1$ - } - - @Override - boolean supportsCatalogs() { - return false; - } - - @Override - char[] getNormalNameStartCharacters() { - return NORMAL_NAME_START_CHARACTERS; - } - private static final char[] NORMAL_NAME_START_CHARACTERS = new char[] { '#', '@', '$' }; - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '_' }; - - } - - private static class Sybase extends Vendor { - static final Vendor ASA = new Sybase("Sybase_ASA"); //$NON-NLS-1$ - static final Vendor ASE = new Sybase("Sybase_ASE"); //$NON-NLS-1$ - - private final String name; - - private Sybase(String name) { - super(); - this.name = name; - } - - @Override - String getName() { - return this.name; - } - - @Override - boolean supportsCatalogs() { - return true; - } - - /** - * The typical default schema on Sybase for any database (catalog) is - * 'dbo'. - * - * Actually, the default schema is more like a search path: - * The server looks for a schema object (e.g table) first in the user's - * schema, the it look for the schema object in the database owner's - * schema (dbo). As a result, it's really not possible to specify - * the "default" schema without knowing the schema object we are - * looking for. - * - * (Note: the current 'user' is not the same thing as the current - * 'login' - see sp_adduser and sp_addlogin; so we probably can't - * use ConnectionProfile#getUserName().) - */ - @Override - String getDefaultSchemaIdentifier(DTPSchemaContainerWrapper sc) { - return DEFAULT_SCHEMA_NAME; - } - private static final String DEFAULT_SCHEMA_NAME = "dbo"; //$NON-NLS-1$ - - /** - * By default, Sybase identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - @Override - Folder getFolder() { - return Folder.NONE; - } - - @Override - char[] getNormalNameStartCharacters() { - return NORMAL_NAME_START_CHARACTERS; - } - private static final char[] NORMAL_NAME_START_CHARACTERS = new char[] { '_', '@' }; - - @Override - char[] getNormalNamePartCharacters() { - return NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] NORMAL_NAME_PART_CHARACTERS = new char[] { '$', '¥', '£', '#' }; - - /** - * By default, Sybase delimits identifiers with brackets ([]); but it - * can also be configured to use double-quotes. - */ - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsBracketed(identifier) - || super.identifierIsDelimited(identifier); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java deleted file mode 100644 index 10e9df6dd2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP ForeignKey - */ -final class DTPForeignKeyWrapper - extends DTPDatabaseObjectWrapper - implements ForeignKey -{ - // the wrapped DTP foreign key - private final org.eclipse.datatools.modelbase.sql.constraints.ForeignKey dtpForeignKey; - - // lazy-initialized - private DTPTableWrapper referencedTable; - - // lazy-initialized - private LocalColumnPair[] columnPairs; - - // lazy-initialized - but it can be 'null' so we use a flag - private String defaultAttributeName; - private boolean defaultAttributeNameCalculated = false; - - - // ********** constructor ********** - - DTPForeignKeyWrapper(DTPTableWrapper baseTable, org.eclipse.datatools.modelbase.sql.constraints.ForeignKey dtpForeignKey) { - super(baseTable, dtpForeignKey); - this.dtpForeignKey = dtpForeignKey; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().foreignKeyChanged(this); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName() + ": " + Arrays.asList(this.getColumnPairs())); //$NON-NLS-1$ - } - - - // ********** ForeignKey implementation ********** - - public String getName() { - return this.dtpForeignKey.getName(); - } - - public DTPTableWrapper getBaseTable() { - return (DTPTableWrapper) this.getParent(); - } - - public synchronized DTPTableWrapper getReferencedTable() { - if (this.referencedTable == null) { - this.referencedTable = this.getBaseTable().getTable(this.dtpForeignKey.getUniqueConstraint().getBaseTable()); - } - return this.referencedTable; - } - - public boolean referencesSingleColumnPrimaryKey() { - if (this.columnPairsSize() != 1) { - return false; - } - if (this.getReferencedTable().primaryKeyColumnsSize() != 1) { - return false; - } - return this.getColumnPair().getReferencedColumn() == this.getReferencedTable().getPrimaryKeyColumn(); - } - - // ***** column pairs - - public Iterator<ColumnPair> columnPairs() { - return new ArrayIterator<ColumnPair>(this.getColumnPairs()); - } - - public LocalColumnPair getColumnPair() { - LocalColumnPair[] pairs = this.getColumnPairs(); - if (pairs.length != 1) { - throw new IllegalStateException("multiple column pairs: " + pairs.length); //$NON-NLS-1$ - } - return pairs[0]; - } - - private Iterator<LocalColumnPair> localColumnPairs() { - return new ArrayIterator<LocalColumnPair>(this.getColumnPairs()); - } - - private synchronized LocalColumnPair[] getColumnPairs() { - if (this.columnPairs == null) { - this.columnPairs = this.buildColumnPairs(); - } - return this.columnPairs; - } - - private LocalColumnPair[] buildColumnPairs() { - List<org.eclipse.datatools.modelbase.sql.tables.Column> baseColumns = this.getDTPBaseColumns(); - int size = baseColumns.size(); - List<org.eclipse.datatools.modelbase.sql.tables.Column> refColumns = this.getDTPReferenceColumns(); - if (refColumns.size() != size) { - throw new IllegalStateException(this.getBaseTable().getName() + '.' + this.getName() + - " - mismatched sizes: " + size + " vs. " + refColumns.size()); //$NON-NLS-1$ //$NON-NLS-2$ - } - LocalColumnPair[] result = new LocalColumnPair[baseColumns.size()]; - for (int i = baseColumns.size(); i-- > 0; ) { - result[i] = new LocalColumnPair( - this.getBaseTable().getColumn(baseColumns.get(i)), - this.getBaseTable().getColumn(refColumns.get(i)) - ); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPBaseColumns() { - return this.dtpForeignKey.getMembers(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPReferenceColumns() { - return this.dtpForeignKey.getUniqueConstraint().getMembers(); - } - - public int columnPairsSize() { - return this.getColumnPairs().length; - } - - public Iterator<Column> baseColumns() { - return new TransformationIterator<LocalColumnPair, Column>(this.localColumnPairs()) { - @Override - protected Column transform(LocalColumnPair pair) { - return pair.getBaseColumn(); - } - }; - } - - boolean baseColumnsContains(Column column) { - return CollectionTools.contains(this.baseColumns(), column); - } - - public Iterator<Column> nonPrimaryKeyBaseColumns() { - return new FilteringIterator<Column, Column>(this.baseColumns()) { - @Override - protected boolean accept(Column column) { - return ! column.isPartOfPrimaryKey(); - } - }; - } - - public Iterator<Column> referencedColumns() { - return new TransformationIterator<LocalColumnPair, Column>(this.localColumnPairs()) { - @Override - protected Column transform(LocalColumnPair columnPair) { - return columnPair.getReferencedColumn(); - } - }; - } - - // ***** attribute name - - public String getAttributeName() { - String defaultName = this.getDefaultAttributeName(); - return (defaultName != null) ? defaultName : this.getNonDefaultAttributeName(); - } - - public synchronized String getDefaultAttributeName() { - if ( ! this.defaultAttributeNameCalculated) { - this.defaultAttributeNameCalculated = true; - this.defaultAttributeName = this.buildDefaultAttributeName(); - } - return this.defaultAttributeName; - } - - private String buildDefaultAttributeName() { - if ( ! this.referencesSingleColumnPrimaryKey()) { - return null; - } - LocalColumnPair columnPair = this.getColumnPair(); - String baseColName = columnPair.getBaseColumn().getName(); - String refColName = columnPair.getReferencedColumn().getName(); - if (baseColName.length() <= (refColName.length() + 1)) { - return null; - } - if ( ! baseColName.endsWith(refColName)) { - return null; - } - int _index = baseColName.length() - refColName.length() - 1; - if (baseColName.charAt(_index) != '_') { - return null; - } - return baseColName.substring(0, _index); - } - - /** - * If this is a simple (single-column) foreign key, use the name of the - * single base column to build a name. If this is a compound foreign key, - * return the name of the referenced table. - */ - // TODO if there is only one FK to a given table, use the table's name instead of the column's name? - private String getNonDefaultAttributeName() { - return (this.columnPairsSize() == 1) ? - this.getNonDefaultAttributeNameFromBaseColumn() - : - this.getReferencedTable().getName(); - } - - /** - * The underscore check is helpful when the referenced column is NOT the - * primary key of the referenced table (i.e. it has only a UNIQUE constraint). - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * ForeignKey(EMP.CUBICLEID => CUBICLE.ID) => "CUBICLE" - * ForeignKey(EMP.CUBICLE_PK => CUBICLE.ID) => "CUBICLE_PK" - */ - private String getNonDefaultAttributeNameFromBaseColumn() { - LocalColumnPair columnPair = this.getColumnPair(); - String baseColName = columnPair.getBaseColumn().getName(); - String refColName = columnPair.getReferencedColumn().getName(); - int len = baseColName.length(); - int refLen = refColName.length(); - if ((len > refLen) && baseColName.endsWith(refColName)) { - len = len - refLen; - if ((len > 1) && baseColName.charAt(len - 1) == '_') { - len = len - 1; - } - } - return baseColName.substring(0, len); - } - - /** - * Examples: - * Oracle etc. - * ForeignKey(FOO_ID => ID) vs. "foo" => null - * ForeignKey(FOO_ID => FOO_ID) vs. "foo" => "FOO_ID" - * ForeignKey(FOO => ID) vs. "foo" => "FOO" - * ForeignKey(Foo_ID => ID) vs. "foo" => "\"Foo_ID\"" - * - * PostgreSQL etc. - * ForeignKey(foo_id => id) vs. "foo" => null - * ForeignKey(foo_id => foo_id) vs. "foo" => "foo_id" - * ForeignKey(foo => id) vs. "foo" => "foo" - * ForeignKey(Foo_ID => ID) vs. "foo" => "\"Foo_ID\"" - * - * SQL Server etc. - * ForeignKey(foo_ID => ID) vs. "foo" => null - * ForeignKey(FOO_ID => FOO_ID) vs. "foo" => "FOO_ID" - * ForeignKey(FOO => ID) vs. "foo" => "FOO" - * ForeignKey(Foo_ID => ID) vs. "foo" => "Foo_ID" - */ - public String getJoinColumnAnnotationIdentifier(String attributeName) { - String baseColumnName = this.getColumnPair().getBaseColumn().getName(); - String defaultBaseColumnName = attributeName + '_' + this.getReferencedTable().getPrimaryKeyColumn().getName(); - return this.getDatabase().convertNameToIdentifier(baseColumnName, defaultBaseColumnName); - } - - - // ********** Comparable implementation ********** - - public int compareTo(ForeignKey foreignKey) { - return Collator.getInstance().compare(this.getName(), foreignKey.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.constraints.ForeignKey foreignKey) { - return this.dtpForeignKey == foreignKey; - } - - @Override - void clear() { - // the foreign key does not "contain" any other objects, - // so we don't need to forward the #clear() - this.defaultAttributeNameCalculated = false; - this.defaultAttributeName = null; - this.columnPairs = null; - this.referencedTable = null; - } - - - // ********** column pair implementation ********** - - private static class LocalColumnPair implements ColumnPair { - private final DTPColumnWrapper baseColumn; - private final DTPColumnWrapper referencedColumn; - - LocalColumnPair(DTPColumnWrapper baseColumn, DTPColumnWrapper referencedColumn) { - super(); - if ((baseColumn == null) || (referencedColumn == null)) { - throw new NullPointerException(); - } - this.baseColumn = baseColumn; - this.referencedColumn = referencedColumn; - } - - public DTPColumnWrapper getBaseColumn() { - return this.baseColumn; - } - - public DTPColumnWrapper getReferencedColumn() { - return this.referencedColumn; - } - - public int compareTo(ColumnPair columnPair) { - return Collator.getInstance().compare(this.getBaseColumn().getName(), columnPair.getBaseColumn().getName()); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.baseColumn.getName() + "=>" + this.referencedColumn.getName()); //$NON-NLS-1$ - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java deleted file mode 100644 index f04936cbff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Iterator; -import java.util.List; -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.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Coalesce behavior for a schema container (i.e. database or catalog). - */ -abstract class DTPSchemaContainerWrapper - extends DTPDatabaseObjectWrapper - implements SchemaContainer -{ - // lazy-initialized - private DTPSchemaWrapper[] schemata; - - - // ********** constructor ********** - - DTPSchemaContainerWrapper(DTPDatabaseObject parent, Object dtpObject) { - super(parent, dtpObject); - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - } - - - // ********** abstract methods ********** - - /** - * return the schema container's DTP schemata - */ - abstract List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemata(); - - /** - * return the schema for the specified DTP schema - */ - abstract DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema); - - /** - * assume the schema container (database or catalog) contains - * the specified schema - */ - DTPSchemaWrapper getSchema_(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - for (DTPSchemaWrapper schema : this.getSchemata()) { - if (schema.wraps(dtpSchema)) { - return schema; - } - } - throw new IllegalArgumentException("invalid DTP schema: " + dtpSchema); //$NON-NLS-1$ - } - - /** - * return the table for the specified DTP table - */ - abstract DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable); - - /** - * assume the schema container contains the specified table - */ - DTPTableWrapper getTable_(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.getSchema_(dtpTable.getSchema()).getTable_(dtpTable); - } - - /** - * return the column for the specified DTP column - */ - abstract DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn); - - /** - * assume the schema container contains the specified column - */ - DTPColumnWrapper getColumn_(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getTable_(dtpColumn.getTable()).getColumn_(dtpColumn); - } - - - // ********** schemata ********** - - public Iterator<Schema> schemata() { - return new ArrayIterator<Schema>(this.getSchemata()); - } - - Iterator<DTPSchemaWrapper> schemaWrappers() { - return new ArrayIterator<DTPSchemaWrapper>(this.getSchemata()); - } - - synchronized DTPSchemaWrapper[] getSchemata() { - if (this.schemata == null) { - this.schemata = this.buildSchemata(); - } - return this.schemata; - } - - private DTPSchemaWrapper[] buildSchemata() { - List<org.eclipse.datatools.modelbase.sql.schema.Schema> dtpSchemata = this.getDTPSchemata(); - DTPSchemaWrapper[] result = new DTPSchemaWrapper[dtpSchemata.size()]; - for (int i = result.length; i-- > 0; ) { - result[i] = new DTPSchemaWrapper(this, dtpSchemata.get(i)); - } - return CollectionTools.sort(result); - } - - public int schemataSize() { - return this.getSchemata().length; - } - - public DTPSchemaWrapper getSchemaNamed(String name) { - return this.selectDatabaseObjectNamed(this.getSchemata(), name); - } - - public Iterator<String> sortedSchemaIdentifiers() { - // the schemata are already sorted - return new TransformationIterator<DTPSchemaWrapper, String>(this.schemaWrappers()) { - @Override - protected String transform(DTPSchemaWrapper next) { - return next.getIdentifier(); - } - }; - } - - public DTPSchemaWrapper getSchemaForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getSchemata(), identifier); - } - - public DTPSchemaWrapper getDefaultSchema() { - return this.getDatabase().getDefaultSchema(this); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.schemata != null) { - this.startSchemata(); - } - super.startListening(); - } - - private void startSchemata() { - for (DTPSchemaWrapper schema : this.schemata) { - schema.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.schemata != null) { - this.stopSchemata(); - } - super.stopListening(); - } - - private void stopSchemata() { - for (DTPSchemaWrapper schema : this.schemata) { - schema.stopListening(); - } - } - - - // ********** clear ********** - - @Override - synchronized void clear() { - if (this.schemata != null) { - this.clearSchemata(); - } - } - - private void clearSchemata() { - this.stopSchemata(); - for (DTPSchemaWrapper schema : this.schemata) { - schema.clear(); - } - this.schemata = null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java deleted file mode 100644 index f1ceb477f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java +++ /dev/null @@ -1,306 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Sequence; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP Schema - */ -final class DTPSchemaWrapper - extends DTPDatabaseObjectWrapper - implements Schema -{ - // the wrapped DTP schema - private final org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema; - - // lazy-initialized - private DTPTableWrapper[] tables; - - // lazy-initialized - private DTPSequenceWrapper[] sequences; - - - // ********** constructor ********** - - DTPSchemaWrapper(DTPSchemaContainerWrapper container, org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - super(container, dtpSchema); - this.dtpSchema = dtpSchema; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().schemaChanged(this); - } - - - // ********** Schema implementation ********** - - public String getName() { - return this.dtpSchema.getName(); - } - - public DTPSchemaContainerWrapper getContainer() { - return (DTPSchemaContainerWrapper) this.getParent(); - } - - // ***** tables - - public Iterator<Table> tables() { - return new ArrayIterator<Table>(this.getTables()); - } - - private Iterator<DTPTableWrapper> tableWrappers() { - return new ArrayIterator<DTPTableWrapper>(this.getTables()); - } - - private synchronized DTPTableWrapper[] getTables() { - if (this.tables == null) { - this.tables = this.buildTables(); - } - return this.tables; - } - - private DTPTableWrapper[] buildTables() { - List<org.eclipse.datatools.modelbase.sql.tables.Table> dtpTables = this.getDTPTables(); - DTPTableWrapper[] result = new DTPTableWrapper[dtpTables.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPTableWrapper(this, dtpTables.get(i)); - } - return CollectionTools.sort(result); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Table> getDTPTables() { - return this.dtpSchema.getTables(); - } - - public int tablesSize() { - return this.getTables().length; - } - - /** - * return the table for the specified DTP table - */ - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - // try to short-circuit the search - return this.wraps(dtpTable.getSchema()) ? - this.getTable_(dtpTable) - : - this.getContainer().getTable(dtpTable); - } - - /** - * assume the schema contains the specified table - */ - DTPTableWrapper getTable_(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - for (DTPTableWrapper table : this.getTables()) { - if (table.wraps(dtpTable)) { - return table; - } - } - throw new IllegalArgumentException("invalid DTP table: " + dtpTable); //$NON-NLS-1$ - } - - public DTPTableWrapper getTableNamed(String name) { - return this.selectDatabaseObjectNamed(this.getTables(), name); - } - - public Iterator<String> sortedTableIdentifiers() { - // the tables are already sorted - return new TransformationIterator<DTPTableWrapper, String>(this.tableWrappers()) { - @Override - protected String transform(DTPTableWrapper table) { - return table.getIdentifier(); - } - }; - } - - public DTPTableWrapper getTableForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getTables(), identifier); - } - - // ***** sequences - - public Iterator<Sequence> sequences() { - return new ArrayIterator<Sequence>(this.getSequences()); - } - - private Iterator<DTPSequenceWrapper> sequenceWrappers() { - return new ArrayIterator<DTPSequenceWrapper>(this.getSequences()); - } - - private synchronized DTPSequenceWrapper[] getSequences() { - if (this.sequences == null) { - this.sequences = this.buildSequences(); - } - return this.sequences; - } - - private DTPSequenceWrapper[] buildSequences() { - List<org.eclipse.datatools.modelbase.sql.schema.Sequence> dtpSequences = this.getDTPSequences(); - DTPSequenceWrapper[] result = new DTPSequenceWrapper[dtpSequences.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPSequenceWrapper(this, dtpSequences.get(i)); - } - return CollectionTools.sort(result); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.schema.Sequence> getDTPSequences() { - return this.dtpSchema.getSequences(); - } - - public int sequencesSize() { - return this.getSequences().length; - } - - public DTPSequenceWrapper getSequenceNamed(String name) { - return this.selectDatabaseObjectNamed(this.getSequences(), name); - } - - public Iterator<String> sortedSequenceIdentifiers() { - // the sequences are already sorted - return new TransformationIterator<DTPSequenceWrapper, String>(this.sequenceWrappers()) { - @Override - protected String transform(DTPSequenceWrapper sequence) { - return sequence.getIdentifier(); - } - }; - } - - public DTPSequenceWrapper getSequenceForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getSequences(), identifier); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Schema schema) { - return Collator.getInstance().compare(this.getName(), schema.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Schema schema) { - return this.dtpSchema == schema; - } - - /** - * return the column for the specified DTP column - */ - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.wraps(dtpColumn.getTable().getSchema()) ? - this.getColumn_(dtpColumn) - : - this.getContainer().getColumn(dtpColumn); - } - - /** - * assume the schema contains the specified column - */ - DTPColumnWrapper getColumn_(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getTable_(dtpColumn.getTable()).getColumn_(dtpColumn); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.sequences != null) { - this.startSequences(); - } - if (this.tables != null) { - this.startTables(); - } - super.startListening(); - } - - private void startSequences() { - for (DTPSequenceWrapper sequence : this.sequences) { - sequence.startListening(); - } - } - - private void startTables() { - for (DTPTableWrapper table : this.tables) { - table.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.sequences != null) { - this.stopSequences(); - } - if (this.tables != null) { - this.stopTables(); - } - super.stopListening(); - } - - private void stopSequences() { - for (DTPSequenceWrapper sequence : this.sequences) { - sequence.stopListening(); - } - } - - private void stopTables() { - for (DTPTableWrapper table : this.tables) { - table.stopListening(); - } - } - - - // ********** clear ********** - - @Override - synchronized void clear() { - if (this.sequences != null) { - this.clearSequences(); - } - if (this.tables != null) { - this.clearTables(); - } - } - - private void clearSequences() { - this.stopSequences(); - for (DTPSequenceWrapper sequence : this.sequences) { - sequence.clear(); - } - this.sequences = null; - } - - private void clearTables() { - this.stopTables(); - for (DTPTableWrapper table : this.tables) { - table.clear(); - } - this.tables = null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java deleted file mode 100644 index 6b0b76a506..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import org.eclipse.jpt.db.Sequence; - -/** - * Wrap a DTP Sequence - */ -final class DTPSequenceWrapper - extends DTPDatabaseObjectWrapper - 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, dtpSequence); - this.dtpSequence = dtpSequence; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().sequenceChanged(this); - } - - - // ********** Sequence implementation ********** - - public String getName() { - return this.dtpSequence.getName(); - } - - public DTPSchemaWrapper getSchema() { - return (DTPSchemaWrapper) this.getParent(); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Sequence sequence) { - return Collator.getInstance().compare(this.getName(), sequence.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Sequence sequence) { - return this.dtpSequence == sequence; - } - - @Override - void clear() { - // no state to clear - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java deleted file mode 100644 index da8f333510..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java +++ /dev/null @@ -1,420 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Iterator; -import java.util.List; -import org.eclipse.datatools.modelbase.sql.constraints.PrimaryKey; -import org.eclipse.datatools.modelbase.sql.tables.BaseTable; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP Table - */ -final class DTPTableWrapper - extends DTPDatabaseObjectWrapper - implements Table -{ - // the wrapped DTP table - private final org.eclipse.datatools.modelbase.sql.tables.Table dtpTable; - - // lazy-initialized - private DTPColumnWrapper[] columns; - - // lazy-initialized - private DTPColumnWrapper[] primaryKeyColumns; - - // lazy-initialized - private DTPForeignKeyWrapper[] foreignKeys; - - - private static final DTPColumnWrapper[] EMPTY_COLUMNS = new DTPColumnWrapper[0]; - private static final DTPForeignKeyWrapper[] EMPTY_FOREIGN_KEYS = new DTPForeignKeyWrapper[0]; - - - // ********** constructor ********** - - DTPTableWrapper(DTPSchemaWrapper schema, org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - super(schema, dtpTable); - this.dtpTable = dtpTable; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().tableChanged(this); - } - - - // ********** Table implementation ********** - - public String getName() { - return this.dtpTable.getName(); - } - - public DTPSchemaWrapper getSchema() { - return (DTPSchemaWrapper) this.getParent(); - } - - // ***** columns - - public Iterator<Column> columns() { - return new ArrayIterator<Column>(this.getColumns()); - } - - private Iterator<DTPColumnWrapper> columnWrappers() { - return new ArrayIterator<DTPColumnWrapper>(this.getColumns()); - } - - private synchronized DTPColumnWrapper[] getColumns() { - if (this.columns == null) { - this.columns = this.buildColumns(); - } - return this.columns; - } - - private DTPColumnWrapper[] buildColumns() { - List<org.eclipse.datatools.modelbase.sql.tables.Column> dtpColumns = this.getDTPColumns(); - DTPColumnWrapper[] result = new DTPColumnWrapper[dtpColumns.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPColumnWrapper(this, dtpColumns.get(i)); - } - return CollectionTools.sort(result); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPColumns() { - return this.dtpTable.getColumns(); - } - - public int columnsSize() { - return this.getColumns().length; - } - - public DTPColumnWrapper getColumnNamed(String name) { - return this.selectDatabaseObjectNamed(this.getColumns(), name); - } - - /** - * return the column for the specified DTP column - */ - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - // try to short-circuit the search - return this.wraps(dtpColumn.getTable()) ? - this.getColumn_(dtpColumn) - : - this.getSchema().getColumn(dtpColumn); - } - - /** - * assume the table contains the specified column - */ - DTPColumnWrapper getColumn_(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - for (DTPColumnWrapper column : this.getColumns()) { - if (column.wraps(dtpColumn)) { - return column; - } - } - throw new IllegalArgumentException("invalid DTP column: " + dtpColumn); //$NON-NLS-1$ - } - - public Iterator<String> sortedColumnIdentifiers() { - // the columns are already sorted - return new TransformationIterator<DTPColumnWrapper, String>(this.columnWrappers()) { - @Override - protected String transform(DTPColumnWrapper next) { - return next.getIdentifier(); - } - }; - } - - public DTPColumnWrapper getColumnForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getColumns(), identifier); - } - - // ***** primaryKeyColumns - - public Iterator<Column> primaryKeyColumns() { - return new ArrayIterator<Column>(this.getPrimaryKeyColumns()); - } - - public DTPColumnWrapper getPrimaryKeyColumn() { - DTPColumnWrapper[] pkColumns = this.getPrimaryKeyColumns(); - if (pkColumns.length != 1) { - throw new IllegalStateException("multiple primary key columns: " + pkColumns.length); //$NON-NLS-1$ - } - return pkColumns[0]; - } - - private synchronized DTPColumnWrapper[] getPrimaryKeyColumns() { - if (this.primaryKeyColumns == null) { - this.primaryKeyColumns = this.buildPrimaryKeyColumns(); - } - return this.primaryKeyColumns; - } - - private DTPColumnWrapper[] buildPrimaryKeyColumns() { - if ( ! (this.dtpTable instanceof BaseTable)) { - return EMPTY_COLUMNS; - } - PrimaryKey pk = ((BaseTable) this.dtpTable).getPrimaryKey(); - if (pk == null) { - // no PK was defined - return EMPTY_COLUMNS; - } - List<org.eclipse.datatools.modelbase.sql.tables.Column> pkColumns = this.getColumns(pk); - DTPColumnWrapper[] result = new DTPColumnWrapper[pkColumns.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = this.getColumn(pkColumns.get(i)); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getColumns(PrimaryKey pk) { - return pk.getMembers(); - } - - public int primaryKeyColumnsSize() { - return this.getPrimaryKeyColumns().length; - } - - boolean primaryKeyColumnsContains(Column column) { - return CollectionTools.contains(this.getPrimaryKeyColumns(), column); - } - - // ***** foreignKeys - - public Iterator<ForeignKey> foreignKeys() { - return new ArrayIterator<ForeignKey>(this.getForeignKeys()); - } - - private synchronized DTPForeignKeyWrapper[] getForeignKeys() { - if (this.foreignKeys == null) { - this.foreignKeys = this.buildForeignKeys(); - } - return this.foreignKeys; - } - - private DTPForeignKeyWrapper[] buildForeignKeys() { - if ( ! (this.dtpTable instanceof BaseTable)) { - return EMPTY_FOREIGN_KEYS; - } - List<org.eclipse.datatools.modelbase.sql.constraints.ForeignKey> dtpForeignKeys = this.getDTPForeignKeys(); - DTPForeignKeyWrapper[] result = new DTPForeignKeyWrapper[dtpForeignKeys.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPForeignKeyWrapper(this, dtpForeignKeys.get(i)); - } - return result; - } - - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.constraints.ForeignKey> getDTPForeignKeys() { - return ((BaseTable) this.dtpTable).getForeignKeys(); - } - - public int foreignKeysSize() { - return this.getForeignKeys().length; - } - - /** - * return whether the specified column is a base column for at least one - * of the the table's foreign keys - */ - boolean foreignKeyBaseColumnsContains(Column column) { - for (DTPForeignKeyWrapper fkWrapper : this.getForeignKeys()) { - if (fkWrapper.baseColumnsContains(column)) { - return true; - } - } - return false; - } - - // ***** join table - - public boolean isPossibleJoinTable() { - if (this.getForeignKeys().length != 2) { - return false; // the table must have exactly 2 foreign keys - } - for (Column column : this.getColumns()) { - if ( ! this.foreignKeyBaseColumnsContains(column)) { - return false; // all the table's columns must belong to one (or both) of the 2 foreign keys - } - } - return true; - } - - /** - * If the table name is FOO_BAR and it joins tables FOO and BAR, - * return the foreign key to FOO; - * if the table name is BAR_FOO and it joins tables FOO and BAR, - * return the foreign key to BAR; - * otherwise simply return the first foreign key in the array. - */ - public ForeignKey getJoinTableOwningForeignKey() { - ForeignKey fk0 = this.getForeignKeys()[0]; - String name0 = fk0.getReferencedTable().getName(); - - ForeignKey fk1 = this.getForeignKeys()[1]; - String name1 = fk1.getReferencedTable().getName(); - - return this.getName().equals(name1 + '_' + name0) ? fk1 : fk0; - } - - public ForeignKey getJoinTableNonOwningForeignKey() { - ForeignKey fk0 = this.getForeignKeys()[0]; - ForeignKey fk1 = this.getForeignKeys()[1]; - ForeignKey ofk = this.getJoinTableOwningForeignKey(); - return (ofk == fk0) ? fk1 : fk0; - } - - /** - * Hmmm.... - * We might want to go to the platform to allow a vendor-specific - * comparison here; - * but, since all the names are coming directly from the database - * (i.e. there are no conversions to Java identifiers etc.), it seems - * like we can just compare them directly and ignore case-sensitivity - * issues.... ~bjv - */ - public boolean joinTableNameIsDefault() { - return this.getName().equals(this.buildDefaultJoinTableName()); - } - - private String buildDefaultJoinTableName() { - return this.getJoinTableOwningTable().getName() - + '_' - + this.getJoinTableNonOwningTable().getName(); - } - - private Table getJoinTableOwningTable() { - return this.getJoinTableOwningForeignKey().getReferencedTable(); - } - - private Table getJoinTableNonOwningTable() { - return this.getJoinTableNonOwningForeignKey().getReferencedTable(); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Table table) { - return Collator.getInstance().compare(this.getName(), table.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Table table) { - return this.dtpTable == table; - } - - /** - * return the table for the specified DTP table - */ - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table table) { - // try to short-circuit the search - return this.wraps(table) ? this : this.getSchema().getTable(table); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.foreignKeys != null) { - this.startForeignKeys(); - } - if (this.columns != null) { - this.startColumns(); - } - super.startListening(); - } - - private void startForeignKeys() { - for (DTPForeignKeyWrapper foreignKey : this.foreignKeys) { - foreignKey.startListening(); - } - } - - private void startColumns() { - for (DTPColumnWrapper column : this.columns) { - column.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.foreignKeys != null) { - this.stopForeignKeys(); - } - if (this.columns != null) { - this.stopColumns(); - } - super.stopListening(); - } - - private void stopForeignKeys() { - for (DTPForeignKeyWrapper foreignKey : this.foreignKeys) { - foreignKey.stopListening(); - } - } - - private void stopColumns() { - for (DTPColumnWrapper column : this.columns) { - column.stopListening(); - } - } - - - // ********** clear ********** - - @Override - void clear() { - if (this.foreignKeys != null) { - this.clearForeignKeys(); - } - - // the table does not "contain" the pk columns, so no need to forward #clear() - this.primaryKeyColumns = null; - - if (this.columns != null) { - this.clearColumns(); - } - } - - private void clearForeignKeys() { - this.stopForeignKeys(); - for (DTPForeignKeyWrapper foreignKey : this.foreignKeys) { - foreignKey.clear(); - } - this.foreignKeys = null; - } - - private void clearColumns() { - this.stopColumns(); - for (DTPColumnWrapper column : this.columns) { - column.clear(); - } - this.columns = null; - } - -} |