diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.db')
40 files changed, 0 insertions, 4255 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 63e6c0fc9d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/META-INF/MANIFEST.MF +++ /dev/null @@ -1,17 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.db -Bundle-Version: 1.1.1.qualifier -Bundle-Activator: org.eclipse.jpt.db.JptDbPlugin -Bundle-ClassPath: . -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Bundle-ActivationPolicy: lazy -Eclipse-LazyStart: true -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.datatools.sqltools.editor.core;bundle-version="[1.0.0,2.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 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 e87a2d3972..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 = Java Persistence API Tools - DB -providerName = Eclipse.org - 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 2db19a83af..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Catalog.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Database catalog - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Catalog extends Comparable<Catalog> { - - /** - * Return the catalog's name. - */ - String getName(); - -} 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 99af66db0e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.jpt.utility.JavaType; - -/** - * Database column - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Column extends Comparable<Column> { - - /** - * Return the column's name. - */ - String getName(); - - /** - * Return the name of the column's datatype. - */ - String getDataTypeName(); - - /** - * Return a Java-appropriate version of the column's name. - */ - String getJavaFieldName(); - - /** - * Return whether the column's name matches the specified Java identifier, - * respecting the database's case-sensitivity. - */ - boolean matchesJavaFieldName(String javaFieldName); - - /** - * 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(); - - /** - * 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 whether the column's datatype is a LOB type - * (i.e. BLOB, CLOB, or NCLOB). - */ - boolean dataTypeIsLOB(); - -} 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 879ba1bedd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionListener.java +++ /dev/null @@ -1,40 +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; - - -/** - * 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 { - - 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 8388f58ed4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfile.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; - -/** - * Database connection profile - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface ConnectionProfile extends Comparable<ConnectionProfile> { - - /** - * Return the connection profile's name. - */ - String getName(); - - /** - * Return the connection profile's database. - * Return a "null" database if the connection profile is inactive. - */ - Database getDatabase(); - - /** - * Return the connection profile's "default" catalog. - * Return null if the connection profile's database does not support - * catalogs. - */ - Catalog getDefaultCatalog(); - - /** - * Return the connection profile's default schema. - * In most cases the default schema's name will match the user name. - * It may be null. - */ - Schema getDefaultSchema(); - - /** - * 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 driver definition ID. - */ - String getDriverDefinitionID(); - - /** - * Return the jar list for the driver instance as a - * comma-delimited string. - */ - String getDriverJarList(); - - /** - * 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 isWorkingOfflin() - */ - boolean isActive(); - - /** - * 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(); - - /** - * Connect to the database. - */ - void connect(); - - /** - * Disconnect from the database. - */ - void disconnect(); - - /** - * 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(); - - /** - * Return whether the connection profile is a "null" connection profile. - */ - boolean isNull(); - - /** - * 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); - - 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 fb5c601a25..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileAdapter.java +++ /dev/null @@ -1,31 +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 connectionProfileChanged(ConnectionProfile profile) { - // do nothing - } - - public void connectionProfileReplaced(ConnectionProfile oldProfile, ConnectionProfile newProfile) { - // do nothing - } - -} 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 89f6207998..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileListener.java +++ /dev/null @@ -1,39 +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; - -/** - * A ProfileListener is notified of any changes to the 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 { - - /** - * The specified old profile has been replaced with the specified - * new profile. The old profile is a "null" profile when a profile is - * added. The new profile is a "null" profile when a profile is - * removed. - */ - public void connectionProfileReplaced(ConnectionProfile oldProfile, ConnectionProfile newProfile); - - /** - * The specified profile has been modified. Modification includes - * changes to any properties, the name, auto-connect flag, etc. - */ - public void connectionProfileChanged(ConnectionProfile profile); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileRepository.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileRepository.java deleted file mode 100644 index 8f37291f78..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ConnectionProfileRepository.java +++ /dev/null @@ -1,66 +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 repository - * - * 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 ConnectionProfileRepository { - - /** - * Return the repository's connection profiles. - */ - Iterator<ConnectionProfile> connectionProfiles(); - - /** - * Return the number of connection profiles in the repository. - */ - int connectionProfilesSize(); - - /** - * Return the repository's connection profile names. - */ - Iterator<String> connectionProfileNames(); - - /** - * Return whether the repository contains a connection profile - * with the specified name. - */ - boolean containsConnectionProfileNamed(String name); - - /** - * Return the connection profile with the specified name. - * Return a "null" connection profile if the repository does not - * have a connection profile with the specified name. - */ - ConnectionProfile connectionProfileNamed(String name); - - /** - * Add a listener that will be notified of changes to the repository's - * 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/Database.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java deleted file mode 100644 index e4e19babc3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Database.java +++ /dev/null @@ -1,90 +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; -import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition; - -/** - * Database - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Database extends SchemaContainer, Comparable<Database> { - - /** - * Return the database's name. - */ - String getName(); - - /** - * Return the database's vendor. - */ - String getVendor(); - - /** - * Return the database's version. - */ - String getVersion(); - - /** - * Return whether the database's identifiers are case-sensitive. - */ - boolean isCaseSensitive(); - - /** - * Return the database's DTP database definition. - */ - DatabaseDefinition getDtpDefinition(); - - /** - * Return whether the database supports catalogs. - */ - boolean supportsCatalogs(); - - /** - * Return the database's catalogs. - */ - Iterator<Catalog> catalogs(); - - /** - * Return the number of catalogs the database contains. - */ - int catalogsSize(); - - /** - * Return the names of the database's catalogs. - */ - Iterator<String> catalogNames(); - - /** - * Return whether the database contains a catalog with the specified name, - * respecting the database's case-sensitivity. - */ - boolean containsCatalogNamed(String name); - - /** - * Return the catalog in the database with the specified name, - * respecting the database's case-sensitivity. - */ - Catalog catalogNamed(String name); - - /** - * Return the database's "default" catalog. - */ - Catalog getDefaultCatalog(); - -} 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 3215cfdfd4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/ForeignKey.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import 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 Comparable<ForeignKey> { - - /** - * Return the foreign key's name. - */ - String getName(); - - /** - * Return the foreign key's "base" table. - */ - Table getBaseTable(); - - /** - * Return the foreign key's "referenced" table. - */ - Table getReferencedTable(); - - /** - * Return the foreign key's column pairs. - * @see ColumnPair - */ - Iterator<ColumnPair> columnPairs(); - - /** - * Return the foreign key's single column pair. Throw an - * IllegalStateException if the foreign key has more than one column pair. - */ - ColumnPair columnPair(); - - /** - * Return the size of the foreign key's column pairs. - * @see ColumnPair - */ - int columnPairsSize(); - - /** - * Return the foreign key's "base" columns. - * @see ColumnPair - */ - Iterator<Column> baseColumns(); - - /** - * Return the foreign key's "base" columns that are not part of - * the base table's primary key. - * @see ColumnPair - */ - Iterator<Column> nonPrimaryKeyBaseColumns(); - - /** - * Return the foreign key's "referenced" columns. - * @see ColumnPair - */ - Iterator<Column> referencedColumns(); - - /** - * Return a Java-appropriate name for a field that holds the entity - * mapped to the foreign key's "referenced" table. - */ - String getJavaFieldName(); - - /** - * Return whether the foreign key's default Java field name matches the - * specified Java identifier, respecting the database's case-sensitivity. - */ - boolean defaultMatchesJavaFieldName(String javaFieldName); - - /** - * Return whether the foreign key is the default for the specified Java - * field name, respecting the database's case-sensitivity. - */ - boolean isDefaultFor(String javaFieldName); - - /** - * Return whether the foreign key references the primary key of the - * "referenced" table and that primary key has only a single column. - */ - boolean referencesSingleColumnPrimaryKey(); - - - /** - * Pair up the foreign key's column pairs, matching each "base" column with - * the appropriate "referenced" column. - * @see #columnPairs() - */ - interface ColumnPair extends Comparable<ColumnPair> { - - /** - * Return the column pair's "base" column. - */ - Column baseColumn(); - - /** - * Return the column pair's "referenced" column. - */ - Column referencedColumn(); - - } - -} 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 00aa478fb9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/JptDbPlugin.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.jpt.db.internal.DTPConnectionProfileRepository; -import org.osgi.framework.BundleContext; - -/** - * The JPT DB plug-in lifecycle implementation. - * Globally available connection profile repository. - * - * 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 DTPConnectionProfileRepository connectionProfileRepository; - - private static JptDbPlugin INSTANCE; // sorta-final - - /** - * Return the singleton JPT DB plug-in. - */ - public static JptDbPlugin instance() { - return INSTANCE; - } - - /** - * The constructor - */ - public JptDbPlugin() { - super(); - INSTANCE = this; - } - - /** - * This method is called upon plug-in activation - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - this.connectionProfileRepository = DTPConnectionProfileRepository.instance(); - this.connectionProfileRepository.start(); - } - - /** - * This method is called when the plug-in is stopped - */ - @Override - public void stop(BundleContext context) throws Exception { - this.connectionProfileRepository.stop(); - this.connectionProfileRepository = null; - INSTANCE = null; - super.stop(context); - } - - public ConnectionProfileRepository getConnectionProfileRepository() { - return this.connectionProfileRepository; - } - -} 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 2b13ecede0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Schema.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - - -/** - * Database schema - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Schema extends Comparable<Schema> { - - /** - * Return the schema's name. - */ - String getName(); - - /** - * Return the schema's tables. - */ - Iterator<Table> tables(); - - /** - * Return the number of tables the schema contains. - */ - int tablesSize(); - - /** - * Return the names of the schema's tables. - */ - Iterator<String> tableNames(); - - /** - * Return whether the schema contains a table with the specified name, - * respecting the database's case-sensitivity. - */ - boolean containsTableNamed(String name); - - /** - * Return the table in the schema with the specified name, - * respecting the database's case-sensitivity. - */ - Table tableNamed(String name); - - /** - * Return the schema's sequences. - */ - Iterator<Sequence> sequences(); - - /** - * Return the number of sequences the schema contains. - */ - int sequencesSize(); - - /** - * Return the names of the schema's sequences. - */ - Iterator<String> sequenceNames(); - - /** - * Return whether the schema contains a sequence with the specified name, - * respecting the database's case-sensitivity. - */ - boolean containsSequenceNamed(String name); - - /** - * Return the sequence in the schema with the specified name, - * respecting the database's case-sensitivity. - */ - Sequence sequenceNamed(String name); - -} 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 52895619bf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/SchemaContainer.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Schema "container" (i.e. Database or Catalog) - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface SchemaContainer { - - /** - * Return the container's schemata. - */ - Iterator<Schema> schemata(); - - /** - * Return the number of schemata in the container. - */ - int schemataSize(); - - /** - * Return the names of the container's schemata. - */ - Iterator<String> schemaNames(); - - /** - * Return whether the container contains a schema with the specified name, - * respecting the database's case-sensitivity. - */ - boolean containsSchemaNamed(String name); - - /** - * Return the schema in the container with the specified name, - * respecting the database's case-sensitivity. - */ - Schema schemaNamed(String name); - -} 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 bd024a03a6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Sequence.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -/** - * Database sequence - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Sequence extends Comparable<Sequence> { - - /** - * Return the sequence's name. - */ - String getName(); - -} 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 2273973de3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Table.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db; - -import java.util.Iterator; - -/** - * Database table - * - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - * - * This interface is not intended to be implemented by clients. - */ -public interface Table extends Comparable<Table> { - - /** - * Return the table's name. - */ - String getName(); - - /** - * Return the table's columns. - */ - Iterator<Column> columns(); - - /** - * Return the number of columns the table contains. - */ - int columnsSize(); - - /** - * Return the names of the table's columns. - */ - Iterator<String> columnNames(); - - /** - * Return whether the table contains a column with the specified name, - * respecting the database's case-sensitivity. - */ - boolean containsColumnNamed(String name); - - /** - * Return the column in the table with the specified name, - * respecting the database's case-sensitivity. - */ - Column columnNamed(String name); - - /** - * Return the table's primary key columns. - */ - Iterator<Column> primaryKeyColumns(); - - /** - * Return the table's single primary key column. Throw an - * IllegalStateException if the table has more than one primary key column. - */ - Column primaryKeyColumn(); - - /** - * Return the number of primary key columns the table contains. - */ - int primaryKeyColumnsSize(); - - /** - * Return whether the specified column is one of the table's primary key - * columns. - */ - boolean primaryKeyColumnsContains(Column column); - - /** - * Return the table's foreign keys. - */ - Iterator<ForeignKey> foreignKeys(); - - /** - * Return the number of foreign keys the table contains. - */ - int foreignKeysSize(); - - /** - * Return whether the specified column is a "base" column - * for any of the table's foreign keys. - */ - boolean foreignKeyBaseColumnsContains(Column column); - - /** - * Return the table's name, converted to a Java-appropriate class - * identifier, respecting the database's case-sensitivity. - */ - String getShortJavaClassName(); - - /** - * Return whether the table's name matches the specified Java-appropriate - * identifier, respecting the database's case-sensitivity. - */ - boolean matchesShortJavaClassName(String shortJavaClassName); - - /** - * Return the table's name, converted to a Java-appropriate field - * identifier, respecting the database's case-sensitivity. - */ - public String getJavaFieldName(); - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/ConnectionProfileHolder.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/ConnectionProfileHolder.java deleted file mode 100644 index f106e91b4d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/ConnectionProfileHolder.java +++ /dev/null @@ -1,17 +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; - -/** - * Provide a way for clients to access the connection profile. - */ -interface ConnectionProfileHolder { - DTPConnectionProfileWrapper getConnectionProfile(); -} 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 1319675ade..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPCatalogWrapper.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.List; - -import org.eclipse.jpt.db.Catalog; - -/** - * Wrap a DTP Catalog - */ -final class DTPCatalogWrapper - extends DTPSchemaContainerWrapper - implements Catalog -{ - // backpointer to parent - private final DTPDatabaseWrapper database; - - // 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.database = database; - this.dtpCatalog = dtpCatalog; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - super.catalogObjectChanged(eventType); - this.getConnectionProfile().catalogChanged(this, eventType); - } - - - // ********** Catalog implementation ********** - - @Override - public String getName() { - return this.dtpCatalog.getName(); - } - - - // ***** schemata - - @Override - @SuppressWarnings("unchecked") - List<org.eclipse.datatools.modelbase.sql.schema.Schema> dtpSchemata() { - return this.dtpCatalog.getSchemas(); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Catalog catalog) { - return this.dtpCatalog == catalog; - } - - @Override - boolean isCaseSensitive() { - return this.database.isCaseSensitive(); - } - - @Override - DTPDatabaseWrapper database() { - return this.database; - } - - - // ********** Comparable implementation ********** - - public int compareTo(Catalog catalog) { - return Collator.getInstance().compare(this.getName(), catalog.getName()); - } - -} 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 2c32477588..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; - -import org.eclipse.datatools.modelbase.dbdefinition.PredefinedDataTypeDefinition; -import org.eclipse.datatools.modelbase.sql.datatypes.DataType; -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.NameTools; -import org.eclipse.jpt.utility.internal.SimpleJavaType; - -/** - * Wrap a DTP Column - */ -final class DTPColumnWrapper - extends DTPWrapper - implements Column -{ - // backpointer to parent - private final DTPTableWrapper table; - - // the wrapped DTP column - private final org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn; - - - // ***** some constants used when converting the column to a Java field - // 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); - - - // ********** constructor ********** - - DTPColumnWrapper(DTPTableWrapper table, org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - super(table, dtpColumn); - this.table = table; - this.dtpColumn = dtpColumn; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - this.getConnectionProfile().columnChanged(this, eventType); - } - - - // ********** Column implementation ********** - - @Override - public String getName() { - return this.dtpColumn.getName(); - } - - public String getDataTypeName() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType == null) ? null : dataType.getName(); - } - - public String getJavaFieldName() { - String jName = this.getName(); - if ( ! this.isCaseSensitive()) { - jName = jName.toLowerCase(); - } - return NameTools.convertToJavaIdentifier(jName); - } - - public boolean matchesJavaFieldName(String javaFieldName) { - return this.isCaseSensitive() ? - this.getName().equals(javaFieldName) - : - this.getName().equalsIgnoreCase(javaFieldName); - } - - public String getPrimaryKeyJavaTypeDeclaration() { - return this.getPrimaryKeyJavaType().declaration(); - } - - public JavaType getPrimaryKeyJavaType() { - return this.jpaSpecCompliantPrimaryKeyJavaType(this.getJavaType()); - } - - /** - * 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 JavaType jpaSpecCompliantPrimaryKeyJavaType(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; - } - - public String getJavaTypeDeclaration() { - return this.getJavaType().declaration(); - } - - public JavaType getJavaType() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof PredefinedDataType) ? - this.jpaSpecCompliantJavaType(this.javaType((PredefinedDataType) dataType)) - : - DEFAULT_JAVA_TYPE; - } - - private JavaType javaType(PredefinedDataType dataType) { - // this is just a bit hacky: moving from a type declaration to a class name to a type declaration... - String dtpJavaClassName = this.predefinedDataTypeDefinition(dataType).getJavaClassName(); - return new SimpleJavaType(ClassTools.classNameForTypeDeclaration(dtpJavaClassName)); - } - - private PredefinedDataTypeDefinition predefinedDataTypeDefinition(PredefinedDataType dataType) { - return this.database().getDtpDefinition().getPredefinedDataTypeDefinition(dataType.getName()); - } - - /** - * The JDBC spec says JDBC drivers should be able to map BLOBs and CLOBs - * directly, but the JPA spec does not allow them. - */ - private JavaType jpaSpecCompliantJavaType(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; - } - - public boolean dataTypeIsLOB() { - DataType dataType = this.dtpColumn.getDataType(); - return (dataType instanceof PredefinedDataType) ? - this.primitiveTypeIsLob(((PredefinedDataType) dataType).getPrimitiveType()) - : - false; - } - - private boolean primitiveTypeIsLob(PrimitiveType primitiveType) { - return (primitiveType == PrimitiveType.BINARY_LARGE_OBJECT_LITERAL) - || (primitiveType == PrimitiveType.CHARACTER_LARGE_OBJECT_LITERAL) - || (primitiveType == PrimitiveType.NATIONAL_CHARACTER_LARGE_OBJECT_LITERAL); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Column column) { - return Collator.getInstance().compare(this.getName(), column.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Column column) { - return this.dtpColumn == column; - } - - boolean isCaseSensitive() { - return this.table.isCaseSensitive(); - } - - DTPDatabaseWrapper database() { - return this.table.database(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileRepository.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileRepository.java deleted file mode 100644 index 694ae57176..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileRepository.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Iterator; -import java.util.Vector; - -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.IProfileListener; -import org.eclipse.datatools.connectivity.ProfileManager; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.ConnectionProfileRepository; -import org.eclipse.jpt.db.ConnectionProfileListener; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap the DTP ProfileManager. - */ -public final class DTPConnectionProfileRepository - implements ConnectionProfileRepository -{ - private ProfileManager dtpProfileManager; - - private LocalProfileListener profileListener; - - private final Vector<DTPConnectionProfileWrapper> connectionProfiles = new Vector<DTPConnectionProfileWrapper>(); - - - // ********** singleton ********** - - private static final DTPConnectionProfileRepository INSTANCE = new DTPConnectionProfileRepository(); - - public static DTPConnectionProfileRepository instance() { - return INSTANCE; - } - - /** - * 'private' to ensure singleton - */ - private DTPConnectionProfileRepository() { - super(); - } - - - // ********** lifecycle ********** - - /** - * called by plug-in - */ - public synchronized void start() { - this.dtpProfileManager = ProfileManager.getInstance(); - this.profileListener = new LocalProfileListener(); - this.dtpProfileManager.addProfileListener(this.profileListener); - for (IConnectionProfile dtpProfile : this.dtpProfileManager.getProfiles()) { - this.connectionProfiles.add(new DTPConnectionProfileWrapper(dtpProfile)); - } - } - - /** - * called by plug-in - */ - public synchronized void stop() { - for (DTPConnectionProfileWrapper profile : this.connectionProfiles) { - profile.dispose(); - } - this.connectionProfiles.clear(); - this.dtpProfileManager.removeProfileListener(this.profileListener); - this.profileListener = null; - this.dtpProfileManager = null; - } - - - // ********** profiles ********** - - public synchronized Iterator<ConnectionProfile> connectionProfiles() { - return new CloneIterator<ConnectionProfile>(this.connectionProfiles); // read-only - } - - private synchronized Iterator<DTPConnectionProfileWrapper> connectionProfileWrappers() { - return new CloneIterator<DTPConnectionProfileWrapper>(this.connectionProfiles); // read-only - } - - public int connectionProfilesSize() { - return this.connectionProfiles.size(); - } - - public Iterator<String> connectionProfileNames() { - return new TransformationIterator<DTPConnectionProfileWrapper, String>(this.connectionProfileWrappers()) { - @Override - protected String transform(DTPConnectionProfileWrapper profile) { - return profile.getName(); - } - }; - } - - public boolean containsConnectionProfileNamed(String name) { - return ! this.connectionProfileNamed(name).isNull(); - } - - public ConnectionProfile connectionProfileNamed(String name) { - for (Iterator<DTPConnectionProfileWrapper> stream = this.connectionProfileWrappers(); stream.hasNext(); ) { - DTPConnectionProfileWrapper profile = stream.next(); - if (profile.getName().equals(name)) { - return profile; - } - } - return NullConnectionProfile.instance(); - } - - synchronized DTPConnectionProfileWrapper addConnectionProfile(IConnectionProfile dtpConnectionProfile) { - for (DTPConnectionProfileWrapper wrapper : this.connectionProfiles) { - if (wrapper.wraps(dtpConnectionProfile)) { - throw new IllegalStateException("duplicate connection profile: " + dtpConnectionProfile.getName()); //$NON-NLS-1$ - } - } - DTPConnectionProfileWrapper wrapper = new DTPConnectionProfileWrapper(dtpConnectionProfile); - this.connectionProfiles.add(wrapper); - return wrapper; - } - - synchronized DTPConnectionProfileWrapper removeConnectionProfile(IConnectionProfile dtpConnectionProfile) { - for (Iterator<DTPConnectionProfileWrapper> stream = this.connectionProfiles.iterator(); stream.hasNext(); ) { - DTPConnectionProfileWrapper wrapper = stream.next(); - if (wrapper.wraps(dtpConnectionProfile)) { - stream.remove(); - return wrapper; - } - } - throw new IllegalStateException("invalid connection profile: " + dtpConnectionProfile.getName()); //$NON-NLS-1$ - } - - synchronized DTPConnectionProfileWrapper connectionProfile(IConnectionProfile dtpConnectionProfile) { - for (DTPConnectionProfileWrapper wrapper : this.connectionProfiles) { - if (wrapper.wraps(dtpConnectionProfile)) { - return wrapper; - } - } - throw new IllegalStateException("invalid connection profile: " + dtpConnectionProfile.getName()); //$NON-NLS-1$ - } - - - // ********** Object overrides ********** - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(ClassTools.toStringClassNameForObject(this)); - sb.append((this.connectionProfiles != null) ? this.connectionProfiles : "<'connectionProfiles' uninitialized>"); //$NON-NLS-1$ - return sb.toString(); - } - - - // ********** listeners ********** - - public void addConnectionProfileListener(ConnectionProfileListener listener) { - this.profileListener.addConnectionProfileListener(listener); - } - - public void removeConnectionProfileListener(ConnectionProfileListener listener) { - this.profileListener.removeConnectionProfileListener(listener); - } - - - // ********** listener ********** - - /** - * Keep the repository in synch with the DTP profile manager - * and forward events to the repository's listeners. - */ - private class LocalProfileListener implements IProfileListener { - private Vector<ConnectionProfileListener> listeners = new Vector<ConnectionProfileListener>(); - - LocalProfileListener() { - super(); - } - - void addConnectionProfileListener(ConnectionProfileListener listener) { - this.listeners.add(listener); - } - - void removeConnectionProfileListener(ConnectionProfileListener listener) { - this.listeners.remove(listener); - } - - private Iterator<ConnectionProfileListener> listeners() { - return new CloneIterator<ConnectionProfileListener>(this.listeners); - } - - // ********** IProfileListener implementation ********** - - public void profileAdded(IConnectionProfile dtpProfile) { - // synch the repository then notify listeners - DTPConnectionProfileWrapper profile = DTPConnectionProfileRepository.this.addConnectionProfile(dtpProfile); - for (Iterator<ConnectionProfileListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().connectionProfileReplaced(NullConnectionProfile.instance(), profile); - } - } - - public void profileChanged(IConnectionProfile dtpProfile) { - DTPConnectionProfileWrapper profile = DTPConnectionProfileRepository.this.connectionProfile(dtpProfile); - for (Iterator<ConnectionProfileListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().connectionProfileChanged(profile); - } - } - - public void profileDeleted(IConnectionProfile dtpProfile) { - // synch the repository then notify listeners - DTPConnectionProfileWrapper profile = DTPConnectionProfileRepository.this.removeConnectionProfile(dtpProfile); - for (Iterator<ConnectionProfileListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().connectionProfileReplaced(profile, NullConnectionProfile.instance()); - } - } - - } - -} 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 742f3447ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPConnectionProfileWrapper.java +++ /dev/null @@ -1,483 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Iterator; -import java.util.Vector; - -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.Schema; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; - -/** - * Wrap a DTP ConnectionProfile - */ -final class DTPConnectionProfileWrapper - implements ConnectionProfile, ConnectionProfileHolder -{ - // the wrapped DTP connection profile - private final IConnectionProfile dtpConnectionProfile; - - // the DTP managed connection we listen to - private final IManagedConnection dtpManagedConnection; - - // forward events from the DTP connection profile's managed connections - private final LocalConnectionListener connectionListener; - - // lazy-initialized - can be a "null" database - private InternalDatabase database; - - - // ********** constants ********** - - public static final String LIVE_DTP_CONNECTION_TYPE = "java.sql.Connection"; //$NON-NLS-1$ - - public static final String OFFLINE_DTP_CONNECTION_TYPE = ConnectionInfo.class.getName(); - - public static final String DATABASE_PRODUCT_PROP_ID = "org.eclipse.datatools.connectivity.server.version"; //$NON-NLS-1$ - - public static final String POSTGRESQL_VENDOR = "postgres"; //$NON-NLS-1$ - - public static final String POSTGRESQL_DEFAULT_SCHEMA_NAME = "public"; //$NON-NLS-1$ - - - // ********** constructor ********** - - DTPConnectionProfileWrapper(IConnectionProfile dtpConnectionProfile) { - super(); - this.dtpConnectionProfile = dtpConnectionProfile; - this.dtpManagedConnection = this.buildDTPManagedConnection(); - this.connectionListener = new LocalConnectionListener(); - this.dtpManagedConnection.addConnectionListener(this.connectionListener); - } - - private IManagedConnection buildDTPManagedConnection() { - String connectionType = this.dtpConnectionProfile.supportsWorkOfflineMode() ? - OFFLINE_DTP_CONNECTION_TYPE : LIVE_DTP_CONNECTION_TYPE; - return this.dtpConnectionProfile.getManagedConnection(connectionType); - } - - - // ********** ConnectionProfileHolder implementation ********** - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this; - } - - - // ********** ConnectionProfile implementation ********** - - public String getName() { - return this.dtpConnectionProfile.getName(); - } - - public boolean isNull() { - return false; - } - - public void connect() { - if (this.isDisconnected()) { - this.checkStatus(this.dtpConnectionProfile.connect()); - } - } - - public void disconnect() { - this.checkStatus(this.dtpConnectionProfile.disconnect()); - } - - 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 boolean isWorkingOffline() { - return this.dtpManagedConnection.isWorkingOffline(); - } - - public boolean supportsWorkOfflineMode() { - return this.dtpConnectionProfile.supportsWorkOfflineMode(); - } - - public boolean canWorkOffline() { - return this.dtpConnectionProfile.canWorkOffline(); - } - - public IStatus saveWorkOfflineData() { - return this.dtpConnectionProfile.saveWorkOfflineData(); - } - - public IStatus workOffline() { - return this.dtpConnectionProfile.workOffline(); - } - - public String getDatabaseVendor() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID); - } - - public String getDatabaseName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_NAME_PROP_ID); - } - - public String getDatabaseProduct() { - return this.getProperty(DATABASE_PRODUCT_PROP_ID); - } - - public String getDatabaseVersion() { - return this.getProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID); - } - - public String getUserName() { - String userName = this.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID); - if (userName.contains(" ")){ - return userName.split("\\s")[0]; - } - return userName; - } - - public String getUserPassword() { - return this.getProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID); - } - - public synchronized InternalDatabase getDatabase() { - if (this.database == null) { - this.database = this.buildDatabase(); - } - return this.database; - } - - public DTPCatalogWrapper getDefaultCatalog() { - return this.getDatabase().getDefaultCatalog(); - } - - public void addConnectionListener(ConnectionListener listener) { - this.connectionListener.addConnectionListener(listener); - } - - public void removeConnectionListener(ConnectionListener listener) { - this.connectionListener.removeConnectionListener(listener); - } - - public Schema getDefaultSchema() { - return this.getDatabase().schemaNamed(this.getDefaultSchemaName()); - } - - public String getDriverClassName() { - return this.getProperty(IJDBCDriverDefinitionConstants.DRIVER_CLASS_PROP_ID); - } - - public String getUrl() { - return this.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID); - } - - public String getInstanceID() { - return this.dtpConnectionProfile.getInstanceID(); - } - - public String getProviderID() { - return this.dtpConnectionProfile.getProviderId(); - } - - public String getDriverDefinitionID() { - return this.getProperty(DRIVER_DEFINITION_PROP_ID); - } - - public String getDriverJarList() { - return DriverManager.getInstance().getDriverInstanceByID(this.getDriverDefinitionID()).getJarList(); - } - - - // ********** internal methods ********** - - private void checkStatus(IStatus status) { - if (status.isOK()) { - return; - } - if (status.isMultiStatus()) { - status = status.getChildren()[0]; // take the first one? - } - throw new RuntimeException(status.getMessage(), status.getException()); - } - - private InternalDatabase buildDatabase() { - if (this.isInactive()) { - return NullDatabase.instance(); - } - - 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)); - } - - boolean wraps(IConnectionProfile dtpCP) { - return this.dtpConnectionProfile == dtpCP; - } - - void databaseChanged(DTPDatabaseWrapper db, int eventType) { - this.connectionListener.databaseChanged(db, eventType); - } - - void catalogChanged(DTPCatalogWrapper catalog, int eventType) { - this.connectionListener.catalogChanged(catalog, eventType); - } - - void schemaChanged(DTPSchemaWrapper schema, int eventType) { - this.connectionListener.schemaChanged(schema, eventType); - } - - void sequenceChanged(DTPSequenceWrapper sequence, int eventType) { - this.connectionListener.sequenceChanged(sequence, eventType); - } - - void tableChanged(DTPTableWrapper table, int eventType) { - this.connectionListener.tableChanged(table, eventType); - } - - void columnChanged(DTPColumnWrapper column, int eventType) { - this.connectionListener.columnChanged(column, eventType); - } - - void foreignKeyChanged(DTPForeignKeyWrapper foreignKey, int eventType) { - this.connectionListener.foreignKeyChanged(foreignKey, eventType); - } - - /** - * private - use #getDefaultSchema() : Schema instead - */ - private String getDefaultSchemaName() { - if (this.getDatabase().getVendor().equalsIgnoreCase(POSTGRESQL_VENDOR)) { - return POSTGRESQL_DEFAULT_SCHEMA_NAME; - } - return this.getUserName(); - } - - private String getProperty(String propertyName) { - return this.dtpConnectionProfile.getBaseProperties().getProperty(propertyName); - } - - - // ********** disposal ********** - - synchronized void dispose() { - this.disposeDatabase(); - this.dtpManagedConnection.removeConnectionListener(this.connectionListener); - } - - synchronized void disposeDatabase() { - if (this.database != null) { - this.database.dispose(); - this.database = null; - } - } - - - // ********** Comparable implementation ********** - - public int compareTo(ConnectionProfile connectionProfile) { - return Collator.getInstance().compare(this.getName(), connectionProfile.getName()); - } - - - // ********** overrides ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } - - - // ********** DTP connection listener ********** - - /** - * This listener translates and forwards IManagedConnectionListener and - * IManagedConnectionOfflineListener events to ConnectionListeners. - */ - private class LocalConnectionListener implements IManagedConnectionOfflineListener { - private Vector<ConnectionListener> listeners = new Vector<ConnectionListener>(); - - LocalConnectionListener() { - super(); - } - - void addConnectionListener(ConnectionListener listener) { - this.listeners.add(listener); - } - - void removeConnectionListener(ConnectionListener listener) { - this.listeners.remove(listener); - } - - private Iterator<ConnectionListener> listeners() { - return new CloneIterator<ConnectionListener>(this.listeners); - } - - - // ********** IManagedConnectionListener implementation ********** - - public void opened(ConnectEvent event) { - // clear the (possibly "null") database so it will be rebuilt with the "live" data - DTPConnectionProfileWrapper.this.disposeDatabase(); - // forward event to listeners - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().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 (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().modified(DTPConnectionProfileWrapper.this); - } - } - - public boolean okToClose(ConnectEvent event) { - // forward event to listeners - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - if ( ! stream.next().okToClose(DTPConnectionProfileWrapper.this)) { - return false; - } - } - return true; - } - - public void aboutToClose(ConnectEvent event) { - // forward event to listeners - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().aboutToClose(DTPConnectionProfileWrapper.this); - } - } - - public void closed(ConnectEvent event) { - // clear the database - DTPConnectionProfileWrapper.this.disposeDatabase(); - // forward event to listeners - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().closed(DTPConnectionProfileWrapper.this); - } - } - - - // ********** IManagedConnectionOfflineListener implementation ********** - - // live => off-line - public boolean okToDetach(ConnectEvent event) { - // don't forward the event to listeners (?) - return true; - } - - // live => off-line - public void aboutToDetach(ConnectEvent event) { - // don't forward the event; the database will be cleared and - // listeners will be notified once the "offline" connection is "opened/workingOffline" - } - - // live => off-line - public void workingOffline(ConnectEvent event) { - // clear the (possibly null) database so it will be rebuilt with the "off-line" data - DTPConnectionProfileWrapper.this.disposeDatabase(); - // convert the event to an "open" event and forward it to listeners - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().opened(DTPConnectionProfileWrapper.this); - } - } - - // off-line => live - public void aboutToAttach(ConnectEvent event) { - // don't forward the event; the database will be cleared and - // listeners will be notified once the "live" connection is "opened" - } - - - // ********** internal methods ********** - - void databaseChanged(DTPDatabaseWrapper db, int eventType) { - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().databaseChanged(DTPConnectionProfileWrapper.this, db); - } - } - - void catalogChanged(DTPCatalogWrapper catalog, int eventType) { - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().catalogChanged(DTPConnectionProfileWrapper.this, catalog); - } - } - - void schemaChanged(DTPSchemaWrapper schema, int eventType) { - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().schemaChanged(DTPConnectionProfileWrapper.this, schema); - } - } - - void sequenceChanged(DTPSequenceWrapper sequence, int eventType) { - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().sequenceChanged(DTPConnectionProfileWrapper.this, sequence); - } - } - - void tableChanged(DTPTableWrapper table, int eventType) { - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().tableChanged(DTPConnectionProfileWrapper.this, table); - } - } - - void columnChanged(DTPColumnWrapper column, int eventType) { - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().columnChanged(DTPConnectionProfileWrapper.this, column); - } - } - - void foreignKeyChanged(DTPForeignKeyWrapper foreignKey, int eventType) { - for (Iterator<ConnectionListener> stream = this.listeners(); stream.hasNext(); ) { - stream.next().foreignKeyChanged(DTPConnectionProfileWrapper.this, foreignKey); - } - } - - } - -} 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 911d334423..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPDatabaseWrapper.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.datatools.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.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP Database. - * Sometimes the database will directly hold schemata; but if the database - * supports catalogs, it will not hold the schemata directly, but will delegate - * to the "default" catalog. - */ -final class DTPDatabaseWrapper - extends DTPSchemaContainerWrapper - implements InternalDatabase -{ - // backpointer to parent - private final DTPConnectionProfileWrapper connectionProfile; - - // the wrapped DTP database - private final org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase; - - // lazy-initialized - private DTPCatalogWrapper[] catalogs; - - // lazy-initialized - private DTPCatalogWrapper defaultCatalog; - private boolean defaultCatalogCalculated = false; - - // TODO allow user to configure? - private boolean caseSensitive = false; - - - private static final DTPCatalogWrapper[] EMPTY_CATALOGS = new DTPCatalogWrapper[0]; - - - // ********** constructor ********** - - DTPDatabaseWrapper(DTPConnectionProfileWrapper connectionProfile, org.eclipse.datatools.modelbase.sql.schema.Database dtpDatabase) { - super(connectionProfile, dtpDatabase); - this.connectionProfile = connectionProfile; - this.dtpDatabase = dtpDatabase; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - super.catalogObjectChanged(eventType); - this.getConnectionProfile().databaseChanged(this, eventType); - } - - - // ********** Database implementation ********** - - @Override - public String getName() { - return this.dtpDatabase.getName(); - } - - public String getVendor() { - return this.dtpDatabase.getVendor(); - } - - public String getVersion() { - return this.dtpDatabase.getVersion(); - } - - public DatabaseDefinition getDtpDefinition() { - return RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(this.dtpDatabase); - } - - // ***** caseSensitive - - @Override - public boolean isCaseSensitive() { - return this.caseSensitive; - } - - // TODO - public void setCaseSensitive(boolean caseSensitive) { - this.caseSensitive = caseSensitive; - } - - // ***** catalogs - - public boolean supportsCatalogs() { - // if the DTP database does not have any schemata, it must have catalogs... - List<org.eclipse.datatools.modelbase.sql.schema.Schema> dtpSchemata = this.dtpSchemata(); - return (dtpSchemata == null) || dtpSchemata.isEmpty(); - } - - public Iterator<Catalog> catalogs() { - return new ArrayIterator<Catalog>(this.catalogs_()); - } - - private Iterator<DTPCatalogWrapper> catalogWrappers() { - return new ArrayIterator<DTPCatalogWrapper>(this.catalogs_()); - } - - private synchronized DTPCatalogWrapper[] catalogs_() { - if (this.catalogs == null) { - this.catalogs = this.buildCatalogs(); - } - return this.catalogs; - } - - private DTPCatalogWrapper[] buildCatalogs() { - List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs = this.dtpCatalogs(); - if ((dtpCatalogs == null) || dtpCatalogs.isEmpty()) { - return EMPTY_CATALOGS; - } - DTPCatalogWrapper[] result = new DTPCatalogWrapper[dtpCatalogs.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPCatalogWrapper(this, dtpCatalogs.get(i)); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.schema.Catalog> dtpCatalogs() { - return this.dtpDatabase.getCatalogs(); - } - - public int catalogsSize() { - return this.catalogs_().length; - } - - public Iterator<String> catalogNames() { - return new TransformationIterator<DTPCatalogWrapper, String>(this.catalogWrappers()) { - @Override - protected String transform(DTPCatalogWrapper catalog) { - return catalog.getName(); - } - }; - } - - public boolean containsCatalogNamed(String name) { - return this.catalogNamed(name) != null; - } - - public DTPCatalogWrapper catalogNamed(String name) { - return this.isCaseSensitive() ? this.catalogNamedCaseSensitive(name) : this.catalogNamedIgnoreCase(name); - } - - private DTPCatalogWrapper catalogNamedCaseSensitive(String name) { - for (Iterator<DTPCatalogWrapper> stream = this.catalogWrappers(); stream.hasNext(); ) { - DTPCatalogWrapper catalog = stream.next(); - if (catalog.getName().equals(name)) { - return catalog; - } - } - return null; - } - - private DTPCatalogWrapper catalogNamedIgnoreCase(String name) { - for (Iterator<DTPCatalogWrapper> stream = this.catalogWrappers(); stream.hasNext(); ) { - DTPCatalogWrapper catalog = stream.next(); - if (StringTools.stringsAreEqualIgnoreCase(catalog.getName(), name)) { - return catalog; - } - } - return null; - } - - public synchronized DTPCatalogWrapper getDefaultCatalog() { - if ( ! this.defaultCatalogCalculated) { - this.defaultCatalogCalculated = true; - this.defaultCatalog = this.buildDefaultCatalog(); - } - return this.defaultCatalog; - } - - private DTPCatalogWrapper buildDefaultCatalog() { - if ( ! this.supportsCatalogs()) { - return null; - } - String userName = this.connectionProfile.getUserName(); - for (Iterator<DTPCatalogWrapper> stream = this.catalogWrappers(); stream.hasNext(); ) { - DTPCatalogWrapper catalog = stream.next(); - if (catalog.getName().length() == 0) { - return catalog; // special catalog that contains all schemata - } - if (catalog.getName().equals(userName)) { - return catalog; // user name is default catalog - } - if (catalog.getName().equals(this.getName())) { - return catalog; // special catalog with same name as DB (PostgreSQL) - } - } - throw new IllegalStateException("unknown default catalog"); //$NON-NLS-1$ - } - - /** - * return the catalog for the specified DTP catalog - */ - DTPCatalogWrapper catalog(org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) { - for (Iterator<DTPCatalogWrapper> stream = this.catalogWrappers(); stream.hasNext(); ) { - DTPCatalogWrapper catalog = stream.next(); - if (catalog.wraps(dtpCatalog)) { - return catalog; - } - } - throw new IllegalArgumentException("invalid DTP catalog: " + dtpCatalog); //$NON-NLS-1$ - } - - // ***** schemata - - @Override - @SuppressWarnings("unchecked") - List<org.eclipse.datatools.modelbase.sql.schema.Schema> dtpSchemata() { - return this.dtpDatabase.getSchemas(); - } - - @Override - synchronized DTPSchemaWrapper[] schemata_() { - return (this.supportsCatalogs()) ? - this.getDefaultCatalog().schemata_() - : - super.schemata_(); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Database database) { - return Collator.getInstance().compare(this.getName(), database.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Database database) { - return this.dtpDatabase == database; - } - - /** - * return the table for the specified DTP table - */ - DTPTableWrapper table(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - return this.schema(dtpTable.getSchema()).table(dtpTable); - } - - /** - * return the column for the specified DTP column - */ - DTPColumnWrapper column(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.table(dtpColumn.getTable()).column(dtpColumn); - } - - @Override - DTPDatabaseWrapper database() { - return this; - } - - - // ********** disposal ********** - - // must be public because it is defined in InternalDatabase interface - @Override - public synchronized void dispose() { - super.dispose(); - } - - @Override - void dispose_() { - this.defaultCatalogCalculated = false; - this.defaultCatalog = null; - this.disposeCatalogs(); - super.dispose_(); - } - - private void disposeCatalogs() { - if (this.catalogs != null) { - for (DTPCatalogWrapper catalog : this.catalogs) { - catalog.dispose(); - } - 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 74478aed5b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP ForeignKey - */ -final class DTPForeignKeyWrapper - extends DTPWrapper - implements ForeignKey -{ - // backpointer to parent - private final DTPTableWrapper baseTable; - - // 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 - private String defaultEntityFieldName; - private boolean defaultEntityFieldNameCalculated = false; - - - // ********** constructor ********** - - DTPForeignKeyWrapper(DTPTableWrapper baseTable, org.eclipse.datatools.modelbase.sql.constraints.ForeignKey dtpForeignKey) { - super(baseTable, dtpForeignKey); - this.baseTable = baseTable; - this.dtpForeignKey = dtpForeignKey; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - // clear stuff so it will be rebuilt - this.dispose_(); - this.getConnectionProfile().foreignKeyChanged(this, eventType); - } - - - // ********** ForeignKey implementation ********** - - @Override - public String getName() { - return this.dtpForeignKey.getName(); - } - - public DTPTableWrapper getBaseTable() { - return this.baseTable; - } - - public synchronized DTPTableWrapper getReferencedTable() { - if (this.referencedTable == null) { - this.referencedTable = this.baseTable.table(this.dtpForeignKey.getUniqueConstraint().getBaseTable()); - } - return this.referencedTable; - } - - // ***** column pairs - - public Iterator<ColumnPair> columnPairs() { - return new ArrayIterator<ColumnPair>(this.columnPairs_()); - } - - public LocalColumnPair columnPair() { - LocalColumnPair[] pairs = this.columnPairs_(); - 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.columnPairs_()); - } - - private synchronized LocalColumnPair[] columnPairs_() { - if (this.columnPairs == null) { - this.columnPairs = this.buildColumnPairs(); - } - return this.columnPairs; - } - - private LocalColumnPair[] buildColumnPairs() { - List<org.eclipse.datatools.modelbase.sql.tables.Column> baseColumns = this.dtpBaseColumns(); - int size = baseColumns.size(); - List<org.eclipse.datatools.modelbase.sql.tables.Column> refColumns = this.dtpRefColumns(); - if (refColumns.size() != size) { - throw new IllegalStateException(this.getBaseTable().getName() + "." + this.getName() + //$NON-NLS-1$ - " - 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; ) { - DTPColumnWrapper baseColumn = this.baseTable.column(baseColumns.get(i)); - DTPColumnWrapper refColumn = this.baseTable.column(refColumns.get(i)); - result[i] = new LocalColumnPair(baseColumn, refColumn); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> dtpBaseColumns() { - return this.dtpForeignKey.getMembers(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> dtpRefColumns() { - return this.dtpForeignKey.getUniqueConstraint().getMembers(); - } - - public int columnPairsSize() { - return this.columnPairs_().length; - } - - public Iterator<Column> baseColumns() { - return new TransformationIterator<LocalColumnPair, Column>(this.localColumnPairs()) { - @Override - protected Column transform(LocalColumnPair pair) { - return pair.baseColumn(); - } - }; - } - - 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 ! DTPForeignKeyWrapper.this.getBaseTable().primaryKeyColumnsContains(column); - } - }; - } - - public Iterator<Column> referencedColumns() { - return new TransformationIterator<LocalColumnPair, Column>(this.localColumnPairs()) { - @Override - protected Column transform(LocalColumnPair columnPair) { - return columnPair.referencedColumn(); - } - }; - } - - // ***** default entity field name - - /** - * If the name of the "base" column adheres to the EJB standard 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 entity field name: - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.ID) => "CUBICLE" - * Return a null if it does not adhere to the EJB standard: - * ForeignKey(EMP.CUBICLE_ID => CUBICLE.CUBICLE_ID) => null - */ - private synchronized String defaultEntityFieldName() { - if ( ! this.defaultEntityFieldNameCalculated) { - this.defaultEntityFieldNameCalculated = true; - this.defaultEntityFieldName = this.buildDefaultEntityFieldName(); - } - return this.defaultEntityFieldName; - } - - /** - * @see #defaultEntityFieldName() - */ - private String buildDefaultEntityFieldName() { - if ( ! this.referencesSingleColumnPrimaryKey()) { - return null; - } - LocalColumnPair columnPair = this.columnPairs_()[0]; - String baseColName = columnPair.baseColumn().getName(); - String refColName = columnPair.referencedColumn().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; - } - String name = baseColName.substring(0, _index); - return this.isCaseSensitive() ? name : name.toLowerCase(); - } - - // ***** miscellaneous - - public String getJavaFieldName() { - String fieldName = this.defaultEntityFieldName(); - return (fieldName != null) ? fieldName : this.nonDefaultEntityFieldName(); - } - - public boolean defaultMatchesJavaFieldName(String javaFieldName) { - return this.isCaseSensitive() ? - javaFieldName.equals(this.defaultEntityFieldName()) - : - javaFieldName.equalsIgnoreCase(this.defaultEntityFieldName()); - } - - public boolean isDefaultFor(String javaFieldName) { - if (this.columnPairsSize() != 1) { - return false; - } - - if (this.getReferencedTable().primaryKeyColumnsSize() != 1) { - return false; - } - - LocalColumnPair columnPair = this.columnPairs_()[0]; - Column pkColumn = this.getReferencedTable().primaryKeyColumn(); - if (columnPair.referencedColumn() != pkColumn) { - return false; - } - - return columnPair.baseColumn().matchesJavaFieldName(javaFieldName + "_" + pkColumn.getName()); //$NON-NLS-1$ - } - - public boolean referencesSingleColumnPrimaryKey() { - if (this.columnPairsSize() != 1) { - return false; - } - if (this.getReferencedTable().primaryKeyColumnsSize() != 1) { - return false; - } - - return this.columnPair().referencedColumn() == this.getReferencedTable().primaryKeyColumn(); - } - - /** - * If this is a simple (single-column) foreign key, return the java field - * name of the single base column. If this is a compound foreign key, - * return the java field 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? - // TODO if the FK column name ends with the PK column name, strip the PK column name? - private String nonDefaultEntityFieldName() { - return (this.columnPairsSize() == 1) ? - this.columnPair().baseColumn().getJavaFieldName() - : - this.getReferencedTable().getJavaFieldName(); - } - - - // ********** Comparable implementation ********** - - public int compareTo(ForeignKey foreignKey) { - return Collator.getInstance().compare(this.getName(), foreignKey.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.constraints.ForeignKey foreignKey) { - return this.dtpForeignKey == foreignKey; - } - - boolean isCaseSensitive() { - return this.baseTable.isCaseSensitive(); - } - - DTPDatabaseWrapper database() { - return this.baseTable.database(); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName() + ": " + Arrays.asList(this.columnPairs_())); //$NON-NLS-1$ - } - - - // ********** disposal ********** - - @Override - synchronized void dispose() { - this.dispose_(); - super.dispose(); - } - - private void dispose_() { - // the foreign key does not "contain" any other objects, - // so we don't need to forward the #dispose() - this.defaultEntityFieldNameCalculated = false; - this.defaultEntityFieldName = null; - this.columnPairs = null; - this.referencedTable = null; - } - - - // ********** column pair implementation ********** - - private static class LocalColumnPair implements ColumnPair { - private final DTPColumnWrapper baseColumn; - private final DTPColumnWrapper referencedColumn; - - LocalColumnPair(DTPColumnWrapper baseColumn, DTPColumnWrapper referencedColumn) { - super(); - this.baseColumn = baseColumn; - this.referencedColumn = referencedColumn; - } - - - // ********** ColumnPair implementation ********** - - public DTPColumnWrapper baseColumn() { - return this.baseColumn; - } - - public DTPColumnWrapper referencedColumn() { - return this.referencedColumn; - } - - - // ********** Comparable implementation ********** - - public int compareTo(ColumnPair columnPair) { - return Collator.getInstance().compare(this.baseColumn().getName(), columnPair.baseColumn().getName()); - } - - - // ********** Object overrides ********** - - @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 21a13551ad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaContainerWrapper.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Coalesce behavior for a schema container (i.e. database or catalog). - */ -abstract class DTPSchemaContainerWrapper - extends DTPWrapper - implements SchemaContainer -{ - // lazy-initialized - private DTPSchemaWrapper[] schemata; - - - // ********** constructor ********** - - DTPSchemaContainerWrapper(ConnectionProfileHolder connectionProfileHolder, Object dtpObject) { - super(connectionProfileHolder, dtpObject); - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - // clear stuff so it will be rebuilt - this.dispose_(); - } - - - // ********** abstract methods ********** - - abstract DTPDatabaseWrapper database(); - - abstract boolean isCaseSensitive(); - - abstract List<org.eclipse.datatools.modelbase.sql.schema.Schema> dtpSchemata(); - - - // ********** schemata ********** - - public Iterator<Schema> schemata() { - return new ArrayIterator<Schema>(this.schemata_()); - } - - private Iterator<DTPSchemaWrapper> schemaWrappers() { - return new ArrayIterator<DTPSchemaWrapper>(this.schemata_()); - } - - synchronized DTPSchemaWrapper[] schemata_() { - if (this.schemata == null) { - this.schemata = this.buildSchemata(); - } - return this.schemata; - } - - private DTPSchemaWrapper[] buildSchemata() { - List<org.eclipse.datatools.modelbase.sql.schema.Schema> dtpSchemata = this.dtpSchemata(); - DTPSchemaWrapper[] result = new DTPSchemaWrapper[dtpSchemata.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPSchemaWrapper(this, dtpSchemata.get(i)); - } - return result; - } - - public int schemataSize() { - return this.schemata_().length; - } - - public Iterator<String> schemaNames() { - return new TransformationIterator<DTPSchemaWrapper, String>(this.schemaWrappers()) { - @Override - protected String transform(DTPSchemaWrapper schema) { - return schema.getName(); - } - }; - } - - public boolean containsSchemaNamed(String name) { - return this.schemaNamed(name) != null; - } - - public DTPSchemaWrapper schemaNamed(String name) { - return this.isCaseSensitive() ? this.schemaNamedCaseSensitive(name) : this.schemaNamedIgnoreCase(name); - } - - private DTPSchemaWrapper schemaNamedCaseSensitive(String name) { - for (Iterator<DTPSchemaWrapper> stream = this.schemaWrappers(); stream.hasNext(); ) { - DTPSchemaWrapper schema = stream.next(); - if (schema.getName().equals(name)) { - return schema; - } - } - return null; - } - - private DTPSchemaWrapper schemaNamedIgnoreCase(String name) { - for (Iterator<DTPSchemaWrapper> stream = this.schemaWrappers(); stream.hasNext(); ) { - DTPSchemaWrapper schema = stream.next(); - if (StringTools.stringsAreEqualIgnoreCase(schema.getName(), name)) { - return schema; - } - } - return null; - } - - /** - * return the schema for the specified DTP schema - */ - DTPSchemaWrapper schema(org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - for (Iterator<DTPSchemaWrapper> stream = this.schemaWrappers(); stream.hasNext(); ) { - DTPSchemaWrapper schema = stream.next(); - if (schema.wraps(dtpSchema)) { - return schema; - } - } - throw new IllegalArgumentException("invalid DTP schema: " + dtpSchema); //$NON-NLS-1$ - } - - - // ********** disposal ********** - - @Override - synchronized void dispose() { - this.dispose_(); - super.dispose(); - } - - void dispose_() { - this.disposeSchemata(); - } - - private void disposeSchemata() { - if (this.schemata != null) { - for (DTPSchemaWrapper schema : this.schemata) { - schema.dispose(); - } - 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 270f3d711c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSchemaWrapper.java +++ /dev/null @@ -1,289 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Sequence; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP Schema - */ -final class DTPSchemaWrapper - extends DTPWrapper - implements Schema -{ - // backpointer to parent - private final DTPSchemaContainerWrapper container; - - // the wrapped DTP schema - private final org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema; - - // lazy-initialized - private DTPTableWrapper[] tables; - - // lazy-initialized - private DTPSequenceWrapper[] sequences; - - - // ********** constructor ********** - - DTPSchemaWrapper(DTPSchemaContainerWrapper container, org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema) { - super(container, dtpSchema); - this.container = container; - this.dtpSchema = dtpSchema; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - // clear stuff so it can be rebuilt - this.dispose_(); - this.getConnectionProfile().schemaChanged(this, eventType); - } - - - // ********** Schema implementation ********** - - @Override - public String getName() { - return this.dtpSchema.getName(); - } - - // ***** tables - - public Iterator<Table> tables() { - return new ArrayIterator<Table>(this.tables_()); - } - - private Iterator<DTPTableWrapper> tableWrappers() { - return new ArrayIterator<DTPTableWrapper>(this.tables_()); - } - - private synchronized DTPTableWrapper[] tables_() { - if (this.tables == null) { - this.tables = this.buildTables(); - } - return this.tables; - } - - private DTPTableWrapper[] buildTables() { - List<org.eclipse.datatools.modelbase.sql.tables.Table> dtpTables = this.dtpTables(); - DTPTableWrapper[] result = new DTPTableWrapper[dtpTables.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPTableWrapper(this, dtpTables.get(i)); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Table> dtpTables() { - return this.dtpSchema.getTables(); - } - - public int tablesSize() { - return this.tables_().length; - } - - public Iterator<String> tableNames() { - return new TransformationIterator<DTPTableWrapper, String>(this.tableWrappers()) { - @Override - protected String transform(DTPTableWrapper table) { - return table.getName(); - } - }; - } - - public boolean containsTableNamed(String name) { - return this.tableNamed(name) != null; - } - - public DTPTableWrapper tableNamed(String name) { - return this.isCaseSensitive() ? this.tableNamedCaseSensitive(name) : this.tableNamedIgnoreCase(name); - } - - private DTPTableWrapper tableNamedCaseSensitive(String name) { - for (Iterator<DTPTableWrapper> stream = this.tableWrappers(); stream.hasNext(); ) { - DTPTableWrapper table = stream.next(); - if (table.getName().equals(name)) { - return table; - } - } - return null; - } - - private DTPTableWrapper tableNamedIgnoreCase(String name) { - for (Iterator<DTPTableWrapper> stream = this.tableWrappers(); stream.hasNext(); ) { - DTPTableWrapper table = stream.next(); - if (StringTools.stringsAreEqualIgnoreCase(table.getName(), name)) { - return table; - } - } - return null; - } - - /** - * return the table for the specified DTP table - */ - DTPTableWrapper table(org.eclipse.datatools.modelbase.sql.tables.Table dtpTable) { - if (dtpTable.getSchema() != this.dtpSchema) { - return this.database().table(dtpTable); - } - for (Iterator<DTPTableWrapper> stream = this.tableWrappers(); stream.hasNext(); ) { - DTPTableWrapper table = stream.next(); - if (table.wraps(dtpTable)) { - return table; - } - } - throw new IllegalArgumentException("invalid DTP table: " + dtpTable); //$NON-NLS-1$ - } - - // ***** sequences - - public Iterator<Sequence> sequences() { - return new ArrayIterator<Sequence>(this.sequences_()); - } - - private Iterator<DTPSequenceWrapper> sequenceWrappers() { - return new ArrayIterator<DTPSequenceWrapper>(this.sequences_()); - } - - private synchronized DTPSequenceWrapper[] sequences_() { - if (this.sequences == null) { - this.sequences = this.buildSequences(); - } - return this.sequences; - } - - private DTPSequenceWrapper[] buildSequences() { - List<org.eclipse.datatools.modelbase.sql.schema.Sequence> dtpSequences = this.dtpSequences(); - DTPSequenceWrapper[] result = new DTPSequenceWrapper[dtpSequences.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPSequenceWrapper(this, dtpSequences.get(i)); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.schema.Sequence> dtpSequences() { - return this.dtpSchema.getSequences(); - } - - public int sequencesSize() { - return this.sequences_().length; - } - - public Iterator<String> sequenceNames() { - return new TransformationIterator<DTPSequenceWrapper, String>(this.sequenceWrappers()) { - @Override - protected String transform(DTPSequenceWrapper sequence) { - return sequence.getName(); - } - }; - } - - public boolean containsSequenceNamed(String name) { - return this.sequenceNamed(name) != null; - } - - public DTPSequenceWrapper sequenceNamed(String name) { - return this.isCaseSensitive() ? this.sequenceNamedCaseSensitive(name) : this.sequenceNamedIgnoreCase(name); - } - - private DTPSequenceWrapper sequenceNamedCaseSensitive(String name) { - for (Iterator<DTPSequenceWrapper> stream = this.sequenceWrappers(); stream.hasNext(); ) { - DTPSequenceWrapper sequence = stream.next(); - if (sequence.getName().equals(name)) { - return sequence; - } - } - return null; - } - - private DTPSequenceWrapper sequenceNamedIgnoreCase(String name) { - for (Iterator<DTPSequenceWrapper> stream = this.sequenceWrappers(); stream.hasNext(); ) { - DTPSequenceWrapper sequence = stream.next(); - if (sequence.getName().equalsIgnoreCase(name)) { - return sequence; - } - } - return null; - } - - - // ********** Comparable implementation ********** - - public int compareTo(Schema schema) { - return Collator.getInstance().compare(this.getName(), schema.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Schema schema) { - return this.dtpSchema == schema; - } - - boolean isCaseSensitive() { - return this.database().isCaseSensitive(); - } - - DTPColumnWrapper column(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - return this.database().column(dtpColumn); - } - - DTPDatabaseWrapper database() { - return this.container.database(); - } - - - // ********** disposal ********** - - @Override - synchronized void dispose() { - this.dispose_(); - super.dispose(); - } - - private void dispose_() { - this.disposeSequences(); - this.disposeTables(); - } - - private void disposeSequences() { - if (this.sequences != null) { - for (DTPSequenceWrapper sequence : this.sequences) { - sequence.dispose(); - } - this.sequences = null; - } - } - - private void disposeTables() { - if (this.tables != null) { - for (DTPTableWrapper table : this.tables) { - table.dispose(); - } - 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 b1e546bd07..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPSequenceWrapper.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; - -import org.eclipse.jpt.db.Sequence; - -/** - * Wrap a DTP Sequence - */ -final class DTPSequenceWrapper - extends DTPWrapper - implements Sequence -{ - // backpointer to parent - private final DTPSchemaWrapper schema; - - // 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.schema = schema; - this.dtpSequence = dtpSequence; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - this.getConnectionProfile().sequenceChanged(this, eventType); - } - - - // ********** Sequence implementation ********** - - @Override - public String getName() { - return this.dtpSequence.getName(); - } - - - // ********** Comparable implementation ********** - - public int compareTo(Sequence sequence) { - return Collator.getInstance().compare(this.getName(), sequence.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.schema.Sequence sequence) { - return this.dtpSequence == sequence; - } - - boolean isCaseSensitive() { - return this.schema.isCaseSensitive(); - } - - DTPDatabaseWrapper database() { - return this.schema.database(); - } - -} 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 f5db4d69cd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPTableWrapper.java +++ /dev/null @@ -1,351 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.text.Collator; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.datatools.modelbase.sql.constraints.PrimaryKey; -import org.eclipse.datatools.modelbase.sql.tables.BaseTable; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Wrap a DTP Table - */ -final class DTPTableWrapper - extends DTPWrapper - implements Table -{ - // backpointer to parent - private final DTPSchemaWrapper schema; - - // 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.schema = schema; - this.dtpTable = dtpTable; - } - - - // ********** DTPWrapper implementation ********** - - @Override - synchronized void catalogObjectChanged(int eventType) { - // clear stuff so it can be rebuilt - this.dispose_(); - this.getConnectionProfile().tableChanged(this, eventType); - } - - - // ********** Table implementation ********** - - @Override - public String getName() { - return this.dtpTable.getName(); - } - - public String getShortJavaClassName() { - String jName = this.getName(); - if ( ! this.isCaseSensitive()) { - jName = StringTools.capitalize(jName.toLowerCase()); - } - return NameTools.convertToJavaIdentifier(jName); - } - - public boolean matchesShortJavaClassName(String shortJavaClassName) { - return this.isCaseSensitive() ? - this.getName().equals(shortJavaClassName) - : - this.getName().equalsIgnoreCase(shortJavaClassName); - } - - public String getJavaFieldName() { - String jName = this.getName(); - if ( ! this.isCaseSensitive()) { - jName = jName.toLowerCase(); - } - return NameTools.convertToJavaIdentifier(jName); - } - - // ***** columns - - public Iterator<Column> columns() { - return new ArrayIterator<Column>(this.columns_()); - } - - private Iterator<DTPColumnWrapper> columnWrappers() { - return new ArrayIterator<DTPColumnWrapper>(this.columns_()); - } - - private synchronized DTPColumnWrapper[] columns_() { - if (this.columns == null) { - this.columns = this.buildColumns(); - } - return this.columns; - } - - private DTPColumnWrapper[] buildColumns() { - List<org.eclipse.datatools.modelbase.sql.tables.Column> dtpColumns = this.dtpColumns(); - DTPColumnWrapper[] result = new DTPColumnWrapper[dtpColumns.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = new DTPColumnWrapper(this, dtpColumns.get(i)); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> dtpColumns() { - return this.dtpTable.getColumns(); - } - - public int columnsSize() { - return this.columns_().length; - } - - public Iterator<String> columnNames() { - return new TransformationIterator<DTPColumnWrapper, String>(this.columnWrappers()) { - @Override - protected String transform(DTPColumnWrapper next) { - return next.getName(); - } - }; - } - - public boolean containsColumnNamed(String name) { - return this.columnNamed(name) != null; - } - - public DTPColumnWrapper columnNamed(String name) { - return this.isCaseSensitive() ? this.columnNamedCaseSensitive(name) : this.columnNamedIgnoreCase(name); - } - - private DTPColumnWrapper columnNamedCaseSensitive(String name) { - for (Iterator<DTPColumnWrapper> stream = this.columnWrappers(); stream.hasNext(); ) { - DTPColumnWrapper column = stream.next(); - if (column.getName().equals(name)) { - return column; - } - } - return null; - } - - private DTPColumnWrapper columnNamedIgnoreCase(String name) { - for (Iterator<DTPColumnWrapper> stream = this.columnWrappers(); stream.hasNext(); ) { - DTPColumnWrapper column = stream.next(); - if (StringTools.stringsAreEqualIgnoreCase(column.getName(), name)) { - return column; - } - } - return null; - } - - /** - * return the column for the specified DTP column - */ - DTPColumnWrapper column(org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) { - if (dtpColumn.getTable() != this.dtpTable) { - return this.schema.column(dtpColumn); - } - for (DTPColumnWrapper column : this.columns_()) { - if (column.wraps(dtpColumn)) { - return column; - } - } - throw new IllegalArgumentException("invalid DTP column: " + dtpColumn); //$NON-NLS-1$ - } - - // ***** primaryKeyColumns - - public Iterator<Column> primaryKeyColumns() { - return new ArrayIterator<Column>(this.primaryKeyColumns_()); - } - - public DTPColumnWrapper primaryKeyColumn() { - DTPColumnWrapper[] pkColumns = this.primaryKeyColumns_(); - if (pkColumns.length != 1) { - throw new IllegalStateException("multiple primary key columns: " + pkColumns.length); //$NON-NLS-1$ - } - return pkColumns[0]; - } - - private synchronized DTPColumnWrapper[] primaryKeyColumns_() { - 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.columns(pk); - DTPColumnWrapper[] result = new DTPColumnWrapper[pkColumns.size()]; - for (int i = result.length; i-- > 0;) { - result[i] = this.column(pkColumns.get(i)); - } - return result; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<org.eclipse.datatools.modelbase.sql.tables.Column> columns(PrimaryKey pk) { - return pk.getMembers(); - } - - public int primaryKeyColumnsSize() { - return this.primaryKeyColumns_().length; - } - - public boolean primaryKeyColumnsContains(Column column) { - return CollectionTools.contains(this.primaryKeyColumns_(), column); - } - - // ***** foreignKeys - - public Iterator<ForeignKey> foreignKeys() { - return new ArrayIterator<ForeignKey>(this.foreignKeys_()); - } - - private Iterator<DTPForeignKeyWrapper> foreignKeyWrappers() { - return new ArrayIterator<DTPForeignKeyWrapper>(this.foreignKeys_()); - } - - private synchronized DTPForeignKeyWrapper[] foreignKeys_() { - 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.dtpForeignKeys(); - 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> dtpForeignKeys() { - return ((BaseTable) this.dtpTable).getForeignKeys(); - } - - public int foreignKeysSize() { - return this.foreignKeys_().length; - } - - public boolean foreignKeyBaseColumnsContains(Column column) { - for (Iterator<DTPForeignKeyWrapper> stream = this.foreignKeyWrappers(); stream.hasNext(); ) { - DTPForeignKeyWrapper foreignKey = stream.next(); - if (foreignKey.baseColumnsContains(column)) { - return true; - } - } - return false; - } - - - // ********** Comparable implementation ********** - - public int compareTo(Table table) { - return Collator.getInstance().compare(this.getName(), table.getName()); - } - - - // ********** internal methods ********** - - boolean wraps(org.eclipse.datatools.modelbase.sql.tables.Table table) { - return this.dtpTable == table; - } - - boolean isCaseSensitive() { - return this.schema.isCaseSensitive(); - } - - DTPTableWrapper table(org.eclipse.datatools.modelbase.sql.tables.Table table) { - return this.schema.table(table); - } - - DTPDatabaseWrapper database() { - return this.schema.database(); - } - - - // ********** disposal ********** - - @Override - synchronized void dispose() { - this.dispose_(); - super.dispose(); - } - - private void dispose_() { - this.disposeForeignKeys(); - // the table does not "contain" the pk columns, so no need to forward #dispose() - this.primaryKeyColumns = null; - this.disposeColumns(); - } - - private void disposeForeignKeys() { - if (this.foreignKeys != null) { - for (DTPForeignKeyWrapper foreignKey : this.foreignKeys) { - foreignKey.dispose(); - } - this.foreignKeys = null; - } - } - - private void disposeColumns() { - if (this.columns != null) { - for (DTPColumnWrapper column : this.columns) { - column.dispose(); - } - this.columns = null; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPWrapper.java deleted file mode 100644 index cbe702a597..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPWrapper.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObjectListener; -import org.eclipse.datatools.connectivity.sqm.core.rte.RefreshManager; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * DTP Catalog Object Wrapper base class - */ -abstract class DTPWrapper - implements ConnectionProfileHolder -{ - // we need a way to get to the connection profile - private final ConnectionProfileHolder connectionProfileHolder; - - // listen for the "catalog object" being refreshed - private final ICatalogObjectListener catalogObjectListener; - - // we only listen to "live" connections - private final boolean connectionIsLive; - - // listen for this to refresh - final ICatalogObject catalogObject; - - - DTPWrapper(ConnectionProfileHolder connectionProfileHolder, Object dtpObject) { - super(); - this.connectionProfileHolder = connectionProfileHolder; - this.connectionIsLive = this.getConnectionProfile().isConnected(); - if (this.connectionIsLive) { - this.catalogObject = (ICatalogObject) dtpObject; - this.catalogObjectListener = this.buildCatalogObjectListener(); - RefreshManager.getInstance().AddListener(this.catalogObject, this.catalogObjectListener); - } else { - this.catalogObject = null; - this.catalogObjectListener = null; - } - } - - private ICatalogObjectListener buildCatalogObjectListener() { - return new ICatalogObjectListener() { - public void notifyChanged(ICatalogObject dmElement, int eventType) { - if (dmElement == DTPWrapper.this.catalogObject) { - DTPWrapper.this.catalogObjectChanged(eventType); - } - } - }; - } - - // typically, notify the connection profile something has changed - abstract void catalogObjectChanged(int eventType); - - public DTPConnectionProfileWrapper getConnectionProfile() { - return this.connectionProfileHolder.getConnectionProfile(); - } - - void dispose() { - if (this.connectionIsLive) { - RefreshManager.getInstance().removeListener(this.catalogObject, this.catalogObjectListener); - } - } - - // all the subclasses can implement this method - abstract String getName(); - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/InternalDatabase.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/InternalDatabase.java deleted file mode 100644 index aa61c6043f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/InternalDatabase.java +++ /dev/null @@ -1,20 +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.Database; - -/** - * "internal" database - */ -interface InternalDatabase extends Database { - DTPCatalogWrapper getDefaultCatalog(); - void dispose(); -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/NullConnectionProfile.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/NullConnectionProfile.java deleted file mode 100644 index 5673dfb5d9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/NullConnectionProfile.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.ConnectionListener; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.ClassTools; - -/** - * "null" connection profile - */ -final class NullConnectionProfile - implements ConnectionProfile -{ - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - - - // ********** singleton ********** - - private static final NullConnectionProfile INSTANCE = new NullConnectionProfile(); - - static ConnectionProfile instance() { - return INSTANCE; - } - - /** - * 'private' to ensure singleton - */ - private NullConnectionProfile() { - super(); - } - - - // ********** ConnectionProfile implementation ********** - - public void connect() { - // do nothing - } - - public void disconnect() { - // do nothing - } - - public IStatus saveWorkOfflineData() { - return Status.CANCEL_STATUS; - } - - public IStatus workOffline() { - return Status.CANCEL_STATUS; - } - - public Database getDatabase() { - return NullDatabase.instance(); - } - - public String getName() { - return ClassTools.shortClassNameForObject(this); - } - - public String getDatabaseName() { - return EMPTY_STRING; - } - - public String getDatabaseProduct() { - return EMPTY_STRING; - } - - public String getDatabaseVendor() { - return EMPTY_STRING; - } - - public String getDatabaseVersion() { - return EMPTY_STRING; - } - - public String getUserName() { - return EMPTY_STRING; - } - - public String getUserPassword() { - return EMPTY_STRING; - } - - public String getDriverClassName() { - return EMPTY_STRING; - } - - public String getUrl() { - return EMPTY_STRING; - } - - public String getInstanceID() { - return EMPTY_STRING; - } - - public String getProviderID() { - return EMPTY_STRING; - } - - public String getDriverDefinitionID() { - return EMPTY_STRING; - } - - public String getDriverJarList() { - return EMPTY_STRING; - } - - public boolean isActive() { - return false; - } - - public boolean isWorkingOffline() { - return false; - } - - public boolean isConnected() { - return false; - } - - public boolean supportsWorkOfflineMode() { - return false; - } - - public boolean canWorkOffline() { - return false; - } - - public void addConnectionListener( ConnectionListener listener) { - // do nothing - } - - public void removeConnectionListener( ConnectionListener listener) { - // do nothing - } - - public Schema getDefaultSchema() { - return null; - } - - public Catalog getDefaultCatalog() { - return null; - } - - public boolean isNull() { - return true; - } - - - // ********** Comparable implementation ********** - - public int compareTo(ConnectionProfile o) { - throw new UnsupportedOperationException("the \"null\" connection profile should not be in a sorted list"); //$NON-NLS-1$ - } - - - // ********** Object overrides ********** - - @Override - public String toString() { - return ClassTools.toStringClassNameForObject(this); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/NullDatabase.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/NullDatabase.java deleted file mode 100644 index 8ff4139cfd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/NullDatabase.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.internal; - -import java.util.Iterator; - -import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - -/** - * "null" database - * This is used when the connection profile is inactive (i.e. it is neither - * connected to the database nor working off-line). - */ -final class NullDatabase - implements InternalDatabase -{ - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - - - // ********** singleton ********** - - private static final NullDatabase INSTANCE = new NullDatabase(); - - static synchronized InternalDatabase instance() { - return INSTANCE; - } - - /** - * 'private' to ensure singleton - */ - private NullDatabase() { - super(); - } - - - // ********** Database implementation ********** - - public String getName() { - return ClassTools.shortClassNameForObject(this); - } - - public String getVendor() { - return EMPTY_STRING; - } - - public String getVersion() { - return EMPTY_STRING; - } - - public boolean isCaseSensitive() { - return false; - } - - public DatabaseDefinition getDtpDefinition() { - return null; - } - - // ***** catalogs - - public boolean supportsCatalogs() { - return false; - } - - public Iterator<Catalog> catalogs() { - return EmptyIterator.<Catalog>instance(); - } - - public int catalogsSize() { - return 0; - } - - public Iterator<String> catalogNames() { - return EmptyIterator.<String>instance(); - } - - public boolean containsCatalogNamed(String name) { - return false; - } - - public Catalog catalogNamed(String name) { - return null; - } - - public String defaultCatalogName() { - return EMPTY_STRING; - } - - public DTPCatalogWrapper getDefaultCatalog() { - return null; - } - - // ***** schemata - - public Iterator<Schema> schemata() { - return EmptyIterator.<Schema>instance(); - } - - public int schemataSize() { - return 0; - } - - public Iterator<String> schemaNames() { - return EmptyIterator.<String>instance(); - } - - public boolean containsSchemaNamed(String name) { - return false; - } - - public Schema schemaNamed(String name) { - return null; - } - - - // ********** InternalDatabase implementation ********** - - public void dispose() { - // do nothing - } - - - // ********** Comparable implementation ********** - - public int compareTo(Database o) { - throw new UnsupportedOperationException("the \"null\" database should not be in a sorted list"); //$NON-NLS-1$ - } - - - // ********** Object overrides ********** - - @Override - public String toString() { - return ClassTools.toStringClassNameForObject(this); - } - -} |