Skip to main content
summaryrefslogtreecommitdiffstats
blob: d3e6b78194dbb1f63aac9ab647457fb17e2e7b9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
 * Copyright (c) 2009 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.db.internal.vendor;

import java.util.Collections;
import java.util.List;

import org.eclipse.datatools.modelbase.sql.schema.Catalog;
import org.eclipse.datatools.modelbase.sql.schema.Database;
import org.eclipse.datatools.modelbase.sql.schema.Schema;

/**
 * Catalog strategy for DTP databases that simply model the catalogs returned
 * by the underlying JDBC driver (e.g. Sybase).
 * @see java.sql.DatabaseMetaData#getCatalogs()
 */
class SimpleCatalogStrategy
	implements CatalogStrategy
{
	// singleton
	private static final CatalogStrategy INSTANCE = new SimpleCatalogStrategy();

	/**
	 * Return the singleton.
	 */
	static CatalogStrategy instance() {
		return INSTANCE;
	}

	/**
	 * Ensure single instance.
	 */
	private SimpleCatalogStrategy() {
		super();
	}

	@SuppressWarnings("unchecked")
	public boolean supportsCatalogs(Database database) {
		// Bug 327572 - Unfortunately DTP allows for optional support of catalogs in extensions
		List<Catalog> catalogs = database.getCatalogs();
		if ((catalogs == null) || catalogs.isEmpty()) {
			return false;
		}
		
		// normal logic:
		return true;
	}

	@SuppressWarnings("unchecked")
	public List<Catalog> getCatalogs(Database database) {
		List<Catalog> catalogs = database.getCatalogs();
		// Bug 327572 - Unfortunately DTP allows for optional support of catalogs in extensions
		if ((catalogs == null) || catalogs.isEmpty()) {
			return Collections.emptyList();
		}
		
		// normal logic:
		return catalogs;
	}

	@SuppressWarnings("unchecked")
	public List<Schema> getSchemas(Database database) {
		List<Catalog> catalogs = database.getCatalogs();
		// Bug 327572 - Unfortunately DTP allows for optional support of catalogs in extensions
		// if there are no catalogs, the database must hold the schemata directly
		if ((catalogs == null) || catalogs.isEmpty()) {
			return database.getSchemas();
		}
		
		// normal logic:
		return Collections.emptyList();
	}

}

Back to the top