diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse')
53 files changed, 0 insertions, 6788 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Catalog.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Catalog.java deleted file mode 100644 index b976d3f1c9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Catalog.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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.jpa.db/src/org/eclipse/jpt/jpa/db/Column.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Column.java deleted file mode 100644 index 3f24d3d3ad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Column.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.db; - -import org.eclipse.jpt.common.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.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java deleted file mode 100644 index 15cae4fad8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionListener.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionListener.java deleted file mode 100644 index 5cb9129aa4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db; - -import java.util.EventListener; - -/** - * A <code>ConnectionListener</code> is notified of any changes to a connection. - * <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. - * - * @see org.eclipse.datatools.connectivity.IManagedConnectionListener - */ -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.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfile.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfile.java deleted file mode 100644 index a8815874ce..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfile.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.db; - -import java.sql.Connection; -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 <code>null</code> 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(); - - - // ********** identifiers ********** - - /** - * Return whether all identifiers are to be treated as though they were - * delimited. This is determined by the client-supplied database - * identifier adapter. - */ - boolean treatIdentifiersAsDelimited(); - - - // ********** 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(); - - /** - * Return the JDBC connection. - */ - Connection getJDBCConnection(); - - - // ********** 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.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileAdapter.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileAdapter.java deleted file mode 100644 index ecf4a98e1e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileFactory.java deleted file mode 100644 index e31521820c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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 <code>null</code> 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 handled. - */ - ConnectionProfile buildConnectionProfile(String name, DatabaseIdentifierAdapter adapter); - - /** - * Build and return a connection profile that wraps the DTP connection - * profile with the specified name. - * Return <code>null</code> 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 database identifier adapter. - */ - 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.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileListener.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileListener.java deleted file mode 100644 index c7eb1e5236..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfileListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.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.jpa.db/src/org/eclipse/jpt/jpa/db/Database.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Database.java deleted file mode 100644 index 11c486fbf4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Database.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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 -{ - /** - * Return the database's DTP database. - */ - org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase(); - - - // ********** 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 the specified name. The name must be an exact match - * of the catalog's name. - * Return <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 tables the - * table identified by the specified identifier. - * The identifier should be an SQL identifier (i.e. delimited as - * appropriate). - */ - Table selectTableForIdentifier(Iterable<Table> tables, String identifier); - - /** - * Convert the specified name to a database-appropriate SQL identifier - * (i.e. delimit the name as appropriate). - */ - // it seems we don't need database object-specific conversions here; - // i.e. separate methods for tables, columns, etc. - String convertNameToIdentifier(String name); -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseIdentifierAdapter.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseIdentifierAdapter.java deleted file mode 100644 index eb75e2559a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseIdentifierAdapter.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.db; - -/** - * This interface allows clients of the Dali db package to control whether - * database identifiers are to be treated as though they are delimited, which, - * most significantly, usually means the identifiers are case-sensitive. - * <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 { - - /** - * Return whether identifiers are to be treated as though they were - * delimited. - */ - boolean treatIdentifiersAsDelimited(); - - - /** - * This adapter simply returns <code>false</code>, which is compatible - * with JPA 1.0. - */ - final class Default implements DatabaseIdentifierAdapter { - public static final DatabaseIdentifierAdapter INSTANCE = new Default(); - public static DatabaseIdentifierAdapter instance() { - return INSTANCE; - } - // ensure single instance - private Default() { - super(); - } - public boolean treatIdentifiersAsDelimited() { - return false; // JPA 1.0 - } - @Override - public String toString() { - return this.getClass().getDeclaringClass().getSimpleName() + '.' + this.getClass().getSimpleName(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseObject.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseObject.java deleted file mode 100644 index e20a54084b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/DatabaseObject.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.db; - -import java.util.Comparator; -import org.eclipse.jpt.common.utility.internal.Transformer; -import com.ibm.icu.text.Collator; - -/** - * Behavior common 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 <em>identifier</em>, 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 <em>identifier</em>, 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 <code>null</code> if the database object's identifier matches the - * specified default name. - * <p> - * This is used by the Dali entity generation code to determine whether - * a generated annotation must explicitly identify a database object - * (e.g. a table) or the default (as specified here) adequately identifies - * the database object (taking into consideration case-sensitivity, - * special characters, etc.). - */ - String getIdentifier(String defaultName); - - /** - * Return the database object's database. - */ - Database getDatabase(); - - /** - * Return the database object's connection profile. - */ - ConnectionProfile getConnectionProfile(); - - - /** - * Sort by name. - */ - Comparator<DatabaseObject> DEFAULT_COMPARATOR = - new Comparator<DatabaseObject>() { - public int compare(DatabaseObject dbObject1, DatabaseObject dbObject2) { - return Collator.getInstance().compare(dbObject1.getName(), dbObject2.getName()); - } - @Override - public String toString() { - return this.getClass().getEnclosingClass().getSimpleName() + ".DEFAULT_COMPARATOR"; //$NON-NLS-1$ - } - }; - - Transformer<DatabaseObject, String> NAME_TRANSFORMER = - new Transformer<DatabaseObject, String>() { - public String transform(DatabaseObject dbObject) { - return dbObject.getName(); - } - @Override - public String toString() { - return this.getClass().getEnclosingClass().getSimpleName() + ".NAME_TRANSFORMER"; //$NON-NLS-1$ - } - }; - - Transformer<DatabaseObject, String> IDENTIFIER_TRANSFORMER = - new Transformer<DatabaseObject, String>() { - public String transform(DatabaseObject dbObject) { - return dbObject.getIdentifier(); - } - @Override - public String toString() { - return this.getClass().getEnclosingClass().getSimpleName() + ".IDENTIFIER_TRANSFORMER"; //$NON-NLS-1$ - } - }; -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ForeignKey.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ForeignKey.java deleted file mode 100644 index 47c0abcda3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ForeignKey.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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 <em>base</em> table. - */ - Table getBaseTable(); - - /** - * Return the foreign key's <em>referenced</em> 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 <em>base</em> columns. - */ - Iterable<Column> getBaseColumns(); - - /** - * Return the foreign key's <em>base</em> 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 <em>referenced</em> columns. - */ - Iterable<Column> getReferencedColumns(); - - /** - * Return whether the foreign key references the primary key of the - * <em>referenced</em> 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 <em>referenced</em> table. - */ - String getAttributeName(); - - /** - * If the name of the <em>base</em> column adheres to the JPA spec for a - * default mapping (i.e. it ends with an underscore followed by the name - * of the <em>referenced</em> column, and the <em>referenced</em> column is the single - * primary key column of the <em>referenced</em> table), return the corresponding - * default attribute name:<pre> - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * </pre> - * Return <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 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, special characters, etc.). - */ - String getJoinColumnAnnotationIdentifier(String attributeName); - - - // ********** column pair interface ********** - - /** - * Pair up the foreign key's column pairs, matching each <em>base</em> column with - * the appropriate <em>referenced</em> column. - * @see #getColumnPairs() - */ - interface ColumnPair { - - /** - * Return the column pair's <em>base</em> column. - */ - Column getBaseColumn(); - - /** - * Return the column pair's <em>referenced</em> 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.jpa.db/src/org/eclipse/jpt/jpa/db/JptJpaDbPlugin.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/JptJpaDbPlugin.java deleted file mode 100644 index 473ab86097..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/JptJpaDbPlugin.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.eclipse.datatools.enablement.jdt.classpath.DriverClasspathContainer; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jpt.jpa.db.internal.DTPConnectionProfileFactory; -import org.osgi.framework.BundleContext; - -/** - * The Dali JPA 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 JptJpaDbPlugin - extends Plugin -{ - // lazy-initialized - private DTPConnectionProfileFactory connectionProfileFactory; - - private static JptJpaDbPlugin INSTANCE; // sorta-final - - public static final String PLUGIN_ID = "org.eclipse.jpt.jpa.db"; //$NON-NLS-1$ - - /** - * Return the singleton JPT DB plug-in. - */ - public static JptJpaDbPlugin instance() { - return INSTANCE; - } - - - // ********** public static methods ********** - - public static ConnectionProfileFactory getConnectionProfileFactory() { - return INSTANCE.getConnectionProfileFactory_(); - } - - - // ********** logging ********** - - /** - * Log the specified message. - */ - public static void log(String msg) { - log(msg, null); - } - - /** - * Log the specified exception or error. - */ - public static void log(Throwable throwable) { - log(throwable.getLocalizedMessage(), throwable); - } - - /** - * Log the specified message and exception or error. - */ - public static void log(String msg, Throwable throwable) { - log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, throwable)); - } - - /** - * Log the specified status. - */ - public static void log(IStatus status) { - INSTANCE.getLog().log(status); - } - - - // ********** plug-in implementation ********** - - /** - * The constructor - */ - public JptJpaDbPlugin() { - 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); - // the connection profile factory is lazy-initialized... - } - - /** - * This method is called when the plug-in is stopped - */ - @Override - public void stop(BundleContext context) throws Exception { - if (this.connectionProfileFactory != null) { - this.connectionProfileFactory.stop(); - this.connectionProfileFactory = null; - } - INSTANCE = null; - super.stop(context); - } - - private synchronized ConnectionProfileFactory getConnectionProfileFactory_() { - if (this.connectionProfileFactory == null) { - this.connectionProfileFactory = this.buildConnectionProfileFactory(); - this.connectionProfileFactory.start(); - } - return this.connectionProfileFactory; - } - - private DTPConnectionProfileFactory buildConnectionProfileFactory() { - return DTPConnectionProfileFactory.instance(); - } - - /** - * 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.jpa.db/src/org/eclipse/jpt/jpa/db/Schema.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Schema.java deleted file mode 100644 index d23b445a59..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Schema.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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 the 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 the 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.jpa.db/src/org/eclipse/jpt/jpa/db/SchemaContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/SchemaContainer.java deleted file mode 100644 index 9f3fad1acb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/SchemaContainer.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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 the 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 <code>null</code> 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.jpa.db/src/org/eclipse/jpt/jpa/db/Sequence.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Sequence.java deleted file mode 100644 index 886c728fc0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Sequence.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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.jpa.db/src/org/eclipse/jpt/jpa/db/Table.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Table.java deleted file mode 100644 index aa2258ab75..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/Table.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.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 the 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 <em>join</em> table - * (i.e. it contains only 2 foreign keys). Whether the table <em>actually</em> is - * a <em>join</em> table is determined by the semantics of the database design. - */ - boolean isPossibleJoinTable(); - - /** - * Assuming the table is a <em>join</em> table, return the foreign key to the - * <em>owning</em> table. - * @see #isPossibleJoinTable() - */ - ForeignKey getJoinTableOwningForeignKey(); - - /** - * Assuming the table is a <em>join</em> table, return the foreign key to the - * <em>non-owning</em> table. - * @see #isPossibleJoinTable() - */ - ForeignKey getJoinTableNonOwningForeignKey(); - - /** - * Assuming the table is a <em>join</em> 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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPCatalogWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPCatalogWrapper.java deleted file mode 100644 index 8773036640..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPCatalogWrapper.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 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.jpa.db.internal; - -import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.jpa.db.Catalog; - -/** - * Wrap a DTP Catalog - */ -final class DTPCatalogWrapper - extends DTPSchemaContainerWrapper<DTPDatabaseWrapper> - implements Catalog -{ - /** the wrapped DTP catalog */ - private final org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog; - - - // ********** constructor ********** - - DTPCatalogWrapper(DTPDatabaseWrapper database, org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) { - super(database); - this.dtpCatalog = dtpCatalog; - } - - - // ********** DTPDatabaseObjectWrapper implementation ********** - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpCatalog; - } - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().catalogChanged(this); - } - - - // ********** DTPSchemaContainerWrapper implementation ********** - - @Override - @SuppressWarnings("unchecked") - List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemas() { - 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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPColumnWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPColumnWrapper.java deleted file mode 100644 index 4613cab63f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPColumnWrapper.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.datatools.modelbase.dbdefinition.PredefinedDataTypeDefinition; -import org.eclipse.datatools.modelbase.sql.datatypes.CharacterStringDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.DataType; -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.common.utility.JavaType; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.SimpleJavaType; -import org.eclipse.jpt.jpa.db.Column; - -/** - * Wrap a DTP Column - */ -final class DTPColumnWrapper - extends DTPDatabaseObjectWrapper<DTPTableWrapper> - implements Column -{ - /** the wrapped DTP column */ - private final org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn; - - - // ********** constructor ********** - - DTPColumnWrapper(DTPTableWrapper table, org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - super(table); - this.dtpColumn = dtpColumn; - } - - - // ********** DTPDatabaseObjectWrapper implementation ********** - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpColumn; - } - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().columnChanged(this); - } - - - // ********** Column implementation ********** - - public String getName() { - return this.dtpColumn.getName(); - } - - public DTPTableWrapper getTable() { - return this.parent; - } - - 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.resolveDefinition(dataType).getJavaClassName(); - return new SimpleJavaType(ReflectionTools.getClassNameForTypeDeclaration(dtpJavaClassName)); - } - - private PredefinedDataTypeDefinition resolveDefinition(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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileFactory.java deleted file mode 100644 index b64b8f068e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileFactory.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.IProfileListener1; -import org.eclipse.datatools.connectivity.ProfileManager; -import org.eclipse.jpt.common.utility.internal.ListenerList; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.jpa.db.ConnectionProfile; -import org.eclipse.jpt.jpa.db.ConnectionProfileFactory; -import org.eclipse.jpt.jpa.db.ConnectionProfileListener; -import org.eclipse.jpt.jpa.db.DatabaseIdentifierAdapter; - -/** - * Wrap the DTP {@link 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; - } - - /** - * Access is <code>private</code> 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 this.buildConnectionProfile(dtpProfile, adapter); - } - } - return null; - } - - private ConnectionProfile buildConnectionProfile(IConnectionProfile dtpProfile, DatabaseIdentifierAdapter adapter) { - return new DTPConnectionProfileWrapper(dtpProfile, adapter); - } - - 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 final 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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java deleted file mode 100644 index 045b4782bf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java +++ /dev/null @@ -1,535 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import java.sql.Connection; -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.common.utility.internal.ListenerList; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jpa.db.ConnectionListener; -import org.eclipse.jpt.jpa.db.ConnectionProfile; -import org.eclipse.jpt.jpa.db.DatabaseIdentifierAdapter; - -/** - * Wrap a DTP {@link IConnectionProfile} - */ -final class DTPConnectionProfileWrapper - implements DTPDatabaseObject, ConnectionProfile -{ - /** the wrapped DTP connection profile */ - private final IConnectionProfile dtpConnectionProfile; - - /** adapter supplied by the client (determines identifier delimiters) */ - private final DatabaseIdentifierAdapter identifierAdapter; - - /** 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.class.getName(); - - 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 identifierAdapter) { - super(); - this.dtpConnectionProfile = dtpConnectionProfile; - this.identifierAdapter = identifierAdapter; - this.dtpManagedConnection = this.buildDTPManagedConnection(); - this.connectionListener = new LocalConnectionListener(); - // don't listen to the managed connection yet - } - - private IManagedConnection buildDTPManagedConnection() { - return this.dtpConnectionProfile.getManagedConnection(this.getDTPConnectionType()); - } - - private String getDTPConnectionType() { - return this.dtpConnectionProfile.supportsWorkOfflineMode() ? - OFFLINE_DTP_CONNECTION_TYPE : - LIVE_DTP_CONNECTION_TYPE; - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpConnectionProfile.getName(); - } - - public String getIdentifier(String javaIdentifier) { - // connection profiles do not have "identifiers" - throw new UnsupportedOperationException(); - } - - public String getIdentifier() { - // connection profiles do not have "identifiers" - throw new UnsupportedOperationException(); - } - - - // ********** DTPDatabaseObject implementation ********** - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this; - } - - public synchronized DTPDatabaseWrapper getDatabase() { - if (this.database == null) { - this.database = this.buildDatabase(); - } - return this.database; - } - - - // ********** ConnectionProfile implementation ********** - - // ***** properties - public String getProviderID() { - return this.dtpConnectionProfile.getProviderId(); - } - - public String getInstanceID() { - return this.dtpConnectionProfile.getInstanceID(); - } - - public String getDatabaseName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_NAME_PROP_ID); - } - - public String getDatabaseProduct() { - return this.getProperty(DATABASE_PRODUCT_PROP_ID); - } - - public String getDatabaseVendor() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID); - } - - public String getDatabaseVersion() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID); - } - - public String getDriverClassName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DRIVER_CLASS_PROP_ID); - } - - public String getURL() { - return this.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID); - } - - public String getUserName() { - String userName = this.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID); - return this.extractUserName(userName.trim()); - } - - private String extractUserName(String userName) { - String[] strings = userName.split("\\s+"); //$NON-NLS-1$ - // bug 208946 handle username like "sys as sysdba" on Oracle - if ((strings.length == 3) && strings[1].equalsIgnoreCase("as")) { //$NON-NLS-1$ - return strings[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()); - } - - public Connection getJDBCConnection() { - return this.getConnectionInfo().getSharedConnection(); - } - - // ***** 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() { - return this.isInactive() ? null : new DTPDatabaseWrapper(this, this.buildDTPDatabase()); - } - - private org.eclipse.datatools.modelbase.sql.schema.Database buildDTPDatabase() { - return this.isWorkingOffline() ? - this.buildOfflineDTPDatabase() : - this.buildLiveDTPDatabase(); - } - - private org.eclipse.datatools.modelbase.sql.schema.Database buildOfflineDTPDatabase() { - return this.getConnectionInfo().getSharedDatabase(); - } - - private ConnectionInfo getConnectionInfo() { - return (ConnectionInfo) this.dtpManagedConnection.getConnection().getRawConnection(); - } - - private org.eclipse.datatools.modelbase.sql.schema.Database buildLiveDTPDatabase() { - // 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 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; - } - } - - public boolean treatIdentifiersAsDelimited() { - return this.identifierAdapter.treatIdentifiersAsDelimited(); - } - - 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); - } - - - // ********** 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. Also, the connection profile delegates to - * this listener when notifying {@link ConnectionListener}s of changes to - * the database objects (catalogs, schemata, tables, etc.). - */ - private 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 {@link org.eclipse.datatools.connectivity.internal.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); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObject.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObject.java deleted file mode 100644 index 57caa3ec82..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObject.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 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.jpa.db.internal; - -import org.eclipse.jpt.jpa.db.DatabaseObject; - -/** - * Internal interface: DTP database object. - */ -interface DTPDatabaseObject - extends DatabaseObject -{ - /** - * covariant override - */ - DTPConnectionProfileWrapper getConnectionProfile(); - - /** - * covariant override - */ - public DTPDatabaseWrapper getDatabase(); -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObjectWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObjectWrapper.java deleted file mode 100644 index d498e152f2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseObjectWrapper.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObjectListener; -import org.eclipse.datatools.connectivity.sqm.core.rte.RefreshManager; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jpa.db.DatabaseObject; -import org.eclipse.jpt.jpa.db.internal.driver.DTPDriverAdapter; - -/** - * DTP Object Wrapper base class - */ -abstract class DTPDatabaseObjectWrapper<P extends DTPDatabaseObject> - implements DTPDatabaseObject -{ - /** we need a way to get to the connection profile */ - final P parent; - - /** listen for the "catalog object" being refreshed */ - private final ICatalogObjectListener catalogObjectListener; - - - // ********** constructor ********** - - DTPDatabaseObjectWrapper(P parent) { - 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.catalogObjectListener = this.buildCatalogObjectListener(); - if (this.getConnectionProfile().hasAnyListeners()) { - this.startListening(); - } - } else { - this.catalogObjectListener = null; - } - } - - - // ********** names vs. identifiers ********** - - /** - * 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.getDTPDriverAdapter().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> - * <li>MySQL<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.getDTPDriverAdapter().convertNameToIdentifier(name); - } - - - // ********** DTP database object listener ********** - - private ICatalogObjectListener buildCatalogObjectListener() { - return new ICatalogObjectListener() { - public void notifyChanged(ICatalogObject dmElement, int eventType) { - if (dmElement == DTPDatabaseObjectWrapper.this.getCatalogObject()) { - // 'eventType' doesn't seem to be very useful, so drop it - DTPDatabaseObjectWrapper.this.catalogObjectChanged(); - } - } - }; - } - - /** - * Typically, return the wrapped DTP database object. - */ - abstract ICatalogObject getCatalogObject(); - - /** - * Typically, a subclass will override this method to - * call <code>super.catalogObjectChanged()</code> and - * 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(); - - // this should only be called when the connection profile is "live" and has listeners - void startListening() { - this.checkListener(); - RefreshManager.getInstance().AddListener(this.getCatalogObject(), this.catalogObjectListener); - } - - // this should only be called when the connection profile is "live" and has no listeners - void stopListening() { - this.checkListener(); - RefreshManager.getInstance().removeListener(this.getCatalogObject(), this.catalogObjectListener); - } - - /** - * We only build {@link #catalogObjectListener} when the connection - * profile is "live". If we get here and it is <code>null</code>, - * something is wrong. - */ - private void checkListener() { - if (this.catalogObjectListener == null) { - throw new IllegalStateException("the catalog listener is null"); //$NON-NLS-1$ - } - } - - - // ********** misc ********** - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this.parent.getConnectionProfile(); - } - - public DTPDatabaseWrapper getDatabase() { - return this.parent.getDatabase(); - } - - DTPDriverAdapter getDTPDriverAdapter() { - return this.getDatabase().getDTPDriverAdapter(); - } - - /** - * Convenience method. - */ - <T extends DatabaseObject> T selectDatabaseObjectNamed(Iterable<T> databaseObjects, String name) { - for (T databaseObject : databaseObjects) { - if (databaseObject.getName().equals(name)) { - return databaseObject; - } - } - return null; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseWrapper.java deleted file mode 100644 index ed7d51577a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPDatabaseWrapper.java +++ /dev/null @@ -1,358 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.jpa.db.Catalog; -import org.eclipse.jpt.jpa.db.Database; -import org.eclipse.jpt.jpa.db.DatabaseObject; -import org.eclipse.jpt.jpa.db.Table; -import org.eclipse.jpt.jpa.db.internal.driver.DTPDriverAdapter; -import org.eclipse.jpt.jpa.db.internal.driver.DTPDriverAdapterManager; - -/** - * Wrap a DTP Database. - * <p> - * Catalogs vs. Schemata:<br> - * Typically, if a DTP database does not support <em>catalogs</em>, - * 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 <em>no</em> 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 <em>catalogs</em>, 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 <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). - * 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). - */ -final class DTPDatabaseWrapper - extends DTPSchemaContainerWrapper<DTPConnectionProfileWrapper> - implements Database -{ - /** the wrapped DTP database */ - private final org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase; - - /** database-specific behavior */ - private final DTPDriverAdapter dtpDriverAdapter; - - /** lazy-initialized, sorted */ - private DTPCatalogWrapper[] catalogs; - - - // ********** constructor ********** - - DTPDatabaseWrapper(DTPConnectionProfileWrapper connectionProfile, org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase) { - super(connectionProfile); - this.dtpDatabase = dtpDatabase; - this.dtpDriverAdapter = DTPDriverAdapterManager.instance().buildAdapter(this.getVendorName(), this); - } - - - // ********** DTPDatabaseObjectWrapper implementation ********** - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpDatabase; - } - - /* TODO - * We might want to listen to the "virtual" catalog; but that's probably - * not necessary since there is no easy way for the user to refresh it - * (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> getDTPSchemas() { - return this.dtpDriverAdapter.getDTPSchemas(); - } - - @Override - DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - return this.getSchema_(dtpSchema); - } - - /** - * 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. - */ - 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); - } - - - // ********** catalogs ********** - - public boolean supportsCatalogs() { - return this.dtpDriverAdapter.supportsCatalogs(); - } - - 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.dtpDriverAdapter.getDTPCatalogs(); - } - - 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 Catalog getCatalogForIdentifier(String identifier) { - return this.dtpDriverAdapter.selectCatalogForIdentifier(this.getCatalogs(), identifier); - } - - public synchronized DTPCatalogWrapper getDefaultCatalog() { - return this.getCatalogForNames(this.getDefaultCatalogNames()); - } - - private Iterable<String> getDefaultCatalogNames() { - return this.dtpDriverAdapter.getDefaultCatalogNames(); - } - - /** - * 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; - } - - - // ********** 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); - } - - - // ********** misc ********** - - public org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase() { - return this.dtpDatabase; - } - - public String getName() { - return this.dtpDatabase.getName(); - } - - public String getVendorName() { - return this.dtpDatabase.getVendor(); - } - - public String getVersion() { - return this.dtpDatabase.getVersion(); - } - - @Override - DTPDriverAdapter getDTPDriverAdapter() { - return this.dtpDriverAdapter; - } - - public Table selectTableForIdentifier(Iterable<Table> tables, String identifier) { - return this.dtpDriverAdapter.selectTableForIdentifier(tables, identifier); - } - - // TODO add to interface? (so it can be used by AbstractDTPDriverAdapter) - 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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPForeignKeyWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPForeignKeyWrapper.java deleted file mode 100644 index 3a341c636f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPForeignKeyWrapper.java +++ /dev/null @@ -1,337 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.jpa.db.Column; -import org.eclipse.jpt.jpa.db.ForeignKey; - -/** - * Wrap a DTP ForeignKey - */ -final class DTPForeignKeyWrapper - extends DTPDatabaseObjectWrapper<DTPTableWrapper> - 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); - this.dtpForeignKey = dtpForeignKey; - } - - - // ********** DTPDatabaseObjectWrapper implementation ********** - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpForeignKey; - } - - @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 this.parent; - } - - 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.getDTPDriverAdapter().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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaContainerWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaContainerWrapper.java deleted file mode 100644 index 46d0f6a4c8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaContainerWrapper.java +++ /dev/null @@ -1,227 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import java.util.List; - -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.jpa.db.DatabaseObject; -import org.eclipse.jpt.jpa.db.Schema; -import org.eclipse.jpt.jpa.db.SchemaContainer; - -/** - * Coalesce behavior for a schema container (i.e. database or catalog). - */ -abstract class DTPSchemaContainerWrapper<P extends DTPDatabaseObject> - extends DTPDatabaseObjectWrapper<P> - implements SchemaContainer -{ - /** lazy-initialized */ - private DTPSchemaWrapper[] schemata; - - - // ********** constructor ********** - - DTPSchemaContainerWrapper(P parent) { - super(parent); - } - - - // ********** DTPDatabaseObjectWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - } - - - // ********** abstract methods ********** - - /** - * Return the schema container's DTP schemas. - */ - abstract List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemas(); - - /** - * Return the schema for the specified DTP schema. - */ - abstract DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema); - - /** - * Pre-condition: 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); - - /** - * Pre-condition: 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); - - /** - * Pre-condition: 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.getDTPSchemas(); - 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 Schema getSchemaForIdentifier(String identifier) { - return this.getDTPDriverAdapter().selectSchemaForIdentifier(this.getSchemata(), identifier); - } - - public DTPSchemaWrapper getDefaultSchema() { - return this.getSchemaForNames(this.getDTPDriverAdapter().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.getDTPDriverAdapter().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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaWrapper.java deleted file mode 100644 index 80d1b8abea..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSchemaWrapper.java +++ /dev/null @@ -1,332 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProduct; -import org.eclipse.core.runtime.Platform; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.datatools.modelbase.sql.tables.SQLTablesPackage; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.jpa.db.DatabaseObject; -import org.eclipse.jpt.jpa.db.Schema; -import org.eclipse.jpt.jpa.db.Sequence; -import org.eclipse.jpt.jpa.db.Table; - -/** - * Wrap a DTP Schema - */ -final class DTPSchemaWrapper - extends DTPDatabaseObjectWrapper<DTPSchemaContainerWrapper<?>> - 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); - this.dtpSchema = dtpSchema; - } - - - // ********** DTPDatabaseObjectWrapper implementation ********** - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpSchema; - } - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().schemaChanged(this); - } - - - // ********** Schema implementation ********** - - public String getName() { - return this.dtpSchema.getName(); - } - - public DTPSchemaContainerWrapper<?> getContainer() { - return this.parent; - } - - // ***** 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() { - // the product is null during junit testing - IProduct product = Platform.getProduct(); - String hack = (product == null) ? null : product.getProperty(PERSISTENT_AND_VIEW_TABLES_ONLY); - return (hack != null) && hack.equals("true"); //$NON-NLS-1$ - } - - // provides a mechanism for DTP extenders that support synonyms but don't want to have them appear - // in Dali to filter out these table types from Dali - 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 Table getTableForIdentifier(String identifier) { - return this.getDTPDriverAdapter().selectTableForIdentifier(this.getTables(), 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 Sequence getSequenceForIdentifier(String identifier) { - return this.getDTPDriverAdapter().selectSequenceForIdentifier(this.getSequences(), 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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSequenceWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSequenceWrapper.java deleted file mode 100644 index 49114e051d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPSequenceWrapper.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.jpa.db.Sequence; - -/** - * Wrap a DTP Sequence - */ -final class DTPSequenceWrapper - extends DTPDatabaseObjectWrapper<DTPSchemaWrapper> - implements Sequence -{ - /** the wrapped DTP sequence */ - private final org.eclipse.datatools.modelbase.sql.schema.Sequence dtpSequence; - - - // ********** constructor ********** - - DTPSequenceWrapper(DTPSchemaWrapper schema, org.eclipse.datatools.modelbase.sql.schema.Sequence dtpSequence) { - super(schema); - this.dtpSequence = dtpSequence; - } - - - // ********** DTPDatabaseObjectWrapper implementation ********** - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpSequence; - } - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().sequenceChanged(this); - } - - - // ********** Sequence implementation ********** - - public String getName() { - return this.dtpSequence.getName(); - } - - public DTPSchemaWrapper getSchema() { - return this.parent; - } - - - // ********** 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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPTableWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPTableWrapper.java deleted file mode 100644 index a7a58c595f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPTableWrapper.java +++ /dev/null @@ -1,412 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 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.jpa.db.internal; - -import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.datatools.modelbase.sql.constraints.PrimaryKey; -import org.eclipse.datatools.modelbase.sql.tables.BaseTable; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.jpa.db.Column; -import org.eclipse.jpt.jpa.db.DatabaseObject; -import org.eclipse.jpt.jpa.db.ForeignKey; -import org.eclipse.jpt.jpa.db.Table; - -/** - * Wrap a DTP Table - */ -final class DTPTableWrapper - extends DTPDatabaseObjectWrapper<DTPSchemaWrapper> - 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); - this.dtpTable = dtpTable; - } - - - // ********** 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); - } - - /** - * Pre-condition: 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 Column getColumnForIdentifier(String identifier) { - return this.getDTPDriverAdapter().selectColumnForIdentifier(this.getColumns(), identifier); - } - - - // ********** primary key columns ********** - - 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); - } - - - // ********** foreign keys ********** - - 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(); - } - - - // ********** misc ********** - - public DTPSchemaWrapper getSchema() { - return this.parent; - } - - public String getName() { - return this.dtpTable.getName(); - } - - @Override - ICatalogObject getCatalogObject() { - return (ICatalogObject) this.dtpTable; - } - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().tableChanged(this); - } - - 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.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/AbstractDTPDriverAdapter.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/AbstractDTPDriverAdapter.java deleted file mode 100644 index 6a3e845164..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/AbstractDTPDriverAdapter.java +++ /dev/null @@ -1,488 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition; -import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.iterators.ResultSetIterator; -import org.eclipse.jpt.jpa.db.Catalog; -import org.eclipse.jpt.jpa.db.Column; -import org.eclipse.jpt.jpa.db.ConnectionProfile; -import org.eclipse.jpt.jpa.db.Database; -import org.eclipse.jpt.jpa.db.DatabaseObject; -import org.eclipse.jpt.jpa.db.JptJpaDbPlugin; -import org.eclipse.jpt.jpa.db.Schema; -import org.eclipse.jpt.jpa.db.Sequence; -import org.eclipse.jpt.jpa.db.Table; - -/** - * Consolidate the behavior common to the typical DTP drivers. - * - * @see Unknown - */ -abstract class AbstractDTPDriverAdapter - implements DTPDriverAdapter -{ - /** - * The Dali database that wraps the corresponding DTP database. - */ - final Database database; - - /** - * DTP drivers return catalogs and schemata in a variety of ways.... - */ - final CatalogStrategy catalogStrategy; - - /** - * The SQL spec says a <em>regular</em> (non-delimited) identifier should be - * folded to uppercase; but some databases do otherwise (e.g. Sybase). - */ - final FoldingStrategy foldingStrategy; - - - AbstractDTPDriverAdapter(Database database) { - super(); - this.database = database; - this.catalogStrategy = this.buildCatalogStrategy(); - this.foldingStrategy = this.buildFoldingStrategy(); - } - - abstract CatalogStrategy buildCatalogStrategy(); - - abstract FoldingStrategy buildFoldingStrategy(); - - - // ********** catalogs ********** - - public boolean supportsCatalogs() { - return this.catalogStrategy.supportsCatalogs(); - } - - public List<org.eclipse.datatools.modelbase.sql.schema.Catalog> getDTPCatalogs() { - return this.catalogStrategy.getCatalogs(); - } - - /** - * Typically, the name of the default catalog is the user name. - */ - public final Iterable<String> getDefaultCatalogNames() { - return this.supportsCatalogs() ? this.getDefaultCatalogNames_() : Collections.<String>emptyList(); - } - - final Iterable<String> getDefaultCatalogNames_() { - ArrayList<String> names = new ArrayList<String>(); - this.addDefaultCatalogNamesTo(names); - return names; - } - - void addDefaultCatalogNamesTo(ArrayList<String> names) { - names.add(this.getUserName()); - } - - - // ********** schemas ********** - - public List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemas() { - try { - return this.catalogStrategy.getSchemas(); - } catch (Exception ex) { - throw new RuntimeException("driver adapter: " + this, ex); //$NON-NLS-1$ - } - } - - /** - * Typically, the name of the default schema is the user name. - */ - public final Iterable<String> getDefaultSchemaNames() { - ArrayList<String> names = new ArrayList<String>(); - this.addDefaultSchemaNamesTo(names); - return names; - } - - void addDefaultSchemaNamesTo(ArrayList<String> names) { - names.add(this.getUserName()); - } - - - // ********** name -> identifier ********** - - public String convertNameToIdentifier(String name) { - if (this.treatIdentifiersAsDelimited()) { - return name; // no delimiters necessary - } - if (this.nameRequiresDelimiters(name)) { - return this.delimitName(name); - } - return name; - } - - // TODO break into converting table and column names so MySQL works better - public String convertNameToIdentifier(String name, String defaultName) { - if (( ! this.treatIdentifiersAsDelimited()) && this.nameRequiresDelimiters(name)) { - // no match possible - return this.delimitName(name); - } - if (this.regularNamesMatch(name, defaultName)) { - return null; - } - return name; - } - - /** - * Return whether the specified database object name must be delimited - * when used in an SQL statement. - * If the name has any <em>special</em> 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.nameIsReservedWord(name) - || this.nameContainsAnySpecialCharacters(name) - || this.nameIsNotFolded(name); - } - - boolean nameIsReservedWord(String name) { - return this.getDTPDefinition().isSQLKeyword(name); - } - - // TODO make Database.getDTPDefinition() public? - DatabaseDefinition getDTPDefinition() { - return RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(this.database.getDTPDatabase()); - } - - /** - * Return whether the specified name contains any <em>special</em> - * characters that require the name to be delimited. - * <br> - * 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-<em>regular</em> 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, database-specific, <em>regular</em> start characters - * </ul> - */ - boolean characterIsRegularNameStart(char c) { - // all databases allow a letter - return Character.isLetter(c) - || this.characterIsExtendedRegularNameStart(c); - } - - boolean characterIsExtendedRegularNameStart(char c) { - return this.arrayContains(this.getExtendedRegularNameStartCharacters(), c); - } - - /** - * Return the <em>regular</em> characters, beyond letters, for the - * first character of a name. - * Return <code>null</code> if there are no "extended" characters. - */ - char[] getExtendedRegularNameStartCharacters() { - return null; - } - - /** - * Return whether the specified character is non-<em>regular</em> 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, database-specific, <em>regular</em> start characters - * <li>any of the extended, database-specific, <em>regular</em> part characters - * </ul> - */ - boolean characterIsRegularNamePart(char c) { - // all databases allow a letter or digit - return Character.isLetterOrDigit(c) || - (c == '_') || - this.characterIsExtendedRegularNameStart(c) || - this.characterIsExtendedRegularNamePart(c); - } - - boolean characterIsExtendedRegularNamePart(char c) { - return this.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.foldingStrategy.nameIsFolded(name); - } - - /** - * Return whether the specified <em>regular</em> names match. - * Typically, <em>regular</em> identifiers are case-insensitive. - */ - boolean regularNamesMatch(String name1, String name2) { - return name1.equalsIgnoreCase(name2); - } - - /** - * 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) { - if (identifier == null) { - return null; - } - if (this.treatIdentifiersAsDelimited()) { - return identifier; // automatically delimited - } - if (this.identifierIsDelimited(identifier)) { - return StringTools.undelimit(identifier); - } - return this.foldingStrategy.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); - } - - - // ********** selecting database objects ********** - - /** - * By default, convert the identifier to a name and perform a name lookup. - */ - public Catalog selectCatalogForIdentifier(Iterable<Catalog> catalogs, String identifier) { - return this.selectDatabaseObjectForIdentifier(catalogs, identifier); - } - - /** - * By default, convert the identifier to a name and perform a name lookup. - */ - public Schema selectSchemaForIdentifier(Iterable<Schema> schemata, String identifier) { - return this.selectDatabaseObjectForIdentifier(schemata, identifier); - } - - /** - * By default, convert the identifier to a name and perform a name lookup. - */ - public Table selectTableForIdentifier(Iterable<Table> tables, String identifier) { - return this.selectDatabaseObjectForIdentifier(tables, identifier); - } - - /** - * By default, convert the identifier to a name and perform a name lookup. - */ - public Sequence selectSequenceForIdentifier(Iterable<Sequence> sequences, String identifier) { - return this.selectDatabaseObjectForIdentifier(sequences, identifier); - } - - /** - * By default, convert the identifier to a name and perform a name lookup. - */ - public Column selectColumnForIdentifier(Iterable<Column> columns, String identifier) { - return this.selectDatabaseObjectForIdentifier(columns, identifier); - } - - /** - * By default, convert the identifier to a name and perform a name lookup. - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(Iterable<T> databaseObjects, String identifier) { - return this.selectDatabaseObjectNamed(databaseObjects, this.convertIdentifierToName(identifier)); - } - - /** - * We can tanslate identifiers on most databasee into a name we can treat as - * case-sensitive. - */ - <T extends DatabaseObject> T selectDatabaseObjectNamed(Iterable<T> databaseObjects, String name) { - return this.selectDatabaseObjectNamedRespectCase(databaseObjects, name); - } - - <T extends DatabaseObject> T selectDatabaseObjectNamedRespectCase(Iterable<T> databaseObjects, String name) { - for (T databaseObject : databaseObjects) { - if (databaseObject.getName().equals(name)) { - return databaseObject; - } - } - return null; - } - - <T extends DatabaseObject> T selectDatabaseObjectNamedIgnoreCase(Iterable<T> databaseObjects, String name) { - for (T databaseObject : databaseObjects) { - if (databaseObject.getName().equalsIgnoreCase(name)) { - return databaseObject; - } - } - return null; - } - - - // ********** database queries ********** - - List<Map<String, Object>> execute(String sql) { - try { - return this.execute_(sql); - } catch (SQLException ex) { - JptJpaDbPlugin.log("SQL: " + sql, ex); //$NON-NLS-1$ - return Collections.emptyList(); - } - } - - List<Map<String, Object>> execute_(String sql) throws SQLException { - Statement jdbcStatement = this.createJDBCStatement(); - List<Map<String, Object>> rows = Collections.emptyList(); - try { - jdbcStatement.execute(sql); - rows = this.buildRows(jdbcStatement.getResultSet()); - } finally { - jdbcStatement.close(); - } - return rows; - } - - Statement createJDBCStatement() throws SQLException { - return this.getConnectionProfile().getJDBCConnection().createStatement(); - } - - List<Map<String, Object>> buildRows(ResultSet resultSet) throws SQLException { - List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>(); - CollectionTools.addAll(rows, this.buildResultSetIterator(resultSet)); - return rows; - } - - Iterator<Map<String, Object>> buildResultSetIterator(ResultSet resultSet) throws SQLException { - return new ResultSetIterator<Map<String, Object>>(resultSet, new ListResultSetIteratorAdapter(resultSet.getMetaData())); - } - - /** - * Convert each row in the result set into a map whose key is the column - * name and value is the column value. - */ - static class ListResultSetIteratorAdapter - implements ResultSetIterator.Adapter<Map<String, Object>> - { - private final int columnCount; - private final String[] columnNames; - - ListResultSetIteratorAdapter(ResultSetMetaData rsMetaData) throws SQLException { - super(); - this.columnCount = rsMetaData.getColumnCount(); - this.columnNames = new String[this.columnCount + 1]; // leave the zero slot empty - for (int i = 1; i <= this.columnCount; i++) { // NB: ResultSet index/subscript is 1-based - this.columnNames[i] = rsMetaData.getColumnName(i); - } - } - - public Map<String, Object> buildNext(ResultSet rs) throws SQLException { - HashMap<String, Object> row = new HashMap<String, Object>(this.columnCount); - for (int i = 1; i <= this.columnCount; i++) { // NB: ResultSet index/subscript is 1-based - row.put(this.columnNames[i], rs.getObject(i)); - } - return row; - } - } - - - // ********** misc ********** - - String getUserName() { - return this.convertIdentifierToName(this.getConnectionProfile().getUserName()); - } - - boolean treatIdentifiersAsDelimited() { - return this.getConnectionProfile().treatIdentifiersAsDelimited(); - } - - ConnectionProfile getConnectionProfile() { - return this.database.getConnectionProfile(); - } - - /** - * Convenience method: Add <code>null</code> check. - */ - boolean arrayContains(char[] array, char c) { - return (array != null) && ArrayTools.contains(array, c); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.database); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/CatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/CatalogStrategy.java deleted file mode 100644 index 1fa345a172..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/CatalogStrategy.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.List; -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Adapt the variety of catalog (and schema) configurations generated by - * DTP-supplied drivers. - */ -interface CatalogStrategy { - - /** - * Return whether the DTP database has "real" catalogs (i.e. catalogs that - * can be specified by the user). - */ - boolean supportsCatalogs(); - - /** - * Return the DTP database's catalogs. This will be empty if the database - * does <em>not</em> support catalogs. - * @see #supportsCatalogs() - */ - List<Catalog> getCatalogs(); - - /** - * Return the DTP database's schemas. This will be empty if the database - * supports catalogs. - * @see #supportsCatalogs() - */ - List<Schema> getSchemas(); -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DB2.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DB2.java deleted file mode 100644 index 771ff68874..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DB2.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.jpa.db.Database; - -class DB2 - extends AbstractDTPDriverAdapter -{ - DB2(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - // unverified... - return new UnknownCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "DB2 UDB", //$NON-NLS-1$ - "DB2 UDB iSeries", //$NON-NLS-1$ - "DB2 UDB zSeries" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new DB2(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapter.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapter.java deleted file mode 100644 index e94380b533..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapter.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.List; -import org.eclipse.jpt.jpa.db.Catalog; -import org.eclipse.jpt.jpa.db.Column; -import org.eclipse.jpt.jpa.db.Schema; -import org.eclipse.jpt.jpa.db.Sequence; -import org.eclipse.jpt.jpa.db.Table; - -/** - * Delegate DTP driver-specific behavior to implementations of this - * interface:<ul> - * <li>catalogs/schemas - * <li>names/identifiers - * <li>database object selection - * </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 database, - * it may be case-insensitive). - */ -public interface DTPDriverAdapter { - - // ********** catalogs ********** - - /** - * Return whether the DTP driver supports "real" catalogs (e.g. Sybase). - * If it does, use {@link #getDTPCatalogs()} to retrieve them; - * otherwise, use {@link #getDTPSchemas()} to retrieve the schemas directly. - */ - boolean supportsCatalogs(); - - /** - * Return the DTP database's catalogs. - * This will be empty if the database does not support catalogs. - * @see #supportsCatalogs() - */ - List<org.eclipse.datatools.modelbase.sql.schema.Catalog> getDTPCatalogs(); - - /** - * Return the DTP database's default catalog names. - * The first name in the list that identifies an existing catalog - * is <em>the</em> default. - * This will be empty if the database does not support catalogs. - */ - Iterable<String> getDefaultCatalogNames(); - - - // ********** schemas ********** - - /** - * Return the DTP database's schemas. - * This will be empty if the database supports catalogs. - * @see #supportsCatalogs() - */ - List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemas(); - - /** - * Return the DTP database's default schema names. - * The first name in the list that identifies an existing schema - * is <em>the</em> default. - */ - Iterable<String> getDefaultSchemaNames(); - - - // ********** names/identifiers ********** - - /** - * Convert the specified database object name to a database-specific - * identifier (i.e. delimit the name as appropriate). - */ - String convertNameToIdentifier(String name); - - /** - * Convert the specified database object name to a database-specific - * identifier (i.e. delimit the name as appropriate). - * Return <code>null</code> if the resulting identifier matches the - * specified default name. - * <p> - * This is used by 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, - * special characters, etc.). - */ - String convertNameToIdentifier(String name, String defaultName); - - /** - * Convert the specified database object identifier to a database-specific - * name (i.e. stripping delimiters from and folding the identifier as - * appropriate). - */ - String convertIdentifierToName(String identifier); - - - // ********** selecting database objects ********** - - /** - * Select from the specified collection the catalog for the specified - * identifier. - */ - Catalog selectCatalogForIdentifier(Iterable<Catalog> catalogs, String identifier); - - /** - * Select from the specified collection the schema for the specified - * identifier. - */ - Schema selectSchemaForIdentifier(Iterable<Schema> schemata, String identifier); - - /** - * Select from the specified collection the table for the specified - * identifier. - */ - Table selectTableForIdentifier(Iterable<Table> tables, String identifier); - - /** - * Select from the specified collection the sequence for the specified - * identifier. - */ - Sequence selectSequenceForIdentifier(Iterable<Sequence> sequences, String identifier); - - /** - * Select from the specified collection the column for the specified - * identifier. - */ - Column selectColumnForIdentifier(Iterable<Column> columns, String identifier); -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapterFactory.java deleted file mode 100644 index 61319fd784..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapterFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.jpa.db.Database; - -/** - * Factory interface. - */ -interface DTPDriverAdapterFactory { - /** - * Return the vendors supported by the factory's adapter. - */ - String[] getSupportedVendors(); - - /** - * Build a new DTP driver adapter for the specified Dali database. - */ - DTPDriverAdapter buildAdapter(Database database); -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapterManager.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapterManager.java deleted file mode 100644 index 0651326152..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/DTPDriverAdapterManager.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.HashMap; -import org.eclipse.jpt.jpa.db.Database; - -public class DTPDriverAdapterManager { - private final HashMap<String, DTPDriverAdapterFactory> adapterFactories; - - // singleton - private static final DTPDriverAdapterManager INSTANCE = new DTPDriverAdapterManager(); - - /** - * Return the singleton. - */ - public static DTPDriverAdapterManager instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private DTPDriverAdapterManager() { - super(); - this.adapterFactories = this.buildAdapterFactories(); - } - - private HashMap<String, DTPDriverAdapterFactory> buildAdapterFactories() { - HashMap<String, DTPDriverAdapterFactory> factories = new HashMap<String, DTPDriverAdapterFactory>(); - this.addAdapterFactoriesTo(factories); - return factories; - } - - private void addAdapterFactoriesTo(HashMap<String, DTPDriverAdapterFactory> factories) { - this.addAdapterFactoryTo(new DB2.Factory(), factories); - this.addAdapterFactoryTo(new Derby.Factory(), factories); - this.addAdapterFactoryTo(new HSQLDB.Factory(), factories); - this.addAdapterFactoryTo(new Informix.Factory(), factories); - this.addAdapterFactoryTo(new MaxDB.Factory(), factories); - this.addAdapterFactoryTo(new MySQL.Factory(), factories); - this.addAdapterFactoryTo(new Oracle.Factory(), factories); - this.addAdapterFactoryTo(new PostgreSQL.Factory(), factories); - this.addAdapterFactoryTo(new SQLServer.Factory(), factories); - this.addAdapterFactoryTo(new Sybase.Factory(), factories); - } - - /** - * @see org.eclipse.datatools.modelbase.sql.schema.Database#getVendor() - */ - private void addAdapterFactoryTo(DTPDriverAdapterFactory factory, HashMap<String, DTPDriverAdapterFactory> factories) { - for (String name : factory.getSupportedVendors()) { - this.addAdapterFactoryTo(name, factory, factories); - } - } - - private void addAdapterFactoryTo(String name, DTPDriverAdapterFactory factory, HashMap<String, DTPDriverAdapterFactory> factories) { - if (factories.put(name, factory) != null) { - throw new IllegalArgumentException("Duplicate adapter factory: " + name); //$NON-NLS-1$ - } - } - - public DTPDriverAdapter buildAdapter(String dtpVendorName, Database database) { - return this.getAdapterFactory(dtpVendorName).buildAdapter(database); - } - - private DTPDriverAdapterFactory getAdapterFactory(String dtpVendorName) { - DTPDriverAdapterFactory factory = this.adapterFactories.get(dtpVendorName); - return (factory != null) ? factory : UNRECOGNIZED_ADAPTER_FACTORY; - } - private static final DTPDriverAdapterFactory UNRECOGNIZED_ADAPTER_FACTORY = new Unknown.Factory(); -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Derby.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Derby.java deleted file mode 100644 index e990660927..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Derby.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.ArrayList; -import org.eclipse.jpt.jpa.db.Database; - -class Derby - extends AbstractDTPDriverAdapter -{ - Derby(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - return new FauxCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaNamesTo(ArrayList<String> names) { - names.add(this.getDefaultSchemaName()); - } - - /** - * The default user name on Derby is <code>"APP"</code> when the user - * connects without a user name. - */ - private String getDefaultSchemaName() { - String userName = this.getUserName(); - return ((userName != null) && (userName.length() != 0)) ? - userName : - DEFAULT_USER_NAME; - } - private static final String DEFAULT_USER_NAME = "APP"; //$NON-NLS-1$ - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "Derby" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new Derby(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/FauxCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/FauxCatalogStrategy.java deleted file mode 100644 index 507d5cb573..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/FauxCatalogStrategy.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -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 database drivers that build a "virtual" catalog - * (that has no name) because the underlying JDBC driver does not return any - * catalogs (e.g. Oracle). This catalog cannot be specified by the user in - * annotations etc. - * - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class FauxCatalogStrategy - implements CatalogStrategy -{ - private final Database database; - - FauxCatalogStrategy(Database database) { - super(); - this.database = database; - } - - public boolean supportsCatalogs() { - return false; - } - - public List<Catalog> getCatalogs() { - return Collections.emptyList(); - } - - public List<Schema> getSchemas() { - Catalog fauxCatalog = this.getFauxCatalog(); - @SuppressWarnings("unchecked") - List<Schema> schemas = fauxCatalog.getSchemas(); - return schemas; - } - - private Catalog getFauxCatalog() { - List<Catalog> catalogs = this.getCatalogs_(); - if (catalogs == null) { - throw new IllegalStateException("catalogs list is null"); //$NON-NLS-1$ - } - if (catalogs.size() != 1) { - throw new IllegalStateException("not a single catalog: " + catalogs); //$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; - } - - @SuppressWarnings("unchecked") - private List<Catalog> getCatalogs_() { - return this.database.getCatalogs(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/FoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/FoldingStrategy.java deleted file mode 100644 index 523bb7a486..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/FoldingStrategy.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -/** - * Adapt database-specific identifier-folding etc. - */ -interface FoldingStrategy { - - /** - * Fold the specified identifier. - */ - String fold(String identifier); - - /** - * Return whether the specified database object name is already folded, - * meaning, typically, if it has no special characters, it requires no - * delimiters. - */ - boolean nameIsFolded(String name); -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/HSQLDB.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/HSQLDB.java deleted file mode 100644 index 6876c2cf66..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/HSQLDB.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.ArrayList; -import org.eclipse.jpt.jpa.db.Database; - -class HSQLDB - extends AbstractDTPDriverAdapter -{ - HSQLDB(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - // unverified... - return new UnknownCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaNamesTo(ArrayList<String> names) { - names.add(PUBLIC_SCHEMA_NAME); - } - private static final String PUBLIC_SCHEMA_NAME = "PUBLIC"; //$NON-NLS-1$ - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "HSQLDB" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new HSQLDB(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Informix.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Informix.java deleted file mode 100644 index 8ff84a3390..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Informix.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.jpa.db.Database; - -class Informix - extends AbstractDTPDriverAdapter -{ - Informix(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - // unverified... - return new UnknownCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - 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[] { '$' }; - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "Informix" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new Informix(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/LowerCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/LowerCaseFoldingStrategy.java deleted file mode 100644 index 903ad0b9d1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/LowerCaseFoldingStrategy.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.common.utility.internal.StringTools; - -/** - * Fold <em>regular</em> identifiers to lower case. - */ -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 identifier) { - return identifier.toLowerCase(); - } - - public boolean nameIsFolded(String name) { - return StringTools.stringIsLowercase(name); - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/MaxDB.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/MaxDB.java deleted file mode 100644 index 9a3d08fce7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/MaxDB.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.jpa.db.Database; - -class MaxDB - extends AbstractDTPDriverAdapter -{ - MaxDB(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - // unverified... - return new UnknownCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedRegularNameStartCharacters() { - return EXTENDED_REGULAR_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_START_CHARACTERS = new char[] { '#', '@', '$' }; - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "MaxDB" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new MaxDB(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/MySQL.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/MySQL.java deleted file mode 100644 index 8d76aaf498..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/MySQL.java +++ /dev/null @@ -1,311 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.Tools; -import org.eclipse.jpt.jpa.db.Database; -import org.eclipse.jpt.jpa.db.DatabaseObject; -import org.eclipse.jpt.jpa.db.Schema; -import org.eclipse.jpt.jpa.db.Table; - -/** - * MySQL is a bit unusual in that it does <em>not</em> fold <em>regular</em> - * identifiers and its identifiers are <em>not</em> case-sensitive - * (except in special cases, described below). Even <em>delimited</em> identifiers - * are case-<em>in</em>sensitive. (Delimiters are only needed for identifiers - * that contain special characters or are reserved words.) - * <p> - * MySQL handles the case-sensitivity of databases and tables according to the - * value of the system variable <code>lower_case_table_names</code>:<ul> - * <li>0 (Unix/Linux default): database and table names are <em>not</em> folded - * and they are case-sensitive - * <li>1 (Windows default): database and table names are folded to lowercase - * and they are <em>not</em> case-sensitive - * <li>2 (Mac OS X default): database and table names are <em>not</em> folded - * and they are <em>not</em> case-sensitive - * </ul> - * These values will not work perfectly on all platforms because databases are - * stored as directories and tables are stored as files in the underlying - * O/S; and the actual case-sensitivity of the names will ulimately be - * determined by the behavior of filenames on the O/S. - * <p> - * See <a href=http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html> - * Identifier Case Sensitivity</a>. - */ -class MySQL - extends AbstractDTPDriverAdapter -{ - /** lazy-initialized; value comes from the database server */ - private int lower_case_table_names = -1; - - /** lazy-initialized; value comes from the database server */ - private Boolean ANSI_QUOTES = null; - - - MySQL(Database database) { - super(database); - } - - /** - * 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 - * {@link org.eclipse.datatools.enablement.mysql.catalog.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.... - * <p> - * <strong>NB:</strong> In MySQL DDL, <code>SCHEMA</code> is a synonym - * for <code>DATABASE</code>; but the JDBC - * method {@link java.sql.DatabaseMetaData#getSchemas()} returns an empty list, - * while {@link java.sql.DatabaseMetaData#getCatalogs()} returns a list of the - * available databases. - * You can also use the JDBC method {@link java.sql.Connection#setCatalog(String)} - * to set the default database. - */ - @Override - CatalogStrategy buildCatalogStrategy() { - return new NoCatalogStrategy(this.database.getDTPDatabase()); - } - - /** - * There are some cases where MySQL folds identifiers, but using the - * non-folding strategy should work:<ul> - * <li>We only fold identifiers when - * converting them to names; but MySQL is case-<em>in</em>sensitive - * when it is folding database and table names - * (<code>lower_case_table_names</code>=1), so lookups will work - * fine without any folding anyways. - * <li>We only test whether a name is already folded when determining - * whether it must be delimited; and MySQL ignores delimiters - * when it comes to case-sensitivity, so we can leave any <em>regular</em> - * mixed-case names undelimited. (MySQL only requires delimiters for - * special characters and reserved words.) - * </ul> - */ - @Override - FoldingStrategy buildFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaNamesTo(ArrayList<String> names) { - names.add(this.database.getName()); - } - - - // ********** identifiers/names ********** - - /** - * MySQL is the only vendor that allows a digit. - * Although, the name cannnot be <em>all</em> digits - * (unless delimited). - */ - @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[] { '_', '$' }; - - @Override - String delimitName(String name) { - return StringTools.delimit(name, BACKTICK); - } - - /** - * By default, MySQL delimits identifiers with backticks (<code>`</code>); - * but it can also be configured to use double-quotes. - */ - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsDelimited(identifier, BACKTICK) - || (StringTools.stringIsQuoted(identifier) && this.doubleQuoteIsIdentifierDelimiter()); - } - private static final char BACKTICK = '`'; - - /** - * This method should only affect whether entity - * generation will generate a specified table or column identifier when the - * default identifier is not a match. Worst case: Entity generation will - * generate explicit identifiers unnecessarily for columns when tables are - * case-sensitive. The generated annotation will be valid but the column - * name will be redundant. - */ - @Override - boolean regularNamesMatch(String name1, String name2) { - return this.tableNamesAreCaseSensitive() ? - name1.equals(name2) : - name1.equalsIgnoreCase(name2); - } - - - // ********** selecting database objects ********** - - /** - * DTP schemata are MySQL databases(?). Of course, we only have one per - * connection.... - */ - @Override - public Schema selectSchemaForIdentifier(Iterable<Schema> schemata, String identifier) { - return this.tableNamesAreCaseSensitive() ? - this.selectDatabaseObjectForIdentifierRespectCase(schemata, identifier) : - super.selectSchemaForIdentifier(schemata, identifier); - } - - @Override - public Table selectTableForIdentifier(Iterable<Table> tables, String identifier) { - return this.tableNamesAreCaseSensitive() ? - this.selectDatabaseObjectForIdentifierRespectCase(tables, identifier) : - super.selectTableForIdentifier(tables, identifier); - } - - private <T extends DatabaseObject> T selectDatabaseObjectForIdentifierRespectCase(Iterable<T> databaseObjects, String identifier) { - return this.selectDatabaseObjectNamedRespectCase(databaseObjects, this.convertIdentifierToName(identifier)); - } - - /** - * MySQL database object names are usually case-insensitive; - * the exception being databases (schemata) and tables when the system - * variable <code>lower_case_table_names</code> is 0 (the default on - * UNIX/Linux). (For some odd reason, trigger names are also - * case-sensitive.... Fortunately, we don't care yet.) - */ - @Override - <T extends DatabaseObject> T selectDatabaseObjectNamed(Iterable<T> databaseObjects, String name) { - return this.selectDatabaseObjectNamedIgnoreCase(databaseObjects, name); - } - - - // ********** lower_case_table_names ********** - - private boolean tableNamesAreCaseSensitive() { - return this.getLowerCaseTableNames() == 0; - } - - private int getLowerCaseTableNames() { - if (this.lower_case_table_names == -1) { - this.lower_case_table_names = this.buildLowerCaseTableNames(); - } - return this.lower_case_table_names; - } - - /** - * If we don't have a live connection (i.e. we are working off-line), - * use the current O/S default setting(?). - */ - private int buildLowerCaseTableNames() { - int dbValue = this.getLowerCaseTableNamesFromDatabase(); - return (dbValue != -1) ? dbValue : this.getLowerCaseTableNamesFromOS(); - } - - /** - * See <a href=http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html> - * Identifier Case Sensitivity</a>. - */ - private int getLowerCaseTableNamesFromDatabase() { - if (this.getConnectionProfile().isDisconnected()) { - return -1; - } - // the underscore is a wild character on MySQL, so we need to escape it - List<Map<String, Object>> rows = this.execute("SHOW VARIABLES LIKE 'lower\\_case\\_table\\_names'"); //$NON-NLS-1$ - if (rows.isEmpty()) { - return -1; - } - Map<String, Object> row = rows.get(0); - if (Tools.valuesAreEqual(row.get("Variable_name"), "lower_case_table_names")) { //$NON-NLS-1$ //$NON-NLS-2$ - return Integer.valueOf((String) row.get("Value")).intValue(); //$NON-NLS-1$ - } - return -1; - } - - /** - * Make a best guess at what the setting might be: - * Return the default value for the current O/S (unfortunately this is the - * client O/S, not the MySQL Server O/S...). - */ - private int getLowerCaseTableNamesFromOS() { - if (Tools.osIsMac()) { - return 2; - } - if (Tools.osIsWindows()) { - return 1; - } - return 0; // Linux etc. - } - - - // ********** ANSI_QUOTES ********** - - private boolean doubleQuoteIsIdentifierDelimiter() { - return this.getANSIQuotes().booleanValue(); - } - - private Boolean getANSIQuotes() { - if (this.ANSI_QUOTES == null) { - this.ANSI_QUOTES = this.buildANSIQuotes(); - } - return this.ANSI_QUOTES; - } - - /** - * If we don't have a live connection (i.e. we are working off-line), - * return <code>FALSE</code> (the default setting). - */ - private Boolean buildANSIQuotes() { - Boolean dbValue = this.getANSIQuotesFromDatabase(); - return (dbValue != null) ? dbValue : Boolean.FALSE; - } - - /** - * See <a href=http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_ansi_quotes> - * ANSI_QUOTES</a>. - */ - private Boolean getANSIQuotesFromDatabase() { - if (this.getConnectionProfile().isDisconnected()) { - return null; - } - List<Map<String, Object>> rows = this.execute("SELECT @@SESSION.sql_mode"); //$NON-NLS-1$ - if (rows.isEmpty()) { - return null; - } - Map<String, Object> row = rows.get(0); - String sql_mode = (String) row.get("@@SESSION.sql_mode"); //$NON-NLS-1$ - if (sql_mode == null) { - return null; - } - String[] modes = sql_mode.split(","); //$NON-NLS-1$ - return Boolean.valueOf(ArrayTools.contains(modes, "ANSI_QUOTES")); //$NON-NLS-1$ - } - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "MySql" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new MySQL(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/NoCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/NoCatalogStrategy.java deleted file mode 100644 index 348bd59869..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/NoCatalogStrategy.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -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 database drivers that do not have catalogs - * (e.g. MySQL; see bug 249013). - */ -class NoCatalogStrategy - implements CatalogStrategy -{ - private final Database database; - - NoCatalogStrategy(Database database) { - super(); - this.database = database; - } - - public boolean supportsCatalogs() { - return false; - } - - public List<Catalog> getCatalogs() { - return Collections.emptyList(); - } - - @SuppressWarnings("unchecked") - public List<Schema> getSchemas() { - return this.database.getSchemas(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/NonFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/NonFoldingStrategy.java deleted file mode 100644 index 045367776b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/NonFoldingStrategy.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -/** - * Do not fold <em>regular</em> 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 <em>folded</em>. - */ - public String fold(String identifier) { - return identifier; - } - - /** - * Since identifiers are not folded to upper- or lower-case, the name is - * already <em>folded</em>. - * (Non-folding databases do not require delimiters around mixed-case - * <em>regular</em> identifiers.) - */ - public boolean nameIsFolded(String name) { - return true; - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Oracle.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Oracle.java deleted file mode 100644 index 48fc149991..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Oracle.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.jpa.db.Database; - -class Oracle - extends AbstractDTPDriverAdapter -{ - Oracle(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - return new FauxCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedRegularNamePartCharacters() { - return EXTENDED_REGULAR_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_REGULAR_NAME_PART_CHARACTERS = new char[] { '$', '#' }; - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "Oracle" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new Oracle(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/PostgreSQL.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/PostgreSQL.java deleted file mode 100644 index 93598f1a54..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/PostgreSQL.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.ArrayList; -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.jpt.jpa.db.Database; - -class PostgreSQL - extends AbstractDTPDriverAdapter -{ - PostgreSQL(Database database) { - super(database); - } - - /** - * The PostgreSQL JDBC driver returns a single catalog from the call to - * {@link java.sql.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 buildCatalogStrategy() { - return new SimpleCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return LowerCaseFoldingStrategy.instance(); - } - - /** - * The PostgreSQL database holds a single catalog that has the same name as - * the database. - */ - @Override - void addDefaultCatalogNamesTo(ArrayList<String> names) { - names.add(this.buildDefaultCatalogName()); - } - - private String buildDefaultCatalogName() { - return ((Catalog) this.database.getDTPDatabase().getCatalogs().get(0)).getName(); - } - - /** - * PostgreSQL has a "schema search path". The default is:<br><code> - * "$user",public - * </code><br> - * If the <code>"$user"</code> schema is not found, use the - * <code>"public"</code> schema. - */ - @Override - void addDefaultSchemaNamesTo(ArrayList<String> names) { - super.addDefaultSchemaNamesTo(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[] { '$' }; - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "postgres" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new PostgreSQL(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/SQLServer.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/SQLServer.java deleted file mode 100644 index d9aefb05a1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/SQLServer.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.ArrayList; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jpa.db.Database; - -/** - * Microsoft SQL Server - */ -class SQLServer - extends AbstractDTPDriverAdapter -{ - SQLServer(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - return new SimpleCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - /** - * By default, SQL Server identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - //TODO query database for collation setting - @Override - boolean regularNamesMatch(String name1, String name2) { - return name1.equals(name2); - } - - /** - * SQL Server will use the user-requested database; if that database is not - * found, it will default to <code>master</code>. - */ - @Override - void addDefaultCatalogNamesTo(ArrayList<String> names) { - names.add(this.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 - * <code>dbo</code>. - */ - @Override - void addDefaultSchemaNamesTo(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[] { '$' }; - - //TODO query database for delimiter setting - @Override - String delimitName(String name) { - return '[' + name + ']'; - } - - /** - * By default, SQL Server delimits identifiers with brackets - * (<code>[]</code>); but it - * can also be configured to use double-quotes. - */ - //TODO query database for delimiter setting - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsBracketed(identifier) - || super.identifierIsDelimited(identifier); - } - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "SQL Server" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new SQLServer(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/SimpleCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/SimpleCatalogStrategy.java deleted file mode 100644 index 8d42d07226..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/SimpleCatalogStrategy.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -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 database drivers that simply model the catalogs - * returned by the underlying JDBC driver (e.g. Sybase). - * - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class SimpleCatalogStrategy - implements CatalogStrategy -{ - private final Database database; - - SimpleCatalogStrategy(Database database) { - super(); - this.database = database; - } - - public boolean supportsCatalogs() { - return true; - } - - @SuppressWarnings("unchecked") - public List<Catalog> getCatalogs() { - return this.database.getCatalogs(); - } - - public List<Schema> getSchemas() { - return Collections.emptyList(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Sybase.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Sybase.java deleted file mode 100644 index 0847a0c2db..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Sybase.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import java.util.ArrayList; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jpa.db.Database; - -class Sybase - extends AbstractDTPDriverAdapter -{ - Sybase(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - return new SimpleCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - /** - * By default, Sybase identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - //TODO query database for collation setting - @Override - boolean regularNamesMatch(String name1, String name2) { - return name1.equals(name2); - } - - /** - * Sybase will use the user-requested database; if that database is not - * found, it will default to <code>master</code>. - */ - @Override - void addDefaultCatalogNamesTo(ArrayList<String> names) { - names.add(this.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 - * <code>dbo</code>. - * <br> - * 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 (<code>dbo</code>). As a result, it's really not possible to specify - * the "default" schema without knowing the schema object we are - * looking for. - * <br> - * (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 {@link org.eclipse.jpt.jpa.db.ConnectionProfile#getUserName()}.) - */ - @Override - void addDefaultSchemaNamesTo(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[] { '$', '¥', '£', '#' }; - - //TODO query database for delimiter setting - @Override - String delimitName(String name) { - return '[' + name + ']'; - } - - /** - * By default, Sybase delimits identifiers with brackets - * (<code>[]</code>); but it - * can also be configured to use double-quotes. - */ - //TODO query database for delimiter setting - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsBracketed(identifier) - || super.identifierIsDelimited(identifier); - } - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - private static final String[] VENDORS = { - "Sybase_ASA", //$NON-NLS-1$ - "Sybase_ASE" //$NON-NLS-1$ - }; - public String[] getSupportedVendors() { - return VENDORS; - } - public DTPDriverAdapter buildAdapter(Database database) { - return new Sybase(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Unknown.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Unknown.java deleted file mode 100644 index a417250363..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/Unknown.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.jpa.db.Database; - -class Unknown - extends AbstractDTPDriverAdapter -{ - Unknown(Database database) { - super(database); - } - - @Override - CatalogStrategy buildCatalogStrategy() { - // infer from existing catalogs and schemas - return new UnknownCatalogStrategy(this.database.getDTPDatabase()); - } - - @Override - FoldingStrategy buildFoldingStrategy() { - // SQL standard - return UpperCaseFoldingStrategy.instance(); - } - - - // ********** factory ********** - - static class Factory implements DTPDriverAdapterFactory { - public String[] getSupportedVendors() { - throw new UnsupportedOperationException(); - } - public DTPDriverAdapter buildAdapter(Database database) { - return new Unknown(database); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/UnknownCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/UnknownCatalogStrategy.java deleted file mode 100644 index ca7722c5bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/UnknownCatalogStrategy.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -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 database drivers. - * Infer the strategy from the returned catalogs and schemas. - * - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class UnknownCatalogStrategy - implements CatalogStrategy -{ - private final Database database; - - UnknownCatalogStrategy(Database database) { - super(); - this.database = database; - } - - /** - * Return <code>true</code> if the database returns a list of catalogs and - * that list does not contain only a "faux" catalog. - */ - public boolean supportsCatalogs() { - return ! this.getCatalogs().isEmpty(); - } - - public List<Catalog> getCatalogs() { - List<Catalog> catalogs = this.getCatalogs_(); - // if there are no catalogs, the database must hold the schemata directly - if ((catalogs == null) || catalogs.isEmpty()) { - return Collections.emptyList(); - } - - Catalog fauxCatalog = this.selectFauxCatalog(catalogs); - // if we don't have a "faux" catalog, we must have "real" catalogs - return (fauxCatalog == null) ? catalogs : Collections.<Catalog>emptyList(); - } - - public List<Schema> getSchemas() { - List<Catalog> catalogs = this.getCatalogs_(); - // if there are no catalogs, the database must hold the schemata directly - if ((catalogs == null) || catalogs.isEmpty()) { - return this.getSchemas_(); - } - - Catalog fauxCatalog = this.selectFauxCatalog(catalogs); - return (fauxCatalog != null) ? this.getSchemas(fauxCatalog) : Collections.<Schema>emptyList(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<Schema> getSchemas(Catalog catalog) { - return catalog.getSchemas(); - } - - /** - * If the specified list of catalogs contains a "faux" catalog (i.e. a - * single catalog with an empty string for a name), return it; otherwise - * return <code>null</code>. - */ - private Catalog selectFauxCatalog(List<Catalog> catalogs) { - if (catalogs.size() == 1) { - Catalog catalog = catalogs.get(0); - if (catalog.getName().equals("")) { //$NON-NLS-1$ - return catalog; - } - } - return null; - } - - @SuppressWarnings("unchecked") - private List<Catalog> getCatalogs_() { - return this.database.getCatalogs(); - } - - @SuppressWarnings("unchecked") - private List<Schema> getSchemas_() { - return this.database.getSchemas(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/UpperCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/UpperCaseFoldingStrategy.java deleted file mode 100644 index 00afecc306..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/driver/UpperCaseFoldingStrategy.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 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.jpa.db.internal.driver; - -import org.eclipse.jpt.common.utility.internal.StringTools; - -/** - * Fold <em>regular</em> identifiers to upper case. - */ -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 identifier) { - return identifier.toUpperCase(); - } - - public boolean nameIsFolded(String name) { - return StringTools.stringIsUppercase(name); - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } -} |