diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.db/src')
52 files changed, 0 insertions, 6334 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 69cfd0801b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 - * <p> - * 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 Catalog extends SchemaContainer { - // 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 e1ee3fda36..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 - * <p> - * 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 Column extends DatabaseObject { - - /** - * Return the column's table. - */ - Table getTable(); - - - // ********** constraints ********** - - /** - * Return whether the column is part of its table's primary key. - */ - boolean isPartOfPrimaryKey(); - - /** - * Return whether the column is part of one of its 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 c18f3f995f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionAdapter.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 {@link ConnectionListener}. - * <p> - * 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 0c15b93187..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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 <code>ConnectionListener</code> is notified of any changes to a connection. - * <p> - * @see org.eclipse.datatools.connectivity.IManagedConnectionListener - * <p> - * 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 d16a7e8d41..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 - * <p> - * 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 ConnectionProfile extends DatabaseObject { - - // ********** 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 832b56f73a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 {@link ConnectionProfileListener}. - * <p> - * 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 5001c55663..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 connection profile factory - * <p> - * 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 ConnectionProfileFactory { - - /** - * Return the names of the DTP connection profiles the factory can wrap with - * new connection profiles. - */ - Iterable<String> getConnectionProfileNames(); - - /** - * 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 identifier adapter to allow clients to control how - * database identifiers are converted to names and vice versa. - */ - ConnectionProfile buildConnectionProfile(String name, DatabaseIdentifierAdapter adapter); - - /** - * 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. - * <p> - * Clients should use this method when a JPA platform is unavailable - * (e.g. during project creation). The returned connection profile will - * use the default conversions for identifiers and names. - */ - 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 5631e32a71..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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 <code>ProfileListener</code> is notified of any changes to the DTP connection profiles. - * <p> - * @see org.eclipse.datatools.connectivity.IProfileListener - * <p> - * 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 955fea1040..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 - * <p> - * 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 Database extends SchemaContainer { - - // ********** 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. If it does, all database - * objects are contained by the database's catalogs; otherwise all database - * objects are contained by the database's schemata. - * <br> - * Practically speaking:<ul> - * <li>If {@link #supportsCatalogs()} returns <code>true</code><ul> - * <li>{@link #getCatalogs()} returns catalogs that contain the database's schemata - * <li>{@link #getSchemata()} returns an empty iterable - * </ul> - * <li>else<ul> - * <li>{@link #getCatalogs()} returns an empty iterable - * <li>{@link #getSchemata()} returns the database's schemata - * </ul> - * </ul> - * This is complicated by the presence of a "default" catalog that clients can - * use to allow the specification of a catalog to be optional; but clients - * must manage this explicitly. - * - * @see #getCatalogs() - * @see #getSchemata() - */ - boolean supportsCatalogs(); - - /** - * Return the database's catalogs. - * Return an empty iterable if the database does not support catalogs. - * @see #supportsCatalogs() - */ - Iterable<Catalog> getCatalogs(); - - /** - * Return the number of catalogs the database contains. - * Return zero if the database does not support catalogs. - * @see #supportsCatalogs() - */ - int getCatalogsSize(); - - /** - * Return the database's catalog names, sorted. - * Return an empty iterable if the database does not support catalogs. - * This is useful when the user is selecting a catalog from a read-only - * combo-box (e.g. in a wizard). - * @see #getSortedCatalogIdentifiers() - * @see #getCatalogNamed(String) - */ - Iterable<String> getSortedCatalogNames(); - - /** - * Return the catalog with specified name. The name must be an exact match - * of the catalog's name. - * Return null if the database does not support catalogs. - * @see #supportsCatalogs() - * @see #getSortedCatalogNames() - * @see #getCatalogForIdentifier(String) - */ - Catalog getCatalogNamed(String name); - - /** - * Return the database's catalog identifiers, sorted by name. - * Return an empty iterable if the database does not support catalogs. - * This is useful when the user is selecting an identifier that will be - * placed in a text file (e.g. in a Java annotation). - * @see #getSortedCatalogNames() - * @see #getCatalogForIdentifier(String) - */ - Iterable<String> getSortedCatalogIdentifiers(); - - /** - * 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). - * Return null if the database does not support catalogs. - * @see #supportsCatalogs() - * @see #getSortedCatalogIdentifiers() - * @see #getCatalogNamed(String) - */ - Catalog getCatalogForIdentifier(String identifier); - - /** - * Return the database's "default" catalog, as defined by the database vendor. - * In most cases the default catalog's name will match the user name. - * Return null if the database does not support catalogs or if the default - * catalog does not exist (e.g. the database has no catalog whose name - * matches the user name). - * @see #supportsCatalogs() - * @see #getDefaultCatalogIdentifier() - */ - Catalog getDefaultCatalog(); - - /** - * Return the database's "default" catalog identifier. - * The database may or may not have a catalog with a matching name. - * @see #supportsCatalogs() - * @see #getDefaultCatalog() - */ - String getDefaultCatalogIdentifier(); - - - // ********** 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(Iterable<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/DatabaseIdentifierAdapter.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseIdentifierAdapter.java deleted file mode 100644 index cef37c0be9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseIdentifierAdapter.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 converting a database identifier to a database name and vice - * versa. - * <p> - * 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 DatabaseIdentifierAdapter { - - /** - * Convert the specified "identifier" to a "name". - */ - String convertIdentifierToName(String identifier, DefaultCallback defaultCallback); - - /** - * Convert the specified "name" to an "identifier". - */ - String convertNameToIdentifier(String name, DefaultCallback defaultCallback); - - /** - * The client-provided finder is passed a "default" callback that can be - * used if appropriate. - */ - interface DefaultCallback { - - /** - * Convert the specified "identifier" to a "name". - */ - String convertIdentifierToName(String identifier); - - /** - * Convert the specified "name" to an "identifier". - */ - String convertNameToIdentifier(String name); - - } - - /** - * This adapter simply uses the passed in default callback. - */ - final class Default implements DatabaseIdentifierAdapter { - public static final DatabaseIdentifierAdapter INSTANCE = new Default(); - public static DatabaseIdentifierAdapter instance() { - return INSTANCE; - } - // ensure single instance - private Default() { - super(); - } - // simply use the default callback - public String convertIdentifierToName(String identifier, DefaultCallback defaultCallback) { - return defaultCallback.convertIdentifierToName(identifier); - } - // simply use the default callback - public String convertNameToIdentifier(String name, DefaultCallback defaultCallback) { - return defaultCallback.convertNameToIdentifier(name); - } - @Override - public String toString() { - return "DatabaseIdentifierAdapter.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 155435050e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseObject.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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.Comparator; - -import org.eclipse.jpt.utility.internal.Transformer; - -import com.ibm.icu.text.Collator; - -/** - * Common behavior to all database objects - * <p> - * 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 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". - * <p> - * This is used by the old entity generation code to determine whether - * a generated annotation must explicitly identify a database object - * (e.g. a table) or the specified default adequately identifies the database object - * (taking into consideration case-sensitivity and special characters). - */ - 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(); - - - Comparator<DatabaseObject> DEFAULT_COMPARATOR = - new Comparator<DatabaseObject>() { - public int compare(DatabaseObject dbObject1, DatabaseObject dbObject2) { - return Collator.getInstance().compare(dbObject1.getName(), dbObject2.getName()); - } - @Override - public String toString() { - return "DatabaseObject.DEFAULT_COMPARATOR"; //$NON-NLS-1$ - } - }; - - Transformer<DatabaseObject, String> NAME_TRANSFORMER = - new Transformer<DatabaseObject, String>() { - public String transform(DatabaseObject dbObject) { - return dbObject.getName(); - } - @Override - public String toString() { - return "DatabaseObject.NAME_TRANSFORMER"; //$NON-NLS-1$ - } - }; - - Transformer<DatabaseObject, String> IDENTIFIER_TRANSFORMER = - new Transformer<DatabaseObject, String>() { - public String transform(DatabaseObject dbObject) { - return dbObject.getIdentifier(); - } - @Override - public String toString() { - return "DatabaseObject.IDENTIFIER_TRANSFORMER"; //$NON-NLS-1$ - } - }; - -} 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 5d9dae3ab0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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.Comparator; - -import com.ibm.icu.text.Collator; - -/** - * Database foreign key - * <p> - * 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 ForeignKey extends DatabaseObject { - - // ********** 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. - */ - Iterable<ColumnPair> getColumnPairs(); - - /** - * Return the size of the foreign key's column pairs. - */ - int getColumnPairsSize(); - - /** - * Return the foreign key's single column pair. Throw an - * {@link IllegalStateException} if the foreign key has more than one column pair. - */ - ColumnPair getColumnPair(); - - /** - * Return the foreign key's "base" columns. - */ - Iterable<Column> getBaseColumns(); - - /** - * 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.) - */ - Iterable<Column> getNonPrimaryKeyBaseColumns(); - - /** - * Return the foreign key's "referenced" columns. - */ - Iterable<Column> getReferencedColumns(); - - /** - * 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:<pre> - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * </pre> - * Return a <code>null</code> if it does not adhere to the JPA spec:<pre> - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.CUBICLE_ID) => null - * ForeignKey(EMP.CUBICLE => CUBICLE.ID) => null - * </pre> - */ - 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 - * <code>@javax.persistence.JoinColumn</code> annotation's <code>name</code> element. - * Return <code>null</code> if the attribute - * maps to the join column by default. - * <p> - * 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. - * <p> - * This is used by the old entity generation code to determine whether - * a generated annotation must explicitly identify the join column - * or the calculated default adequately identifies the join column - * (taking into consideration case-sensitivity and special characters). - */ - 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 { - - /** - * Return the column pair's "base" column. - */ - Column getBaseColumn(); - - /** - * Return the column pair's "referenced" column. - */ - Column getReferencedColumn(); - - Comparator<ColumnPair> BASE_COLUMN_COMPARATOR = - new Comparator<ColumnPair>() { - public int compare(ColumnPair cp1, ColumnPair cp2) { - return Collator.getInstance().compare(cp1.getBaseColumn().getName(), cp2.getBaseColumn().getName()); - } - @Override - public String toString() { - return "ForeignKey.ColumnPair.BASE_COLUMN_COMPARATOR"; //$NON-NLS-1$ - } - }; - - } - -} 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 bfecfb1555..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.datatools.enablement.jdt.classpath.DriverClasspathContainer; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jpt.db.internal.DTPConnectionProfileFactory; -import org.osgi.framework.BundleContext; - -/** - * The JPT DB plug-in lifecycle implementation. - * Globally available connection profile factory. - * <p> - * 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(); - if (INSTANCE != null) { - throw new IllegalStateException(); - } - // this convention is *wack*... ~bjv - 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; - } - - /** - * Creates a jar list container for the given DTP driver. - */ - public IClasspathContainer buildDriverClasspathContainerFor(String driverName) { - return new DriverClasspathContainer(driverName); - } - -} 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 6b0fd2b29c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 schema - * <p> - * 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 Schema extends DatabaseObject { - - /** - * Return the schema's container; either a catalog or a database. - */ - SchemaContainer getContainer(); - - - // ********** tables ********** - - /** - * Return the schema's tables. - */ - Iterable<Table> getTables(); - - /** - * Return the number of tables the schema contains. - */ - int getTablesSize(); - - /** - * 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. - * @see #getTableForIdentifier(String) - */ - Iterable<String> getSortedTableIdentifiers(); - - /** - * 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) - * @see #getSortedTableIdentifiers() - */ - Table getTableForIdentifier(String identifier); - - - // ********** sequences ********** - - /** - * Return the schema's sequences. - */ - Iterable<Sequence> getSequences(); - - /** - * Return the number of sequences the schema contains. - */ - int getSequencesSize(); - - /** - * 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. - * @see #getSequenceForIdentifier(String) - */ - Iterable<String> getSortedSequenceIdentifiers(); - - /** - * 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) - * @see #getSortedSequenceIdentifiers() - */ - 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 882c8d0e48..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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; - -/** - * Schema "container" (i.e. Database or Catalog) - * <p> - * 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 SchemaContainer extends DatabaseObject { - - /** - * Return the container's schemata. - */ - Iterable<Schema> getSchemata(); - - /** - * Return the number of schemata in the container. - */ - int getSchemataSize(); - - /** - * Return the container's schema names, sorted. - * This is useful when the user is selecting a schema from a read-only - * combo-box (e.g. in a wizard). - * @see #getSchemaNamed(String) - * @see #getSortedSchemaIdentifiers() - */ - Iterable<String> getSortedSchemaNames(); - - /** - * Return the schema with specified name. The name must be an exact match - * of the schema's name. - * @see #getSortedSchemaNames() - * @see #getSchemaForIdentifier(String) - */ - Schema getSchemaNamed(String name); - - /** - * Return the container's schema identifiers, sorted by name. - * This is useful when the user is selecting an identifier that will be - * placed in a text file (e.g. in a Java annotation). - * @see #getSchemaForIdentifier(String) - * @see #getSortedSchemaNames() - */ - Iterable<String> getSortedSchemaIdentifiers(); - - /** - * 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 #getSortedSchemaIdentifiers() - * @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. - * Return null if the default schema does not exist (e.g. the container has - * no schema whose name matches the user name). - * @see #getDefaultSchemaIdentifier() - */ - Schema getDefaultSchema(); - - /** - * Return the container's "default" schema identifier. - * The container may or may not have a schema with a matching name. - * @see #getDefaultSchema() - */ - String getDefaultSchemaIdentifier(); - -} 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 5351fffa9b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 - * <p> - * 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 Sequence extends DatabaseObject { - - /** - * 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 4f629214c5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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 table - * <p> - * 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 Table extends DatabaseObject { - - /** - * Return the table's schema. - */ - Schema getSchema(); - - - // ********** columns ********** - - /** - * Return the table's columns. - */ - Iterable<Column> getColumns(); - - /** - * Return the number of columns the table contains. - */ - int getColumnsSize(); - - /** - * 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. - * @see #getColumnForIdentifier(String) - */ - Iterable<String> getSortedColumnIdentifiers(); - - /** - * 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) - * @see #getSortedColumnIdentifiers() - */ - Column getColumnForIdentifier(String identifier); - - - // ********** primary key columns ********** - - /** - * Return the table's primary key columns. - */ - Iterable<Column> getPrimaryKeyColumns(); - - /** - * Return the number of primary key columns the table contains. - */ - int getPrimaryKeyColumnsSize(); - - /** - * Return the table's single primary key column. Throw an - * {@link IllegalStateException} if the table has more than one primary key column. - */ - Column getPrimaryKeyColumn(); - - - // ********** foreign keys ********** - - /** - * Return the table's foreign keys. - */ - Iterable<ForeignKey> getForeignKeys(); - - /** - * Return the number of foreign keys the table contains. - */ - int getForeignKeysSize(); - - - // ********** join table support ********** - - /** - * Return whether the table is possibly a "join" table - * (i.e. it contains only 2 foreign keys). Whether the table <em>actually</em> 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. <code>"OWNINGTABLE_NONOWNINGTABLE"</code>). - * @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 96d924fbee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.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) { - // try to short-circuit the search - return this.wraps(dtpSchema.getCatalog()) ? - this.getSchema_(dtpSchema) : - this.getDatabase().getSchemaFromCatalogs(dtpSchema); - } - - @Override - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - // try to short-circuit the search - return this.wraps(dtpTable.getSchema().getCatalog()) ? - this.getTable_(dtpTable) : - this.getDatabase().getTableFromCatalogs(dtpTable); - } - - @Override - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - // try to short-circuit the search - return this.wraps(dtpColumn.getTable().getSchema().getCatalog()) ? - this.getColumn_(dtpColumn) : - this.getDatabase().getColumnFromCatalogs(dtpColumn); - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpCatalog.getName(); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Catalog catalog) { - return this.dtpCatalog == catalog; - } - -} 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 af837e3e63..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.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.ReflectionTools; -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(ReflectionTools.getClassNameForTypeDeclaration(dtpJavaClassName)); - } - - private PredefinedDataTypeDefinition getDefinition(PredefinedDataType dataType) { - return this.getDatabase().getDTPDefinition().getPredefinedDataTypeDefinition(dataType.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:<ul> - * <li>[variable] primitives - * <li>[variable] primitive wrappers - * <li>{@link java.lang.String} - * <li>{@link java.util.Date} - * <li>{@link java.sql.Date} - * </ul> - */ - 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 a543bd5a93..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileFactory.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.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.DatabaseIdentifierAdapter; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -/** - * 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 synchronized ConnectionProfile buildConnectionProfile(String name, DatabaseIdentifierAdapter adapter) { - for (IConnectionProfile dtpProfile : this.dtpProfileManager.getProfiles()) { - if (dtpProfile.getName().equals(name)) { - return new DTPConnectionProfileWrapper(dtpProfile, adapter); - } - } - return null; - } - - public ConnectionProfile buildConnectionProfile(String name) { - return this.buildConnectionProfile(name, DatabaseIdentifierAdapter.Default.instance()); - } - - public Iterable<String> getConnectionProfileNames() { - return new TransformationIterable<IConnectionProfile, String>(this.getDTPConnectionProfiles()) { - @Override - protected String transform(IConnectionProfile dtpProfile) { - return dtpProfile.getName(); - } - }; - } - - private synchronized Iterable<IConnectionProfile> getDTPConnectionProfiles() { - return new ArrayIterable<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 static 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 49c61517bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java +++ /dev/null @@ -1,574 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.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.DatabaseIdentifierAdapter; -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; - - /** adapter supplied by the client (determines identifier delimiters, etc.) */ - private final DatabaseIdentifierAdapter identifierAdapter; - - /** callback passed to the identifier adapter */ - private final DatabaseIdentifierAdapter.DefaultCallback identifierAdapterCallback; - - /** 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, DatabaseIdentifierAdapter adapter) { - super(); - this.dtpConnectionProfile = dtpConnectionProfile; - this.identifierAdapter = adapter; - this.identifierAdapterCallback = new IdentifierAdapterCallback(); - 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); - } - - /** - * Returns the user name. - * Allows user name composed by more than one word. - * If the user name contains a keyword, it returns the first word only. - */ - public String getUserName() { - String userName = this.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID); - userName = userName.trim(); - String[] names = userName.split("\\s+"); //$NON-NLS-1$ - if(names.length == 3) { // 208946 handle username like "sys as sysdba" on Oracle - if(this.nameIsKeyword(names[1])) { - return names[0]; - } - } - return userName; - } - - 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 convert an identifier to a name - * (e.g. {@link org.eclipse.jpt.db.Table#getColumnForIdentifier(String)}). - * We channel all the calls to here and then we delegate to the - * client-supplied "database identifier adapter". - */ - String convertIdentifierToName(String identifier) { - return this.identifierAdapter.convertIdentifierToName(identifier, this.identifierAdapterCallback); - } - - /** - * The default "database identifier adapter" calls back to here so we can delegate to - * the database, which contains all the information necessary to properly - * convert identifiers. - */ - String convertIdentifierToName_(String identifier) { - // the database should not be null here - call its internal method - return this.database.convertIdentifierToName_(identifier); - } - - /** - * This is called whenever we need to convert a name to an identifier - * (e.g. {@link org.eclipse.jpt.db.Table#getColumnForIdentifier(String)}). - * We channel all the calls to here and then we delegate to the - * client-supplied "database identifier adapter". - */ - String convertNameToIdentifier(String name) { - return this.identifierAdapter.convertNameToIdentifier(name, this.identifierAdapterCallback); - } - - /** - * The default "database identifier adapter" calls back to here so we can delegate to - * the database, which contains all the information necessary to properly - * convert names. - */ - String convertNameToIdentifier_(String name) { - // the database should not be null here - call its internal method - return this.database.convertNameToIdentifier_(name); - } - - 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); - } - - private boolean nameIsKeyword(String name) { - return name.equalsIgnoreCase("as"); //$NON-NLS-1$ - } - - - // ********** overrides ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } - - - // ********** DTP connection listener ********** - - /** - * This listener translates and forwards {@link org.eclipse.datatools.connectivity.IManagedConnectionListener} and - * {@link IManagedConnectionOfflineListener} events to {@link ConnectionListener}s. - */ - 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 IdentifierAdapterCallback implements DatabaseIdentifierAdapter.DefaultCallback { - public String convertIdentifierToName(String identifier) { - // call back to the internal method - return DTPConnectionProfileWrapper.this.convertIdentifierToName_(identifier); - } - public String convertNameToIdentifier(String name) { - // call back to the internal method - return DTPConnectionProfileWrapper.this.convertNameToIdentifier_(name); - } - } - -} 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 37c3cb7d0c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObjectWrapper.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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); - // and the model is rebuilt when the connection connects or disconnects - 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(); - } - - /** - * 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 "regular" (i.e. not delimited), - * it will be folded to the appropriate case (typically uppercase). - * This is called by whenever we need to find a component by identifier - * (e.g. {{@link org.eclipse.jpt.db.Table#getColumnForIdentifier(String)}). - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(Iterable<T> databaseObjects, String identifier) { - return this.selectDatabaseObjectNamed(databaseObjects, this.convertIdentifierToName(identifier)); - } - - private String convertIdentifierToName(String identifier) { - return this.getConnectionProfile().convertIdentifierToName(identifier); - } - - /** - * Convenience method. - */ - <T extends DatabaseObject> T selectDatabaseObjectNamed(Iterable<T> databaseObjects, String name) { - for (T dbObject : databaseObjects) { - if (dbObject.getName().equals(name)) { - return dbObject; - } - } - return null; - } - - /** - * Examples:<ul> - * <li>Oracle etc.<ul><code> - * <li>Table(FOO) vs. "Foo" => null - * <li>Table(BAR) vs. "Foo" => "BAR" - * <li>Table(Foo) vs. "Foo" => "\"Foo\"" - * <li>Table(Bar) vs. "Foo" => "\"Bar\"" - * </code></ul> - * <li>PostgreSQL etc.<ul><code> - * <li>Table(foo) vs. "Foo" => null - * <li>Table(bar) vs. "Foo" => "bar" - * <li>Table(Foo) vs. "Foo" => "\"Foo\"" - * <li>Table(Bar) vs. "Foo" => "\"Bar\"" - * </code></ul> - * <li>SQL Server etc.<ul><code> - * <li>Table(Foo) vs. "Foo" => null - * <li>Table(foo) vs. "Foo" => "foo" - * <li>Table(bar) vs. "Foo" => "bar" - * <li>Table(Bar) vs. "Foo" => "Bar" - * </code></ul> - * </ul> - */ - public String getIdentifier(String defaultName) { - return this.getDatabase().convertNameToIdentifier(this.getName(), defaultName); - } - - /** - * Examples:<ul> - * <li>Oracle etc.<ul><code> - * <li>Table(FOO) => "FOO" - * <li>Table(Foo) => "\"Foo\"" - * <li>Table(foo) => "\"foo\"" - * <li>Table(foo++) => "\"foo++\"" - * <li>Table(f"o) => "\"f\"\"o\"" (i.e. "f""o") - * </code></ul> - * <li>PostgreSQL etc.<ul><code> - * <li>Table(FOO) => "\"FOO\"" - * <li>Table(Foo) => "\"Foo\"" - * <li>Table(foo) => "foo" - * <li>Table(foo++) => "\"foo++\"" - * <li>Table(f"o) => "\"f\"\"o\"" (i.e. "f""o") - * </code></ul> - * <li>SQL Server etc.<ul><code> - * <li>Table(FOO) => "FOO" - * <li>Table(Foo) => "Foo" - * <li>Table(foo) => "foo" - * <li>Table(foo++) => "\"foo++\"" - * <li>Table(f"o) => "\"f\"\"o\"" (i.e. "f""o") - * </code></ul> - * </ul> - */ - public String getIdentifier() { - return this.convertNameToIdentifier(this.getName()); - } - - String convertNameToIdentifier(String name) { - return this.getConnectionProfile().convertNameToIdentifier(name); - } - - @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 7821854ecf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java +++ /dev/null @@ -1,380 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.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.db.internal.vendor.Vendor; -import org.eclipse.jpt.db.internal.vendor.VendorRepository; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -/** - * Wrap a DTP Database. - * <p> - * Catalogs vs. Schemata:<br> - * 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. - * <p> - * Catalog Note 1:<br> - * As of Jan 2009, the DTP MySQL driver is not consistent with this pattern. - * A DTP MySQL database has *no* catalogs; it holds a single schema - * directly, and that schema has the same name as the database. See bug 249013. - * <p> - * Catalog Note 2:<br> - * As of Jan 2009, the PostgreSQL JDBC driver complicates this pattern a bit. - * Even though PostgreSQL does not support "catalogs", its JDBC driver - * returns a single catalog that has the same name as the database specified - * in the JDBC connection URL. The DTP PostgreSQL driver simply replicates this - * behavior. Unfortunately, this catalog can be unnamed; i.e. its name is an - * empty string.... - * <p> - * (Yet Another) Note:<br> - * 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; - - /** vendor-specific behavior */ - private final Vendor vendor; - - /** lazy-initialized, sorted */ - private DTPCatalogWrapper[] catalogs; - - - // ********** constructor ********** - - DTPDatabaseWrapper(DTPConnectionProfileWrapper connectionProfile, org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase) { - super(connectionProfile, dtpDatabase); - this.dtpDatabase = dtpDatabase; - this.vendor = VendorRepository.instance().getVendor(this.getVendorName()); - } - - - // ********** DTPWrapper implementation ********** - - /* TODO - * We might want to listen to the "virtual" catalog; but that's probably - * not necessary since there is no easy way for the user to refresh it - * (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 - List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemata() { - return this.vendor.getSchemas(this.dtpDatabase); - } - - @Override - DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - return this.getSchema_(dtpSchema); - } - - DTPSchemaWrapper getSchemaFromCatalogs(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - return this.getCatalog(dtpSchema.getCatalog()).getSchema_(dtpSchema); - } - - /** - * this is only called from a schema when the database is the schema - * container, so we know we don't have any catalogs - */ - @Override - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.getTable_(dtpTable); - } - - /** - * this is only called from a catalog, so we know we have catalogs; - * i.e. the search has to descend through catalogs, then to schemata - */ - DTPTableWrapper getTableFromCatalogs(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.getCatalog(dtpTable.getSchema().getCatalog()).getTable_(dtpTable); - } - - /** - * this is only called from a schema when the database is the schema - * container, so we know we don't have any catalogs - */ - @Override - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getColumn_(dtpColumn); - } - - /** - * this is only called from a catalog, so we know we have catalogs; - * i.e. the search has to descend through catalogs, then to schemata - */ - DTPColumnWrapper getColumnFromCatalogs(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getCatalog(dtpColumn.getTable().getSchema().getCatalog()).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(Iterable<T> databaseObjects, String identifier) { - return super.selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - - // ***** catalogs - - public boolean supportsCatalogs() { - return this.vendor.supportsCatalogs(this.dtpDatabase); - } - - public Iterable<Catalog> getCatalogs() { - return new ArrayIterable<Catalog>(this.getCatalogArray()); - } - - private Iterable<DTPCatalogWrapper> getCatalogWrappers() { - return new ArrayIterable<DTPCatalogWrapper>(this.getCatalogArray()); - } - - private synchronized DTPCatalogWrapper[] getCatalogArray() { - if (this.catalogs == null) { - this.catalogs = this.buildCatalogArray(); - } - return this.catalogs; - } - - private DTPCatalogWrapper[] buildCatalogArray() { - List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs = this.getDTPCatalogs(); - DTPCatalogWrapper[] result = new DTPCatalogWrapper[dtpCatalogs.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPCatalogWrapper(this, dtpCatalogs.get(i)); - } - return ArrayTools.sort(result, DEFAULT_COMPARATOR); - } - - private List<org.eclipse.datatools.modelbase.sql.schema.Catalog> getDTPCatalogs() { - return this.vendor.getCatalogs(this.dtpDatabase); - } - - public int getCatalogsSize() { - return this.getCatalogArray().length; - } - - /** - * return the catalog for the specified DTP catalog - */ - DTPCatalogWrapper getCatalog(org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) { - for (DTPCatalogWrapper catalog : this.getCatalogArray()) { - if (catalog.wraps(dtpCatalog)) { - return catalog; - } - } - throw new IllegalArgumentException("invalid DTP catalog: " + dtpCatalog); //$NON-NLS-1$ - } - - public Iterable<String> getSortedCatalogNames() { - // the catalogs are already sorted - return new TransformationIterable<DatabaseObject, String>(this.getCatalogWrappers(), NAME_TRANSFORMER); - } - - public DTPCatalogWrapper getCatalogNamed(String name) { - return this.selectDatabaseObjectNamed(this.getCatalogWrappers(), name); - } - - public Iterable<String> getSortedCatalogIdentifiers() { - // the catalogs are already sorted - return new TransformationIterable<DatabaseObject, String>(this.getCatalogWrappers(), IDENTIFIER_TRANSFORMER); - } - - public DTPCatalogWrapper getCatalogForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getCatalogWrappers(), identifier); - } - - public synchronized DTPCatalogWrapper getDefaultCatalog() { - return this.getCatalogForNames(this.getDefaultCatalogNames()); - } - - private Iterable<String> getDefaultCatalogNames() { - return this.vendor.getDefaultCatalogNames(this.dtpDatabase, this.getConnectionProfile().getUserName()); - } - - /** - * Return the first catalog found. - */ - private DTPCatalogWrapper getCatalogForNames(Iterable<String> names) { - for (String name : names) { - DTPCatalogWrapper catalog = this.getCatalogNamed(name); - if (catalog != null) { - return catalog; - } - } - return null; - } - - /** - * If we find a default catalog, return its identifier; - * otherwise, return the last name on the list of default names. - * (Some databases have multiple possible default names.) - * Return null if the database does not support catalogs. - */ - public synchronized String getDefaultCatalogIdentifier() { - Iterable<String> names = this.getDefaultCatalogNames(); - DTPCatalogWrapper catalog = this.getCatalogForNames(names); - if (catalog != null) { - return catalog.getIdentifier(); - } - Iterator<String> stream = names.iterator(); - return stream.hasNext() ? this.convertNameToIdentifier(CollectionTools.last(stream)) : null; - } - - // ***** schemata - - Iterable<String> getDefaultSchemaNames() { - return this.vendor.getDefaultSchemaNames(this.dtpDatabase, this.getConnectionProfile().getUserName()); - } - - - // ********** names vs. identifiers ********** - - // override to make method public since it's in the Database interface - @Override - public String convertNameToIdentifier(String name) { - return super.convertNameToIdentifier(name); - } - - /** - * Delegate to the vendor. - */ - String convertNameToIdentifier_(String name) { - return this.vendor.convertNameToIdentifier(name); - } - - /** - * Delegate to the vendor. - */ - String convertIdentifierToName_(String identifier) { - return this.vendor.convertIdentifierToName(identifier); - } - - /** - * Convert the specified name to an identifier. Return null if the resulting - * identifier matches the specified default name. - * <p> - * This is used by the old entity generation code to determine whether - * a generated annotation must explicitly identify a database object - * (e.g. a table) or the specified default adequately identifies the - * specified database object (taking into consideration case-sensitivity - * and special characters). - */ - // TODO add to database identifier adapter? currently not used... - String convertNameToIdentifier(String name, String defaultName) { - return this.vendor.convertNameToIdentifier(name, defaultName); - } - - - // ********** internal methods ********** - - DatabaseDefinition getDTPDefinition() { - return RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(this.dtpDatabase); - } - - - // ********** 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 - synchronized void clear() { - if (this.catalogs != null) { - this.clearCatalogs(); - } - super.clear(); - } - - private void clearCatalogs() { - this.stopCatalogs(); - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.clear(); - } - this.catalogs = null; - } - -} 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 633a0f45a1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.Arrays; -import java.util.List; - -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -/** - * 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.getColumnPairArray())); //$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.getColumnPairsSize() != 1) { - return false; - } - if (this.getReferencedTable().getPrimaryKeyColumnsSize() != 1) { - return false; - } - return this.getColumnPair().getReferencedColumn() == this.getReferencedTable().getPrimaryKeyColumn(); - } - - // ***** column pairs - - public Iterable<ColumnPair> getColumnPairs() { - return new ArrayIterable<ColumnPair>(this.getColumnPairArray()); - } - - public LocalColumnPair getColumnPair() { - LocalColumnPair[] pairs = this.getColumnPairArray(); - if (pairs.length != 1) { - throw new IllegalStateException("multiple column pairs: " + pairs.length); //$NON-NLS-1$ - } - return pairs[0]; - } - - private Iterable<LocalColumnPair> getLocalColumnPairs() { - return new ArrayIterable<LocalColumnPair>(this.getColumnPairArray()); - } - - private synchronized LocalColumnPair[] getColumnPairArray() { - if (this.columnPairs == null) { - this.columnPairs = this.buildColumnPairArray(); - } - return this.columnPairs; - } - - private LocalColumnPair[] buildColumnPairArray() { - 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 ArrayTools.sort(result, ColumnPair.BASE_COLUMN_COMPARATOR); - } - - // 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 getColumnPairsSize() { - return this.getColumnPairArray().length; - } - - public Iterable<Column> getBaseColumns() { - return new TransformationIterable<LocalColumnPair, Column>(this.getLocalColumnPairs()) { - @Override - protected Column transform(LocalColumnPair pair) { - return pair.getBaseColumn(); - } - }; - } - - boolean baseColumnsContains(Column column) { - return CollectionTools.contains(this.getBaseColumns(), column); - } - - public Iterable<Column> getNonPrimaryKeyBaseColumns() { - return new FilteringIterable<Column>(this.getBaseColumns()) { - @Override - protected boolean accept(Column column) { - return ! column.isPartOfPrimaryKey(); - } - }; - } - - public Iterable<Column> getReferencedColumns() { - return new TransformationIterable<LocalColumnPair, Column>(this.getLocalColumnPairs()) { - @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.getColumnPairsSize() == 1) ? - this.getNonDefaultAttributeNameFromBaseColumn() : - this.getReferencedTable().getName(); - } - - /** - * The underscore check is helpful when the referenced column is <em>not</em> the - * primary key of the referenced table (i.e. it has only a <em>unique</em> constraint). - * <pre> - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * ForeignKey(EMP.CUBICLEID => CUBICLE.ID) => "CUBICLE" - * ForeignKey(EMP.CUBICLE_PK => CUBICLE.ID) => "CUBICLE_PK" - * </pre> - */ - 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:<ul> - * <li>Oracle etc.<ul><code> - * <li>ForeignKey(FOO_ID => ID) vs. "foo" => null - * <li>ForeignKey(FOO_ID => FOO_ID) vs. "foo" => "FOO_ID" - * <li>ForeignKey(FOO => ID) vs. "foo" => "FOO" - * <li>ForeignKey(Foo_ID => ID) vs. "foo" => "\"Foo_ID\"" - * </code></ul> - * <li>PostgreSQL etc.<ul><code> - * <li>ForeignKey(foo_id => id) vs. "foo" => null - * <li>ForeignKey(foo_id => foo_id) vs. "foo" => "foo_id" - * <li>ForeignKey(foo => id) vs. "foo" => "foo" - * <li>ForeignKey(Foo_ID => ID) vs. "foo" => "\"Foo_ID\"" - * </code></ul> - * <li>SQL Server etc.<ul><code> - * <li>ForeignKey(foo_ID => ID) vs. "foo" => null - * <li>ForeignKey(FOO_ID => FOO_ID) vs. "foo" => "FOO_ID" - * <li>ForeignKey(FOO => ID) vs. "foo" => "FOO" - * <li>ForeignKey(Foo_ID => ID) vs. "foo" => "Foo_ID" - * </code></ul> - * </ul> - */ - public String getJoinColumnAnnotationIdentifier(String attributeName) { - String baseColumnName = this.getColumnPair().getBaseColumn().getName(); - String defaultBaseColumnName = attributeName + '_' + this.getReferencedTable().getPrimaryKeyColumn().getName(); - return this.getDatabase().convertNameToIdentifier(baseColumnName, defaultBaseColumnName); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.constraints.ForeignKey foreignKey) { - return this.dtpForeignKey == foreignKey; - } - - @Override - synchronized 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 ********** - - 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; - } - - @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 2df5d64db7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.List; - -import org.eclipse.jpt.db.DatabaseObject; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -/** - * 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 dtpSchemaContainer) { - super(parent, dtpSchemaContainer); - } - - - // ********** 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.getSchemaArray()) { - if (schema.wraps(dtpSchema)) { - return schema; - } - } - throw new IllegalArgumentException("invalid DTP schema: " + dtpSchema); //$NON-NLS-1$ - } - - /** - * return the table for the specified DTP table; - * this is only called from a schema (to its container) - */ - 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; - * this is only called from a schema (to its container) - */ - 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 Iterable<Schema> getSchemata() { - return new ArrayIterable<Schema>(this.getSchemaArray()); - } - - Iterable<DTPSchemaWrapper> getSchemaWrappers() { - return new ArrayIterable<DTPSchemaWrapper>(this.getSchemaArray()); - } - - synchronized DTPSchemaWrapper[] getSchemaArray() { - if (this.schemata == null) { - this.schemata = this.buildSchemaArray(); - } - return this.schemata; - } - - private DTPSchemaWrapper[] buildSchemaArray() { - 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 ArrayTools.sort(result, DEFAULT_COMPARATOR); - } - - public int getSchemataSize() { - return this.getSchemaArray().length; - } - - public Iterable<String> getSortedSchemaNames() { - // the schemata are already sorted - return new TransformationIterable<DatabaseObject, String>(this.getSchemaWrappers(), NAME_TRANSFORMER); - } - - public DTPSchemaWrapper getSchemaNamed(String name) { - return this.selectDatabaseObjectNamed(this.getSchemaWrappers(), name); - } - - public Iterable<String> getSortedSchemaIdentifiers() { - // the schemata are already sorted - return new TransformationIterable<DatabaseObject, String>(this.getSchemaWrappers(), IDENTIFIER_TRANSFORMER); - } - - public DTPSchemaWrapper getSchemaForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getSchemaWrappers(), identifier); - } - - public DTPSchemaWrapper getDefaultSchema() { - return this.getSchemaForNames(this.getDatabase().getDefaultSchemaNames()); - } - - /** - * Return the first schema found. - */ - DTPSchemaWrapper getSchemaForNames(Iterable<String> names) { - for (String name : names) { - DTPSchemaWrapper schema = this.getSchemaNamed(name); - if (schema != null) { - return schema; - } - } - return null; - } - - /** - * If we find a default schema, return its identifier; - * otherwise, return the last name on the list of default names. - * (Some containers have multiple possible default names.) - */ - public synchronized String getDefaultSchemaIdentifier() { - Iterable<String> names = this.getDatabase().getDefaultSchemaNames(); - DTPSchemaWrapper schema = this.getSchemaForNames(names); - // assume 'names' is non-empty (!) - return (schema != null) ? - schema.getIdentifier() : - this.convertNameToIdentifier(CollectionTools.last(names)); - } - - - // ********** 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 6eab36d0ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java +++ /dev/null @@ -1,321 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.datatools.modelbase.sql.tables.SQLTablesPackage; -import org.eclipse.jpt.db.DatabaseObject; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Sequence; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -/** - * 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; - - - // ********** constants ********** - - /** used for adopter product customization */ - private static final String PERSISTENT_AND_VIEW_TABLES_ONLY = "supportPersistentAndViewTablesOnly"; //$NON-NLS-1$ - - - // ********** 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 Iterable<Table> getTables() { - return new ArrayIterable<Table>(this.getTableArray()); - } - - private Iterable<DTPTableWrapper> getTableWrappers() { - return new ArrayIterable<DTPTableWrapper>(this.getTableArray()); - } - - private synchronized DTPTableWrapper[] getTableArray() { - if (this.tables == null) { - this.tables = this.buildTableArray(); - } - return this.tables; - } - - private DTPTableWrapper[] buildTableArray() { - 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 ArrayTools.sort(result, DEFAULT_COMPARATOR); - } - - private List<org.eclipse.datatools.modelbase.sql.tables.Table> getDTPTables() { - List<org.eclipse.datatools.modelbase.sql.tables.Table> dtpTables = this.getDTPTables_(); - return this.hack() ? this.hack(dtpTables) : dtpTables; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Table> getDTPTables_() { - return this.dtpSchema.getTables(); - } - - private boolean hack() { - String hack = Platform.getProduct().getProperty(PERSISTENT_AND_VIEW_TABLES_ONLY); - return (hack != null) && hack.equals("true"); //$NON-NLS-1$ - } - - private List<org.eclipse.datatools.modelbase.sql.tables.Table> hack(List<org.eclipse.datatools.modelbase.sql.tables.Table> dtpTables) { - List<org.eclipse.datatools.modelbase.sql.tables.Table> result = new ArrayList<org.eclipse.datatools.modelbase.sql.tables.Table>(); - for (org.eclipse.datatools.modelbase.sql.tables.Table dtpTable : dtpTables) { - if (this.hack(dtpTable)) { - result.add(dtpTable); - } - } - return result; - } - - private boolean hack(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return SQLTablesPackage.eINSTANCE.getPersistentTable().isSuperTypeOf(dtpTable.eClass()) || - SQLTablesPackage.eINSTANCE.getViewTable().isSuperTypeOf(dtpTable.eClass()); - } - - public int getTablesSize() { - return this.getTableArray().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.getTableArray()) { - 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.getTableWrappers(), name); - } - - public Iterable<String> getSortedTableIdentifiers() { - // the tables are already sorted - return new TransformationIterable<DatabaseObject, String>(this.getTableWrappers(), IDENTIFIER_TRANSFORMER); - } - - public DTPTableWrapper getTableForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getTableWrappers(), identifier); - } - - // ***** sequences - - public Iterable<Sequence> getSequences() { - return new ArrayIterable<Sequence>(this.getSequenceArray()); - } - - private Iterable<DTPSequenceWrapper> getSequenceWrappers() { - return new ArrayIterable<DTPSequenceWrapper>(this.getSequenceArray()); - } - - private synchronized DTPSequenceWrapper[] getSequenceArray() { - if (this.sequences == null) { - this.sequences = this.buildSequenceArray(); - } - return this.sequences; - } - - private DTPSequenceWrapper[] buildSequenceArray() { - 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 ArrayTools.sort(result, DEFAULT_COMPARATOR); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.schema.Sequence> getDTPSequences() { - return this.dtpSchema.getSequences(); - } - - public int getSequencesSize() { - return this.getSequenceArray().length; - } - - public DTPSequenceWrapper getSequenceNamed(String name) { - return this.selectDatabaseObjectNamed(this.getSequenceWrappers(), name); - } - - public Iterable<String> getSortedSequenceIdentifiers() { - // the sequences are already sorted - return new TransformationIterable<DatabaseObject, String>(this.getSequenceWrappers(), IDENTIFIER_TRANSFORMER); - } - - public DTPSequenceWrapper getSequenceForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getSequenceWrappers(), identifier); - } - - - // ********** 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) { - // try to short-circuit the search - 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 f8e3edf700..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.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(); - } - - - // ********** 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 b109675c90..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java +++ /dev/null @@ -1,409 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.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.DatabaseObject; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -/** - * 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 Iterable<Column> getColumns() { - return new ArrayIterable<Column>(this.getColumnArray()); - } - - private Iterable<DTPColumnWrapper> getColumnWrappers() { - return new ArrayIterable<DTPColumnWrapper>(this.getColumnArray()); - } - - private synchronized DTPColumnWrapper[] getColumnArray() { - if (this.columns == null) { - this.columns = this.buildColumnArray(); - } - return this.columns; - } - - private DTPColumnWrapper[] buildColumnArray() { - 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 ArrayTools.sort(result, DEFAULT_COMPARATOR); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPColumns() { - return this.dtpTable.getColumns(); - } - - public int getColumnsSize() { - return this.getColumnArray().length; - } - - public DTPColumnWrapper getColumnNamed(String name) { - return this.selectDatabaseObjectNamed(this.getColumnWrappers(), 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.getColumnArray()) { - if (column.wraps(dtpColumn)) { - return column; - } - } - throw new IllegalArgumentException("invalid DTP column: " + dtpColumn); //$NON-NLS-1$ - } - - public Iterable<String> getSortedColumnIdentifiers() { - // the columns are already sorted - return new TransformationIterable<DatabaseObject, String>(this.getColumnWrappers(), IDENTIFIER_TRANSFORMER); - } - - public DTPColumnWrapper getColumnForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getColumnWrappers(), identifier); - } - - // ***** primaryKeyColumns - - public Iterable<Column> getPrimaryKeyColumns() { - return new ArrayIterable<Column>(this.getPrimaryKeyColumnArray()); - } - - public DTPColumnWrapper getPrimaryKeyColumn() { - DTPColumnWrapper[] pkColumns = this.getPrimaryKeyColumnArray(); - if (pkColumns.length != 1) { - throw new IllegalStateException("multiple primary key columns: " + pkColumns.length); //$NON-NLS-1$ - } - return pkColumns[0]; - } - - private synchronized DTPColumnWrapper[] getPrimaryKeyColumnArray() { - if (this.primaryKeyColumns == null) { - this.primaryKeyColumns = this.buildPrimaryKeyColumnArray(); - } - return this.primaryKeyColumns; - } - - private DTPColumnWrapper[] buildPrimaryKeyColumnArray() { - 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 getPrimaryKeyColumnsSize() { - return this.getPrimaryKeyColumnArray().length; - } - - boolean primaryKeyColumnsContains(Column column) { - return ArrayTools.contains(this.getPrimaryKeyColumnArray(), column); - } - - // ***** foreignKeys - - public Iterable<ForeignKey> getForeignKeys() { - return new ArrayIterable<ForeignKey>(this.getForeignKeyArray()); - } - - private synchronized DTPForeignKeyWrapper[] getForeignKeyArray() { - if (this.foreignKeys == null) { - this.foreignKeys = this.buildForeignKeyArray(); - } - return this.foreignKeys; - } - - private DTPForeignKeyWrapper[] buildForeignKeyArray() { - 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 getForeignKeysSize() { - return this.getForeignKeyArray().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.getForeignKeyArray()) { - if (fkWrapper.baseColumnsContains(column)) { - return true; - } - } - return false; - } - - // ***** join table - - public boolean isPossibleJoinTable() { - if (this.getForeignKeyArray().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 <code>FOO_BAR</code> - * and it joins tables <code>FOO</code> and <code>BAR</code>, - * return the foreign key to <code>FOO</code>; - * if the table name is <code>BAR_FOO</code> - * and it joins tables <code>FOO</code> and <code>BAR</code>, - * return the foreign key to <code>BAR</code>; - * otherwise simply return the first foreign key in the array. - */ - public ForeignKey getJoinTableOwningForeignKey() { - ForeignKey fk0 = this.getForeignKeyArray()[0]; - String name0 = fk0.getReferencedTable().getName(); - - ForeignKey fk1 = this.getForeignKeyArray()[1]; - String name1 = fk1.getReferencedTable().getName(); - - return this.getName().equals(name1 + '_' + name0) ? fk1 : fk0; - } - - public ForeignKey getJoinTableNonOwningForeignKey() { - ForeignKey fk0 = this.getForeignKeyArray()[0]; - ForeignKey fk1 = this.getForeignKeyArray()[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(); - } - - - // ********** 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 - synchronized 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; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/AbstractVendor.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/AbstractVendor.java deleted file mode 100644 index 3e6a08fefb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/AbstractVendor.java +++ /dev/null @@ -1,304 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Consolidate the behavior common to the typical vendors. - * - * @see UnrecognizedVendor - */ -abstract class AbstractVendor - implements Vendor -{ - AbstractVendor() { - super(); - } - - public abstract String getDTPVendorName(); - - - // ********** catalog and schema support ********** - - abstract CatalogStrategy getCatalogStrategy(); - - public boolean supportsCatalogs(Database database) { - return this.getCatalogStrategy().supportsCatalogs(database); - } - - public List<Catalog> getCatalogs(Database database) { - return this.getCatalogStrategy().getCatalogs(database); - } - - public List<Schema> getSchemas(Database database) { - try { - return this.getCatalogStrategy().getSchemas(database); - } catch (Exception ex) { - throw new RuntimeException("vendor: " + this, ex); //$NON-NLS-1$ - } - } - - /** - * Typically, the name of the default catalog is the user name. - */ - public final Iterable<String> getDefaultCatalogNames(Database database, String userName) { - if ( ! this.supportsCatalogs(database)) { - return Collections.emptyList(); - } - ArrayList<String> names = new ArrayList<String>(); - this.addDefaultCatalogNamesTo(database, userName, names); - return names; - } - - /** - * See comment at - * {@link #addDefaultSchemaNamesTo(Database, String, ArrayList)}. - */ - void addDefaultCatalogNamesTo(@SuppressWarnings("unused") Database database, String userName, ArrayList<String> names) { - names.add(this.convertIdentifierToName(userName)); - } - - /** - * Typically, the name of the default schema is the user name. - */ - public final Iterable<String> getDefaultSchemaNames(Database database, String userName) { - ArrayList<String> names = new ArrayList<String>(); - this.addDefaultSchemaNamesTo(database, userName, names); - return names; - } - - /** - * The user name passed in here was retrieved from DTP. - * DTP stores the user name that was passed to it during the connection - * to the database. As a result, this user name is an <em>identifier</em> - * not a <em>name</em>. - * If the user name were retrieved from the JDBC connection it would probably - * be a <em>name</em>. For example, you can connect to an Oracle database with the - * user name "scott", but that identifer is folded to the actual user name - * "SCOTT". DTP stores the original string "scott", while the Oracle JDBC - * driver stores the folded string "SCOTT". - */ - void addDefaultSchemaNamesTo(@SuppressWarnings("unused") Database database, String userName, ArrayList<String> names) { - names.add(this.convertIdentifierToName(userName)); - } - - - // ********** folding strategy used to convert names and identifiers ********** - - /** - * The SQL spec says a <em>regular</em> (non-delimited) identifier should be - * folded to uppercase; but some databases do otherwise (e.g. Sybase). - */ - abstract FoldingStrategy getFoldingStrategy(); - - - // ********** name -> identifier ********** - - public String convertNameToIdentifier(String name, String defaultName) { - return this.nameRequiresDelimiters(name) ? - this.delimitName(name) : - this.regularNamesMatch(name, defaultName) ? null : name; - } - - public 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. - */ - 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 - */ - boolean nameContainsAnySpecialCharacters(String name) { - char[] string = name.toCharArray(); - if (this.characterIsNonRegularNameStart(string[0])) { - return true; - } - for (int i = string.length; i-- > 1; ) { // note: stop at 1 - if (this.characterIsNonRegularNamePart(string[i])) { - return true; - } - } - return false; - } - - /** - * Return whether the specified character is "non-regular" for the first - * character of a name. - * Typically, databases are more restrictive about what characters can - * be used to <em>start</em> an identifier (as opposed to the characters - * allowed for the remainder of the identifier). - */ - boolean characterIsNonRegularNameStart(char c) { - return ! this.characterIsRegularNameStart(c); - } - - /** - * Return whether the specified character is <em>regular</em> for the first - * character of a name. - * The first character of an identifier can be:<ul> - * <li>a letter - * <li>any of the extended, vendor-specific, <em>regular</em> start characters - * </ul> - */ - boolean characterIsRegularNameStart(char c) { - // all vendors allow a letter - return Character.isLetter(c) - || this.characterIsExtendedRegularNameStart(c); - } - - boolean characterIsExtendedRegularNameStart(char c) { - return arrayContains(this.getExtendedRegularNameStartCharacters(), c); - } - - /** - * Return the <em>regular</em> characters, beyond letters, for the - * first character of a name. - * Return null if there are no "extended" characters. - */ - char[] getExtendedRegularNameStartCharacters() { - return null; - } - - /** - * Return whether the specified character is "non-regular" for the second - * and subsequent characters of a name. - */ - boolean characterIsNonRegularNamePart(char c) { - return ! this.characterIsRegularNamePart(c); - } - - /** - * Return whether the specified character is <em>regular</em> for the second and - * subsequent characters of a name. - * The second and subsequent characters of a <em>regular</em> name can be:<ul> - * <li>a letter - * <li>a digit - * <li>an underscore - * <li>any of the extended, vendor-specific, <em>regular</em> start characters - * <li>any of the extended, vendor-specific, <em>regular</em> part characters - * </ul> - */ - boolean characterIsRegularNamePart(char c) { - // all vendors allow a letter or digit - return Character.isLetterOrDigit(c) || - (c == '_') || - this.characterIsExtendedRegularNameStart(c) || - this.characterIsExtendedRegularNamePart(c); - } - - boolean characterIsExtendedRegularNamePart(char c) { - return arrayContains(this.getExtendedRegularNamePartCharacters(), c); - } - - /** - * Return the <em>regular</em> characters, beyond letters and digits and the - * <em>regular</em> first characters, for the second and subsequent characters - * of an identifier. Return <code>null</code> if there are no additional characters. - */ - char[] getExtendedRegularNamePartCharacters() { - return null; - } - - /** - * Return whether the specified name is not folded to the database's - * case, requiring it to be delimited. - */ - boolean nameIsNotFolded(String name) { - return ! this.getFoldingStrategy().nameIsFolded(name); - } - - /** - * Return whether the specified <em>regular</em> names match. - */ - boolean regularNamesMatch(String name1, String name2) { - return this.regularIdentifiersAreCaseSensitive() ? - name1.equals(name2) : - name1.equalsIgnoreCase(name2); - } - - /** - * Typically, <em>regular</em> identifiers are case-insensitive. - */ - boolean regularIdentifiersAreCaseSensitive() { - return this.getFoldingStrategy().regularIdentifiersAreCaseSensitive(); - } - - /** - * Wrap the specified name in delimiters (typically double-quotes), - * converting it to an identifier. - */ - String delimitName(String name) { - return StringTools.quote(name); - } - - - // ********** identifier -> name ********** - - // not sure how to handle an empty string: - // both "" and "\"\"" are converted to "" ... - // convert "" to 'null' since empty strings must be delimited? - public String convertIdentifierToName(String identifier) { - return (identifier == null) ? - null : - this.identifierIsDelimited(identifier) ? - StringTools.undelimit(identifier) : - this.getFoldingStrategy().fold(identifier); - } - - /** - * Return whether the specified identifier is <em>delimited</em>. - * 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.getDTPVendorName(); - } - - /** - * static convenience method - array null check - */ - static boolean arrayContains(char[] array, char c) { - return (array != null) && ArrayTools.contains(array, c); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/CatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/CatalogStrategy.java deleted file mode 100644 index 9c7a4b59c8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/CatalogStrategy.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Handle the variety of catalog (and schema) configurations generated by DTP. - */ -interface CatalogStrategy { - - /** - * Return whether the DTP database has real catalogs. - */ - boolean supportsCatalogs(Database database); - - /** - * Return the specified database's catalogs. - */ - List<Catalog> getCatalogs(Database database); - - /** - * Return the specified database's schemas. - */ - List<Schema> getSchemas(Database database); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/DB2.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/DB2.java deleted file mode 100644 index 48254049d5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/DB2.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -class DB2 - extends AbstractVendor -{ - private final String dtpVendorName; - - private static final Vendor UDB = new DB2("DB2 UDB"); //$NON-NLS-1$ - private static final Vendor UDB_I_SERIES = new DB2("DB2 UDB iSeries"); //$NON-NLS-1$ - private static final Vendor UDB_Z_SERIES = new DB2("DB2 UDB zSeries"); //$NON-NLS-1$ - - static Vendor udb() { - return UDB; - } - - static Vendor udbISeries() { - return UDB_I_SERIES; - } - - static Vendor udbZSeries() { - return UDB_Z_SERIES; - } - - /** - * Ensure only static instances. - */ - private DB2(String dtpVendorName) { - super(); - this.dtpVendorName = dtpVendorName; - } - - @Override - public String getDTPVendorName() { - return this.dtpVendorName; - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Derby.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Derby.java deleted file mode 100644 index 3194ca89de..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Derby.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; - -class Derby - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new Derby(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Derby() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Derby"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return FauxCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(this.buildDefaultSchemaName(userName)); - } - - /** - * The default user name on Derby is "APP" when the user connects without - * a user name. - */ - private String buildDefaultSchemaName(String userName) { - return ((userName != null) && (userName.length() != 0)) ? - this.convertIdentifierToName(userName) : - DEFAULT_USER_NAME; - } - private static final String DEFAULT_USER_NAME = "APP"; //$NON-NLS-1$ - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FauxCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FauxCatalogStrategy.java deleted file mode 100644 index b5b5b4218d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FauxCatalogStrategy.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for DTP databases that build a "virtual" catalog (that has - * no name) because the underlying JDBC driver does not return any catalogs - * (e.g. Oracle). - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class FauxCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new FauxCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private FauxCatalogStrategy() { - super(); - } - - public boolean supportsCatalogs(Database database) { - return false; - } - - public List<Catalog> getCatalogs(Database database) { - return Collections.emptyList(); - } - - @SuppressWarnings("unchecked") - public List<Schema> getSchemas(Database database) { - return this.getFauxCatalog(database.getCatalogs()).getSchemas(); - } - - private Catalog getFauxCatalog(List<Catalog> catalogs) { - if (catalogs == null) { - throw new IllegalStateException(); - } - if (catalogs.size() != 1) { - throw new IllegalStateException("not a single catalog: " + catalogs.size()); //$NON-NLS-1$ - } - - Catalog catalog = catalogs.get(0); - if (catalog.getName().length() != 0) { - throw new IllegalStateException("illegal name: " + catalog.getName()); //$NON-NLS-1$ - } - return catalog; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FoldingStrategy.java deleted file mode 100644 index 2a80289884..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FoldingStrategy.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -/** - * Handle database-specific identifier-folding issues. - */ -interface FoldingStrategy { - - /** - * Fold the specified name. - */ - String fold(String name); - - /** - * Return whether the specified database object name is already folded, - * meaning, if it has no special characters, it requires no delimiters. - */ - boolean nameIsFolded(String name); - - /** - * Return whether the database is case-sensitive when using "regular" - * (i.e. non-delimited) identifiers. - */ - boolean regularIdentifiersAreCaseSensitive(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/HSQLDB.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/HSQLDB.java deleted file mode 100644 index 3be0393255..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/HSQLDB.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; - -class HSQLDB - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new HSQLDB(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private HSQLDB() { - super(); - } - - @Override - public String getDTPVendorName() { - return "HSQLDB"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(PUBLIC_SCHEMA_NAME); - } - private static final String PUBLIC_SCHEMA_NAME = "PUBLIC"; //$NON-NLS-1$ - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Informix.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Informix.java deleted file mode 100644 index f4de2a9685..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Informix.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -class Informix - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new Informix(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Informix() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Informix"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return LowerCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedRegularNameStartCharacters() { - return EXTENDED_REGULAR_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_START_CHARACTERS = new char[] { '_' }; - - @Override - char[] getExtendedRegularNamePartCharacters() { - return EXTENDED_REGULAR_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_PART_CHARACTERS = new char[] { '$' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java deleted file mode 100644 index 73e19744bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.vendor; - -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Fold "normal" identifiers to lower case. - * Ignore the case of "normal" identifiers. - */ -class LowerCaseFoldingStrategy - implements FoldingStrategy -{ - - // singleton - private static final FoldingStrategy INSTANCE = new LowerCaseFoldingStrategy(); - - /** - * Return the singleton. - */ - static FoldingStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private LowerCaseFoldingStrategy() { - super(); - } - - public String fold(String name) { - return name.toLowerCase(); - } - - public boolean nameIsFolded(String name) { - return StringTools.stringIsLowercase(name); - } - - public boolean regularIdentifiersAreCaseSensitive() { - return false; - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MaxDB.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MaxDB.java deleted file mode 100644 index 56f459ed02..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MaxDB.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -class MaxDB - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new MaxDB(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private MaxDB() { - super(); - } - - @Override - public String getDTPVendorName() { - return "MaxDB"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedRegularNameStartCharacters() { - return EXTENDED_REGULAR_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_START_CHARACTERS = new char[] { '#', '@', '$' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MySQL.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MySQL.java deleted file mode 100644 index 210fea37bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MySQL.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.jpt.utility.internal.StringTools; - -class MySQL - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new MySQL(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private MySQL() { - super(); - } - - @Override - public String getDTPVendorName() { - return "MySql"; //$NON-NLS-1$ - } - - /** - * The DTP model for MySQL has a database that contains no catalogs; - * but, instead, directly holds a single schema with the same name as - * the database. (This is hard-coded in MySqlCatalogDatabase.getSchemas().) - * 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 - CatalogStrategy getCatalogStrategy() { - return NoCatalogStrategy.instance(); - } - - /** - * 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 index and column names, are folded; - * but they are case-insensitive, unless delimited. See - * http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html.) - */ - @Override - FoldingStrategy getFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(database.getName()); - } - - /** - * MySQL is the only vendor that allows a digit. - * Although, the name cannnot be *all* digits. - */ - @Override - boolean characterIsRegularNameStart(char c) { - return Character.isDigit(c) || super.characterIsRegularNameStart(c); - } - - @Override - char[] getExtendedRegularNameStartCharacters() { - return EXTENDED_REGULAR_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_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 = '`'; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NoCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NoCatalogStrategy.java deleted file mode 100644 index a7fb79d9ba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NoCatalogStrategy.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for DTP databases that do not have catalogs - * (e.g. MySQL see bug 249013). - */ -class NoCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new NoCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NoCatalogStrategy() { - super(); - } - - public boolean supportsCatalogs(Database database) { - return false; - } - - public List<Catalog> getCatalogs(Database database) { - return Collections.emptyList(); - } - - @SuppressWarnings("unchecked") - public List<Schema> getSchemas(Database database) { - return database.getSchemas(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java deleted file mode 100644 index e943d18ec8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.vendor; - - -/** - * Do not fold "normal" identifiers. - * Respect the case of "normal" identifiers. - */ -class NonFoldingStrategy - implements FoldingStrategy -{ - - // singleton - private static final FoldingStrategy INSTANCE = new NonFoldingStrategy(); - - /** - * Return the singleton. - */ - static FoldingStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NonFoldingStrategy() { - super(); - } - - /** - * Since identifiers are not folded to upper- or lower-case, the name is - * already "folded". - */ - public String fold(String name) { - return name; - } - - /** - * Since identifiers are not folded to upper- or lower-case, the name is - * already "folded". - * (Non-folding databases do not require delimiters around mixed-case - * "normal" identifiers.) - */ - public boolean nameIsFolded(String name) { - return true; - } - - public boolean regularIdentifiersAreCaseSensitive() { - return true; - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Oracle.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Oracle.java deleted file mode 100644 index 33ad7a9c50..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Oracle.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -class Oracle - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new Oracle(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Oracle() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Oracle"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return FauxCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedRegularNamePartCharacters() { - return EXTENDED_REGULAR_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_PART_CHARACTERS = new char[] { '$', '#' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/PostgreSQL.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/PostgreSQL.java deleted file mode 100644 index b55f5cb5c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/PostgreSQL.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; - -class PostgreSQL - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new PostgreSQL(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private PostgreSQL() { - super(); - } - - @Override - public String getDTPVendorName() { - return "postgres"; //$NON-NLS-1$ - } - - /** - * The PostgreSQL JDBC driver returns a single catalog from the call to - * DatabaseMetaData.getCatalogs() that has the same name as the - * database initially specified by the connection (in the JDBC URL). - * DTP uses this configuration unmodified. Unfortunately, the DTP - * database's name is not the same as the PostgreSQL database's - * name. - */ - @Override - CatalogStrategy getCatalogStrategy() { - return SimpleCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return LowerCaseFoldingStrategy.instance(); - } - - /** - * The PostgreSQL database holds a single catalog that has the same name as - * the database. - */ - @Override - void addDefaultCatalogNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(this.buildDefaultCatalogName(database)); - } - - private String buildDefaultCatalogName(Database database) { - return ((Catalog) database.getCatalogs().get(0)).getName(); - } - - /** - * PostgreSQL has a "schema search path". The default is: - * "$user",public - * If the "$user" schema is not found, use the "public" schema. - */ - @Override - void addDefaultSchemaNamesTo(Database database, String userName, ArrayList<String> names) { - super.addDefaultSchemaNamesTo(database, userName, names); - names.add(PUBLIC_SCHEMA_NAME); - } - private static final String PUBLIC_SCHEMA_NAME = "public"; //$NON-NLS-1$ - - @Override - char[] getExtendedRegularNameStartCharacters() { - return EXTENDED_REGULAR_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_START_CHARACTERS = new char[] { '_' }; - - @Override - char[] getExtendedRegularNamePartCharacters() { - return EXTENDED_REGULAR_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_PART_CHARACTERS = new char[] { '$' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java deleted file mode 100644 index fccef59084..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.jpt.utility.internal.StringTools; - -class SQLServer - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new SQLServer(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SQLServer() { - super(); - } - - @Override - public String getDTPVendorName() { - return "SQL Server"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return SimpleCatalogStrategy.instance(); - } - - /** - * By default, SQL Server identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - @Override - FoldingStrategy getFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - /** - * SQL Server will use the user-requested database; if that database is not - * found, it will default to 'master'. - */ - @Override - void addDefaultCatalogNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(database.getName()); - names.add(MASTER_CATALOG_IDENTIFIER); - } - private static final String MASTER_CATALOG_IDENTIFIER = "master"; //$NON-NLS-1$ - - /** - * The default schema on SQL Server for any database (catalog) is 'dbo'. - */ - @Override - void addDefaultSchemaNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(DEFAULT_SCHEMA_NAME); - } - private static final String DEFAULT_SCHEMA_NAME = "dbo"; //$NON-NLS-1$ - - @Override - char[] getExtendedRegularNameStartCharacters() { - return EXTENDED_REGULAR_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_START_CHARACTERS = new char[] { '_', '@', '#' }; - - @Override - char[] getExtendedRegularNamePartCharacters() { - return EXTENDED_REGULAR_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_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); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SimpleCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SimpleCatalogStrategy.java deleted file mode 100644 index 8a1a04129e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SimpleCatalogStrategy.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for DTP databases that simply model the catalogs returned - * by the underlying JDBC driver (e.g. Sybase). - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class SimpleCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new SimpleCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SimpleCatalogStrategy() { - super(); - } - - public boolean supportsCatalogs(Database database) { - return true; - } - - @SuppressWarnings("unchecked") - public List<Catalog> getCatalogs(Database database) { - return database.getCatalogs(); - } - - public List<Schema> getSchemas(Database database) { - return Collections.emptyList(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java deleted file mode 100644 index e90b9b9a0f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.jpt.utility.internal.StringTools; - -class Sybase - extends AbstractVendor -{ - private final String dtpVendorName; - - static final Vendor ASA = new Sybase("Sybase_ASA"); //$NON-NLS-1$ - static final Vendor ASE = new Sybase("Sybase_ASE"); //$NON-NLS-1$ - - static Vendor asa() { - return ASA; - } - - static Vendor ase() { - return ASE; - } - - /** - * Ensure only static instances. - */ - private Sybase(String dtpVendorName) { - super(); - this.dtpVendorName = dtpVendorName; - } - - @Override - public String getDTPVendorName() { - return this.dtpVendorName; - } - - @Override - CatalogStrategy getCatalogStrategy() { - return SimpleCatalogStrategy.instance(); - } - - /** - * By default, Sybase identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - @Override - FoldingStrategy getFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - /** - * Sybase will use the user-requested database; if that database is not - * found, it will default to 'master'. - */ - @Override - void addDefaultCatalogNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(database.getName()); - names.add(MASTER_CATALOG_NAME); - } - private static final String MASTER_CATALOG_NAME = "master"; //$NON-NLS-1$ - - /** - * 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. a table) first in the user's - * schema, then it looks 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 - void addDefaultSchemaNamesTo(Database database, String userName, ArrayList<String> names) { - names.add(DEFAULT_SCHEMA_NAME); - } - private static final String DEFAULT_SCHEMA_NAME = "dbo"; //$NON-NLS-1$ - - @Override - char[] getExtendedRegularNameStartCharacters() { - return EXTENDED_REGULAR_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_START_CHARACTERS = new char[] { '_', '@' }; - - @Override - char[] getExtendedRegularNamePartCharacters() { - return EXTENDED_REGULAR_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_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/vendor/UnknownCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnknownCatalogStrategy.java deleted file mode 100644 index ea9a729e35..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnknownCatalogStrategy.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for unknown DTP databases. - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class UnknownCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new UnknownCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private UnknownCatalogStrategy() { - super(); - } - - @SuppressWarnings("unchecked") - public boolean supportsCatalogs(Database database) { - List<Catalog> catalogs = database.getCatalogs(); - if ((catalogs == null) || catalogs.isEmpty()) { - return false; - } - - return this.getFauxCatalog(catalogs) == null; - } - - @SuppressWarnings("unchecked") - public List<Catalog> getCatalogs(Database database) { - List<Catalog> catalogs = database.getCatalogs(); - // if there are no catalogs, the database must hold the schemata directly - if ((catalogs == null) || catalogs.isEmpty()) { - return Collections.emptyList(); - } - - Catalog fauxCatalog = this.getFauxCatalog(catalogs); - return (fauxCatalog == null) ? catalogs : Collections.<Catalog>emptyList(); - } - - @SuppressWarnings("unchecked") - public List<Schema> getSchemas(Database database) { - List<Catalog> catalogs = database.getCatalogs(); - // if there are no catalogs, the database must hold the schemata directly - if ((catalogs == null) || catalogs.isEmpty()) { - return database.getSchemas(); - } - - Catalog fauxCatalog = this.getFauxCatalog(catalogs); - return (fauxCatalog != null) ? fauxCatalog.getSchemas() : Collections.emptyList(); - } - - private Catalog getFauxCatalog(List<Catalog> catalogs) { - if (catalogs.size() == 1) { - Catalog catalog = catalogs.get(0); - if (catalog.getName().equals("")) { //$NON-NLS-1$ - return catalog; - } - } - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnrecognizedVendor.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnrecognizedVendor.java deleted file mode 100644 index f5751232ff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnrecognizedVendor.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -/** - * - */ -class UnrecognizedVendor - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new UnrecognizedVendor(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private UnrecognizedVendor() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Unrecognized Vendor"; //$NON-NLS-1$ - } - - /** - * Not sure what to do here.... - * Assume the DTP database is organized into one or more catalogs and - * the schemata are contained by those catalogs. This appears to be the - * default way DTP builds models these days (i.e. a database with at - * least one catalog, instead of the database holding schemata - * directly). - */ - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java deleted file mode 100644 index f3e88967d6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.vendor; - -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Fold "normal" identifiers to upper case. - * Ignore the case of "normal" identifiers. - */ -class UpperCaseFoldingStrategy - implements FoldingStrategy -{ - - // singleton - private static final FoldingStrategy INSTANCE = new UpperCaseFoldingStrategy(); - - /** - * Return the singleton. - */ - static FoldingStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private UpperCaseFoldingStrategy() { - super(); - } - - public String fold(String name) { - return name.toUpperCase(); - } - - public boolean nameIsFolded(String name) { - return StringTools.stringIsUppercase(name); - } - - public boolean regularIdentifiersAreCaseSensitive() { - return false; - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Vendor.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Vendor.java deleted file mode 100644 index 4c7dc0292e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Vendor.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Delegate vendor-specific behavior to implementations of this interface:<ul> - * <li>catalog support - * <li>default catalog and schema - * <li>converting names to identifiers and vice-versa - * </ul> - * <strong>NB:</strong><br> - * We use <em>name</em> 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). - * <br> - * We use <em>identifier</em> 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). - */ -public interface Vendor { - - /** - * This must match the DTP vendor name. - * @see org.eclipse.datatools.modelbase.sql.schema.Database#getVendor() - */ - String getDTPVendorName(); - - /** - * Return whether the vendor supports "real" catalogs (e.g. Sybase). - */ - boolean supportsCatalogs(Database database); - - /** - * Return the specified database's catalogs. - */ - List<Catalog> getCatalogs(Database database); - - /** - * Return the specified database's default catalog names for the - * specified user. The first name in the list that identifies a catalog - * that exists is "the" default. - */ - Iterable<String> getDefaultCatalogNames(Database database, String userName); - - /** - * Return the specified database's schemas. - */ - List<Schema> getSchemas(Database database); - - /** - * Return the specified database's default schema names for the - * specified user. The first name in the list that identifies a schema - * that exists is "the" default. - */ - Iterable<String> getDefaultSchemaNames(Database database, String userName); - - /** - * Convert the specified database object name to a vendor identifier. - * Return <code>null</code> if the identifier matches the specified default name. - */ - String convertNameToIdentifier(String name, String defaultName); - - /** - * Convert the specified database object name to a vendor identifier. - */ - String convertNameToIdentifier(String name); - - /** - * Convert the specified database object identifier to a vendor name. - */ - String convertIdentifierToName(String identifier); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/VendorRepository.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/VendorRepository.java deleted file mode 100644 index 468f09ea44..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/VendorRepository.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.vendor; - -import java.util.ArrayList; -import java.util.Iterator; - -public class VendorRepository { - private final Vendor[] vendors; - - // singleton - private static final VendorRepository INSTANCE = new VendorRepository(); - - /** - * Return the singleton. - */ - public static VendorRepository instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private VendorRepository() { - super(); - this.vendors = this.buildVendors(); - } - - private Vendor[] buildVendors() { - ArrayList<Vendor> list = new ArrayList<Vendor>(); - this.addVendorsTo(list); - return list.toArray(new Vendor[list.size()]); - } - - private void addVendorsTo(ArrayList<Vendor> list) { - this.addVendorTo(DB2.udb(), list); - this.addVendorTo(DB2.udbISeries(), list); - this.addVendorTo(DB2.udbZSeries(), list); - this.addVendorTo(Derby.instance(), list); - this.addVendorTo(HSQLDB.instance(), list); - this.addVendorTo(Informix.instance(), list); - this.addVendorTo(MaxDB.instance(), list); - this.addVendorTo(MySQL.instance(), list); - this.addVendorTo(Oracle.instance(), list); - this.addVendorTo(PostgreSQL.instance(), list); - this.addVendorTo(SQLServer.instance(), list); - this.addVendorTo(Sybase.asa(), list); - this.addVendorTo(Sybase.ase(), list); - } - - private void addVendorTo(Vendor vendor, ArrayList<Vendor> list) { - String name = vendor.getDTPVendorName(); - for (Iterator<Vendor> stream = list.iterator(); stream.hasNext(); ) { - if (stream.next().getDTPVendorName().equals(name)) { - throw new IllegalArgumentException("Duplicate vendor: " + name); //$NON-NLS-1$ - } - } - list.add(vendor); - } - - public Vendor getVendor(String dtpVendorName) { - for (int i = this.vendors.length; i-- > 0;) { - Vendor vendor = this.vendors[i]; - if (vendor.getDTPVendorName().equals(dtpVendorName)) { - return vendor; - } - } - return UnrecognizedVendor.instance(); - } - -} |