Skip to main content
summaryrefslogtreecommitdiffstats
blob: 11c486fbf436561b451f62e13f392e72c1730dd9 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * Copyright (c) 2008, 2011 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.jpa.db;

/**
 * Database
 * <p>
 * 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 Database
	extends SchemaContainer
{
	/**
	 * Return the database's DTP database.
	 */
	org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase();


	// ********** properties **********

	/**
	 * Return the name of the database's vendor.
	 */
	String getVendorName();

	/**
	 * Return the database's version.
	 */
	String getVersion();


	// ********** catalogs **********

	/**
	 * Return whether the database supports catalogs. If it does, all database
	 * objects are contained by the database's catalogs; otherwise all database
	 * objects are contained by the database's schemata.
	 * <br>
	 * Practically speaking:<ul>
	 *     <li>If {@link #supportsCatalogs()} returns <code>true</code><ul>
	 *         <li>{@link #getCatalogs()} returns catalogs that contain the database's schemata
	 *         <li>{@link #getSchemata()} returns an empty iterable
	 *     </ul>
	 *     <li>else<ul>
	 *         <li>{@link #getCatalogs()} returns an empty iterable
	 *         <li>{@link #getSchemata()} returns the database's schemata
	 *     </ul>
	 * </ul>
	 * This is complicated by the presence of a "default" catalog that clients can
	 * use to allow the specification of a catalog to be optional; but clients
	 * must manage this explicitly.
	 * @see #getCatalogs()
	 * @see #getSchemata()
	 */
	boolean supportsCatalogs();

	/**
	 * Return the database's catalogs.
	 * Return an empty iterable if the database does not support catalogs.
	 * @see #supportsCatalogs()
	 */
	Iterable<Catalog> getCatalogs();

	/**
	 * Return the number of catalogs the database contains.
	 * Return zero if the database does not support catalogs.
	 * @see #supportsCatalogs()
	 */
	int getCatalogsSize();

	/**
	 * Return the database's catalog names, sorted.
	 * Return an empty iterable if the database does not support catalogs.
	 * This is useful when the user is selecting a catalog from a read-only
	 * combo-box (e.g. in a wizard).
	 * @see #getSortedCatalogIdentifiers()
	 * @see #getCatalogNamed(String)
	 */
	Iterable<String> getSortedCatalogNames();

	/**
	 * Return the catalog with the specified name. The name must be an exact match
	 * of the catalog's name.
	 * Return <code>null</code> if the database does not support catalogs.
	 * @see #supportsCatalogs()
	 * @see #getSortedCatalogNames()
	 * @see #getCatalogForIdentifier(String)
	 */
	Catalog getCatalogNamed(String name);

	/**
	 * Return the database's catalog identifiers, sorted by name.
	 * Return an empty iterable if the database does not support catalogs.
	 * This is useful when the user is selecting an identifier that will be
	 * placed in a text file (e.g. in a Java annotation).
	 * @see #getSortedCatalogNames()
	 * @see #getCatalogForIdentifier(String)
	 */
	Iterable<String> getSortedCatalogIdentifiers();

	/**
	 * Return the catalog for the specified identifier. The identifier should
	 * be an SQL identifier (i.e. quoted when case-sensitive or containing
	 * special characters, unquoted otherwise).
	 * Return <code>null</code> if the database does not support catalogs.
	 * @see #supportsCatalogs()
	 * @see #getSortedCatalogIdentifiers()
	 * @see #getCatalogNamed(String)
	 */
	Catalog getCatalogForIdentifier(String identifier);

	/**
	 * Return the database's default catalog, as defined by the database vendor.
	 * In most cases the default catalog's name will match the user name.
	 * Return <code>null</code> if the database does not support catalogs or
	 * if the default catalog does not exist (e.g. the database has no catalog
	 * whose name matches the user name).
	 * @see #supportsCatalogs()
	 * @see #getDefaultCatalogIdentifier()
	 */
	Catalog getDefaultCatalog();

	/**
	 * Return the database's default catalog identifier.
	 * The database may or may not have a catalog with a matching name.
	 * @see #supportsCatalogs()
	 * @see #getDefaultCatalog()
	 */
	String getDefaultCatalogIdentifier();


	// ********** utility methods **********

	/**
	 * Select and return from the specified list of tables the
	 * table identified by the specified identifier.
	 * The identifier should be an SQL identifier (i.e. delimited as
	 * appropriate).
	 */
	Table selectTableForIdentifier(Iterable<Table> tables, String identifier);

	/**
	 * Convert the specified name to a database-appropriate SQL identifier
	 * (i.e. delimit the name as appropriate).
	 */
	// it seems we don't need database object-specific conversions here;
	// i.e. separate methods for tables, columns, etc.
	String convertNameToIdentifier(String name);
}

Back to the top