diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.db')
62 files changed, 0 insertions, 6537 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.db/.classpath b/jpa/plugins/org.eclipse.jpt.db/.classpath deleted file mode 100644 index 304e86186a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/jpa/plugins/org.eclipse.jpt.db/.cvsignore b/jpa/plugins/org.eclipse.jpt.db/.cvsignore deleted file mode 100644 index a196dd7686..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -bin -@dot -temp.folder -build.xml -javaCompiler...args -javaCompiler...args.*
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.db/.project b/jpa/plugins/org.eclipse.jpt.db/.project deleted file mode 100644 index 5675a48e3a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jpt.db</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/jpa/plugins/org.eclipse.jpt.db/.settings/org.eclipse.core.resources.prefs b/jpa/plugins/org.eclipse.jpt.db/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 84ebb5c739..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Jan 15 11:11:02 EST 2008 -eclipse.preferences.version=1 -encoding/<project>=ISO-8859-1 diff --git a/jpa/plugins/org.eclipse.jpt.db/.settings/org.eclipse.jdt.core.prefs b/jpa/plugins/org.eclipse.jpt.db/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 929d54536d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Sun May 27 14:59:18 EDT 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/plugins/org.eclipse.jpt.db/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.db/META-INF/MANIFEST.MF deleted file mode 100644 index eba715983c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/META-INF/MANIFEST.MF +++ /dev/null @@ -1,20 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.db -Bundle-Version: 1.2.200.qualifier -Bundle-Activator: org.eclipse.jpt.db.JptDbPlugin -Bundle-ActivationPolicy: lazy -Bundle-ClassPath: . -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.datatools.enablement.jdt.classpath;bundle-version="[1.0.1,2.0.0)", - org.eclipse.datatools.sqltools.editor.core;bundle-version="[1.0.0,2.0.0)", - org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)", - org.eclipse.jpt.utility;bundle-version="[1.2.0,2.0.0)" -Export-Package: org.eclipse.jpt.db, - org.eclipse.jpt.db.internal;x-internal:=true, - org.eclipse.jpt.db.internal.vendor;x-internal:=true -Import-Package: com.ibm.icu.text;version="4.0.1" diff --git a/jpa/plugins/org.eclipse.jpt.db/about.html b/jpa/plugins/org.eclipse.jpt.db/about.html deleted file mode 100644 index be534ba44f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/about.html +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> -<HTML> - -<head> -<title>About</title> -<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> -</head> - -<BODY lang="EN-US"> - -<H3>About This Content</H3> - -<P>May 02, 2008</P> - -<H3>License</H3> - -<P>The Eclipse Foundation makes available all content in this plug-in -("Content"). Unless otherwise indicated below, the Content is provided to you -under the terms and conditions of the Eclipse Public License Version 1.0 -("EPL"). A copy of the EPL is available at -<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>. -For purposes of the EPL, "Program" will mean the Content.</P> - -<P>If you did not receive this Content directly from the Eclipse Foundation, the -Content is being redistributed by another party ("Redistributor") and different -terms and conditions may apply to your use of any object code in the Content. -Check the Redistributor's license that was provided with the Content. If no such -license exists, contact the Redistributor. Unless otherwise indicated below, the -terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at -<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P> - -</BODY> -</HTML> diff --git a/jpa/plugins/org.eclipse.jpt.db/build.properties b/jpa/plugins/org.eclipse.jpt.db/build.properties deleted file mode 100644 index 974eadac6b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/build.properties +++ /dev/null @@ -1,19 +0,0 @@ -############################################################################### -# Copyright (c) 2006, 2007 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 -############################################################################### -javacSource=1.5 -javacTarget=1.5 -source.. = src/ -output.. = bin/ -bin.includes = .,\ - META-INF/,\ - about.html,\ - plugin.properties -jars.compile.order = . diff --git a/jpa/plugins/org.eclipse.jpt.db/component.xml b/jpa/plugins/org.eclipse.jpt.db/component.xml deleted file mode 100644 index 644c396149..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/component.xml +++ /dev/null @@ -1 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?><component xmlns="http://eclipse.org/wtp/releng/tools/component-model" name="org.eclipse.jpt.db"><description url=""></description><component-depends unrestricted="true"></component-depends><plugin id="org.eclipse.jpt.db" fragment="false"/></component>
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.db/plugin.properties b/jpa/plugins/org.eclipse.jpt.db/plugin.properties deleted file mode 100644 index c334a30550..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/plugin.properties +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################### -# Copyright (c) 2006 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 -############################################################################### -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName = Dali Java Persistence Tools - DB -providerName = Eclipse Web Tools Platform - diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java deleted file mode 100644 index 308ccb7c0a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Database catalog - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Catalog extends SchemaContainer { - // nothing yet -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java deleted file mode 100644 index 85a8f2c026..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.jpt.utility.JavaType; - -/** - * Database column - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Column extends DatabaseObject { - - /** - * Return the column's table. - */ - Table getTable(); - - - // ********** constraints ********** - - /** - * Return whether the column is part of it's table's primary key. - */ - boolean isPartOfPrimaryKey(); - - /** - * Return whether the column is part of one of it's table's foreign keys. - */ - boolean isPartOfForeignKey(); - - /** - * Return whether the column is part of a unique constraint defined for its - * table. - */ - boolean isPartOfUniqueConstraint(); - - /** - * Return whether the column is nullable. - */ - boolean isNullable(); - - - // ********** data type ********** - - /** - * Return the name of the column's datatype. - */ - String getDataTypeName(); - - /** - * Return whether the column's type is numeric. - */ - boolean isNumeric(); - - /** - * Return the column's precision if it is a NumericalDataType; - * otherwise, return -1. - */ - public int getPrecision(); - - /** - * Return the column's scale if it is an ExactNumericDataType; - * otherwise, return -1. - */ - public int getScale(); - - /** - * If the column is a CharacterStringDataType, return its length; - * otherwise, return -1. - */ - public int getLength(); - - /** - * Return whether the column's datatype is a LOB type - * (i.e. BLOB, CLOB, or NCLOB). - */ - boolean isLOB(); - - - // ********** Java type ********** - - /** - * Return a Java type declaration that is reasonably - * similar to the column's data type. - */ - String getJavaTypeDeclaration(); - - /** - * Return a Java type that is reasonably - * similar to the column's data type. - */ - JavaType getJavaType(); - - /** - * Return a Java type declaration that is reasonably - * similar to the column's data type and suitable for use as a - * primary key field. - */ - String getPrimaryKeyJavaTypeDeclaration(); - - /** - * Return a Java type that is reasonably - * similar to the column's data type and suitable for use as a - * primary key field. - */ - JavaType getPrimaryKeyJavaType(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionAdapter.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionAdapter.java deleted file mode 100644 index 972848965c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionAdapter.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - - -/** - * An empty implementation of ConnectionListener. - * - * Provisional API: This class is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public class ConnectionAdapter implements ConnectionListener { - - public void aboutToClose(ConnectionProfile profile) { - // do nothing - } - - public void closed(ConnectionProfile profile) { - // do nothing - } - - public void databaseChanged(ConnectionProfile profile, Database database) { - // do nothing - } - - public void modified(ConnectionProfile profile) { - // do nothing - } - - public boolean okToClose(ConnectionProfile profile) { - return true; - } - - public void opened(ConnectionProfile profile) { - // do nothing - } - - public void catalogChanged(ConnectionProfile profile, Catalog catalog) { - // do nothing - } - - public void schemaChanged(ConnectionProfile profile, Schema schema) { - // do nothing - } - - public void sequenceChanged(ConnectionProfile profile, Sequence sequence) { - // do nothing - } - - public void tableChanged(ConnectionProfile profile, Table table) { - // do nothing - } - - public void columnChanged(ConnectionProfile profile, Column column) { - // do nothing - } - - public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java deleted file mode 100644 index 4f3b09bae8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.EventListener; - - -/** - * A ConnectionListener is notified of any changes to a connection. - * - * @see org.eclipse.datatools.connectivity.IManagedConnectionListener - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public interface ConnectionListener extends EventListener { - - public void opened(ConnectionProfile profile); - public void modified(ConnectionProfile profile); - public boolean okToClose(ConnectionProfile profile); - public void aboutToClose(ConnectionProfile profile); - public void closed(ConnectionProfile profile); - - public void databaseChanged(ConnectionProfile profile, Database database); - public void catalogChanged(ConnectionProfile profile, Catalog catalog); - public void schemaChanged(ConnectionProfile profile, Schema schema); - public void sequenceChanged(ConnectionProfile profile, Sequence sequence); - public void tableChanged(ConnectionProfile profile, Table table); - public void columnChanged(ConnectionProfile profile, Column column); - public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java deleted file mode 100644 index 6dde62ba25..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; - -/** - * Database connection profile - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface ConnectionProfile extends DatabaseObject { - - // ********** properties ********** - - /** - * Return the connection profile's database. - * Return null if the connection profile is inactive. - */ - Database getDatabase(); - - /** - * Return ID of the provider managing the DTP profile. - */ - String getProviderID(); - - /** - * Return the connection profile's static ID. - */ - String getInstanceID(); - - /** - * Return the default database name. - */ - String getDatabaseName(); - - /** - * Return the database product name. - */ - String getDatabaseProduct(); - - /** - * Return the database vendor. - */ - String getDatabaseVendor(); - - /** - * Return the database version. - */ - String getDatabaseVersion(); - - /** - * Return the driver class name. - */ - String getDriverClassName(); - - /** - * Return the default connection URL. - */ - String getURL(); - - /** - * Return the default user name. - */ - String getUserName(); - - /** - * Return the default user password. - */ - String getUserPassword(); - - /** - * Return the ID of the associated Driver definition. - */ - String getDriverDefinitionID(); - - /** - * Return the jar list for the associated Driver as a - * comma-delimited string. - */ - String getDriverJarList(); - - /** - * Return the name of the associated Driver definition. - */ - String getDriverName(); - - // ********** connection ********** - - /** - * Return whether the profile is either connected to a live database - * session or working off-line (i.e. it has access to meta-data). - * @see isConnected() - * @see isWorkingOffline() - */ - boolean isActive(); - - /** - * Return whether the profile is neither connected to a live database - * session nor working off-line (i.e. it has access to meta-data). - * @see isActive() - */ - boolean isInactive(); - - /** - * Return whether the profile is connected to a live database session - * (i.e. the meta-data comes from the database), as opposed to working - * off-line. - * @see #isActive() - */ - boolean isConnected(); - - /** - * Return whether the profile is not connected to a live database session - * (i.e. the meta-data comes from the database), as opposed to working - * off-line. - * @see #isConnected() - */ - boolean isDisconnected(); - - /** - * Connect to the database. - * @see #disconnect() - */ - void connect(); - - /** - * Disconnect from the database. - * @see #connect() - */ - void disconnect(); - - - // ********** off-line support ********** - - /** - * Return whether the profile is working off-line (i.e. the meta-data - * comes from a local cache), as opposed to connected to a live - * database session. - * @see #isActive() - */ - boolean isWorkingOffline(); - - /** - * Return whether the connection factories associated with the - * connection profile's provider support working offline. - */ - boolean supportsWorkOfflineMode(); - - /** - * Save the state of the connection profile for working in an offline mode. - * If the connection profile does not support working in an offline mode, no - * exception is thrown and the method will return immediately. - */ - IStatus saveWorkOfflineData(); - - /** - * Return whether the connection profile supports working offline and data - * has been saved for working offline. - */ - boolean canWorkOffline(); - - /** - * Begin working off-line. - */ - IStatus workOffline(); - - - // ********** listeners ********** - - /** - * Add the specified connection listener to the connection profile. - */ - void addConnectionListener(ConnectionListener listener); - - /** - * Remove the specified connection listener from the connection profile. - */ - void removeConnectionListener(ConnectionListener listener); - - - // ********** constants ********** - - String CONNECTION_PROFILE_TYPE = "org.eclipse.datatools.connectivity.db.generic.connectionProfile"; //$NON-NLS-1$ - String DRIVER_DEFINITION_PROP_ID = "org.eclipse.datatools.connectivity.driverDefinitionID"; //$NON-NLS-1$ - String DRIVER_DEFINITION_TYPE_PROP_ID = "org.eclipse.datatools.connectivity.drivers.defnType"; //$NON-NLS-1$ - String DRIVER_JAR_LIST_PROP_ID = "jarList"; //$NON-NLS-1$ - String DATABASE_SAVE_PWD_PROP_ID = IJDBCDriverDefinitionConstants.PROP_PREFIX + "savePWD"; //$NON-NLS-1$ - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java deleted file mode 100644 index 648daa5bf6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * An empty implementation of ProfileListener. - * - * Provisional API: This class is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public class ConnectionProfileAdapter implements ConnectionProfileListener { - - public void connectionProfileAdded(String name) { - // do nothing - } - - public void connectionProfileRemoved(String name) { - // do nothing - } - - public void connectionProfileRenamed(String oldName, String newName) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileFactory.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileFactory.java deleted file mode 100644 index e44773953a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database connection profile factory - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface ConnectionProfileFactory { - - /** - * Return the names of the DTP connection profiles the factory can wrap with - * new connection profiles. - */ - Iterator<String> connectionProfileNames(); - - /** - * Build and return a connection profile that wraps the DTP connection - * profile with the specified name. - * Return null if there is no DTP connection profile with the specified - * name. - * Use the specified database finder to allow clients to control how - * database objects are found based on their names. - */ - ConnectionProfile buildConnectionProfile(String name, DatabaseFinder finder); - - /** - * Build and return a connection profile that wraps the DTP connection - * profile with the specified name. - * Return null if there is no DTP connection profile with the specified - * name. - * Clients should use this method when a JPA platform is unavailable - * (e.g. during project creation). The returned connection profile will - * not be able to search for database objects by any names other than - * those supplied by the factory (i.e. lookups cannot be performed with - * "identifiers"). - */ - ConnectionProfile buildConnectionProfile(String name); - - /** - * Add a listener that will be notified of changes to the DTP - * connection profiles. - */ - void addConnectionProfileListener(ConnectionProfileListener listener); - - /** - * Remove the specified listener. - */ - void removeConnectionProfileListener(ConnectionProfileListener listener); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java deleted file mode 100644 index f020c5505d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.EventListener; - -/** - * A ProfileListener is notified of any changes to the DTP connection profiles. - * - * @see org.eclipse.datatools.connectivity.IProfileListener - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public interface ConnectionProfileListener - extends EventListener -{ - - /** - * The specified profile has been added. - */ - public void connectionProfileAdded(String name); - - /** - * The specified profile has been removed. - */ - public void connectionProfileRemoved(String name); - - /** - * The specified profile has been renamed. - */ - public void connectionProfileRenamed(String oldName, String newName); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java deleted file mode 100644 index 492e2d991e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Database extends SchemaContainer { - - // ********** 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. - * - * Practically speaking: - * if #supportsCatalogs() returns 'true' - * #catalogs() returns catalogs that contain the database's schemata - * #schemata() returns an empty iterator - * else - * #catalogs() returns an empty iterator - * #schemata() returns the database's schemata - * 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 #catalogs() - * @see #schemata() - */ - boolean supportsCatalogs(); - - /** - * Return the database's catalogs. - * Return an empty iterator if the database does not support catalogs. - * @see #supportsCatalogs() - */ - Iterator<Catalog> catalogs(); - - /** - * Return the number of catalogs the database contains. - * Return zero if the database does not support catalogs. - * @see #supportsCatalogs() - */ - int catalogsSize(); - - /** - * Return the database's catalog names, sorted. - * Return an empty iterator 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 #sortedCatalogIdentifiers() - * @see #getCatalogNamed(String) - */ - Iterator<String> sortedCatalogNames(); - - /** - * Return the catalog with specified name. The name must be an exact match - * of the catalog's name. - * Return null if the database does not support catalogs. - * @see #supportsCatalogs() - * @see #sortedCatalogNames() - * @see #getCatalogForIdentifier(String) - */ - Catalog getCatalogNamed(String name); - - /** - * Return the database's catalog identifiers, sorted by name. - * Return an empty iterator 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 #sortedCatalogNames() - * @see #getCatalogForIdentifier(String) - */ - Iterator<String> sortedCatalogIdentifiers(); - - /** - * Return the catalog for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * Return null if the database does not support catalogs. - * @see #supportsCatalogs() - * @see #sortedCatalogIdentifiers() - * @see #getCatalogNamed(String) - */ - Catalog getCatalogForIdentifier(String identifier); - - /** - * Return the database's "default" catalog, as defined by the database vendor. - * In most cases the default catalog's name will match the user name. - * Return null if the database does not support catalogs or if the default - * catalog does not exist (e.g. the database has no catalog whose name - * matches the user name). - * @see #supportsCatalogs() - * @see #getDefaultCatalogIdentifier() - */ - Catalog getDefaultCatalog(); - - /** - * Return the database's "default" catalog identifier. - * The database may or may not have a catalog with a matching name. - * @see #supportsCatalogs() - * @see #getDefaultCatalog() - */ - String getDefaultCatalogIdentifier(); - - - // ********** utility methods ********** - - /** - * Select and return from the specified list of database objects the - * database object identified by the specified identifier. - * The identifier should be an SQL identifier (i.e. delimited when - * non-"normal"). - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier); - - /** - * Convert the specified name to a database-appropriate SQL identifier. - */ - String convertNameToIdentifier(String name); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseFinder.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseFinder.java deleted file mode 100644 index aea6742474..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseFinder.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * This interface allows clients of the Dali db package to plug in a custom - * strategy for comparing an identifier to the names of a collection of - * database objects. - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface DatabaseFinder { - - /** - * Select and return from the specified list of database objects the - * database object identified by the specified identifier. - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier, DefaultCallback defaultCallback); - - /** - * The platform-provided finder is passed a "default" callback that can be - * used if appropriate. - */ - interface DefaultCallback { - - /** - * Select and return from the specified list of database objects the - * database object identified by the specified identifier. - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier); - - } - - /** - * This finder searches for an exact match. - */ - final class Simple implements DatabaseFinder { - public static final DatabaseFinder INSTANCE = new Simple(); - public static DatabaseFinder instance() { - return INSTANCE; - } - // ensure single instance - private Simple() { - super(); - } - // search for an exact match on the name - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier, DefaultCallback defaultCallback) { - for (T databaseObject : databaseObjects) { - if (databaseObject.getName().equals(identifier)) { - return databaseObject; - } - } - return null; - } - @Override - public String toString() { - return "DatabaseFinder.Simple"; //$NON-NLS-1$ - } - } - - /** - * This finder uses the passed in callback to search the list of database objects. - */ - final class Default implements DatabaseFinder { - public static final DatabaseFinder INSTANCE = new Default(); - public static DatabaseFinder instance() { - return INSTANCE; - } - // ensure single instance - private Default() { - super(); - } - // simply use the callback - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier, DefaultCallback defaultCallback) { - return defaultCallback.selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - @Override - public String toString() { - return "DatabaseFinder.Default"; //$NON-NLS-1$ - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseObject.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseObject.java deleted file mode 100644 index e9f755dbb0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/DatabaseObject.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Common behavior to all database objects - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface DatabaseObject { - - /** - * Return the database object's name. - */ - String getName(); - - /** - * Return the database object's "identifier", which is the object's name - * modified so it can be used in an SQL statement (e.g. if the name contains - * special characters or is mixed case, it will be delimited, typically by - * double-quotes). - * Return null if the database object's identifier matches the specified - * "default name". - */ - String getIdentifier(String defaultName); - - /** - * Return the database object's "identifier", which is the object's name - * modified so it can be used in an SQL statement (e.g. if the name contains - * special characters or is mixed case, it will be delimited, typically by - * double-quotes). - */ - String getIdentifier(); - - /** - * Return the database object's database. - */ - Database getDatabase(); - - /** - * Return the database object's connection profile. - */ - ConnectionProfile getConnectionProfile(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java deleted file mode 100644 index 37da78e2c7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database foreign key - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface ForeignKey extends DatabaseObject { - - // ********** tables ********** - - /** - * Return the foreign key's "base" table. - */ - Table getBaseTable(); - - /** - * Return the foreign key's "referenced" table. - */ - Table getReferencedTable(); - - - // ********** column pairs ********** - - /** - * Return the foreign key's column pairs. - */ - Iterator<ColumnPair> columnPairs(); - - /** - * Return the size of the foreign key's column pairs. - */ - int columnPairsSize(); - - /** - * Return the foreign key's single column pair. Throw an - * IllegalStateException if the foreign key has more than one column pair. - */ - ColumnPair getColumnPair(); - - /** - * Return the foreign key's "base" columns. - */ - Iterator<Column> baseColumns(); - - /** - * Return the foreign key's "base" columns that are not part of the base - * table's primary key. (The non-primary key base columns are not used to - * generate basic attributes during entity generation.) - */ - Iterator<Column> nonPrimaryKeyBaseColumns(); - - /** - * Return the foreign key's "referenced" columns. - */ - Iterator<Column> referencedColumns(); - - /** - * Return whether the foreign key references the primary key of the - * "referenced" table and that primary key has only a single column. - * This can be used when determining JPA defaults. - */ - boolean referencesSingleColumnPrimaryKey(); - - - // ********** JPA support ********** - - /** - * Return an appropriate name for an attribute that holds the entity - * mapped to the foreign key's "referenced" table. - */ - String getAttributeName(); - - /** - * If the name of the "base" column adheres to the JPA spec for a - * default mapping (i.e. it ends with an underscore followed by the name - * of the "referenced" column, and the "referenced" column is the single - * primary key column of the "referenced" table), return the corresponding - * default attribute name: - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * Return a null if it does not adhere to the JPA spec: - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.CUBICLE_ID) => null - * ForeignKey(EMP.CUBICLE => CUBICLE.ID) => null - */ - String getDefaultAttributeName(); - - /** - * Given the name of an attribute (field or property) that is mapped to the - * foreign key, - * build and return a string to be used as the value for the attribute's - * JoinColumn annotation's 'name' element. Return null if the attribute - * maps to the join column by default. - * Precondition: The foreign key consists of a single column pair whose - * referenced column is the single-column primary key of the foreign - * key's referenced table. - */ - String getJoinColumnAnnotationIdentifier(String attributeName); - - // ********** column pair interface ********** - - /** - * Pair up the foreign key's column pairs, matching each "base" column with - * the appropriate "referenced" column. - * @see #columnPairs() - */ - interface ColumnPair { - - /** - * Return the column pair's "base" column. - */ - Column getBaseColumn(); - - /** - * Return the column pair's "referenced" column. - */ - Column getReferencedColumn(); - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java deleted file mode 100644 index 014f7362b1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.datatools.enablement.jdt.classpath.DriverClasspathContainer; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jpt.db.internal.DTPConnectionProfileFactory; -import org.osgi.framework.BundleContext; - -/** - * The JPT DB plug-in lifecycle implementation. - * Globally available connection profile factory. - * - * Provisional API: This class is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public class JptDbPlugin extends Plugin { - private DTPConnectionProfileFactory connectionProfileFactory; - - private static JptDbPlugin INSTANCE; // sorta-final - - /** - * Return the singleton JPT DB plug-in. - */ - public static JptDbPlugin instance() { - return INSTANCE; - } - - /** - * The constructor - */ - public JptDbPlugin() { - super(); - if (INSTANCE != null) { - throw new IllegalStateException(); - } - // this convention is *wack*... ~bjv - INSTANCE = this; - } - - /** - * This method is called upon plug-in activation - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - this.connectionProfileFactory = DTPConnectionProfileFactory.instance(); - this.connectionProfileFactory.start(); - } - - /** - * This method is called when the plug-in is stopped - */ - @Override - public void stop(BundleContext context) throws Exception { - this.connectionProfileFactory.stop(); - this.connectionProfileFactory = null; - INSTANCE = null; - super.stop(context); - } - - public ConnectionProfileFactory getConnectionProfileFactory() { - return this.connectionProfileFactory; - } - - /** - * Creates a jar list container for the given DTP driver. - */ - public IClasspathContainer buildDriverClasspathContainerFor(String driverName) { - return new DriverClasspathContainer(driverName); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java deleted file mode 100644 index 7264cf2598..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - - -/** - * Database schema - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Schema extends DatabaseObject { - /** - * Return the schema's container; either a catalog or a database. - */ - SchemaContainer getContainer(); - - - // ********** tables ********** - - /** - * Return the schema's tables. - */ - Iterator<Table> tables(); - - /** - * Return the number of tables the schema contains. - */ - int tablesSize(); - - /** - * Return the table with specified name. The name must be an exact match - * of the table's name. - * @see #getTableForIdentifier(String) - */ - Table getTableNamed(String name); - - /** - * Return the schema's table identifiers, sorted by name. - */ - Iterator<String> sortedTableIdentifiers(); - - /** - * Return the table for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #getTableNamed(String) - */ - Table getTableForIdentifier(String identifier); - - - // ********** sequences ********** - - /** - * Return the schema's sequences. - */ - Iterator<Sequence> sequences(); - - /** - * Return the number of sequences the schema contains. - */ - int sequencesSize(); - - /** - * Return the sequence with specified name. The name must be an exact match - * of the sequence's name. - * @see #getSequenceForIdentifier(String) - */ - Sequence getSequenceNamed(String name); - - /** - * Return the schema's sequence identifers, sorted by name. - */ - Iterator<String> sortedSequenceIdentifiers(); - - /** - * Return the sequence for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #getSequenceNamed(String) - */ - Sequence getSequenceForIdentifier(String identifier); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java deleted file mode 100644 index 7dcd44db0f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Schema "container" (i.e. Database or Catalog) - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface SchemaContainer - extends DatabaseObject -{ - - /** - * Return the container's schemata. - */ - Iterator<Schema> schemata(); - - /** - * Return the number of schemata in the container. - */ - int schemataSize(); - - /** - * Return the 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 #sortedSchemaIdentifiers() - */ - Iterator<String> sortedSchemaNames(); - - /** - * Return the schema with specified name. The name must be an exact match - * of the schema's name. - * @see #sortedSchemaNames() - * @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 #sortedSchemaNames() - */ - Iterator<String> sortedSchemaIdentifiers(); - - /** - * Return the schema for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #sortedSchemaIdentifiers() - * @see #getSchemaNamed(String) - */ - Schema getSchemaForIdentifier(String identifier); - - /** - * Return the container's "default" schema, as defined by the database vendor. - * In most cases the default schema's name will match the user name. - * Return null if the default schema does not exist (e.g. the container has - * no schema whose name matches the user name). - * @see #getDefaultSchemaIdentifier() - */ - Schema getDefaultSchema(); - - /** - * Return the container's "default" schema identifier. - * The container may or may not have a schema with a matching name. - * @see #getDefaultSchema() - */ - String getDefaultSchemaIdentifier(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java deleted file mode 100644 index c24c2315ea..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Database sequence - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Sequence extends DatabaseObject { - - /** - * Return the sequence's schema. - */ - Schema getSchema(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java deleted file mode 100644 index edde31cd72..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database table - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Table extends DatabaseObject { - - /** - * Return the table's schema. - */ - Schema getSchema(); - - - // ********** columns ********** - - /** - * Return the table's columns. - */ - Iterator<Column> columns(); - - /** - * Return the number of columns the table contains. - */ - int columnsSize(); - - /** - * Return the column with specified name. The name must be an exact match - * of the column's name. - * @see #getColumnForIdentifier(String) - */ - Column getColumnNamed(String name); - - /** - * Return the table's column identifers, sorted by name. - */ - Iterator<String> sortedColumnIdentifiers(); - - /** - * Return the column for the specified identifier. The identifier should - * be an SQL identifier (i.e. quoted when case-sensitive or containing - * special characters, unquoted otherwise). - * @see #getColumnNamed(String) - */ - Column getColumnForIdentifier(String identifier); - - - // ********** primary key columns ********** - - /** - * Return the table's primary key columns. - */ - Iterator<Column> primaryKeyColumns(); - - /** - * Return the number of primary key columns the table contains. - */ - int primaryKeyColumnsSize(); - - /** - * Return the table's single primary key column. Throw an - * IllegalStateException if the table has more than one primary key column. - */ - Column getPrimaryKeyColumn(); - - - // ********** foreign keys ********** - - /** - * Return the table's foreign keys. - */ - Iterator<ForeignKey> foreignKeys(); - - /** - * Return the number of foreign keys the table contains. - */ - int foreignKeysSize(); - - - // ********** join table support ********** - - /** - * Return whether the table is possibly a "join" table - * (i.e. it contains only 2 foreign keys). Whether the table *actually* is - * a "join" table is determined by the semantics of the database design. - */ - boolean isPossibleJoinTable(); - - /** - * Assuming the table is a "join" table, return the foreign key to the - * "owning" table. - * @see #isPossibleJoinTable() - */ - ForeignKey getJoinTableOwningForeignKey(); - - /** - * Assuming the table is a "join" table, return the foreign key to the - * "non-owning" table. - * @see #isPossibleJoinTable() - */ - ForeignKey getJoinTableNonOwningForeignKey(); - - /** - * Assuming the table is a "join" table, return whether its name matches - * the JPA default (i.e. "OWNINGTABLE_NONOWNINGTABLE"). - * @see #isPossibleJoinTable() - */ - boolean joinTableNameIsDefault(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java deleted file mode 100644 index 9d1a3666d4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.List; - -import org.eclipse.jpt.db.Catalog; - -/** - * Wrap a DTP Catalog - */ -final class DTPCatalogWrapper - extends DTPSchemaContainerWrapper - implements Catalog -{ - // the wrapped DTP catalog - private final org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog; - - - // ********** constructor ********** - - DTPCatalogWrapper(DTPDatabaseWrapper database, org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) { - super(database, dtpCatalog); - this.dtpCatalog = dtpCatalog; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().catalogChanged(this); - } - - - // ********** DTPSchemaContainerWrapper implementation ********** - - @Override - @SuppressWarnings("unchecked") - List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemata() { - return this.dtpCatalog.getSchemas(); - } - - @Override - DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - // try to short-circuit the search - return this.wraps(dtpSchema.getCatalog()) ? - this.getSchema_(dtpSchema) - : - this.getDatabase().getSchemaFromCatalogs(dtpSchema); - } - - @Override - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - // try to short-circuit the search - return this.wraps(dtpTable.getSchema().getCatalog()) ? - this.getTable_(dtpTable) - : - this.getDatabase().getTableFromCatalogs(dtpTable); - } - - @Override - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - // try to short-circuit the search - return this.wraps(dtpColumn.getTable().getSchema().getCatalog()) ? - this.getColumn_(dtpColumn) - : - this.getDatabase().getColumnFromCatalogs(dtpColumn); - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpCatalog.getName(); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Catalog catalog) { - return this.dtpCatalog == catalog; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java deleted file mode 100644 index c9af9aa89f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.datatools.modelbase.dbdefinition.PredefinedDataTypeDefinition; -import org.eclipse.datatools.modelbase.sql.datatypes.CharacterStringDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.DataType; -import org.eclipse.datatools.modelbase.sql.datatypes.ExactNumericDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.NumericalDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.PredefinedDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.PrimitiveType; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.utility.JavaType; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.SimpleJavaType; - -/** - * Wrap a DTP Column - */ -final class DTPColumnWrapper - extends DTPDatabaseObjectWrapper - implements Column -{ - // the wrapped DTP column - private final org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn; - - - // ********** constructor ********** - - DTPColumnWrapper(DTPTableWrapper table, org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - super(table, dtpColumn); - this.dtpColumn = dtpColumn; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().columnChanged(this); - } - - - // ********** Column implementation ********** - - public String getName() { - return this.dtpColumn.getName(); - } - - public DTPTableWrapper getTable() { - return (DTPTableWrapper) this.getParent(); - } - - public boolean isPartOfPrimaryKey() { - return this.getTable().primaryKeyColumnsContains(this); - } - - public boolean isPartOfForeignKey() { - return this.getTable().foreignKeyBaseColumnsContains(this); - } - - public boolean isPartOfUniqueConstraint() { - return this.dtpColumn.isPartOfUniqueConstraint(); - } - - public boolean isNullable() { - return this.dtpColumn.isNullable(); - } - - public String getDataTypeName() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType == null) ? null : dataType.getName(); - } - - public boolean isNumeric() { - return this.dtpColumn.getDataType() instanceof NumericalDataType; - } - - public int getPrecision() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof NumericalDataType) ? - ((NumericalDataType) dataType).getPrecision() - : - -1; - } - - public int getScale(){ - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof ExactNumericDataType) ? - ((ExactNumericDataType) dataType).getScale() - : - -1; - } - - public int getLength() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof CharacterStringDataType) ? - ((CharacterStringDataType) dataType).getLength() - : - -1; - } - - public boolean isLOB() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof PredefinedDataType) ? - primitiveTypeIsLob(((PredefinedDataType) dataType).getPrimitiveType()) - : - false; - } - - public String getJavaTypeDeclaration() { - return this.getJavaType().declaration(); - } - - public JavaType getJavaType() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof PredefinedDataType) ? - convertToJPAJavaType(this.getJavaType((PredefinedDataType) dataType)) - : - DEFAULT_JAVA_TYPE; - } - - public String getPrimaryKeyJavaTypeDeclaration() { - return this.getPrimaryKeyJavaType().declaration(); - } - - public JavaType getPrimaryKeyJavaType() { - return convertToJPAPrimaryKeyJavaType(this.getJavaType()); - } - - private JavaType getJavaType(PredefinedDataType dataType) { - // this is just a bit hacky: moving from a type declaration to a class name to a type declaration... - String dtpJavaClassName = this.getDefinition(dataType).getJavaClassName(); - return new SimpleJavaType(ClassTools.classNameForTypeDeclaration(dtpJavaClassName)); - } - - private PredefinedDataTypeDefinition getDefinition(PredefinedDataType dataType) { - return this.getDatabase().getDTPDefinition().getPredefinedDataTypeDefinition(dataType.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Column column) { - return this.dtpColumn == column; - } - - @Override - void clear() { - // no state to clear - } - - - // ********** static methods ********** - - /** - * The JDBC spec says JDBC drivers should be able to map BLOBs and CLOBs - * directly, but the JPA spec does not allow them. - */ - private static JavaType convertToJPAJavaType(JavaType javaType) { - if (javaType.equals(BLOB_JAVA_TYPE)) { - return BYTE_ARRAY_JAVA_TYPE; - } - if (javaType.equals(CLOB_JAVA_TYPE)) { - return STRING_JAVA_TYPE; - } - return javaType; - } - - /** - * The JPA spec [2.1.4] says only the following types are allowed in - * primary key fields: - * [variable] primitives - * [variable] primitive wrappers - * java.lang.String - * java.util.Date - * java.sql.Date - */ - private static JavaType convertToJPAPrimaryKeyJavaType(JavaType javaType) { - if (javaType.isVariablePrimitive() - || javaType.isVariablePrimitiveWrapper() - || javaType.equals(STRING_JAVA_TYPE) - || javaType.equals(UTIL_DATE_JAVA_TYPE) - || javaType.equals(SQL_DATE_JAVA_TYPE)) { - return javaType; - } - if (javaType.equals(BIG_DECIMAL_JAVA_TYPE)) { - return LONG_JAVA_TYPE; // ?? - } - if (javaType.equals(SQL_TIME_JAVA_TYPE)) { - return UTIL_DATE_JAVA_TYPE; // ??? - } - if (javaType.equals(SQL_TIMESTAMP_JAVA_TYPE)) { - return UTIL_DATE_JAVA_TYPE; // ??? - } - // all the other typical types are pretty much un-mappable - return String(?) - return STRING_JAVA_TYPE; - } - - private static boolean primitiveTypeIsLob(PrimitiveType primitiveType) { - return (primitiveType == PrimitiveType.BINARY_LARGE_OBJECT_LITERAL) - || (primitiveType == PrimitiveType.CHARACTER_LARGE_OBJECT_LITERAL) - || (primitiveType == PrimitiveType.NATIONAL_CHARACTER_LARGE_OBJECT_LITERAL); - } - - - // ***** some constants used when converting the column to a Java attribute - // TODO Object is the default? - private static final JavaType DEFAULT_JAVA_TYPE = new SimpleJavaType(java.lang.Object.class); - - private static final JavaType BLOB_JAVA_TYPE = new SimpleJavaType(java.sql.Blob.class); - private static final JavaType BYTE_ARRAY_JAVA_TYPE = new SimpleJavaType(byte[].class); - - private static final JavaType CLOB_JAVA_TYPE = new SimpleJavaType(java.sql.Clob.class); - private static final JavaType STRING_JAVA_TYPE = new SimpleJavaType(java.lang.String.class); - - private static final JavaType UTIL_DATE_JAVA_TYPE = new SimpleJavaType(java.util.Date.class); - private static final JavaType SQL_DATE_JAVA_TYPE = new SimpleJavaType(java.sql.Date.class); - private static final JavaType SQL_TIME_JAVA_TYPE = new SimpleJavaType(java.sql.Time.class); - private static final JavaType SQL_TIMESTAMP_JAVA_TYPE = new SimpleJavaType(java.sql.Timestamp.class); - - private static final JavaType BIG_DECIMAL_JAVA_TYPE = new SimpleJavaType(java.math.BigDecimal.class); - private static final JavaType LONG_JAVA_TYPE = new SimpleJavaType(long.class); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileFactory.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileFactory.java deleted file mode 100644 index e3cb2c729f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileFactory.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Iterator; - -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.IProfileListener1; -import org.eclipse.datatools.connectivity.ProfileManager; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.ConnectionProfileListener; -import org.eclipse.jpt.db.DatabaseFinder; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap the DTP ProfileManager in yet another singleton. - */ -public final class DTPConnectionProfileFactory - implements ConnectionProfileFactory -{ - private ProfileManager dtpProfileManager; - - private LocalProfileListener profileListener; - - - // ********** singleton ********** - - private static final DTPConnectionProfileFactory INSTANCE = new DTPConnectionProfileFactory(); - - public static DTPConnectionProfileFactory instance() { - return INSTANCE; - } - - /** - * 'private' to ensure singleton - */ - private DTPConnectionProfileFactory() { - super(); - } - - - // ********** lifecycle ********** - - /** - * called by plug-in - */ - public synchronized void start() { - this.dtpProfileManager = ProfileManager.getInstance(); - this.profileListener = new LocalProfileListener(); - this.dtpProfileManager.addProfileListener(this.profileListener); - } - - /** - * called by plug-in - */ - public synchronized void stop() { - this.dtpProfileManager.removeProfileListener(this.profileListener); - this.profileListener = null; - this.dtpProfileManager = null; - } - - - // ********** connection profiles ********** - - public synchronized ConnectionProfile buildConnectionProfile(String name, DatabaseFinder finder) { - for (IConnectionProfile dtpProfile : this.dtpProfileManager.getProfiles()) { - if (dtpProfile.getName().equals(name)) { - return new DTPConnectionProfileWrapper(dtpProfile, finder); - } - } - return null; - } - - public ConnectionProfile buildConnectionProfile(String name) { - return this.buildConnectionProfile(name, DatabaseFinder.Simple.instance()); - } - - public Iterator<String> connectionProfileNames() { - return new TransformationIterator<IConnectionProfile, String>(this.dtpConnectionProfiles()) { - @Override - protected String transform(IConnectionProfile dtpProfile) { - return dtpProfile.getName(); - } - }; - } - - private synchronized Iterator<IConnectionProfile> dtpConnectionProfiles() { - return new ArrayIterator<IConnectionProfile>(this.dtpProfileManager.getProfiles()); - } - - - // ********** listeners ********** - - public void addConnectionProfileListener(ConnectionProfileListener listener) { - this.profileListener.addConnectionProfileListener(listener); - } - - public void removeConnectionProfileListener(ConnectionProfileListener listener) { - this.profileListener.removeConnectionProfileListener(listener); - } - - - // ********** listener ********** - - /** - * Forward events to the factory's listeners. - */ - private static class LocalProfileListener implements IProfileListener1 { - private ListenerList<ConnectionProfileListener> listenerList = new ListenerList<ConnectionProfileListener>(ConnectionProfileListener.class); - - LocalProfileListener() { - super(); - } - - void addConnectionProfileListener(ConnectionProfileListener listener) { - this.listenerList.add(listener); - } - - void removeConnectionProfileListener(ConnectionProfileListener listener) { - this.listenerList.remove(listener); - } - - // ********** IProfileListener implementation ********** - - public void profileAdded(IConnectionProfile dtpProfile) { - String name = dtpProfile.getName(); - for (ConnectionProfileListener listener : this.listenerList.getListeners()) { - listener.connectionProfileAdded(name); - } - } - - public void profileChanged(IConnectionProfile dtpProfile, String oldName, String oldDescription, Boolean oldAutoConnect) { - String newName = dtpProfile.getName(); - if ( ! newName.equals(oldName)) { - for (ConnectionProfileListener listener : this.listenerList.getListeners()) { - listener.connectionProfileRenamed(oldName, newName); - } - } - } - - public void profileChanged(IConnectionProfile dtpProfile) { - // this method shouldn't be called on IProfileListener1 - throw new UnsupportedOperationException(); - } - - public void profileDeleted(IConnectionProfile dtpProfile) { - String name = dtpProfile.getName(); - for (ConnectionProfileListener listener : this.listenerList.getListeners()) { - listener.connectionProfileRemoved(name); - } - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java deleted file mode 100644 index ccb563e6b3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java +++ /dev/null @@ -1,548 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.datatools.connectivity.ConnectEvent; -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.IManagedConnection; -import org.eclipse.datatools.connectivity.IManagedConnectionOfflineListener; -import org.eclipse.datatools.connectivity.drivers.DriverManager; -import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; -import org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionInfo; -import org.eclipse.datatools.sqltools.core.DatabaseIdentifier; -import org.eclipse.datatools.sqltools.core.profile.ProfileUtil; -import org.eclipse.jpt.db.ConnectionListener; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.DatabaseFinder; -import org.eclipse.jpt.db.DatabaseObject; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Wrap a DTP ConnectionProfile - */ -final class DTPConnectionProfileWrapper - implements DTPDatabaseObject, ConnectionProfile -{ - // the wrapped DTP connection profile - private final IConnectionProfile dtpConnectionProfile; - - // finder supplied by the JPA platform (determines case-sensitivity, etc.) - private final DatabaseFinder finder; - - // callback passed to the finder - private final DatabaseFinder.DefaultCallback databaseFinderCallback; - - // the DTP managed connection we listen to - private final IManagedConnection dtpManagedConnection; - - // forward events from the DTP managed connection above; - // we listen and propagate events iff we have listeners ourselves - private final LocalConnectionListener connectionListener; - - // lazy-initialized, and deleted at disconnect - private DTPDatabaseWrapper database; - - - // ********** constants ********** - - private static final String LIVE_DTP_CONNECTION_TYPE = "java.sql.Connection"; //$NON-NLS-1$ - - private static final String OFFLINE_DTP_CONNECTION_TYPE = ConnectionInfo.class.getName(); - - private static final String DATABASE_PRODUCT_PROP_ID = "org.eclipse.datatools.connectivity.server.version"; //$NON-NLS-1$ - - - // ********** constructor ********** - - DTPConnectionProfileWrapper(IConnectionProfile dtpConnectionProfile, DatabaseFinder finder) { - super(); - this.dtpConnectionProfile = dtpConnectionProfile; - this.finder = finder; - this.databaseFinderCallback = new DatabaseFinderCallback(); - this.dtpManagedConnection = this.buildDTPManagedConnection(); - this.connectionListener = new LocalConnectionListener(); - // don't listen to the managed connection yet - } - - private IManagedConnection buildDTPManagedConnection() { - String connectionType = this.dtpConnectionProfile.supportsWorkOfflineMode() ? - OFFLINE_DTP_CONNECTION_TYPE : LIVE_DTP_CONNECTION_TYPE; - return this.dtpConnectionProfile.getManagedConnection(connectionType); - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpConnectionProfile.getName(); - } - - public String getIdentifier(String javaIdentifier) { - // connection profiles do not have "identifiers" - throw new UnsupportedOperationException(); - } - - public String getIdentifier() { - // connection profiles do not have "identifiers" - throw new UnsupportedOperationException(); - } - - - // ********** DTPDatabaseObject implementation ********** - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this; - } - - public synchronized DTPDatabaseWrapper getDatabase() { - if (this.database == null) { - this.database = this.buildDatabase(); - } - return this.database; - } - - - // ********** ConnectionProfile implementation ********** - - // ***** properties - public String getProviderID() { - return this.dtpConnectionProfile.getProviderId(); - } - - public String getInstanceID() { - return this.dtpConnectionProfile.getInstanceID(); - } - - public String getDatabaseName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_NAME_PROP_ID); - } - - public String getDatabaseProduct() { - return this.getProperty(DATABASE_PRODUCT_PROP_ID); - } - - public String getDatabaseVendor() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID); - } - - public String getDatabaseVersion() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID); - } - - public String getDriverClassName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DRIVER_CLASS_PROP_ID); - } - - public String getURL() { - return this.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID); - } - - /** - * Returns the user name. - * Allows user name composed by more than one word. - * If the user name contains a keyword, it returns the first word only. - */ - public String getUserName() { - String userName = this.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID); - userName = userName.trim(); - String[] names = userName.split("\\s+"); //$NON-NLS-1$ - if(names.length == 3) { // 208946 handle username like "sys as sysdba" on Oracle - if(this.nameIsKeyword(names[1])) { - return names[0]; - } - } - return userName; - } - - public String getUserPassword() { - return this.getProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID); - } - - public String getDriverDefinitionID() { - return this.getProperty(DRIVER_DEFINITION_PROP_ID); - } - - public String getDriverJarList() { - return DriverManager.getInstance().getDriverInstanceByID(this.getDriverDefinitionID()).getJarList(); - } - - public String getDriverName() { - return DriverManager.getInstance().getDriverInstanceByID(this.getDriverDefinitionID()).getName(); - } - - // ***** connection - public boolean isActive() { - return this.isConnected() || this.isWorkingOffline(); - } - - public boolean isInactive() { - return ! this.isActive(); - } - - public boolean isConnected() { - return this.dtpManagedConnection.isConnected() - && ! this.dtpManagedConnection.isWorkingOffline(); - } - - public boolean isDisconnected() { - return ! this.isConnected(); - } - - public void connect() { - if (this.isDisconnected()) { - this.checkStatus(this.dtpConnectionProfile.connect()); - } - } - - public void disconnect() { - this.checkStatus(this.dtpConnectionProfile.disconnect()); - } - - // ***** off-line support - public boolean isWorkingOffline() { - return this.dtpManagedConnection.isWorkingOffline(); - } - - public boolean supportsWorkOfflineMode() { - return this.dtpConnectionProfile.supportsWorkOfflineMode(); - } - - public IStatus saveWorkOfflineData() { - return this.dtpConnectionProfile.saveWorkOfflineData(); - } - - public boolean canWorkOffline() { - return this.dtpConnectionProfile.canWorkOffline(); - } - - public IStatus workOffline() { - return this.dtpConnectionProfile.workOffline(); - } - - // ***** listeners - public synchronized void addConnectionListener(ConnectionListener listener) { - if (this.hasNoListeners()) { // first listener added - this.startListening(); - } - this.connectionListener.addConnectionListener(listener); - } - - private void startListening() { - this.dtpManagedConnection.addConnectionListener(this.connectionListener); - if (this.database != null) { // don't trigger database creation - if (this.isConnected()) { // DTP does not change when off-line - this.database.startListening(); - } - } - } - - public synchronized void removeConnectionListener(ConnectionListener listener) { - this.connectionListener.removeConnectionListener(listener); - if (this.hasNoListeners()) { // last listener removed - this.stopListening(); - } - } - - private void stopListening() { - if (this.database != null) { // don't trigger database creation - if (this.isConnected()) { // DTP does not change when off-line - this.database.stopListening(); - } - } - this.dtpManagedConnection.removeConnectionListener(this.connectionListener); - } - - boolean hasNoListeners() { - return this.connectionListener.hasNoListeners(); - } - - boolean hasAnyListeners() { - return this.connectionListener.hasAnyListeners(); - } - - - // ********** internal methods ********** - - private void checkStatus(IStatus status) { - if (status.isOK()) { - return; - } - if (status.isMultiStatus()) { - for (IStatus child : status.getChildren()) { - this.checkStatus(child); // recurse, looking for the first error - } - } - throw new RuntimeException(status.getMessage(), status.getException()); - } - - private DTPDatabaseWrapper buildDatabase() { - if (this.isInactive()) { - return null; - } - - if (this.isWorkingOffline()) { - ConnectionInfo connectionInfo = (ConnectionInfo) this.dtpManagedConnection.getConnection().getRawConnection(); - return new DTPDatabaseWrapper(this, connectionInfo.getSharedDatabase()); - } - - // TODO see DTP bug 202306 - // pass connect=true in to ProfileUtil.getDatabase() - // there is a bug mentioned in a comment: - // "during the profile connected event notification, - // IManagedConnection is connected while IConnectionProfile is not" - // so, some hackery here to handle hackery there - return new DTPDatabaseWrapper(this, ProfileUtil.getDatabase(new DatabaseIdentifier(this.getName(), this.getDatabaseName()), true)); - } - - synchronized void clearDatabase() { - if (this.database != null) { - if (this.isConnected()) { // DTP does not change when off-line - this.database.stopListening(); - } - this.database = null; - } - } - - /** - * This is called whenever we need to find a component by identifier - * (e.g. Table.getColumnForIdentifier(String)). We channel all the calls to here - * and then we delegate to the JPA platform-supplied "database finder". - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - return this.finder.selectDatabaseObjectForIdentifier(databaseObjects, identifier, this.databaseFinderCallback); - } - - /** - * The default "database finder" calls back to here so we can delegate to - * the database, which contains all the information necessary to properly - * match identifiers. - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier_(T[] databaseObjects, String identifier) { - // the database should not be null here - call its internal method - return this.database.selectDatabaseObjectForIdentifier_(databaseObjects, identifier); - } - - void databaseChanged(DTPDatabaseWrapper db) { - this.connectionListener.databaseChanged(db); - } - - void catalogChanged(DTPCatalogWrapper catalog) { - this.connectionListener.catalogChanged(catalog); - } - - void schemaChanged(DTPSchemaWrapper schema) { - this.connectionListener.schemaChanged(schema); - } - - void sequenceChanged(DTPSequenceWrapper sequence) { - this.connectionListener.sequenceChanged(sequence); - } - - void tableChanged(DTPTableWrapper table) { - this.connectionListener.tableChanged(table); - } - - void columnChanged(DTPColumnWrapper column) { - this.connectionListener.columnChanged(column); - } - - void foreignKeyChanged(DTPForeignKeyWrapper foreignKey) { - this.connectionListener.foreignKeyChanged(foreignKey); - } - - private String getProperty(String propertyName) { - return this.dtpConnectionProfile.getBaseProperties().getProperty(propertyName); - } - - private boolean nameIsKeyword(String name) { - return name.equalsIgnoreCase("as"); //$NON-NLS-1$ - } - - - // ********** overrides ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } - - - // ********** DTP connection listener ********** - - /** - * This listener translates and forwards IManagedConnectionListener and - * IManagedConnectionOfflineListener events to ConnectionListeners. - */ - class LocalConnectionListener implements IManagedConnectionOfflineListener { - private ListenerList<ConnectionListener> listenerList = new ListenerList<ConnectionListener>(ConnectionListener.class); - - LocalConnectionListener() { - super(); - } - - void addConnectionListener(ConnectionListener listener) { - this.listenerList.add(listener); - } - - void removeConnectionListener(ConnectionListener listener) { - this.listenerList.remove(listener); - } - - boolean hasNoListeners() { - return this.listenerList.isEmpty(); - } - - boolean hasAnyListeners() { - return ! this.listenerList.isEmpty(); - } - - - // ********** IManagedConnectionListener implementation ********** - - // off-line or inactive => live - public void opened(ConnectEvent event) { - // do not build the database here - it is built on-demand - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.opened(DTPConnectionProfileWrapper.this); - } - } - - /** - * This method is never called from the base DTP code. - * Perhaps DTP extenders call it.... - * @see ManagedConnection#fireModifiedEvent(Object) - * which is never called... - */ - public void modified(ConnectEvent event) { - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.modified(DTPConnectionProfileWrapper.this); - } - } - - public boolean okToClose(ConnectEvent event) { - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - if ( ! listener.okToClose(DTPConnectionProfileWrapper.this)) { - return false; - } - } - return true; - } - - public void aboutToClose(ConnectEvent event) { - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.aboutToClose(DTPConnectionProfileWrapper.this); - } - } - - // live or off-line => inactive - public void closed(ConnectEvent event) { - // clear the database - DTPConnectionProfileWrapper.this.clearDatabase(); - // forward event to listeners - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.closed(DTPConnectionProfileWrapper.this); - } - } - - - // ********** IManagedConnectionOfflineListener implementation ********** - - // live => off-line - public boolean okToDetach(ConnectEvent event) { - // convert the event to an "ok to close" event; - // we are "closing" the live connection - return this.okToClose(event); - } - - // live => off-line - public void aboutToDetach(ConnectEvent event) { - // convert the event to a "close" event; - // we are "closing" the live connection - this.closed(event); - } - - // inactive or live => off-line - public void workingOffline(ConnectEvent event) { - // convert the event to an "open" event; - // we are "opening" the off-line connection - this.opened(event); - } - - // off-line => live - public void aboutToAttach(ConnectEvent event) { - // convert the event to an "close" event; - // we are "closing" the off-line connection - this.closed(event); - } - - - // ********** internal methods ********** - - void databaseChanged(DTPDatabaseWrapper db) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.databaseChanged(DTPConnectionProfileWrapper.this, db); - } - } - - void catalogChanged(DTPCatalogWrapper catalog) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.catalogChanged(DTPConnectionProfileWrapper.this, catalog); - } - } - - void schemaChanged(DTPSchemaWrapper schema) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.schemaChanged(DTPConnectionProfileWrapper.this, schema); - } - } - - void sequenceChanged(DTPSequenceWrapper sequence) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.sequenceChanged(DTPConnectionProfileWrapper.this, sequence); - } - } - - void tableChanged(DTPTableWrapper table) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.tableChanged(DTPConnectionProfileWrapper.this, table); - } - } - - void columnChanged(DTPColumnWrapper column) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.columnChanged(DTPConnectionProfileWrapper.this, column); - } - } - - void foreignKeyChanged(DTPForeignKeyWrapper foreignKey) { - for (ConnectionListener listener : this.listenerList.getListeners()) { - listener.foreignKeyChanged(DTPConnectionProfileWrapper.this, foreignKey); - } - } - - } - - - // ********** default DatabaseFinder ********** - - class DatabaseFinderCallback implements DatabaseFinder.DefaultCallback { - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - // call back to the internal method - return DTPConnectionProfileWrapper.this.selectDatabaseObjectForIdentifier_(databaseObjects, identifier); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObject.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObject.java deleted file mode 100644 index c976fe4b39..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObject.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.jpt.db.DatabaseObject; - -/** - * DTP database object - */ -public interface DTPDatabaseObject extends DatabaseObject { - - /** - * covariant override - */ - DTPConnectionProfileWrapper getConnectionProfile(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObjectWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObjectWrapper.java deleted file mode 100644 index 86d2d2cce3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseObjectWrapper.java +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObjectListener; -import org.eclipse.datatools.connectivity.sqm.core.rte.RefreshManager; -import org.eclipse.jpt.db.DatabaseObject; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * DTP Catalog Object Wrapper base class - */ -abstract class DTPDatabaseObjectWrapper - implements DTPDatabaseObject -{ - // we need a way to get to the connection profile - private final DTPDatabaseObject parent; - - // listen for the "catalog object" being refreshed - private final ICatalogObjectListener catalogObjectListener; - - // listen for this DTP catalog object to refresh - final ICatalogObject catalogObject; - - - // ********** construction/initialization ********** - - DTPDatabaseObjectWrapper(DTPDatabaseObject parent, Object dtpObject) { - super(); - this.parent = parent; - if (this.getConnectionProfile().isConnected()) { - // we only listen to "live" connections (as opposed to "off-line" connections); - // and the model is rebuilt when the connection connects or disconnects - this.catalogObject = (ICatalogObject) dtpObject; - this.catalogObjectListener = this.buildCatalogObjectListener(); - if (this.getConnectionProfile().hasAnyListeners()) { - this.startListening(); - } - } else { - this.catalogObject = null; - this.catalogObjectListener = null; - } - } - - private ICatalogObjectListener buildCatalogObjectListener() { - return new ICatalogObjectListener() { - public void notifyChanged(ICatalogObject dmElement, int eventType) { - if (dmElement == DTPDatabaseObjectWrapper.this.catalogObject) { - // 'eventType' doesn't seem to be very useful, so drop it - DTPDatabaseObjectWrapper.this.catalogObjectChanged(); - } - } - }; - } - - // typically, notify the connection profile something has changed - void catalogObjectChanged() { - this.clear(); - } - - /** - * The DTP object has changed, clear the wrapper's state so it will be - * synchronized on-demand. - */ - abstract void clear(); - - - - // ********** queries ********** - - DTPDatabaseObject getParent() { - return this.parent; - } - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this.parent.getConnectionProfile(); - } - - public DTPDatabaseWrapper getDatabase() { - return this.getConnectionProfile().getDatabase(); - } - - /** - * This is called by whenever we need to find a component by identifier - * (e.g. Table.getColumnForIdentifier(String)). We channel all the calls to the - * connection profile, which then delegates to the JPA platform-supplied - * "database finder". - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - return this.getConnectionProfile().selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - - /** - * Convenience method. - */ - <T extends DatabaseObject> T selectDatabaseObjectNamed(T[] databaseObjects, String name) { - for (T dbObject : databaseObjects) { - if (dbObject.getName().equals(name)) { - return dbObject; - } - } - return null; - } - - /** - * Examples: - * Oracle etc. - * Table(FOO) vs. "Foo" => null - * Table(BAR) vs. "Foo" => "BAR" - * Table(Foo) vs. "Foo" => "\"Foo\"" - * Table(Bar) vs. "Foo" => "\"Bar\"" - * - * PostgreSQL etc. - * Table(foo) vs. "Foo" => null - * Table(bar) vs. "Foo" => "bar" - * Table(Foo) vs. "Foo" => "\"Foo\"" - * Table(Bar) vs. "Foo" => "\"Bar\"" - * - * SQL Server etc. - * Table(Foo) vs. "Foo" => null - * Table(foo) vs. "Foo" => "foo" - * Table(bar) vs. "Foo" => "bar" - * Table(Bar) vs. "Foo" => "Bar" - */ - public String getIdentifier(String defaultName) { - return this.getDatabase().convertNameToIdentifier(this.getName(), defaultName); - } - - /** - * Examples: - * Oracle etc. - * Table(FOO) => "FOO" - * Table(Foo) => "\"Foo\"" - * Table(foo) => "\"foo\"" - * Table(foo++) => "\"foo++\"" - * Table(f"o) => "\"f\"\"o++\"" (i.e. "f""o") - * - * PostgreSQL etc. - * Table(FOO) => "\"FOO\"" - * Table(Foo) => "\"Foo\"" - * Table(foo) => "foo" - * Table(foo++) => "\"foo++\"" - * Table(f"o) => "\"f\"\"o++\"" (i.e. "f""o") - * - * SQL Server etc. - * Table(FOO) => "FOO" - * Table(Foo) => "Foo" - * Table(foo) => "foo" - * Table(foo++) => "\"foo++\"" - * Table(f"o) => "\"f\"\"o++\"" (i.e. "f""o") - */ - public String getIdentifier() { - return this.getDatabase().convertNameToIdentifier(this.getName()); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } - - - // ********** listening to DTP database object ********** - - // this should only be called when the connection profile is "live" and has listeners - void startListening() { - this.checkListener(); - RefreshManager.getInstance().AddListener(this.catalogObject, this.catalogObjectListener); - } - - // this should only be called when the connection profile is "live" and has no listeners - void stopListening() { - this.checkListener(); - RefreshManager.getInstance().removeListener(this.catalogObject, this.catalogObjectListener); - } - - private void checkListener() { - if (this.catalogObjectListener == null) { - throw new IllegalStateException("the catalog listener is null"); //$NON-NLS-1$ - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java deleted file mode 100644 index cfd8b8f134..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java +++ /dev/null @@ -1,401 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition; -import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.DatabaseObject; -import org.eclipse.jpt.db.internal.vendor.Vendor; -import org.eclipse.jpt.db.internal.vendor.VendorRepository; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -import com.ibm.icu.text.Collator; - -/** - * Wrap a DTP Database. - * - * Catalogs vs. Schemata: - * Typically, if a DTP database does not support "catalogs", - * o.e.datatools.modelbase.sql.schema.Database#getCatalogs() will return a - * single catalog without a name (actually, it's an empty string). This catalog - * will contain all the database's schemata. We try to ignore this catalog and - * return the schemata from the database directly. - * - * Catalog Note 1: - * As of Jan 2009, the DTP MySQL driver is not consistent with this pattern. - * A DTP MySQL database has *no* catalogs; it holds a single schema - * directly, and that schema has the same name as the database. See bug 249013. - * - * Catalog Note 2: - * As of Jan 2009, the PostgreSQL JDBC driver complicates this pattern a bit. - * Even though PostgreSQL does not support "catalogs", its JDBC driver - * returns a single catalog that has the same name as the database specified - * in the JDBC connection URL. The DTP PostgreSQL driver simply replicates this - * behavior. Unfortunately, this catalog can be unnamed; i.e. its name is an - * empty string.... - * - * (Yet Another) Note: - * We use "name" when dealing with the unmodified name of a database object - * as supplied by the database itself (i.e. it is not delimited and it is always - * case-sensitive). - * We use "identifier" when dealing with a string representation of a database - * object name (i.e. it may be delimited and, depending on the vendor, it may - * be case-insensitive). - */ -final class DTPDatabaseWrapper - extends DTPSchemaContainerWrapper - implements Database -{ - // the wrapped DTP database - private final org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase; - - // vendor-specific behavior - private final Vendor vendor; - - // lazy-initialized, sorted - private DTPCatalogWrapper[] catalogs; - - - // ********** constructor ********** - - DTPDatabaseWrapper(DTPConnectionProfileWrapper connectionProfile, org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase) { - super(connectionProfile, dtpDatabase); - this.dtpDatabase = dtpDatabase; - this.vendor = VendorRepository.instance().getVendor(this.getVendorName()); - } - - - // ********** DTPWrapper implementation ********** - - /* TODO - * We might want to listen to the "virtual" catalog; but that's probably - * not necessary since there is no easy way for the user to refresh it - * (i.e. it is not displayed in the DTP UI). - */ - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().databaseChanged(this); - } - - @Override - public DTPDatabaseWrapper getDatabase() { - return this; - } - - - // ********** DTPSchemaContainerWrapper implementation ********** - - @Override - List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemata() { - return this.vendor.getSchemas(this.dtpDatabase); - } - - @Override - DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - return this.getSchema_(dtpSchema); - } - - DTPSchemaWrapper getSchemaFromCatalogs(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - return this.getCatalog(dtpSchema.getCatalog()).getSchema_(dtpSchema); - } - - /** - * this is only called from a schema when the database is the schema - * container, so we know we don't have any catalogs - */ - @Override - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.getTable_(dtpTable); - } - - /** - * this is only called from a catalog, so we know we have catalogs; - * i.e. the search has to descend through catalogs, then to schemata - */ - DTPTableWrapper getTableFromCatalogs(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.getCatalog(dtpTable.getSchema().getCatalog()).getTable_(dtpTable); - } - - /** - * this is only called from a schema when the database is the schema - * container, so we know we don't have any catalogs - */ - @Override - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getColumn_(dtpColumn); - } - - /** - * this is only called from a catalog, so we know we have catalogs; - * i.e. the search has to descend through catalogs, then to schemata - */ - DTPColumnWrapper getColumnFromCatalogs(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getCatalog(dtpColumn.getTable().getSchema().getCatalog()).getColumn_(dtpColumn); - } - - - // ********** DatabaseObject implementation ********** - - public String getName() { - return this.dtpDatabase.getName(); - } - - - // ********** Database implementation ********** - - public String getVendorName() { - return this.dtpDatabase.getVendor(); - } - - public String getVersion() { - return this.dtpDatabase.getVersion(); - } - - // override to make method public since it's in the Database interface - @Override - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - return super.selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - - // ***** catalogs - - public boolean supportsCatalogs() { - return this.vendor.supportsCatalogs(this.dtpDatabase); - } - - public Iterator<Catalog> catalogs() { - return new ArrayIterator<Catalog>(this.getCatalogs()); - } - - private Iterator<DTPCatalogWrapper> catalogWrappers() { - return new ArrayIterator<DTPCatalogWrapper>(this.getCatalogs()); - } - - private synchronized DTPCatalogWrapper[] getCatalogs() { - if (this.catalogs == null) { - this.catalogs = this.buildCatalogs(); - } - return this.catalogs; - } - - private DTPCatalogWrapper[] buildCatalogs() { - List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs = this.getDTPCatalogs(); - 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, this.buildCatalogComparator()); - } - - private Comparator<Catalog> buildCatalogComparator() { - return new Comparator<Catalog>() { - public int compare(Catalog catalog1, Catalog catalog2) { - return Collator.getInstance().compare(catalog1.getName(), catalog2.getName()); - } - }; - } - - private List<org.eclipse.datatools.modelbase.sql.schema.Catalog> getDTPCatalogs() { - return this.vendor.getCatalogs(this.dtpDatabase); - } - - public int catalogsSize() { - return this.getCatalogs().length; - } - - /** - * return the catalog for the specified DTP catalog - */ - DTPCatalogWrapper getCatalog(org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) { - for (DTPCatalogWrapper catalog : this.getCatalogs()) { - if (catalog.wraps(dtpCatalog)) { - return catalog; - } - } - throw new IllegalArgumentException("invalid DTP catalog: " + dtpCatalog); //$NON-NLS-1$ - } - - public Iterator<String> sortedCatalogNames() { - // the catalogs are already sorted - return new TransformationIterator<DTPCatalogWrapper, String>(this.catalogWrappers()) { - @Override - protected String transform(DTPCatalogWrapper next) { - return next.getName(); - } - }; - } - - public DTPCatalogWrapper getCatalogNamed(String name) { - return this.selectDatabaseObjectNamed(this.getCatalogs(), name); - } - - public Iterator<String> sortedCatalogIdentifiers() { - // the catalogs are already sorted - return new TransformationIterator<DTPCatalogWrapper, String>(this.catalogWrappers()) { - @Override - protected String transform(DTPCatalogWrapper next) { - return next.getIdentifier(); - } - }; - } - - public DTPCatalogWrapper getCatalogForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getCatalogs(), identifier); - } - - public synchronized DTPCatalogWrapper getDefaultCatalog() { - return this.getCatalogForIdentifiers(this.getDefaultCatalogIdentifiers()); - } - - private List<String> getDefaultCatalogIdentifiers() { - return this.vendor.getDefaultCatalogIdentifiers(this.dtpDatabase, this.getConnectionProfile().getUserName()); - } - - /** - * Return the first catalog found. - */ - private DTPCatalogWrapper getCatalogForIdentifiers(List<String> identifiers) { - for (String identifier : identifiers) { - DTPCatalogWrapper catalog = this.getCatalogForIdentifier(identifier); - if (catalog != null) { - return catalog; - } - } - return null; - } - - /** - * If we find a default catalog, return its identifier; - * otherwise, return the last identifier on the list of default identifiers. - * (Some databases have multiple possible default names.) - * Return null if the database does not support catalogs. - */ - public synchronized String getDefaultCatalogIdentifier() { - DTPCatalogWrapper catalog = this.getDefaultCatalog(); - return (catalog != null) ? catalog.getIdentifier() : this.getDefaultCatalogIdentifier_(); - } - - private String getDefaultCatalogIdentifier_() { - List<String> identifiers = this.getDefaultCatalogIdentifiers(); - return identifiers.isEmpty() ? null : identifiers.get(identifiers.size() - 1); - } - - // ***** schemata - - List<String> getDefaultSchemaIdentifiers() { - return this.vendor.getDefaultSchemaIdentifiers(this.dtpDatabase, this.getConnectionProfile().getUserName()); - } - - - // ********** names vs. identifiers ********** - - /** - * Convert the specified name to an identifier. Return null if the resulting - * identifier matches the specified default name. - */ - String convertNameToIdentifier(String name, String defaultName) { - return this.vendor.convertNameToIdentifier(name, defaultName); - } - - /** - * Convert the specified name to an identifier. - */ - public String convertNameToIdentifier(String name) { - return this.vendor.convertNameToIdentifier(name); - } - - /** - * Return the database object identified by the specified identifier. If - * the identifier is "delimited" (typically with double-quotes), it will be - * used without any folding. If the name is "normal" (i.e. not delimited), - * it will be folded to the appropriate case (typically uppercase). - * - * Since the database has the appropriate state to compare identifiers and - * names, the connection profile delegates to here when using the default - * "database finder". - */ - <T extends DatabaseObject> T selectDatabaseObjectForIdentifier_(T[] databaseObjects, String identifier) { - return this.selectDatabaseObjectNamed(databaseObjects, this.convertIdentifierToName(identifier)); - } - - /** - * Convert the specified identifier to a name. - */ - String convertIdentifierToName(String identifier) { - return this.vendor.convertIdentifierToName(identifier); - } - - - // ********** internal methods ********** - - DatabaseDefinition getDTPDefinition() { - return RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(this.dtpDatabase); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.catalogs != null) { - this.startCatalogs(); - } - super.startListening(); - } - - private void startCatalogs() { - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.catalogs != null) { - this.stopCatalogs(); - } - super.stopListening(); - } - - private void stopCatalogs() { - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.stopListening(); - } - } - - - // ********** clear ********** - - @Override - synchronized void clear() { - if (this.catalogs != null) { - this.clearCatalogs(); - } - super.clear(); - } - - private void clearCatalogs() { - this.stopCatalogs(); - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.clear(); - } - this.catalogs = null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java deleted file mode 100644 index 43be1d33d9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java +++ /dev/null @@ -1,340 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Arrays; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -import com.ibm.icu.text.Collator; - -/** - * Wrap a DTP ForeignKey - */ -final class DTPForeignKeyWrapper - extends DTPDatabaseObjectWrapper - implements ForeignKey -{ - // the wrapped DTP foreign key - private final org.eclipse.datatools.modelbase.sql.constraints.ForeignKey dtpForeignKey; - - // lazy-initialized - private DTPTableWrapper referencedTable; - - // lazy-initialized - private LocalColumnPair[] columnPairs; - - // lazy-initialized - but it can be 'null' so we use a flag - private String defaultAttributeName; - private boolean defaultAttributeNameCalculated = false; - - - // ********** constructor ********** - - DTPForeignKeyWrapper(DTPTableWrapper baseTable, org.eclipse.datatools.modelbase.sql.constraints.ForeignKey dtpForeignKey) { - super(baseTable, dtpForeignKey); - this.dtpForeignKey = dtpForeignKey; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().foreignKeyChanged(this); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName() + ": " + Arrays.asList(this.getColumnPairs())); //$NON-NLS-1$ - } - - - // ********** ForeignKey implementation ********** - - public String getName() { - return this.dtpForeignKey.getName(); - } - - public DTPTableWrapper getBaseTable() { - return (DTPTableWrapper) this.getParent(); - } - - public synchronized DTPTableWrapper getReferencedTable() { - if (this.referencedTable == null) { - this.referencedTable = this.getBaseTable().getTable(this.dtpForeignKey.getUniqueConstraint().getBaseTable()); - } - return this.referencedTable; - } - - public boolean referencesSingleColumnPrimaryKey() { - if (this.columnPairsSize() != 1) { - return false; - } - if (this.getReferencedTable().primaryKeyColumnsSize() != 1) { - return false; - } - return this.getColumnPair().getReferencedColumn() == this.getReferencedTable().getPrimaryKeyColumn(); - } - - // ***** column pairs - - public Iterator<ColumnPair> columnPairs() { - return new ArrayIterator<ColumnPair>(this.getColumnPairs()); - } - - public LocalColumnPair getColumnPair() { - LocalColumnPair[] pairs = this.getColumnPairs(); - if (pairs.length != 1) { - throw new IllegalStateException("multiple column pairs: " + pairs.length); //$NON-NLS-1$ - } - return pairs[0]; - } - - private Iterator<LocalColumnPair> localColumnPairs() { - return new ArrayIterator<LocalColumnPair>(this.getColumnPairs()); - } - - private synchronized LocalColumnPair[] getColumnPairs() { - if (this.columnPairs == null) { - this.columnPairs = this.buildColumnPairs(); - } - return this.columnPairs; - } - - private LocalColumnPair[] buildColumnPairs() { - List<org.eclipse.datatools.modelbase.sql.tables.Column> baseColumns = this.getDTPBaseColumns(); - int size = baseColumns.size(); - List<org.eclipse.datatools.modelbase.sql.tables.Column> refColumns = this.getDTPReferenceColumns(); - if (refColumns.size() != size) { - throw new IllegalStateException(this.getBaseTable().getName() + '.' + this.getName() + - " - mismatched sizes: " + size + " vs. " + refColumns.size()); //$NON-NLS-1$ //$NON-NLS-2$ - } - LocalColumnPair[] result = new LocalColumnPair[baseColumns.size()]; - for (int i = baseColumns.size(); i-- > 0; ) { - result[i] = new LocalColumnPair( - this.getBaseTable().getColumn(baseColumns.get(i)), - this.getBaseTable().getColumn(refColumns.get(i)) - ); - } - return ArrayTools.sort(result, this.buildColumnPairComparator()); - } - - private Comparator<ColumnPair> buildColumnPairComparator() { - return new Comparator<ColumnPair>() { - public int compare(ColumnPair columnPair1, ColumnPair columnPair2) { - return Collator.getInstance().compare(columnPair1.getBaseColumn().getName(), columnPair2.getBaseColumn().getName()); - } - }; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPBaseColumns() { - return this.dtpForeignKey.getMembers(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPReferenceColumns() { - return this.dtpForeignKey.getUniqueConstraint().getMembers(); - } - - public int columnPairsSize() { - return this.getColumnPairs().length; - } - - public Iterator<Column> baseColumns() { - return new TransformationIterator<LocalColumnPair, Column>(this.localColumnPairs()) { - @Override - protected Column transform(LocalColumnPair pair) { - return pair.getBaseColumn(); - } - }; - } - - boolean baseColumnsContains(Column column) { - return CollectionTools.contains(this.baseColumns(), column); - } - - public Iterator<Column> nonPrimaryKeyBaseColumns() { - return new FilteringIterator<Column, Column>(this.baseColumns()) { - @Override - protected boolean accept(Column column) { - return ! column.isPartOfPrimaryKey(); - } - }; - } - - public Iterator<Column> referencedColumns() { - return new TransformationIterator<LocalColumnPair, Column>(this.localColumnPairs()) { - @Override - protected Column transform(LocalColumnPair columnPair) { - return columnPair.getReferencedColumn(); - } - }; - } - - // ***** attribute name - - public String getAttributeName() { - String defaultName = this.getDefaultAttributeName(); - return (defaultName != null) ? defaultName : this.getNonDefaultAttributeName(); - } - - public synchronized String getDefaultAttributeName() { - if ( ! this.defaultAttributeNameCalculated) { - this.defaultAttributeNameCalculated = true; - this.defaultAttributeName = this.buildDefaultAttributeName(); - } - return this.defaultAttributeName; - } - - private String buildDefaultAttributeName() { - if ( ! this.referencesSingleColumnPrimaryKey()) { - return null; - } - LocalColumnPair columnPair = this.getColumnPair(); - String baseColName = columnPair.getBaseColumn().getName(); - String refColName = columnPair.getReferencedColumn().getName(); - if (baseColName.length() <= (refColName.length() + 1)) { - return null; - } - if ( ! baseColName.endsWith(refColName)) { - return null; - } - int _index = baseColName.length() - refColName.length() - 1; - if (baseColName.charAt(_index) != '_') { - return null; - } - return baseColName.substring(0, _index); - } - - /** - * If this is a simple (single-column) foreign key, use the name of the - * single base column to build a name. If this is a compound foreign key, - * return the name of the referenced table. - */ - // TODO if there is only one FK to a given table, use the table's name instead of the column's name? - private String getNonDefaultAttributeName() { - return (this.columnPairsSize() == 1) ? - this.getNonDefaultAttributeNameFromBaseColumn() - : - this.getReferencedTable().getName(); - } - - /** - * The underscore check is helpful when the referenced column is NOT the - * primary key of the referenced table (i.e. it has only a UNIQUE constraint). - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * ForeignKey(EMP.CUBICLEID => CUBICLE.ID) => "CUBICLE" - * ForeignKey(EMP.CUBICLE_PK => CUBICLE.ID) => "CUBICLE_PK" - */ - private String getNonDefaultAttributeNameFromBaseColumn() { - LocalColumnPair columnPair = this.getColumnPair(); - String baseColName = columnPair.getBaseColumn().getName(); - String refColName = columnPair.getReferencedColumn().getName(); - int len = baseColName.length(); - int refLen = refColName.length(); - if ((len > refLen) && baseColName.endsWith(refColName)) { - len = len - refLen; - if ((len > 1) && baseColName.charAt(len - 1) == '_') { - len = len - 1; - } - } - return baseColName.substring(0, len); - } - - /** - * Examples: - * Oracle etc. - * ForeignKey(FOO_ID => ID) vs. "foo" => null - * ForeignKey(FOO_ID => FOO_ID) vs. "foo" => "FOO_ID" - * ForeignKey(FOO => ID) vs. "foo" => "FOO" - * ForeignKey(Foo_ID => ID) vs. "foo" => "\"Foo_ID\"" - * - * PostgreSQL etc. - * ForeignKey(foo_id => id) vs. "foo" => null - * ForeignKey(foo_id => foo_id) vs. "foo" => "foo_id" - * ForeignKey(foo => id) vs. "foo" => "foo" - * ForeignKey(Foo_ID => ID) vs. "foo" => "\"Foo_ID\"" - * - * SQL Server etc. - * ForeignKey(foo_ID => ID) vs. "foo" => null - * ForeignKey(FOO_ID => FOO_ID) vs. "foo" => "FOO_ID" - * ForeignKey(FOO => ID) vs. "foo" => "FOO" - * ForeignKey(Foo_ID => ID) vs. "foo" => "Foo_ID" - */ - public String getJoinColumnAnnotationIdentifier(String attributeName) { - String baseColumnName = this.getColumnPair().getBaseColumn().getName(); - String defaultBaseColumnName = attributeName + '_' + this.getReferencedTable().getPrimaryKeyColumn().getName(); - return this.getDatabase().convertNameToIdentifier(baseColumnName, defaultBaseColumnName); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.constraints.ForeignKey foreignKey) { - return this.dtpForeignKey == foreignKey; - } - - @Override - synchronized void clear() { - // the foreign key does not "contain" any other objects, - // so we don't need to forward the #clear() - this.defaultAttributeNameCalculated = false; - this.defaultAttributeName = null; - this.columnPairs = null; - this.referencedTable = null; - } - - - // ********** column pair implementation ********** - - static class LocalColumnPair implements ColumnPair { - private final DTPColumnWrapper baseColumn; - private final DTPColumnWrapper referencedColumn; - - LocalColumnPair(DTPColumnWrapper baseColumn, DTPColumnWrapper referencedColumn) { - super(); - if ((baseColumn == null) || (referencedColumn == null)) { - throw new NullPointerException(); - } - this.baseColumn = baseColumn; - this.referencedColumn = referencedColumn; - } - - public DTPColumnWrapper getBaseColumn() { - return this.baseColumn; - } - - public DTPColumnWrapper getReferencedColumn() { - return this.referencedColumn; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.baseColumn.getName() + "=>" + this.referencedColumn.getName()); //$NON-NLS-1$ - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java deleted file mode 100644 index ab361c7c12..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -import com.ibm.icu.text.Collator; - -/** - * Coalesce behavior for a schema container (i.e. database or catalog). - */ -abstract class DTPSchemaContainerWrapper - extends DTPDatabaseObjectWrapper - implements SchemaContainer -{ - // lazy-initialized - private DTPSchemaWrapper[] schemata; - - - // ********** constructor ********** - - DTPSchemaContainerWrapper(DTPDatabaseObject parent, Object dtpSchemaContainer) { - super(parent, dtpSchemaContainer); - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - } - - - // ********** abstract methods ********** - - /** - * return the schema container's DTP schemata - */ - abstract List<org.eclipse.datatools.modelbase.sql.schema.Schema> getDTPSchemata(); - - /** - * return the schema for the specified DTP schema - */ - abstract DTPSchemaWrapper getSchema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema); - - /** - * assume the schema container (database or catalog) contains - * the specified schema - */ - DTPSchemaWrapper getSchema_(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - for (DTPSchemaWrapper schema : this.getSchemata()) { - if (schema.wraps(dtpSchema)) { - return schema; - } - } - throw new IllegalArgumentException("invalid DTP schema: " + dtpSchema); //$NON-NLS-1$ - } - - /** - * return the table for the specified DTP table; - * this is only called from a schema (to its container) - */ - abstract DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable); - - /** - * assume the schema container contains the specified table - */ - DTPTableWrapper getTable_(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.getSchema_(dtpTable.getSchema()).getTable_(dtpTable); - } - - /** - * return the column for the specified DTP column; - * this is only called from a schema (to its container) - */ - abstract DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn); - - /** - * assume the schema container contains the specified column - */ - DTPColumnWrapper getColumn_(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getTable_(dtpColumn.getTable()).getColumn_(dtpColumn); - } - - - // ********** schemata ********** - - public Iterator<Schema> schemata() { - return new ArrayIterator<Schema>(this.getSchemata()); - } - - Iterator<DTPSchemaWrapper> schemaWrappers() { - return new ArrayIterator<DTPSchemaWrapper>(this.getSchemata()); - } - - synchronized DTPSchemaWrapper[] getSchemata() { - if (this.schemata == null) { - this.schemata = this.buildSchemata(); - } - return this.schemata; - } - - private DTPSchemaWrapper[] buildSchemata() { - List<org.eclipse.datatools.modelbase.sql.schema.Schema> dtpSchemata = this.getDTPSchemata(); - DTPSchemaWrapper[] result = new DTPSchemaWrapper[dtpSchemata.size()]; - for (int i = result.length; i-- > 0; ) { - result[i] = new DTPSchemaWrapper(this, dtpSchemata.get(i)); - } - return ArrayTools.sort(result, this.buildSchemaComparator()); - } - - private Comparator<Schema> buildSchemaComparator() { - return new Comparator<Schema>() { - public int compare(Schema schema1, Schema schema2) { - return Collator.getInstance().compare(schema1.getName(), schema2.getName()); - } - }; - } - - public int schemataSize() { - return this.getSchemata().length; - } - - public Iterator<String> sortedSchemaNames() { - // the schemata are already sorted - return new TransformationIterator<DTPSchemaWrapper, String>(this.schemaWrappers()) { - @Override - protected String transform(DTPSchemaWrapper next) { - return next.getName(); - } - }; - } - - public DTPSchemaWrapper getSchemaNamed(String name) { - return this.selectDatabaseObjectNamed(this.getSchemata(), name); - } - - public Iterator<String> sortedSchemaIdentifiers() { - // the schemata are already sorted - return new TransformationIterator<DTPSchemaWrapper, String>(this.schemaWrappers()) { - @Override - protected String transform(DTPSchemaWrapper next) { - return next.getIdentifier(); - } - }; - } - - public DTPSchemaWrapper getSchemaForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getSchemata(), identifier); - } - - public DTPSchemaWrapper getDefaultSchema() { - return this.getSchemaForIdentifiers(this.getDatabase().getDefaultSchemaIdentifiers()); - } - - /** - * Return the first schema found. - */ - DTPSchemaWrapper getSchemaForIdentifiers(List<String> identifiers) { - for (String identifier : identifiers) { - DTPSchemaWrapper schema = this.getSchemaForIdentifier(identifier); - if (schema != null) { - return schema; - } - } - return null; - } - - /** - * If we find a default schema, return its identifier; - * otherwise, return the last identifier on the list of default identifiers. - * (Some containers have multiple possible default names.) - */ - public synchronized String getDefaultSchemaIdentifier() { - DTPSchemaWrapper schema = this.getDefaultSchema(); - return (schema != null) ? schema.getIdentifier() : this.getDefaultSchemaIdentifier_(); - } - - private String getDefaultSchemaIdentifier_() { - List<String> identifiers = this.getDatabase().getDefaultSchemaIdentifiers(); - // assume 'identifiers' is non-empty (!) - return identifiers.get(identifiers.size() - 1); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.schemata != null) { - this.startSchemata(); - } - super.startListening(); - } - - private void startSchemata() { - for (DTPSchemaWrapper schema : this.schemata) { - schema.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.schemata != null) { - this.stopSchemata(); - } - super.stopListening(); - } - - private void stopSchemata() { - for (DTPSchemaWrapper schema : this.schemata) { - schema.stopListening(); - } - } - - - // ********** clear ********** - - @Override - synchronized void clear() { - if (this.schemata != null) { - this.clearSchemata(); - } - } - - private void clearSchemata() { - this.stopSchemata(); - for (DTPSchemaWrapper schema : this.schemata) { - schema.clear(); - } - this.schemata = null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java deleted file mode 100644 index 11f90e55c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.datatools.modelbase.sql.tables.SQLTablesPackage; - -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Sequence; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -import com.ibm.icu.text.Collator; - -/** - * Wrap a DTP Schema - */ -final class DTPSchemaWrapper - extends DTPDatabaseObjectWrapper - implements Schema -{ - // the wrapped DTP schema - private final org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema; - - // lazy-initialized - private DTPTableWrapper[] tables; - - // lazy-initialized - private DTPSequenceWrapper[] sequences; - - - // ********** constants ********** - - //used for adopter product customization - private static final String PERSISTENT_AND_VIEW_TABLES_ONLY = "supportPersistentAndViewTablesOnly"; - - - // ********** constructor ********** - - DTPSchemaWrapper(DTPSchemaContainerWrapper container, org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - super(container, dtpSchema); - this.dtpSchema = dtpSchema; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().schemaChanged(this); - } - - - // ********** Schema implementation ********** - - public String getName() { - return this.dtpSchema.getName(); - } - - public DTPSchemaContainerWrapper getContainer() { - return (DTPSchemaContainerWrapper) this.getParent(); - } - - // ***** tables - - public Iterator<Table> tables() { - return new ArrayIterator<Table>(this.getTables()); - } - - private Iterator<DTPTableWrapper> tableWrappers() { - return new ArrayIterator<DTPTableWrapper>(this.getTables()); - } - - private synchronized DTPTableWrapper[] getTables() { - if (this.tables == null) { - this.tables = this.buildTables(); - } - return this.tables; - } - - private DTPTableWrapper[] buildTables() { - List<org.eclipse.datatools.modelbase.sql.tables.Table> dtpTables = this.getDTPTables(); - DTPTableWrapper[] result = new DTPTableWrapper[dtpTables.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPTableWrapper(this, dtpTables.get(i)); - } - return ArrayTools.sort(result, this.buildTableComparator()); - } - - private Comparator<Table> buildTableComparator() { - return new Comparator<Table>() { - public int compare(Table table1, Table table2) { - return Collator.getInstance().compare(table1.getName(), table2.getName()); - } - }; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Table> getDTPTables() { - - //if product customization flag is set to true return only persistent and view tables. - //this will filter out synonyms where they are not fully supported and potentially other - //problematic table types - see bug 269057 - String supportPersistentAndViewTablesOnly = Platform.getProduct().getProperty(PERSISTENT_AND_VIEW_TABLES_ONLY); - if ( supportPersistentAndViewTablesOnly != null && supportPersistentAndViewTablesOnly.equals("true") ) { - List<org.eclipse.datatools.modelbase.sql.tables.Table> result = - new ArrayList<org.eclipse.datatools.modelbase.sql.tables.Table>(); - for (Iterator iterT = this.dtpSchema.getTables().iterator();iterT.hasNext();) { - org.eclipse.datatools.modelbase.sql.tables.Table table - = (org.eclipse.datatools.modelbase.sql.tables.Table) iterT.next(); - if (SQLTablesPackage.eINSTANCE.getPersistentTable().isSuperTypeOf(table.eClass()) || - SQLTablesPackage.eINSTANCE.getViewTable().isSuperTypeOf(table.eClass()) ) { - result.add(table); - } - } - return result; - } - else { - return this.dtpSchema.getTables(); - } - } - - public int tablesSize() { - return this.getTables().length; - } - - /** - * return the table for the specified DTP table - */ - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - // try to short-circuit the search - return this.wraps(dtpTable.getSchema()) ? - this.getTable_(dtpTable) - : - this.getContainer().getTable(dtpTable); - } - - /** - * assume the schema contains the specified table - */ - DTPTableWrapper getTable_(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - for (DTPTableWrapper table : this.getTables()) { - if (table.wraps(dtpTable)) { - return table; - } - } - throw new IllegalArgumentException("invalid DTP table: " + dtpTable); //$NON-NLS-1$ - } - - public DTPTableWrapper getTableNamed(String name) { - return this.selectDatabaseObjectNamed(this.getTables(), name); - } - - public Iterator<String> sortedTableIdentifiers() { - // the tables are already sorted - return new TransformationIterator<DTPTableWrapper, String>(this.tableWrappers()) { - @Override - protected String transform(DTPTableWrapper table) { - return table.getIdentifier(); - } - }; - } - - public DTPTableWrapper getTableForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getTables(), identifier); - } - - // ***** sequences - - public Iterator<Sequence> sequences() { - return new ArrayIterator<Sequence>(this.getSequences()); - } - - private Iterator<DTPSequenceWrapper> sequenceWrappers() { - return new ArrayIterator<DTPSequenceWrapper>(this.getSequences()); - } - - private synchronized DTPSequenceWrapper[] getSequences() { - if (this.sequences == null) { - this.sequences = this.buildSequences(); - } - return this.sequences; - } - - private DTPSequenceWrapper[] buildSequences() { - List<org.eclipse.datatools.modelbase.sql.schema.Sequence> dtpSequences = this.getDTPSequences(); - DTPSequenceWrapper[] result = new DTPSequenceWrapper[dtpSequences.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPSequenceWrapper(this, dtpSequences.get(i)); - } - return ArrayTools.sort(result, this.buildSequenceComparator()); - } - - private Comparator<Sequence> buildSequenceComparator() { - return new Comparator<Sequence>() { - public int compare(Sequence sequence1, Sequence sequence2) { - return Collator.getInstance().compare(sequence1.getName(), sequence2.getName()); - } - }; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.schema.Sequence> getDTPSequences() { - return this.dtpSchema.getSequences(); - } - - public int sequencesSize() { - return this.getSequences().length; - } - - public DTPSequenceWrapper getSequenceNamed(String name) { - return this.selectDatabaseObjectNamed(this.getSequences(), name); - } - - public Iterator<String> sortedSequenceIdentifiers() { - // the sequences are already sorted - return new TransformationIterator<DTPSequenceWrapper, String>(this.sequenceWrappers()) { - @Override - protected String transform(DTPSequenceWrapper sequence) { - return sequence.getIdentifier(); - } - }; - } - - public DTPSequenceWrapper getSequenceForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getSequences(), identifier); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Schema schema) { - return this.dtpSchema == schema; - } - - /** - * return the column for the specified DTP column - */ - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - // try to short-circuit the search - return this.wraps(dtpColumn.getTable().getSchema()) ? - this.getColumn_(dtpColumn) - : - this.getContainer().getColumn(dtpColumn); - } - - /** - * assume the schema contains the specified column - */ - DTPColumnWrapper getColumn_(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.getTable_(dtpColumn.getTable()).getColumn_(dtpColumn); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.sequences != null) { - this.startSequences(); - } - if (this.tables != null) { - this.startTables(); - } - super.startListening(); - } - - private void startSequences() { - for (DTPSequenceWrapper sequence : this.sequences) { - sequence.startListening(); - } - } - - private void startTables() { - for (DTPTableWrapper table : this.tables) { - table.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.sequences != null) { - this.stopSequences(); - } - if (this.tables != null) { - this.stopTables(); - } - super.stopListening(); - } - - private void stopSequences() { - for (DTPSequenceWrapper sequence : this.sequences) { - sequence.stopListening(); - } - } - - private void stopTables() { - for (DTPTableWrapper table : this.tables) { - table.stopListening(); - } - } - - - // ********** clear ********** - - @Override - synchronized void clear() { - if (this.sequences != null) { - this.clearSequences(); - } - if (this.tables != null) { - this.clearTables(); - } - } - - private void clearSequences() { - this.stopSequences(); - for (DTPSequenceWrapper sequence : this.sequences) { - sequence.clear(); - } - this.sequences = null; - } - - private void clearTables() { - this.stopTables(); - for (DTPTableWrapper table : this.tables) { - table.clear(); - } - this.tables = null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java deleted file mode 100644 index fc8848f1b9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.jpt.db.Sequence; - -/** - * Wrap a DTP Sequence - */ -final class DTPSequenceWrapper - extends DTPDatabaseObjectWrapper - implements Sequence -{ - // the wrapped DTP sequence - private final org.eclipse.datatools.modelbase.sql.schema.Sequence dtpSequence; - - - // ********** constructor ********** - - DTPSequenceWrapper(DTPSchemaWrapper schema, org.eclipse.datatools.modelbase.sql.schema.Sequence dtpSequence) { - super(schema, dtpSequence); - this.dtpSequence = dtpSequence; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().sequenceChanged(this); - } - - - // ********** Sequence implementation ********** - - public String getName() { - return this.dtpSequence.getName(); - } - - public DTPSchemaWrapper getSchema() { - return (DTPSchemaWrapper) this.getParent(); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Sequence sequence) { - return this.dtpSequence == sequence; - } - - @Override - void clear() { - // no state to clear - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java deleted file mode 100644 index 4c4e0f0702..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java +++ /dev/null @@ -1,424 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.constraints.PrimaryKey; -import org.eclipse.datatools.modelbase.sql.tables.BaseTable; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -import com.ibm.icu.text.Collator; - -/** - * Wrap a DTP Table - */ -final class DTPTableWrapper - extends DTPDatabaseObjectWrapper - implements Table -{ - // the wrapped DTP table - private final org.eclipse.datatools.modelbase.sql.tables.Table dtpTable; - - // lazy-initialized - private DTPColumnWrapper[] columns; - - // lazy-initialized - private DTPColumnWrapper[] primaryKeyColumns; - - // lazy-initialized - private DTPForeignKeyWrapper[] foreignKeys; - - - private static final DTPColumnWrapper[] EMPTY_COLUMNS = new DTPColumnWrapper[0]; - private static final DTPForeignKeyWrapper[] EMPTY_FOREIGN_KEYS = new DTPForeignKeyWrapper[0]; - - - // ********** constructor ********** - - DTPTableWrapper(DTPSchemaWrapper schema, org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - super(schema, dtpTable); - this.dtpTable = dtpTable; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged() { - super.catalogObjectChanged(); - this.getConnectionProfile().tableChanged(this); - } - - - // ********** Table implementation ********** - - public String getName() { - return this.dtpTable.getName(); - } - - public DTPSchemaWrapper getSchema() { - return (DTPSchemaWrapper) this.getParent(); - } - - // ***** columns - - public Iterator<Column> columns() { - return new ArrayIterator<Column>(this.getColumns()); - } - - private Iterator<DTPColumnWrapper> columnWrappers() { - return new ArrayIterator<DTPColumnWrapper>(this.getColumns()); - } - - private synchronized DTPColumnWrapper[] getColumns() { - if (this.columns == null) { - this.columns = this.buildColumns(); - } - return this.columns; - } - - private DTPColumnWrapper[] buildColumns() { - List<org.eclipse.datatools.modelbase.sql.tables.Column> dtpColumns = this.getDTPColumns(); - DTPColumnWrapper[] result = new DTPColumnWrapper[dtpColumns.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPColumnWrapper(this, dtpColumns.get(i)); - } - return ArrayTools.sort(result, this.buildColumnComparator()); - } - - private Comparator<Column> buildColumnComparator() { - return new Comparator<Column>() { - public int compare(Column column1, Column column2) { - return Collator.getInstance().compare(column1.getName(), column2.getName()); - } - }; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getDTPColumns() { - return this.dtpTable.getColumns(); - } - - public int columnsSize() { - return this.getColumns().length; - } - - public DTPColumnWrapper getColumnNamed(String name) { - return this.selectDatabaseObjectNamed(this.getColumns(), name); - } - - /** - * return the column for the specified DTP column - */ - DTPColumnWrapper getColumn(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - // try to short-circuit the search - return this.wraps(dtpColumn.getTable()) ? - this.getColumn_(dtpColumn) - : - this.getSchema().getColumn(dtpColumn); - } - - /** - * assume the table contains the specified column - */ - DTPColumnWrapper getColumn_(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - for (DTPColumnWrapper column : this.getColumns()) { - if (column.wraps(dtpColumn)) { - return column; - } - } - throw new IllegalArgumentException("invalid DTP column: " + dtpColumn); //$NON-NLS-1$ - } - - public Iterator<String> sortedColumnIdentifiers() { - // the columns are already sorted - return new TransformationIterator<DTPColumnWrapper, String>(this.columnWrappers()) { - @Override - protected String transform(DTPColumnWrapper next) { - return next.getIdentifier(); - } - }; - } - - public DTPColumnWrapper getColumnForIdentifier(String identifier) { - return this.selectDatabaseObjectForIdentifier(this.getColumns(), identifier); - } - - // ***** primaryKeyColumns - - public Iterator<Column> primaryKeyColumns() { - return new ArrayIterator<Column>(this.getPrimaryKeyColumns()); - } - - public DTPColumnWrapper getPrimaryKeyColumn() { - DTPColumnWrapper[] pkColumns = this.getPrimaryKeyColumns(); - if (pkColumns.length != 1) { - throw new IllegalStateException("multiple primary key columns: " + pkColumns.length); //$NON-NLS-1$ - } - return pkColumns[0]; - } - - private synchronized DTPColumnWrapper[] getPrimaryKeyColumns() { - if (this.primaryKeyColumns == null) { - this.primaryKeyColumns = this.buildPrimaryKeyColumns(); - } - return this.primaryKeyColumns; - } - - private DTPColumnWrapper[] buildPrimaryKeyColumns() { - if ( ! (this.dtpTable instanceof BaseTable)) { - return EMPTY_COLUMNS; - } - PrimaryKey pk = ((BaseTable) this.dtpTable).getPrimaryKey(); - if (pk == null) { - // no PK was defined - return EMPTY_COLUMNS; - } - List<org.eclipse.datatools.modelbase.sql.tables.Column> pkColumns = this.getColumns(pk); - DTPColumnWrapper[] result = new DTPColumnWrapper[pkColumns.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = this.getColumn(pkColumns.get(i)); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> getColumns(PrimaryKey pk) { - return pk.getMembers(); - } - - public int primaryKeyColumnsSize() { - return this.getPrimaryKeyColumns().length; - } - - boolean primaryKeyColumnsContains(Column column) { - return ArrayTools.contains(this.getPrimaryKeyColumns(), column); - } - - // ***** foreignKeys - - public Iterator<ForeignKey> foreignKeys() { - return new ArrayIterator<ForeignKey>(this.getForeignKeys()); - } - - private synchronized DTPForeignKeyWrapper[] getForeignKeys() { - if (this.foreignKeys == null) { - this.foreignKeys = this.buildForeignKeys(); - } - return this.foreignKeys; - } - - private DTPForeignKeyWrapper[] buildForeignKeys() { - if ( ! (this.dtpTable instanceof BaseTable)) { - return EMPTY_FOREIGN_KEYS; - } - List<org.eclipse.datatools.modelbase.sql.constraints.ForeignKey> dtpForeignKeys = this.getDTPForeignKeys(); - DTPForeignKeyWrapper[] result = new DTPForeignKeyWrapper[dtpForeignKeys.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPForeignKeyWrapper(this, dtpForeignKeys.get(i)); - } - return result; - } - - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.constraints.ForeignKey> getDTPForeignKeys() { - return ((BaseTable) this.dtpTable).getForeignKeys(); - } - - public int foreignKeysSize() { - return this.getForeignKeys().length; - } - - /** - * return whether the specified column is a base column for at least one - * of the the table's foreign keys - */ - boolean foreignKeyBaseColumnsContains(Column column) { - for (DTPForeignKeyWrapper fkWrapper : this.getForeignKeys()) { - if (fkWrapper.baseColumnsContains(column)) { - return true; - } - } - return false; - } - - // ***** join table - - public boolean isPossibleJoinTable() { - if (this.getForeignKeys().length != 2) { - return false; // the table must have exactly 2 foreign keys - } - for (Column column : this.getColumns()) { - if ( ! this.foreignKeyBaseColumnsContains(column)) { - return false; // all the table's columns must belong to one (or both) of the 2 foreign keys - } - } - return true; - } - - /** - * If the table name is FOO_BAR and it joins tables FOO and BAR, - * return the foreign key to FOO; - * if the table name is BAR_FOO and it joins tables FOO and BAR, - * return the foreign key to BAR; - * otherwise simply return the first foreign key in the array. - */ - public ForeignKey getJoinTableOwningForeignKey() { - ForeignKey fk0 = this.getForeignKeys()[0]; - String name0 = fk0.getReferencedTable().getName(); - - ForeignKey fk1 = this.getForeignKeys()[1]; - String name1 = fk1.getReferencedTable().getName(); - - return this.getName().equals(name1 + '_' + name0) ? fk1 : fk0; - } - - public ForeignKey getJoinTableNonOwningForeignKey() { - ForeignKey fk0 = this.getForeignKeys()[0]; - ForeignKey fk1 = this.getForeignKeys()[1]; - ForeignKey ofk = this.getJoinTableOwningForeignKey(); - return (ofk == fk0) ? fk1 : fk0; - } - - /** - * Hmmm.... - * We might want to go to the platform to allow a vendor-specific - * comparison here; - * but, since all the names are coming directly from the database - * (i.e. there are no conversions to Java identifiers etc.), it seems - * like we can just compare them directly and ignore case-sensitivity - * issues.... ~bjv - */ - public boolean joinTableNameIsDefault() { - return this.getName().equals(this.buildDefaultJoinTableName()); - } - - private String buildDefaultJoinTableName() { - return this.getJoinTableOwningTable().getName() - + '_' - + this.getJoinTableNonOwningTable().getName(); - } - - private Table getJoinTableOwningTable() { - return this.getJoinTableOwningForeignKey().getReferencedTable(); - } - - private Table getJoinTableNonOwningTable() { - return this.getJoinTableNonOwningForeignKey().getReferencedTable(); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Table table) { - return this.dtpTable == table; - } - - /** - * return the table for the specified DTP table - */ - DTPTableWrapper getTable(org.eclipse.datatools.modelbase.sql.tables.Table table) { - // try to short-circuit the search - return this.wraps(table) ? this : this.getSchema().getTable(table); - } - - - // ********** listening ********** - - @Override - synchronized void startListening() { - if (this.foreignKeys != null) { - this.startForeignKeys(); - } - if (this.columns != null) { - this.startColumns(); - } - super.startListening(); - } - - private void startForeignKeys() { - for (DTPForeignKeyWrapper foreignKey : this.foreignKeys) { - foreignKey.startListening(); - } - } - - private void startColumns() { - for (DTPColumnWrapper column : this.columns) { - column.startListening(); - } - } - - @Override - synchronized void stopListening() { - if (this.foreignKeys != null) { - this.stopForeignKeys(); - } - if (this.columns != null) { - this.stopColumns(); - } - super.stopListening(); - } - - private void stopForeignKeys() { - for (DTPForeignKeyWrapper foreignKey : this.foreignKeys) { - foreignKey.stopListening(); - } - } - - private void stopColumns() { - for (DTPColumnWrapper column : this.columns) { - column.stopListening(); - } - } - - - // ********** clear ********** - - @Override - synchronized void clear() { - if (this.foreignKeys != null) { - this.clearForeignKeys(); - } - - // the table does not "contain" the pk columns, so no need to forward #clear() - this.primaryKeyColumns = null; - - if (this.columns != null) { - this.clearColumns(); - } - } - - private void clearForeignKeys() { - this.stopForeignKeys(); - for (DTPForeignKeyWrapper foreignKey : this.foreignKeys) { - foreignKey.clear(); - } - this.foreignKeys = null; - } - - private void clearColumns() { - this.stopColumns(); - for (DTPColumnWrapper column : this.columns) { - column.clear(); - } - this.columns = null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/AbstractVendor.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/AbstractVendor.java deleted file mode 100644 index b310c554cd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/AbstractVendor.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Consolidate the behavior common to the typical vendors. - */ -abstract class AbstractVendor - implements Vendor -{ - - AbstractVendor() { - super(); - } - - public abstract String getDTPVendorName(); - - - // ********** catalog and schema support ********** - - abstract CatalogStrategy getCatalogStrategy(); - - public boolean supportsCatalogs(Database database) { - return this.getCatalogStrategy().supportsCatalogs(database); - } - - public List<Catalog> getCatalogs(Database database) { - return this.getCatalogStrategy().getCatalogs(database); - } - - public List<Schema> getSchemas(Database database) { - try { - return this.getCatalogStrategy().getSchemas(database); - } catch (Exception ex) { - throw new RuntimeException("vendor: " + this, ex); //$NON-NLS-1$ - } - } - - /** - * Typically, the name of the default catalog is the user name. - */ - public final List<String> getDefaultCatalogIdentifiers(Database database, String userName) { - if ( ! this.supportsCatalogs(database)) { - return Collections.emptyList(); - } - ArrayList<String> identifiers = new ArrayList<String>(); - this.addDefaultCatalogIdentifiersTo(database, userName, identifiers); - return identifiers; - } - - void addDefaultCatalogIdentifiersTo(@SuppressWarnings("unused") Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(this.convertNameToIdentifier(userName)); - } - - /** - * Typically, the name of the default schema is the user name. - */ - public final List<String> getDefaultSchemaIdentifiers(Database database, String userName) { - ArrayList<String> identifiers = new ArrayList<String>(); - this.addDefaultSchemaIdentifiersTo(database, userName, identifiers); - return identifiers; - } - - /** - * The user name passed in here was retrieved from DTP. - * DTP stores the user name that was passed to it during the connection - * to the database. As a result, this user name is an "identifier" not a "name". - * If the user name were retrieved from the JDBC connection it would probably - * be a "name". For example, you can connect to an Oracle database with the - * user name "scott", but that identifer is folded to the actual user name - * "SCOTT". DTP stores the original string "scott", while the Oracle JDBC - * driver stores the folded string "SCOTT". - */ - void addDefaultSchemaIdentifiersTo(@SuppressWarnings("unused") Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(userName); - } - - - // ********** folding strategy used to convert names and identifiers ********** - - /** - * The SQL spec says a "normal" (non-delimited) identifier should be - * folded to uppercase; but some databases do otherwise (e.g. Sybase). - */ - abstract FoldingStrategy getFoldingStrategy(); - - - // ********** name -> identifier ********** - - public String convertNameToIdentifier(String name, String defaultName) { - return this.nameRequiresDelimiters(name) ? - this.delimitName(name) : - this.normalNamesMatch(name, defaultName) ? null : name; - } - - public String convertNameToIdentifier(String name) { - return this.nameRequiresDelimiters(name) ? this.delimitName(name) : name; - } - - /** - * Return whether the specified database object name must be delimited - * when used in an SQL statement. - * If the name has any "special" characters (as opposed to letters, - * digits, and other allowed characters [e.g. underscores]), it requires - * delimiters. - * If the name is mixed case and the database folds undelimited names - * (to either uppercase or lowercase), it requires delimiters. - */ - boolean nameRequiresDelimiters(String name) { - return (name.length() == 0) // an empty string must be delimited(?) - || this.nameContainsAnyNonNormalCharacters(name) - || this.nameIsNotFolded(name); - } - - /** - * Return whether the specified name contains any "non-normal" characters - * that require the name to be delimited. - * Pre-condition: the specified name is not empty - */ - boolean nameContainsAnyNonNormalCharacters(String name) { - char[] string = name.toCharArray(); - if (this.characterIsNonNormalNameStart(string[0])) { - return true; - } - for (int i = string.length; i-- > 1; ) { // note: stop at 1 - if (this.characterIsNonNormalNamePart(string[i])) { - return true; - } - } - return false; - } - - /** - * Return whether the specified character is "non-normal" for the first - * character of a name. - * Typically, databases are more restrictive about what characters can - * be used to *start* an identifier (as opposed to the characters - * allowed for the remainder of the identifier). - */ - boolean characterIsNonNormalNameStart(char c) { - return ! this.characterIsNormalNameStart(c); - } - - /** - * Return whether the specified character is "normal" for the first - * character of a name. - * The first character of an identifier can be: - * - a letter - * - any of the extended, vendor-specific, "normal" start characters - */ - boolean characterIsNormalNameStart(char c) { - // all vendors allow a letter - return Character.isLetter(c) - || this.characterIsExtendedNormalNameStart(c); - } - - boolean characterIsExtendedNormalNameStart(char c) { - return arrayContains(this.getExtendedNormalNameStartCharacters(), c); - } - - /** - * Return the "normal" characters, beyond letters, for the - * first character of a name. - * Return null if there are no "extended" characters. - */ - char[] getExtendedNormalNameStartCharacters() { - return null; - } - - /** - * Return whether the specified character is "non-normal" for the second - * and subsequent characters of a name. - */ - boolean characterIsNonNormalNamePart(char c) { - return ! this.characterIsNormalNamePart(c); - } - - /** - * Return whether the specified character is "normal" for the second and - * subsequent characters of a name. - * The second and subsequent characters of a "normal" name can be: - * - a letter - * - a digit - * - any of the extended, vendor-specific, "normal" start characters - * - any of the extended, vendor-specific, "normal" part characters - */ - boolean characterIsNormalNamePart(char c) { - // all vendors allow a letter or digit - return Character.isLetterOrDigit(c) - || this.characterIsExtendedNormalNameStart(c) - || this.characterIsExtendedNormalNamePart(c); - } - - boolean characterIsExtendedNormalNamePart(char c) { - return arrayContains(this.getExtendedNormalNamePartCharacters(), c); - } - - /** - * Return the "normal" characters, beyond letters and digits and the - * "normal" first characters, for the second and subsequent characters - * of an identifier. Return null if there are no additional characters. - */ - char[] getExtendedNormalNamePartCharacters() { - return null; - } - - /** - * Return whether the specified name is not folded to the database's - * case, requiring it to be delimited. - */ - boolean nameIsNotFolded(String name) { - return ! this.getFoldingStrategy().nameIsFolded(name); - } - - /** - * Return whether the specified "normal" names match. - */ - boolean normalNamesMatch(String name1, String name2) { - return this.normalIdentifiersAreCaseSensitive() ? - name1.equals(name2) : - name1.equalsIgnoreCase(name2); - } - - /** - * Typically, "normal" identifiers are case-insensitive. - */ - boolean normalIdentifiersAreCaseSensitive() { - return this.getFoldingStrategy().normalIdentifiersAreCaseSensitive(); - } - - /** - * Wrap the specified name in delimiters (typically double-quotes), - * converting it to an identifier. - */ - String delimitName(String name) { - return StringTools.quote(name); - } - - - // ********** identifier -> name ********** - - // not sure how to handle an empty string: - // both "" and "\"\"" are converted to "" ... - // convert "" to 'null' since empty strings must be delimited? - public String convertIdentifierToName(String identifier) { - return (identifier == null) ? - null : - this.identifierIsDelimited(identifier) ? - StringTools.undelimit(identifier) : - this.getFoldingStrategy().fold(identifier); - } - - /** - * Return whether the specified identifier is "delimited". - * The SQL-92 spec says identifiers should be delimited by - * double-quotes; but some databases allow otherwise (e.g. Sybase). - */ - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsQuoted(identifier); - } - - - // ********** misc ********** - - @Override - public String toString() { - return this.getDTPVendorName(); - } - - /** - * static convenience method - array null check - */ - static boolean arrayContains(char[] array, char c) { - return (array != null) && ArrayTools.contains(array, c); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/CatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/CatalogStrategy.java deleted file mode 100644 index 9c7a4b59c8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/CatalogStrategy.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Handle the variety of catalog (and schema) configurations generated by DTP. - */ -interface CatalogStrategy { - - /** - * Return whether the DTP database has real catalogs. - */ - boolean supportsCatalogs(Database database); - - /** - * Return the specified database's catalogs. - */ - List<Catalog> getCatalogs(Database database); - - /** - * Return the specified database's schemas. - */ - List<Schema> getSchemas(Database database); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/DB2.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/DB2.java deleted file mode 100644 index 259d039185..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/DB2.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -class DB2 - extends AbstractVendor -{ - private final String dtpVendorName; - - private static final Vendor UDB = new DB2("DB2 UDB"); //$NON-NLS-1$ - private static final Vendor UDB_I_SERIES = new DB2("DB2 UDB iSeries"); //$NON-NLS-1$ - private static final Vendor UDB_Z_SERIES = new DB2("DB2 UDB zSeries"); //$NON-NLS-1$ - - static Vendor udb() { - return UDB; - } - - static Vendor udbISeries() { - return UDB_I_SERIES; - } - - static Vendor udbZSeries() { - return UDB_Z_SERIES; - } - - /** - * Ensure only static instances. - */ - private DB2(String dtpVendorName) { - super(); - this.dtpVendorName = dtpVendorName; - } - - @Override - public String getDTPVendorName() { - return this.dtpVendorName; - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '_' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Derby.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Derby.java deleted file mode 100644 index 01bce02199..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Derby.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; - -class Derby - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new Derby(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Derby() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Derby"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return FauxCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(this.buildDefaultSchemaIdentifier(userName)); - } - - /** - * The default user name on Derby is "APP" when the user connects without - * a user name. - */ - private String buildDefaultSchemaIdentifier(String userName) { - return ((userName != null) && (userName.length() != 0)) ? userName : DEFAULT_USER_IDENTIFIER; - } - private static final String DEFAULT_USER_IDENTIFIER = "APP"; //$NON-NLS-1$ - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '_' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FauxCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FauxCatalogStrategy.java deleted file mode 100644 index b5b5b4218d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FauxCatalogStrategy.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for DTP databases that build a "virtual" catalog (that has - * no name) because the underlying JDBC driver does not return any catalogs - * (e.g. Oracle). - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class FauxCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new FauxCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private FauxCatalogStrategy() { - super(); - } - - public boolean supportsCatalogs(Database database) { - return false; - } - - public List<Catalog> getCatalogs(Database database) { - return Collections.emptyList(); - } - - @SuppressWarnings("unchecked") - public List<Schema> getSchemas(Database database) { - return this.getFauxCatalog(database.getCatalogs()).getSchemas(); - } - - private Catalog getFauxCatalog(List<Catalog> catalogs) { - if (catalogs == null) { - throw new IllegalStateException(); - } - if (catalogs.size() != 1) { - throw new IllegalStateException("not a single catalog: " + catalogs.size()); //$NON-NLS-1$ - } - - Catalog catalog = catalogs.get(0); - if (catalog.getName().length() != 0) { - throw new IllegalStateException("illegal name: " + catalog.getName()); //$NON-NLS-1$ - } - return catalog; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FoldingStrategy.java deleted file mode 100644 index 9527f568e2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/FoldingStrategy.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -/** - * Handle database-specific identifier-folding issues. - */ -interface FoldingStrategy { - - /** - * Fold the specified name. - */ - String fold(String name); - - /** - * Return whether the specified database object name is already folded, - * meaning, if it has no special characters, it requires no delimiters. - */ - boolean nameIsFolded(String name); - - /** - * Return whether the database is case-sensitive when using "normal" - * (i.e. non-delimited) identifiers. - */ - boolean normalIdentifiersAreCaseSensitive(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/HSQLDB.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/HSQLDB.java deleted file mode 100644 index 45f51b79b3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/HSQLDB.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; - -class HSQLDB - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new HSQLDB(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private HSQLDB() { - super(); - } - - @Override - public String getDTPVendorName() { - return "HSQLDB"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(PUBLIC_SCHEMA_IDENTIFIER); - } - private static final String PUBLIC_SCHEMA_IDENTIFIER = "PUBLIC"; //$NON-NLS-1$ - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Informix.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Informix.java deleted file mode 100644 index 200c4b2de4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Informix.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -class Informix - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new Informix(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Informix() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Informix"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return LowerCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedNormalNameStartCharacters() { - return EXTENDED_NORMAL_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_START_CHARACTERS = new char[] { '_' }; - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '$' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java deleted file mode 100644 index 833c70f1d2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Fold "normal" identifiers to lower case. - * Ignore the case of "normal" identifiers. - */ -class LowerCaseFoldingStrategy - implements FoldingStrategy -{ - - // singleton - private static final FoldingStrategy INSTANCE = new LowerCaseFoldingStrategy(); - - /** - * Return the singleton. - */ - static FoldingStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private LowerCaseFoldingStrategy() { - super(); - } - - public String fold(String name) { - return name.toLowerCase(); - } - - public boolean nameIsFolded(String name) { - return StringTools.stringIsLowercase(name); - } - - public boolean normalIdentifiersAreCaseSensitive() { - return false; - } - - @Override - public String toString() { - return ClassTools.toStringClassNameForObject(this); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MaxDB.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MaxDB.java deleted file mode 100644 index 7d0818c7d8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MaxDB.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -class MaxDB - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new MaxDB(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private MaxDB() { - super(); - } - - @Override - public String getDTPVendorName() { - return "MaxDB"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); // not verified yet... - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedNormalNameStartCharacters() { - return EXTENDED_NORMAL_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_START_CHARACTERS = new char[] { '#', '@', '$' }; - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '_' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MySQL.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MySQL.java deleted file mode 100644 index d0235b9b68..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/MySQL.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.jpt.utility.internal.StringTools; - -class MySQL - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new MySQL(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private MySQL() { - super(); - } - - @Override - public String getDTPVendorName() { - return "MySql"; //$NON-NLS-1$ - } - - /** - * The DTP model for MySQL has a database that contains no catalogs; - * but, instead, directly holds a single schema with the same name as - * the database. (This is hard-coded in MySqlCatalogDatabase.getSchemas().) - * Although you can qualify identifiers with a database name - * in MySQL, only the database specified at login seems to be available - * in the DTP model.... - * - * NB: In MySQL DDL, SCHEMA is a synonym for DATABASE; but the JDBC - * method DatabaseMetaData.getSchemas() returns an empty list, - * while getCatalogs() returns a list of the available databases. - * You can also use the JDBC method Connection.setCatalog(String) to - * set the default database. - */ - @Override - CatalogStrategy getCatalogStrategy() { - return NoCatalogStrategy.instance(); - } - - /** - * MySQL is a bit unusual, so we force exact matches. - * (e.g. MySQL folds database and table names to lowercase on Windows - * by default; but that default can be changed by the - * 'lower_case_table_names' system variable. This is because databases are - * stored as directories and tables are stored as files in the underlying - * O/S; and the case-sensitivity of the names is determined by the behavior - * of filenames on the O/S. Then, to complicate things, - * none of the other identifiers, like index and column names, are folded; - * but they are case-insensitive, unless delimited. See - * http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html.) - */ - @Override - FoldingStrategy getFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - @Override - void addDefaultSchemaIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(this.convertNameToIdentifier(database.getName())); // hmmm... ~bjv - } - - /** - * MySQL is the only vendor that allows a digit. - * Although, the name cannnot be *all* digits. - */ - @Override - boolean characterIsNormalNameStart(char c) { - return Character.isDigit(c) || super.characterIsNormalNameStart(c); - } - - @Override - char[] getExtendedNormalNameStartCharacters() { - return EXTENDED_NORMAL_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_START_CHARACTERS = new char[] { '_', '$' }; - - /** - * By default, MySQL delimits identifiers with backticks (`); but it - * can also be configured to use double-quotes. - */ - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsDelimited(identifier, BACKTICK) - || super.identifierIsDelimited(identifier); - } - private static final char BACKTICK = '`'; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NoCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NoCatalogStrategy.java deleted file mode 100644 index a7fb79d9ba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NoCatalogStrategy.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for DTP databases that do not have catalogs - * (e.g. MySQL see bug 249013). - */ -class NoCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new NoCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NoCatalogStrategy() { - super(); - } - - public boolean supportsCatalogs(Database database) { - return false; - } - - public List<Catalog> getCatalogs(Database database) { - return Collections.emptyList(); - } - - @SuppressWarnings("unchecked") - public List<Schema> getSchemas(Database database) { - return database.getSchemas(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java deleted file mode 100644 index e63c1ad71d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import org.eclipse.jpt.utility.internal.ClassTools; - -/** - * Do not fold "normal" identifiers. - * Respect the case of "normal" identifiers. - */ -class NonFoldingStrategy - implements FoldingStrategy -{ - - // singleton - private static final FoldingStrategy INSTANCE = new NonFoldingStrategy(); - - /** - * Return the singleton. - */ - static FoldingStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NonFoldingStrategy() { - super(); - } - - /** - * Since identifiers are not folded to upper- or lower-case, the name is - * already "folded". - */ - public String fold(String name) { - return name; - } - - /** - * Since identifiers are not folded to upper- or lower-case, the name is - * already "folded". - * (Non-folding databases do not require delimiters around mixed-case - * "normal" identifiers.) - */ - public boolean nameIsFolded(String name) { - return true; - } - - public boolean normalIdentifiersAreCaseSensitive() { - return true; - } - - @Override - public String toString() { - return ClassTools.toStringClassNameForObject(this); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Oracle.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Oracle.java deleted file mode 100644 index cb04f9f36c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Oracle.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -class Oracle - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new Oracle(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Oracle() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Oracle"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return FauxCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '_', '$', '#' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/PostgreSQL.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/PostgreSQL.java deleted file mode 100644 index 3ecad54899..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/PostgreSQL.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; - -class PostgreSQL - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new PostgreSQL(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private PostgreSQL() { - super(); - } - - @Override - public String getDTPVendorName() { - return "postgres"; //$NON-NLS-1$ - } - - /** - * The PostgreSQL JDBC driver returns a single catalog from the call to - * DatabaseMetaData.getCatalogs() that has the same name as the - * database initially specified by the connection (in the JDBC URL). - * DTP uses this configuration unmodified. Unfortunately, the DTP - * database's name is not the same as the PostgreSQL database's - * name. - */ - @Override - CatalogStrategy getCatalogStrategy() { - return SimpleCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return LowerCaseFoldingStrategy.instance(); - } - - /** - * The PostgreSQL database holds a single catalog that has the same name as - * the database. - */ - @Override - void addDefaultCatalogIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(this.buildDefaultCatalogIdentifier(database)); - } - - private String buildDefaultCatalogIdentifier(Database database) { - return this.convertNameToIdentifier(this.buildDefaultCatalogName(database)); - } - - private String buildDefaultCatalogName(Database database) { - return ((Catalog) database.getCatalogs().get(0)).getName(); - } - - /** - * PostgreSQL has a "schema search path". The default is: - * "$user",public - * If the "$user" schema is not found, use the "public" schema. - */ - @Override - void addDefaultSchemaIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - super.addDefaultSchemaIdentifiersTo(database, userName, identifiers); - identifiers.add(PUBLIC_SCHEMA_IDENTIFIER); - } - private static final String PUBLIC_SCHEMA_IDENTIFIER = "public"; //$NON-NLS-1$ - - @Override - char[] getExtendedNormalNameStartCharacters() { - return EXTENDED_NORMAL_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_START_CHARACTERS = new char[] { '_' }; - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '$' }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java deleted file mode 100644 index c6e597ca82..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SQLServer.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.jpt.utility.internal.StringTools; - -class SQLServer - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new SQLServer(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SQLServer() { - super(); - } - - @Override - public String getDTPVendorName() { - return "SQL Server"; //$NON-NLS-1$ - } - - @Override - CatalogStrategy getCatalogStrategy() { - return SimpleCatalogStrategy.instance(); - } - - /** - * By default, SQL Server identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - @Override - FoldingStrategy getFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - /** - * SQL Server will use the user-requested database; if that database is not - * found, it will default to 'master'. - */ - @Override - void addDefaultCatalogIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(database.getName()); - identifiers.add(MASTER_CATALOG_IDENTIFIER); - } - private static final String MASTER_CATALOG_IDENTIFIER = "master"; //$NON-NLS-1$ - - /** - * The default schema on SQL Server for any database (catalog) is 'dbo'. - */ - @Override - void addDefaultSchemaIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(DEFAULT_SCHEMA_IDENTIFIER); - } - private static final String DEFAULT_SCHEMA_IDENTIFIER = "dbo"; //$NON-NLS-1$ - - @Override - char[] getExtendedNormalNameStartCharacters() { - return EXTENDED_NORMAL_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_START_CHARACTERS = new char[] { '_', '@', '#' }; - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '$' }; - - /** - * By default, SQL Server delimits identifiers with brackets ([]); but it - * can also be configured to use double-quotes. - */ - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsBracketed(identifier) - || super.identifierIsDelimited(identifier); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SimpleCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SimpleCatalogStrategy.java deleted file mode 100644 index 8a1a04129e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/SimpleCatalogStrategy.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for DTP databases that simply model the catalogs returned - * by the underlying JDBC driver (e.g. Sybase). - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class SimpleCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new SimpleCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SimpleCatalogStrategy() { - super(); - } - - public boolean supportsCatalogs(Database database) { - return true; - } - - @SuppressWarnings("unchecked") - public List<Catalog> getCatalogs(Database database) { - return database.getCatalogs(); - } - - public List<Schema> getSchemas(Database database) { - return Collections.emptyList(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java deleted file mode 100644 index c195d2198a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Sybase.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; - -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.jpt.utility.internal.StringTools; - -class Sybase - extends AbstractVendor -{ - private final String dtpVendorName; - - static final Vendor ASA = new Sybase("Sybase_ASA"); //$NON-NLS-1$ - static final Vendor ASE = new Sybase("Sybase_ASE"); //$NON-NLS-1$ - - static Vendor asa() { - return ASA; - } - - static Vendor ase() { - return ASE; - } - - /** - * Ensure only static instances. - */ - private Sybase(String dtpVendorName) { - super(); - this.dtpVendorName = dtpVendorName; - } - - @Override - public String getDTPVendorName() { - return this.dtpVendorName; - } - - @Override - CatalogStrategy getCatalogStrategy() { - return SimpleCatalogStrategy.instance(); - } - - /** - * By default, Sybase identifiers are case-sensitive, even without - * delimiters. This can depend on the collation setting.... - */ - @Override - FoldingStrategy getFoldingStrategy() { - return NonFoldingStrategy.instance(); - } - - /** - * Sybase will use the user-requested database; if that database is not - * found, it will default to 'master'. - */ - @Override - void addDefaultCatalogIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(database.getName()); - identifiers.add(MASTER_CATALOG_IDENTIFIER); - } - private static final String MASTER_CATALOG_IDENTIFIER = "master"; //$NON-NLS-1$ - - /** - * The typical default schema on Sybase for any database (catalog) is - * 'dbo'. - * - * Actually, the default schema is more like a search path: - * The server looks for a schema object (e.g. a table) first in the user's - * schema, then it looks for the schema object in the database owner's - * schema (dbo). As a result, it's really not possible to specify - * the "default" schema without knowing the schema object we are - * looking for. - * - * (Note: the current 'user' is not the same thing as the current - * 'login' - see sp_adduser and sp_addlogin; so we probably can't - * use ConnectionProfile#getUserName().) - */ - @Override - void addDefaultSchemaIdentifiersTo(Database database, String userName, ArrayList<String> identifiers) { - identifiers.add(DEFAULT_SCHEMA_IDENTIFIER); - } - private static final String DEFAULT_SCHEMA_IDENTIFIER = "dbo"; //$NON-NLS-1$ - - @Override - char[] getExtendedNormalNameStartCharacters() { - return EXTENDED_NORMAL_NAME_START_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_START_CHARACTERS = new char[] { '_', '@' }; - - @Override - char[] getExtendedNormalNamePartCharacters() { - return EXTENDED_NORMAL_NAME_PART_CHARACTERS; - } - private static final char[] EXTENDED_NORMAL_NAME_PART_CHARACTERS = new char[] { '$', '¥', '£', '#' }; - - /** - * By default, Sybase delimits identifiers with brackets ([]); but it - * can also be configured to use double-quotes. - */ - @Override - boolean identifierIsDelimited(String identifier) { - return StringTools.stringIsBracketed(identifier) - || super.identifierIsDelimited(identifier); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnknownCatalogStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnknownCatalogStrategy.java deleted file mode 100644 index ea9a729e35..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnknownCatalogStrategy.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Catalog strategy for unknown DTP databases. - * @see java.sql.DatabaseMetaData#getCatalogs() - */ -class UnknownCatalogStrategy - implements CatalogStrategy -{ - // singleton - private static final CatalogStrategy INSTANCE = new UnknownCatalogStrategy(); - - /** - * Return the singleton. - */ - static CatalogStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private UnknownCatalogStrategy() { - super(); - } - - @SuppressWarnings("unchecked") - public boolean supportsCatalogs(Database database) { - List<Catalog> catalogs = database.getCatalogs(); - if ((catalogs == null) || catalogs.isEmpty()) { - return false; - } - - return this.getFauxCatalog(catalogs) == null; - } - - @SuppressWarnings("unchecked") - public List<Catalog> getCatalogs(Database database) { - List<Catalog> catalogs = database.getCatalogs(); - // if there are no catalogs, the database must hold the schemata directly - if ((catalogs == null) || catalogs.isEmpty()) { - return Collections.emptyList(); - } - - Catalog fauxCatalog = this.getFauxCatalog(catalogs); - return (fauxCatalog == null) ? catalogs : Collections.<Catalog>emptyList(); - } - - @SuppressWarnings("unchecked") - public List<Schema> getSchemas(Database database) { - List<Catalog> catalogs = database.getCatalogs(); - // if there are no catalogs, the database must hold the schemata directly - if ((catalogs == null) || catalogs.isEmpty()) { - return database.getSchemas(); - } - - Catalog fauxCatalog = this.getFauxCatalog(catalogs); - return (fauxCatalog != null) ? fauxCatalog.getSchemas() : Collections.emptyList(); - } - - private Catalog getFauxCatalog(List<Catalog> catalogs) { - if (catalogs.size() == 1) { - Catalog catalog = catalogs.get(0); - if (catalog.getName().equals("")) { //$NON-NLS-1$ - return catalog; - } - } - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnrecognizedVendor.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnrecognizedVendor.java deleted file mode 100644 index f5751232ff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UnrecognizedVendor.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -/** - * - */ -class UnrecognizedVendor - extends AbstractVendor -{ - // singleton - private static final Vendor INSTANCE = new UnrecognizedVendor(); - - /** - * Return the singleton. - */ - static Vendor instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private UnrecognizedVendor() { - super(); - } - - @Override - public String getDTPVendorName() { - return "Unrecognized Vendor"; //$NON-NLS-1$ - } - - /** - * Not sure what to do here.... - * Assume the DTP database is organized into one or more catalogs and - * the schemata are contained by those catalogs. This appears to be the - * default way DTP builds models these days (i.e. a database with at - * least one catalog, instead of the database holding schemata - * directly). - */ - @Override - CatalogStrategy getCatalogStrategy() { - return UnknownCatalogStrategy.instance(); - } - - @Override - FoldingStrategy getFoldingStrategy() { - return UpperCaseFoldingStrategy.instance(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java deleted file mode 100644 index 748d4dd162..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Fold "normal" identifiers to upper case. - * Ignore the case of "normal" identifiers. - */ -class UpperCaseFoldingStrategy - implements FoldingStrategy -{ - - // singleton - private static final FoldingStrategy INSTANCE = new UpperCaseFoldingStrategy(); - - /** - * Return the singleton. - */ - static FoldingStrategy instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private UpperCaseFoldingStrategy() { - super(); - } - - public String fold(String name) { - return name.toUpperCase(); - } - - public boolean nameIsFolded(String name) { - return StringTools.stringIsUppercase(name); - } - - public boolean normalIdentifiersAreCaseSensitive() { - return false; - } - - @Override - public String toString() { - return ClassTools.toStringClassNameForObject(this); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Vendor.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Vendor.java deleted file mode 100644 index b3dff3915f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/Vendor.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.schema.Catalog; -import org.eclipse.datatools.modelbase.sql.schema.Database; -import org.eclipse.datatools.modelbase.sql.schema.Schema; - -/** - * Delegate vendor-specific behavior to implementations of this interface:<ul> - * <li>catalog support - * <li>default catalog and schema - * <li>converting names to identifiers and vice-versa - * </ul> - * <strong>NB:</strong><br> - * We use "name" when dealing with the unmodified name of a database object - * as supplied by the database itself (i.e. it is not delimited and it is always - * case-sensitive). - * <br> - * We use "identifier" when dealing with a string representation of a database - * object name (i.e. it may be delimited and, depending on the vendor, it may - * be case-insensitive). - */ -public interface Vendor { - - /** - * This must match the DTP vendor name. - * @see org.eclipse.datatools.modelbase.sql.schema.Database#getVendor() - */ - String getDTPVendorName(); - - /** - * Return whether the vendor supports "real" catalogs (e.g. Sybase). - */ - boolean supportsCatalogs(Database database); - - /** - * Return the specified database's catalogs. - */ - List<Catalog> getCatalogs(Database database); - - /** - * Return the specified database's default catalog identifiers for the - * specified user. - */ - List<String> getDefaultCatalogIdentifiers(Database database, String userName); - - /** - * Return the specified database's schemas. - */ - List<Schema> getSchemas(Database database); - - /** - * Return the specified database's default schema identifiers for the - * specified user. - */ - List<String> getDefaultSchemaIdentifiers(Database database, String userName); - - /** - * Convert the specified database object name to a vendor identifier. - * Return <code>null</code> if the identifier matches the specified default name. - */ - String convertNameToIdentifier(String name, String defaultName); - - /** - * Convert the specified database object name to a vendor identifier. - */ - String convertNameToIdentifier(String name); - - /** - * Convert the specified database object identifier to a vendor name. - */ - String convertIdentifierToName(String identifier); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/VendorRepository.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/VendorRepository.java deleted file mode 100644 index 468f09ea44..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/VendorRepository.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal.vendor; - -import java.util.ArrayList; -import java.util.Iterator; - -public class VendorRepository { - private final Vendor[] vendors; - - // singleton - private static final VendorRepository INSTANCE = new VendorRepository(); - - /** - * Return the singleton. - */ - public static VendorRepository instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private VendorRepository() { - super(); - this.vendors = this.buildVendors(); - } - - private Vendor[] buildVendors() { - ArrayList<Vendor> list = new ArrayList<Vendor>(); - this.addVendorsTo(list); - return list.toArray(new Vendor[list.size()]); - } - - private void addVendorsTo(ArrayList<Vendor> list) { - this.addVendorTo(DB2.udb(), list); - this.addVendorTo(DB2.udbISeries(), list); - this.addVendorTo(DB2.udbZSeries(), list); - this.addVendorTo(Derby.instance(), list); - this.addVendorTo(HSQLDB.instance(), list); - this.addVendorTo(Informix.instance(), list); - this.addVendorTo(MaxDB.instance(), list); - this.addVendorTo(MySQL.instance(), list); - this.addVendorTo(Oracle.instance(), list); - this.addVendorTo(PostgreSQL.instance(), list); - this.addVendorTo(SQLServer.instance(), list); - this.addVendorTo(Sybase.asa(), list); - this.addVendorTo(Sybase.ase(), list); - } - - private void addVendorTo(Vendor vendor, ArrayList<Vendor> list) { - String name = vendor.getDTPVendorName(); - for (Iterator<Vendor> stream = list.iterator(); stream.hasNext(); ) { - if (stream.next().getDTPVendorName().equals(name)) { - throw new IllegalArgumentException("Duplicate vendor: " + name); //$NON-NLS-1$ - } - } - list.add(vendor); - } - - public Vendor getVendor(String dtpVendorName) { - for (int i = this.vendors.length; i-- > 0;) { - Vendor vendor = this.vendors[i]; - if (vendor.getDTPVendorName().equals(dtpVendorName)) { - return vendor; - } - } - return UnrecognizedVendor.instance(); - } - -} |