summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Queinnec2011-10-06 15:37:05 (EDT)
committerBrian Payton2011-10-06 15:37:05 (EDT)
commit65b7da3697e2d4805f006fd8337c2ac913b819d9 (patch)
treeaabc8b3fb635bc5208fb4064b401c2f574a02f20
parent34df1ec75ab23e1d970abc471ef12cf97288a6bd (diff)
downloadorg.eclipse.datatools.enablement.postgresql-65b7da3697e2d4805f006fd8337c2ac913b819d9.zip
org.eclipse.datatools.enablement.postgresql-65b7da3697e2d4805f006fd8337c2ac913b819d9.tar.gz
org.eclipse.datatools.enablement.postgresql-65b7da3697e2d4805f006fd8337c2ac913b819d9.tar.bz2
Checked in changes for bugs 241557 and 359861
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/plugin.xml31
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogDatabase.java124
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogProvider.java44
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogSchema.java126
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresAuthorizationIdentifierLoader.java131
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSchemaLoader.java40
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSequenceLoader.java151
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/containment/PostgresAuthorizationIdContainmentProvider.java22
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/PostgresUser.java24
-rw-r--r--plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/impl/PostgresUserImpl.java23
11 files changed, 720 insertions, 1 deletions
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/META-INF/MANIFEST.MF b/plugins/org.eclipse.datatools.enablement.postgresql/META-INF/MANIFEST.MF
index a0e28e3..e7b009d 100644
--- a/plugins/org.eclipse.datatools.enablement.postgresql/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/META-INF/MANIFEST.MF
@@ -7,8 +7,11 @@ Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.datatools.connectivity;bundle-version="[0.9.1,1.5.0)",
org.eclipse.datatools.connectivity.db.generic;bundle-version="[0.9.1,1.5.0)",
- org.eclipse.datatools.connectivity.sqm.core;bundle-version="[0.9.1,1.5.0)"
+ org.eclipse.datatools.connectivity.sqm.core;bundle-version="[0.9.1,1.5.0)",
+ org.eclipse.datatools.modelbase.sql;bundle-version="[0.9.0,1.5.0)"
Eclipse-LazyStart: true
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.eclipse.datatools.enablement.postgresql.catalog,
+ org.eclipse.datatools.enablement.postgresql.catalog.loaders
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/plugin.xml b/plugins/org.eclipse.datatools.enablement.postgresql/plugin.xml
index f0441c6..6635fd1 100644
--- a/plugins/org.eclipse.datatools.enablement.postgresql/plugin.xml
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/plugin.xml
@@ -88,5 +88,36 @@
providerID="org.eclipse.datatools.enablement.postgresql.connectionProfile">
</providerIDtoDriverCategoryID>
</extension>
+ <extension
+ point="org.eclipse.datatools.connectivity.sqm.core.catalog">
+ <catalog
+ product="postgres"
+ provider="org.eclipse.datatools.enablement.postgresql.catalog.PostgresCatalogProvider"
+ version="8.x">
+ </catalog>
+ </extension>
+ <extension
+ point="org.eclipse.datatools.connectivity.sqm.core.catalog">
+ <overrideLoader
+ eclass="org.eclipse.datatools.modelbase.sql.accesscontrol.AuthorizationIdentifier"
+ product="postgres"
+ provider="org.eclipse.datatools.enablement.postgresql.catalog.loaders.PostgresAuthorizationIdentifierLoader"
+ version="8.x">
+ </overrideLoader>
+ <overrideLoader
+ eclass="org.eclipse.datatools.modelbase.sql.schema.Schema"
+ product="postgres"
+ provider="org.eclipse.datatools.enablement.postgresql.catalog.loaders.PostgresSchemaLoader"
+ version="8.x">
+ </overrideLoader>
+ </extension>
+ <extension
+ point="org.eclipse.datatools.connectivity.sqm.core.logicalContainment">
+ <containment
+ class="User"
+ package="http:///org/eclipse/datatools/modelbase/sql/accesscontrol.ecore"
+ provider="org.eclipse.datatools.enablement.postgresql.containment.PostgresAuthorizationIdContainmentProvider">
+ </containment>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogDatabase.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogDatabase.java
new file mode 100644
index 0000000..bb890c0
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogDatabase.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.catalog;
+
+import java.lang.ref.SoftReference;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition;
+import org.eclipse.datatools.connectivity.sqm.core.rte.RefreshManager;
+import org.eclipse.datatools.connectivity.sqm.core.rte.jdbc.JDBCDatabase;
+import org.eclipse.datatools.connectivity.sqm.core.util.CatalogLoaderOverrideManager;
+import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin;
+import org.eclipse.datatools.connectivity.sqm.loader.JDBCBaseLoader;
+import org.eclipse.datatools.enablement.postgresql.catalog.loaders.PostgresAuthorizationIdentifierLoader;
+import org.eclipse.datatools.modelbase.sql.accesscontrol.SQLAccessControlPackage;
+import org.eclipse.emf.common.util.EList;
+
+/**
+ * A PostgreSQL database.
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresCatalogDatabase extends JDBCDatabase {
+
+ private final Object AUTHORIZATION_IDS_LOCK = new Object();
+
+ private Boolean authorizationIdsLoaded = Boolean.FALSE;
+
+ private transient SoftReference authorizationIdLoaderRef;
+
+ public PostgresCatalogDatabase(Connection connection) {
+ super(connection);
+ }
+
+ public void refresh() {
+ synchronized (AUTHORIZATION_IDS_LOCK) {
+ if (authorizationIdsLoaded.booleanValue()) {
+ authorizationIdsLoaded = Boolean.FALSE;
+ }
+ }
+
+ RefreshManager.getInstance().referesh(this);
+ }
+
+ @Override
+ public EList getAuthorizationIds() {
+ synchronized (AUTHORIZATION_IDS_LOCK) {
+ if (!authorizationIdsLoaded.booleanValue())
+ this.loadAuthorizationIdentifiers();
+ }
+
+ return super.getAuthorizationIds();
+ }
+
+ private void loadAuthorizationIdentifiers() {
+ synchronized (AUTHORIZATION_IDS_LOCK) {
+ boolean deliver = eDeliver();
+ try {
+ List container = super.getAuthorizationIds();
+ List existingAuthorizationIds = new ArrayList(container);
+
+ eSetDeliver(false);
+
+ container.clear();
+ getAuthorizationIdentifierLoader().loadAuthorizationIdentifiers(container, existingAuthorizationIds);
+ getAuthorizationIdentifierLoader().clearAuthorizationIdentifiers(existingAuthorizationIds);
+
+ authorizationIdsLoaded = Boolean.TRUE;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+
+ } finally {
+ eSetDeliver(deliver);
+ }
+ }
+ }
+
+ protected final PostgresAuthorizationIdentifierLoader getAuthorizationIdentifierLoader() {
+ // cache the AuthorizationIdentifierLoader for better performance
+ if (authorizationIdLoaderRef == null || authorizationIdLoaderRef.get() == null) {
+ authorizationIdLoaderRef = new SoftReference(createAuthorizationIdentifierLoader());
+ }
+
+ return (PostgresAuthorizationIdentifierLoader) authorizationIdLoaderRef.get();
+ }
+
+ /**
+ * Creates and returns an instance of the AuthorizationIdentifierLoader. By default an instance of the
+ * <code>PostgresAuthorizationIdentifierLoader</code> is returned. This behavior can be changed by providing an
+ * <code>overrideLoader</code> using the eclass org.eclipse.datatools.modelbase.sql.accesscontrol.
+ * AuthorizationIdentifier.
+ *
+ * @return An instance of PostgresAuthorizationIdentifierLoader.
+ */
+ private PostgresAuthorizationIdentifierLoader createAuthorizationIdentifierLoader() {
+ // get the database definition for the actual database
+ DatabaseDefinition databaseDefinition = RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry()
+ .getDefinition(this.getCatalogDatabase());
+
+ // see if someone is interested in providing an own authorization identifier loader
+ JDBCBaseLoader loader = CatalogLoaderOverrideManager.INSTANCE.getLoaderForDatabase(databaseDefinition,
+ SQLAccessControlPackage.eINSTANCE.getAuthorizationIdentifier().getInstanceClassName());
+
+ if (loader != null) {
+ PostgresAuthorizationIdentifierLoader authorizationIdLoader = (PostgresAuthorizationIdentifierLoader) loader;
+ authorizationIdLoader.setCatalogObject(this);
+ return authorizationIdLoader;
+ }
+
+ return new PostgresAuthorizationIdentifierLoader(this);
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogProvider.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogProvider.java
new file mode 100644
index 0000000..58ca18a
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogProvider.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.catalog;
+
+import java.sql.Connection;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogProvider;
+import org.eclipse.datatools.modelbase.sql.schema.Database;
+
+/**
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresCatalogProvider implements ICatalogProvider, IExecutableExtension {
+
+ private String product;
+ private String version;
+
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
+ throws CoreException {
+
+ this.product = config.getAttribute("product"); //$NON-NLS-1$
+ this.version = config.getAttribute("version"); //$NON-NLS-1$
+ }
+
+ public Database getCatalogDatabase(Connection connection) {
+ Database database = new PostgresCatalogDatabase(connection);
+ database.setVendor(this.product);
+ database.setVersion(this.version);
+ return database;
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogSchema.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogSchema.java
new file mode 100644
index 0000000..f710ee9
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogSchema.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.catalog;
+
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition;
+import org.eclipse.datatools.connectivity.sqm.core.rte.jdbc.JDBCSchema;
+import org.eclipse.datatools.connectivity.sqm.core.util.CatalogLoaderOverrideManager;
+import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin;
+import org.eclipse.datatools.connectivity.sqm.loader.JDBCBaseLoader;
+import org.eclipse.datatools.enablement.postgresql.catalog.loaders.PostgresSequenceLoader;
+import org.eclipse.datatools.modelbase.sql.schema.SQLSchemaPackage;
+import org.eclipse.emf.common.util.EList;
+
+/**
+ * PostgreSQL Schema.
+ *
+ * Enhances the original implementation of <code>JDBCSchema</code> to support
+ * the following features:
+ * <ul>
+ * <li>Sequence loading</li>
+ * </ul>
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresCatalogSchema extends JDBCSchema {
+
+ private final Object SEQUENCE_LOCK = new Object();
+
+ private Boolean sequencesLoaded = Boolean.FALSE;
+
+ private transient SoftReference sequenceLoaderRef;
+
+ public void refresh() {
+ synchronized (SEQUENCE_LOCK) {
+ if (sequencesLoaded.booleanValue()) {
+ sequencesLoaded = Boolean.FALSE;
+ }
+ }
+
+ super.refresh();
+ }
+
+ public EList getSequences() {
+ synchronized (SEQUENCE_LOCK) {
+ if (!sequencesLoaded.booleanValue())
+ this.loadSequences();
+ }
+
+ return super.getSequences();
+ }
+
+ protected final PostgresSequenceLoader getSequenceLoader() {
+ // cache the SequenceLoader for better performance
+ if (sequenceLoaderRef == null || sequenceLoaderRef.get() == null) {
+ sequenceLoaderRef = new SoftReference(createSequenceLoader());
+ }
+
+ return (PostgresSequenceLoader) sequenceLoaderRef.get();
+ }
+
+ private void loadSequences() {
+ synchronized (SEQUENCE_LOCK) {
+ boolean deliver = eDeliver();
+ try {
+ List container = super.getSequences();
+ List existingSequences = new ArrayList(container);
+
+ eSetDeliver(false);
+
+ container.clear();
+ getSequenceLoader().loadSequences(container, existingSequences);
+ getSequenceLoader().clearSequences(existingSequences);
+
+ sequencesLoaded = Boolean.TRUE;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+
+ } finally {
+ eSetDeliver(deliver);
+ }
+ }
+ }
+
+ /**
+ * Creates and returns an instance of the SequenceLoader. By default an
+ * instance of the <code>PostgresSequenceLoader</code> is returned. This
+ * behavior can be changed by providing an <code>overrideLoader</code> using
+ * the eclass org.eclipse.datatools.modelbase.sql.schema.Sequence.
+ *
+ * @return An instance of PostgresSequenceLoader.
+ */
+ private PostgresSequenceLoader createSequenceLoader() {
+ // get the database definiton for the actual database
+ DatabaseDefinition databaseDefinition = RDBCorePlugin.getDefault()
+ .getDatabaseDefinitionRegistry()
+ .getDefinition(this.getCatalogDatabase());
+
+ // see if someone is interested in providing an own sequence loader
+ JDBCBaseLoader loader = CatalogLoaderOverrideManager.INSTANCE
+ .getLoaderForDatabase(databaseDefinition,
+ SQLSchemaPackage.eINSTANCE.getSequence()
+ .getInstanceClassName());
+
+ if (loader != null) {
+ PostgresSequenceLoader sequenceLoader = (PostgresSequenceLoader) loader;
+ sequenceLoader.setCatalogObject(this);
+ return sequenceLoader;
+ }
+
+ return new PostgresSequenceLoader(this);
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresAuthorizationIdentifierLoader.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresAuthorizationIdentifierLoader.java
new file mode 100644
index 0000000..3dd937d
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresAuthorizationIdentifierLoader.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.catalog.loaders;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionFilter;
+import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject;
+import org.eclipse.datatools.connectivity.sqm.loader.IConnectionFilterProvider;
+import org.eclipse.datatools.connectivity.sqm.loader.JDBCBaseLoader;
+import org.eclipse.datatools.connectivity.sqm.loader.SchemaObjectFilterProvider;
+import org.eclipse.datatools.enablement.postgresql.model.impl.PostgresUserImpl;
+import org.eclipse.datatools.modelbase.sql.accesscontrol.User;
+
+/**
+ * This class adds the ability to retrieve a list of authorization identifiers from a PostgreSQL database.
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresAuthorizationIdentifierLoader extends JDBCBaseLoader {
+
+ private static final String USER_QUERY = "SELECT * FROM pg_user;"; //$NON-NLS-1$
+ private static final String USER_NAME = "usename";
+
+ public PostgresAuthorizationIdentifierLoader() {
+ this(null);
+ }
+
+ public PostgresAuthorizationIdentifierLoader(ICatalogObject catalogObject) {
+ this(catalogObject, new SchemaObjectFilterProvider(ConnectionFilter.SEQUENCE_FILTER));
+ }
+
+ /**
+ * @param catalogObject
+ * @param connectionFilterProvider
+ */
+ public PostgresAuthorizationIdentifierLoader(ICatalogObject catalogObject,
+ IConnectionFilterProvider connectionFilterProvider) {
+
+ super(catalogObject, connectionFilterProvider);
+ }
+
+ public void clearAuthorizationIdentifiers(List existingAuthorizationIds) {
+ existingAuthorizationIds.clear();
+ }
+
+ public void loadAuthorizationIdentifiers(List containmentList, List existingAuthorizationIds) throws SQLException {
+ ResultSet rs = null;
+ PreparedStatement stmt = null;
+ try {
+ // initActiveFilter();
+
+ stmt = getCatalogObject().getConnection().prepareStatement(USER_QUERY);
+ rs = createResultSet(stmt);
+
+ while (rs.next()) {
+ String userName = rs.getString(USER_NAME);
+
+ if (userName == null || isFiltered(userName)) {
+ continue;
+ }
+
+ User user = (User) getAndRemoveSQLObject(existingAuthorizationIds, userName);
+
+ if (user == null) {
+ user = processRow(rs);
+ if (user != null) {
+ containmentList.add(user);
+ }
+ } else {
+ containmentList.add(user);
+ if (user instanceof ICatalogObject) {
+ ((ICatalogObject) user).refresh();
+ }
+ }
+ }
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+
+ } catch (SQLException e) {
+ // ignored
+
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (SQLException e) {
+ // ignored
+ }
+ }
+ }
+ }
+
+ protected User processRow(ResultSet rs) throws SQLException {
+ // User user = SQLAccessControlFactory.eINSTANCE.createUser();
+ User user = new PostgresUserImpl();
+ String userName = rs.getString(USER_NAME).trim();
+ user.setName(userName);
+ user.setLabel(userName);
+
+ return user;
+ }
+
+ protected ResultSet createResultSet(PreparedStatement stmt) throws SQLException {
+ try {
+ return stmt.executeQuery();
+
+ } catch (RuntimeException e) {
+ SQLException error = new SQLException(
+ "Error while retrieving database information (authorization identifiers)");
+ error.initCause(e);
+ throw error;
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSchemaLoader.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSchemaLoader.java
new file mode 100644
index 0000000..056e1fd
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSchemaLoader.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.catalog.loaders;
+
+import org.eclipse.datatools.connectivity.sqm.loader.JDBCSchemaLoader;
+import org.eclipse.datatools.enablement.postgresql.catalog.PostgresCatalogSchema;
+import org.eclipse.datatools.modelbase.sql.schema.Schema;
+
+/**
+ * Class for loading schemas from a PostgreSQL database.
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresSchemaLoader extends JDBCSchemaLoader {
+
+ public PostgresSchemaLoader() {
+ super(null);
+ }
+
+ /**
+ * Returns a new Schema object. This method overrides the default behavior
+ * and returns a new PostgreSQLCatalogSchema.
+ *
+ * @return a new Schema object.
+ *
+ * @see org.eclipse.datatools.connectivity.sqm.loader.JDBCSchemaLoader#createSchema()
+ */
+ protected Schema createSchema() {
+ return new PostgresCatalogSchema();
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSequenceLoader.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSequenceLoader.java
new file mode 100644
index 0000000..ab80305
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSequenceLoader.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.catalog.loaders;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionFilter;
+import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject;
+import org.eclipse.datatools.connectivity.sqm.loader.IConnectionFilterProvider;
+import org.eclipse.datatools.connectivity.sqm.loader.JDBCBaseLoader;
+import org.eclipse.datatools.connectivity.sqm.loader.SchemaObjectFilterProvider;
+import org.eclipse.datatools.modelbase.sql.schema.SQLSchemaFactory;
+import org.eclipse.datatools.modelbase.sql.schema.Sequence;
+
+/**
+ * This class adds the ability to retrieve a list of sequences from a PostgreSQL
+ * database.
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresSequenceLoader extends JDBCBaseLoader {
+
+ private static final String SEQUENCE_QUERY = "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S' ORDER BY c.relname"; //$NON-NLS-1$
+ private static final String SEQUENCE_NAME = "relname";
+
+ public PostgresSequenceLoader() {
+ this(null);
+ }
+
+ public PostgresSequenceLoader(ICatalogObject catalogObject) {
+ this(catalogObject, new SchemaObjectFilterProvider(
+ ConnectionFilter.SEQUENCE_FILTER));
+ }
+
+ public PostgresSequenceLoader(ICatalogObject catalogObject,
+ IConnectionFilterProvider connectionFilterProvider) {
+
+ super(catalogObject, connectionFilterProvider);
+ }
+
+ public void clearSequences(List sequences) {
+ sequences.clear();
+ }
+
+ /**
+ * This method loads and fills the containmentList with the sequences. In
+ * addition every reference (to an found sequence) is removed from
+ * existingSequences. Considered are only those sequences, that are owned by
+ * the schema denoted by CatalogObject (should be an Schema).
+ *
+ * @param containmentList
+ * List of new Sequences
+ * @param existingSequences
+ * List of old Sequences
+ * @throws SQLException
+ * In case of an database error
+ */
+ public void loadSequences(List containmentList, Collection existingSequences)
+ throws SQLException {
+
+ ResultSet rs = null;
+ PreparedStatement stmt = null;
+ try {
+ initActiveFilter();
+
+ stmt = getCatalogObject().getConnection().prepareStatement(
+ SEQUENCE_QUERY);
+ rs = createResultSet(stmt);
+
+ while (rs.next()) {
+ String sequenceName = rs.getString(SEQUENCE_NAME);
+
+ if (sequenceName == null || isFiltered(sequenceName)) {
+ continue;
+ }
+
+ Sequence sequence = (Sequence) getAndRemoveSQLObject(
+ existingSequences, sequenceName);
+
+ if (sequence == null) {
+ sequence = processRow(rs);
+ if (sequence != null) {
+ containmentList.add(sequence);
+ }
+ } else {
+ containmentList.add(sequence);
+ if (sequence instanceof ICatalogObject) {
+ ((ICatalogObject) sequence).refresh();
+ }
+ }
+ }
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+
+ } catch (SQLException e) {
+ // ignored
+
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (SQLException e) {
+ // ignored
+ }
+ }
+ }
+ }
+
+ protected Sequence processRow(ResultSet rs) throws SQLException {
+ Sequence sequence = SQLSchemaFactory.eINSTANCE.createSequence();
+ sequence.setName(rs.getString(SEQUENCE_NAME).trim());
+ return sequence;
+ }
+
+ protected ResultSet createResultSet(PreparedStatement stmt)
+ throws SQLException {
+ try {
+ // TODO decide wether to filter on the schema (temp sequences are
+ // generated on a special schema, so decide wether to list them or
+ // not)
+
+ // it's expected that catalog object is an Schema
+ // String schema = ((Schema) getCatalogObject()).getName();
+ // stmt.setString(1, schema);
+ return stmt.executeQuery();
+
+ } catch (RuntimeException e) {
+ SQLException error = new SQLException(
+ "Error while retrieving catalog information (sequences)");
+ error.initCause(e);
+ throw error;
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/containment/PostgresAuthorizationIdContainmentProvider.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/containment/PostgresAuthorizationIdContainmentProvider.java
new file mode 100644
index 0000000..9ebc63c
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/containment/PostgresAuthorizationIdContainmentProvider.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.containment;
+
+import org.eclipse.datatools.connectivity.sqm.internal.core.containment.AuthorizationIdContainmentProvider;
+
+/**
+ * A containment provider for PostgreSQL authorization identifiers.
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresAuthorizationIdContainmentProvider extends AuthorizationIdContainmentProvider {
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/PostgresUser.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/PostgresUser.java
new file mode 100644
index 0000000..e8d21e4
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/PostgresUser.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.model;
+
+import org.eclipse.datatools.modelbase.sql.accesscontrol.User;
+
+/**
+ * A PostgreSQL user definition.
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public interface PostgresUser extends User {
+
+ // TODO add usecreatedb | usesuper | usecatupd | valuntil | useconfig
+
+}
diff --git a/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/impl/PostgresUserImpl.java b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/impl/PostgresUserImpl.java
new file mode 100644
index 0000000..854a9b3
--- /dev/null
+++ b/plugins/org.eclipse.datatools.enablement.postgresql/src/org/eclipse/datatools/enablement/postgresql/model/impl/PostgresUserImpl.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Zenika
+ *
+ * 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: queinnec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.datatools.enablement.postgresql.model.impl;
+
+import org.eclipse.datatools.enablement.postgresql.model.PostgresUser;
+import org.eclipse.datatools.modelbase.sql.accesscontrol.impl.UserImpl;
+
+/**
+ * A PostgreSQL user definition (as in pg_user).
+ *
+ * @author pierre.queinnec@zenika.com
+ */
+public class PostgresUserImpl extends UserImpl implements PostgresUser {
+
+}