Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 241557 | Differences between
and this patch

Collapse All | Expand All

(-)runtime/vendors/postgresql/postgresql_8.x.xmi (-2 / +2 lines)
Lines 4-10 Link Here
4
	xmlns:DBDefinition="http:///org/eclipse/datatools/modelbase/dbdefinition/dbdefinition.ecore"
4
	xmlns:DBDefinition="http:///org/eclipse/datatools/modelbase/dbdefinition/dbdefinition.ecore"
5
	vendor="postgres" version="8.x" maximumIdentifierLength="64"
5
	vendor="postgres" version="8.x" maximumIdentifierLength="64"
6
	joinSupported="true" tablespacesSupported="false" maximumCommentLength="60"
6
	joinSupported="true" tablespacesSupported="false" maximumCommentLength="60"
7
	schemaSupported="true" aliasSupported="true" SQLStatementSupported="true">
7
	schemaSupported="true" aliasSupported="true" sequenceSupported="true" SQLStatementSupported="true">
8
	
8
	
9
	<!-- Label for unresolved data types -->
9
	<!-- Label for unresolved data types -->
10
	<predefinedDataTypeDefinitions xmi:id="UNRESOLVED_DATA_TYPE"
10
	<predefinedDataTypeDefinitions xmi:id="UNRESOLVED_DATA_TYPE"
Lines 1160-1163 Link Here
1160
		<operators>BINARY</operators>
1160
		<operators>BINARY</operators>
1161
		<operators>COLLATE</operators>
1161
		<operators>COLLATE</operators>
1162
	</SQLSyntaxDefinition>
1162
	</SQLSyntaxDefinition>
1163
</DBDefinition:DatabaseVendorDefinition>
1163
</DBDefinition:DatabaseVendorDefinition>
(-)META-INF/MANIFEST.MF (-1 / +4 lines)
Lines 7-14 Link Here
7
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
7
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
8
 org.eclipse.datatools.connectivity;bundle-version="[0.9.1,1.5.0)",
8
 org.eclipse.datatools.connectivity;bundle-version="[0.9.1,1.5.0)",
9
 org.eclipse.datatools.connectivity.db.generic;bundle-version="[0.9.1,1.5.0)",
9
 org.eclipse.datatools.connectivity.db.generic;bundle-version="[0.9.1,1.5.0)",
10
 org.eclipse.datatools.connectivity.sqm.core;bundle-version="[0.9.1,1.5.0)"
10
 org.eclipse.datatools.connectivity.sqm.core;bundle-version="[0.9.1,1.5.0)",
11
 org.eclipse.datatools.modelbase.sql;bundle-version="[0.9.0,1.5.0)"
11
Eclipse-LazyStart: true
12
Eclipse-LazyStart: true
12
Bundle-ActivationPolicy: lazy
13
Bundle-ActivationPolicy: lazy
13
Bundle-Vendor: %providerName
14
Bundle-Vendor: %providerName
14
Bundle-RequiredExecutionEnvironment: J2SE-1.5
15
Bundle-RequiredExecutionEnvironment: J2SE-1.5
16
Export-Package: org.eclipse.datatools.enablement.postgresql.catalog,
17
 org.eclipse.datatools.enablement.postgresql.catalog.loaders
(-)plugin.xml (+9 lines)
Lines 88-92 Link Here
88
          providerID="org.eclipse.datatools.enablement.postgresql.connectionProfile">
88
          providerID="org.eclipse.datatools.enablement.postgresql.connectionProfile">
89
    </providerIDtoDriverCategoryID>
89
    </providerIDtoDriverCategoryID>
90
 </extension>
90
 </extension>
91
 <extension
92
       point="org.eclipse.datatools.connectivity.sqm.core.catalog">
93
    <overrideLoader
94
          eclass="org.eclipse.datatools.modelbase.sql.schema.Schema"
95
          product="postgres"
96
          provider="org.eclipse.datatools.enablement.postgresql.catalog.loaders.PostgresSchemaLoader"
97
          version="8.x">
98
    </overrideLoader>
99
 </extension>
91
100
92
</plugin>
101
</plugin>
(-)src/org/eclipse/datatools/enablement/postgresql/catalog/PostgresCatalogSchema.java (+126 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Zenika
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: queinnec - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.datatools.enablement.postgresql.catalog;
12
13
import java.lang.ref.SoftReference;
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.datatools.connectivity.sqm.core.definition.DatabaseDefinition;
18
import org.eclipse.datatools.connectivity.sqm.core.rte.jdbc.JDBCSchema;
19
import org.eclipse.datatools.connectivity.sqm.core.util.CatalogLoaderOverrideManager;
20
import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin;
21
import org.eclipse.datatools.connectivity.sqm.loader.JDBCBaseLoader;
22
import org.eclipse.datatools.enablement.postgresql.catalog.loaders.PostgresSequenceLoader;
23
import org.eclipse.datatools.modelbase.sql.schema.SQLSchemaPackage;
24
import org.eclipse.emf.common.util.EList;
25
26
/**
27
 * PostgreSQL Schema.
28
 * 
29
 * Enhances the original implementation of <code>JDBCSchema</code> to support
30
 * the following features:
31
 * <ul>
32
 * <li>Sequence loading</li>
33
 * </ul>
34
 * 
35
 * @author pierre.queinnec@zenika.com
36
 */
37
public class PostgresCatalogSchema extends JDBCSchema {
38
39
	private final Object SEQUENCE_LOCK = new Object();
40
41
	private Boolean sequencesLoaded = Boolean.FALSE;
42
43
	private transient SoftReference sequenceLoaderRef;
44
45
	public void refresh() {
46
		synchronized (SEQUENCE_LOCK) {
47
			if (sequencesLoaded.booleanValue()) {
48
				sequencesLoaded = Boolean.FALSE;
49
			}
50
		}
51
52
		super.refresh();
53
	}
54
55
	public EList getSequences() {
56
		synchronized (SEQUENCE_LOCK) {
57
			if (!sequencesLoaded.booleanValue())
58
				this.loadSequences();
59
		}
60
61
		return super.getSequences();
62
	}
63
64
	protected final PostgresSequenceLoader getSequenceLoader() {
65
		// cache the SequenceLoader for better performance
66
		if (sequenceLoaderRef == null || sequenceLoaderRef.get() == null) {
67
			sequenceLoaderRef = new SoftReference(createSequenceLoader());
68
		}
69
70
		return (PostgresSequenceLoader) sequenceLoaderRef.get();
71
	}
72
73
	private void loadSequences() {
74
		synchronized (SEQUENCE_LOCK) {
75
			boolean deliver = eDeliver();
76
			try {
77
				List container = super.getSequences();
78
				List existingSequences = new ArrayList(container);
79
80
				eSetDeliver(false);
81
82
				container.clear();
83
				getSequenceLoader().loadSequences(container, existingSequences);
84
				getSequenceLoader().clearSequences(existingSequences);
85
86
				sequencesLoaded = Boolean.TRUE;
87
88
			} catch (Exception e) {
89
				e.printStackTrace();
90
91
			} finally {
92
				eSetDeliver(deliver);
93
			}
94
		}
95
	}
96
97
	/**
98
	 * Creates and returns an instance of the SequenceLoader. By default an
99
	 * instance of the <code>PostgresSequenceLoader</code> is returned. This
100
	 * behavior can be changed by providing an <code>overrideLoader</code> using
101
	 * the eclass org.eclipse.datatools.modelbase.sql.schema.Sequence.
102
	 * 
103
	 * @return An instance of PostgresSequenceLoader.
104
	 */
105
	private PostgresSequenceLoader createSequenceLoader() {
106
		// get the database definiton for the actual database
107
		DatabaseDefinition databaseDefinition = RDBCorePlugin.getDefault()
108
				.getDatabaseDefinitionRegistry()
109
				.getDefinition(this.getCatalogDatabase());
110
111
		// see if someone is interested in providing an own sequence loader
112
		JDBCBaseLoader loader = CatalogLoaderOverrideManager.INSTANCE
113
				.getLoaderForDatabase(databaseDefinition,
114
						SQLSchemaPackage.eINSTANCE.getSequence()
115
								.getInstanceClassName());
116
117
		if (loader != null) {
118
			PostgresSequenceLoader sequenceLoader = (PostgresSequenceLoader) loader;
119
			sequenceLoader.setCatalogObject(this);
120
			return sequenceLoader;
121
		}
122
123
		return new PostgresSequenceLoader(this);
124
	}
125
126
}
(-)src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSchemaLoader.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Zenika
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: queinnec - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.datatools.enablement.postgresql.catalog.loaders;
12
13
import org.eclipse.datatools.connectivity.sqm.loader.JDBCSchemaLoader;
14
import org.eclipse.datatools.enablement.postgresql.catalog.PostgresCatalogSchema;
15
import org.eclipse.datatools.modelbase.sql.schema.Schema;
16
17
/**
18
 * Class for loading schemas from a PostgreSQL database.
19
 * 
20
 * @author pierre.queinnec@zenika.com
21
 */
22
public class PostgresSchemaLoader extends JDBCSchemaLoader {
23
24
	public PostgresSchemaLoader() {
25
		super(null);
26
	}
27
28
	/**
29
	 * Returns a new Schema object. This method overrides the default behavior
30
	 * and returns a new PostgreSQLCatalogSchema.
31
	 * 
32
	 * @return a new Schema object.
33
	 * 
34
	 * @see org.eclipse.datatools.connectivity.sqm.loader.JDBCSchemaLoader#createSchema()
35
	 */
36
	protected Schema createSchema() {
37
		return new PostgresCatalogSchema();
38
	}
39
40
}
(-)src/org/eclipse/datatools/enablement/postgresql/catalog/loaders/PostgresSequenceLoader.java (+151 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Zenika
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: queinnec - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.datatools.enablement.postgresql.catalog.loaders;
12
13
import java.sql.PreparedStatement;
14
import java.sql.ResultSet;
15
import java.sql.SQLException;
16
import java.util.Collection;
17
import java.util.List;
18
19
import org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionFilter;
20
import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject;
21
import org.eclipse.datatools.connectivity.sqm.loader.IConnectionFilterProvider;
22
import org.eclipse.datatools.connectivity.sqm.loader.JDBCBaseLoader;
23
import org.eclipse.datatools.connectivity.sqm.loader.SchemaObjectFilterProvider;
24
import org.eclipse.datatools.modelbase.sql.schema.SQLSchemaFactory;
25
import org.eclipse.datatools.modelbase.sql.schema.Sequence;
26
27
/**
28
 * This class adds the ability to retrieve a list of sequences from a PostgreSQL
29
 * database.
30
 * 
31
 * @author pierre.queinnec@zenika.com
32
 */
33
public class PostgresSequenceLoader extends JDBCBaseLoader {
34
35
	private static final String SEQUENCE_QUERY = "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S' ORDER BY c.relname"; //$NON-NLS-1$
36
	private static final String SEQUENCE_NAME = "relname";
37
38
	public PostgresSequenceLoader() {
39
		this(null);
40
	}
41
42
	public PostgresSequenceLoader(ICatalogObject catalogObject) {
43
		this(catalogObject, new SchemaObjectFilterProvider(
44
				ConnectionFilter.SEQUENCE_FILTER));
45
	}
46
47
	public PostgresSequenceLoader(ICatalogObject catalogObject,
48
			IConnectionFilterProvider connectionFilterProvider) {
49
50
		super(catalogObject, connectionFilterProvider);
51
	}
52
53
	public void clearSequences(List sequences) {
54
		sequences.clear();
55
	}
56
57
	/**
58
	 * This method loads and fills the containmentList with the sequences. In
59
	 * addition every reference (to an found sequence) is removed from
60
	 * existingSequences. Considered are only those sequences, that are owned by
61
	 * the schema denoted by CatalogObject (should be an Schema).
62
	 * 
63
	 * @param containmentList
64
	 *            List of new Sequences
65
	 * @param existingSequences
66
	 *            List of old Sequences
67
	 * @throws SQLException
68
	 *             In case of an database error
69
	 */
70
	public void loadSequences(List containmentList, Collection existingSequences)
71
			throws SQLException {
72
73
		ResultSet rs = null;
74
		PreparedStatement stmt = null;
75
		try {
76
			initActiveFilter();
77
78
			stmt = getCatalogObject().getConnection().prepareStatement(
79
					SEQUENCE_QUERY);
80
			rs = createResultSet(stmt);
81
82
			while (rs.next()) {
83
				String sequenceName = rs.getString(SEQUENCE_NAME);
84
85
				if (sequenceName == null || isFiltered(sequenceName)) {
86
					continue;
87
				}
88
89
				Sequence sequence = (Sequence) getAndRemoveSQLObject(
90
						existingSequences, sequenceName);
91
92
				if (sequence == null) {
93
					sequence = processRow(rs);
94
					if (sequence != null) {
95
						containmentList.add(sequence);
96
					}
97
				} else {
98
					containmentList.add(sequence);
99
					if (sequence instanceof ICatalogObject) {
100
						((ICatalogObject) sequence).refresh();
101
					}
102
				}
103
			}
104
		} finally {
105
			try {
106
				if (rs != null) {
107
					rs.close();
108
				}
109
110
			} catch (SQLException e) {
111
				// ignored
112
113
			} finally {
114
				try {
115
					if (stmt != null) {
116
						stmt.close();
117
					}
118
				} catch (SQLException e) {
119
					// ignored
120
				}
121
			}
122
		}
123
	}
124
125
	protected Sequence processRow(ResultSet rs) throws SQLException {
126
		Sequence sequence = SQLSchemaFactory.eINSTANCE.createSequence();
127
		sequence.setName(rs.getString(SEQUENCE_NAME).trim());
128
		return sequence;
129
	}
130
131
	protected ResultSet createResultSet(PreparedStatement stmt)
132
			throws SQLException {
133
		try {
134
			// TODO decide wether to filter on the schema (temp sequences are
135
			// generated on a special schema, so decide wether to list them or
136
			// not)
137
138
			// it's expected that catalog object is an Schema
139
			// String schema = ((Schema) getCatalogObject()).getName();
140
			// stmt.setString(1, schema);
141
			return stmt.executeQuery();
142
143
		} catch (RuntimeException e) {
144
			SQLException error = new SQLException(
145
					"Error while retrieving catalog information (sequences)");
146
			error.initCause(e);
147
			throw error;
148
		}
149
	}
150
151
}

Return to bug 241557