1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.sql.dictionary.SchemaDescriptor |
4 | |
5 | Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.sql.dictionary; |
22 | |
23 | import org.apache.derby.iapi.sql.depend.Provider; |
24 | import org.apache.derby.catalog.DependableFinder; |
25 | import org.apache.derby.iapi.services.io.StoredFormatIds; |
26 | import org.apache.derby.iapi.reference.Property; |
27 | import org.apache.derby.catalog.UUID; |
28 | import org.apache.derby.catalog.Dependable; |
29 | |
30 | /** |
31 | * This class represents a schema descriptor |
32 | * |
33 | * @version 0.1 |
34 | * @author Jeff Lichtman |
35 | */ |
36 | |
37 | public class SchemaDescriptor extends TupleDescriptor |
38 | implements UniqueTupleDescriptor, Provider |
39 | { |
40 | |
41 | /* |
42 | ** When we boot, we put the system tables in |
43 | ** in 'SYS', owned by user DBA. |
44 | ** '92 talks about two system schemas: |
45 | ** |
46 | ** Information Schema: literal name is |
47 | ** SYS. This schema contains |
48 | ** a series of well defined views that reference |
49 | ** actual base tables from the Definition Schema. |
50 | ** |
51 | ** Definition Schema: literal name is |
52 | ** DEFINITION_SCHEMA. This schema contains |
53 | ** system tables that can be in any shape or |
54 | ** form. |
55 | ** |
56 | ** SYS is owned by SA_USER_NAME (or DBA). |
57 | */ |
58 | /** |
59 | * STD_SYSTEM_SCHEMA_NAME is the name of the system schema in databases that |
60 | * use ANSI standard identifier casing. In LSA and in Cloudscape target |
61 | * databases the name will use the same case as the source database |
62 | * identifiers. |
63 | * |
64 | * See org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext#getSystemSchemaName |
65 | */ |
66 | public static final String STD_SYSTEM_SCHEMA_NAME = "SYS"; |
67 | |
68 | public static final String IBM_SYSTEM_SCHEMA_NAME = "SYSIBM"; |
69 | |
70 | /* |
71 | * Names of system schemas. |
72 | * The following schemas exist in a standard empty DB2 database. For |
73 | * now creating them in the cloudscape database but not actually putting |
74 | * any objects in them. Users should not be able to create any objects |
75 | * in these schemas. |
76 | **/ |
77 | public static final String IBM_SYSTEM_CAT_SCHEMA_NAME = "SYSCAT"; |
78 | public static final String IBM_SYSTEM_FUN_SCHEMA_NAME = "SYSFUN"; |
79 | public static final String IBM_SYSTEM_PROC_SCHEMA_NAME = "SYSPROC"; |
80 | public static final String IBM_SYSTEM_STAT_SCHEMA_NAME = "SYSSTAT"; |
81 | public static final String IBM_SYSTEM_NULLID_SCHEMA_NAME = "NULLID"; |
82 | |
83 | /** |
84 | * This schema is used for jar handling procedures. |
85 | **/ |
86 | public static final String STD_SQLJ_SCHEMA_NAME = "SQLJ"; |
87 | |
88 | /** |
89 | * This schema is for cloudscape specific system diagnostic procedures and |
90 | * functions which are not available in DB2. |
91 | **/ |
92 | public static final String STD_SYSTEM_DIAG_SCHEMA_NAME = "SYSCS_DIAG"; |
93 | |
94 | /** |
95 | * This schema is for cloudscape specific system diagnostic procedures and |
96 | * functions which are not available in DB2. |
97 | **/ |
98 | public static final String STD_SYSTEM_UTIL_SCHEMA_NAME = "SYSCS_UTIL"; |
99 | |
100 | /** |
101 | * STD_DEFAULT_SCHEMA_NAME is the name of the default schema in databases |
102 | * that use ANSI standard identifier casing. In LSA and in Cloudscape |
103 | * target databases the name will use the same case as the source database |
104 | * identifiers. |
105 | * |
106 | * See org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext#getDefaultSchemaName |
107 | */ |
108 | public static final String STD_DEFAULT_SCHEMA_NAME = Property.DEFAULT_USER_NAME; |
109 | |
110 | |
111 | /** |
112 | * UUID's used as key's in the SYSSCHEMA catalog for the system schema's |
113 | **/ |
114 | public static final String SYSCAT_SCHEMA_UUID = |
115 | "c013800d-00fb-2641-07ec-000000134f30"; |
116 | public static final String SYSFUN_SCHEMA_UUID = |
117 | "c013800d-00fb-2642-07ec-000000134f30"; |
118 | public static final String SYSPROC_SCHEMA_UUID = |
119 | "c013800d-00fb-2643-07ec-000000134f30"; |
120 | public static final String SYSSTAT_SCHEMA_UUID = |
121 | "c013800d-00fb-2644-07ec-000000134f30"; |
122 | public static final String SYSCS_DIAG_SCHEMA_UUID = |
123 | "c013800d-00fb-2646-07ec-000000134f30"; |
124 | public static final String SYSCS_UTIL_SCHEMA_UUID = |
125 | "c013800d-00fb-2649-07ec-000000134f30"; |
126 | public static final String NULLID_SCHEMA_UUID = |
127 | "c013800d-00fb-2647-07ec-000000134f30"; |
128 | public static final String SQLJ_SCHEMA_UUID = |
129 | "c013800d-00fb-2648-07ec-000000134f30"; |
130 | public static final String SYSTEM_SCHEMA_UUID = |
131 | "8000000d-00d0-fd77-3ed8-000a0a0b1900"; |
132 | public static final String SYSIBM_SCHEMA_UUID = |
133 | "c013800d-00f8-5b53-28a9-00000019ed88"; |
134 | public static final String DEFAULT_SCHEMA_UUID = |
135 | "80000000-00d2-b38f-4cda-000a0a412c00"; |
136 | |
137 | |
138 | |
139 | public static final String STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME = "SESSION"; |
140 | public static final String DEFAULT_USER_NAME = Property.DEFAULT_USER_NAME; |
141 | public static final String SA_USER_NAME = "DBA"; |
142 | |
143 | |
144 | /** the public interface for this system: |
145 | <ol> |
146 | <li>public String getSchemaName(); |
147 | <li>public String getAuthorizationId(); |
148 | <li>public void setUUID(UUID uuid); |
149 | <li>public boolean isSystemSchema(); |
150 | </ol> |
151 | */ |
152 | |
153 | //// Implementation |
154 | private final String name; |
155 | private UUID oid; |
156 | private final String aid; |
157 | |
158 | private boolean isSystem; |
159 | private boolean isSYSIBM; |
160 | |
161 | /** |
162 | * Constructor for a SchemaDescriptor. |
163 | * |
164 | * @param dataDictionary |
165 | * @param name The schema descriptor for this table. |
166 | * @param oid The object id |
167 | * @param aid The authorizatin id |
168 | * @param isSystem boolean, true iff this is a system schema, like SYS, |
169 | * SYSIBM, SYSCAT, SYSFUN, .... |
170 | */ |
171 | public SchemaDescriptor( |
172 | DataDictionary dataDictionary, |
173 | String name, |
174 | String aid, |
175 | UUID oid, |
176 | boolean isSystem) |
177 | { |
178 | super (dataDictionary); |
179 | |
180 | this.name = name; |
181 | this.aid = aid; |
182 | this.oid = oid; |
183 | this.isSystem = isSystem; |
184 | if (isSystem) |
185 | isSYSIBM = IBM_SYSTEM_SCHEMA_NAME.equals(name); |
186 | } |
187 | |
188 | /** |
189 | * Gets the name of the schema |
190 | * |
191 | * @return The schema name |
192 | */ |
193 | public String getSchemaName() |
194 | { |
195 | return name; |
196 | } |
197 | |
198 | /** |
199 | * Gets the authorization id of the schema |
200 | * |
201 | * @return Authorization id |
202 | * lives in. |
203 | */ |
204 | public String getAuthorizationId() |
205 | { |
206 | return aid; |
207 | } |
208 | |
209 | /** |
210 | * Gets the oid of the schema |
211 | * |
212 | * @return An oid |
213 | */ |
214 | public UUID getUUID() |
215 | { |
216 | return oid; |
217 | } |
218 | |
219 | /** |
220 | * Sets the oid of the schema |
221 | * |
222 | * @param oid The object id |
223 | * |
224 | */ |
225 | public void setUUID(UUID oid) |
226 | { |
227 | this.oid = oid; |
228 | } |
229 | |
230 | // |
231 | // Provider interface |
232 | // |
233 | |
234 | /** |
235 | @return the stored form of this provider |
236 | |
237 | @see Dependable#getDependableFinder |
238 | */ |
239 | public DependableFinder getDependableFinder() |
240 | { |
241 | // Is this OK? |
242 | return getDependableFinder(StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID); |
243 | } |
244 | |
245 | /** |
246 | * Return the name of this Provider. (Useful for errors.) |
247 | * |
248 | * @return String The name of this provider. |
249 | */ |
250 | public String getObjectName() |
251 | { |
252 | return name; |
253 | } |
254 | |
255 | /** |
256 | * Get the provider's UUID |
257 | * |
258 | * @return String The provider's UUID |
259 | */ |
260 | public UUID getObjectID() |
261 | { |
262 | return oid; |
263 | } |
264 | |
265 | /** |
266 | * Get the provider's type. |
267 | * |
268 | * @return String The provider's type. |
269 | */ |
270 | public String getClassType() |
271 | { |
272 | return Dependable.SCHEMA; |
273 | } |
274 | |
275 | // |
276 | // class interface |
277 | // |
278 | |
279 | /** |
280 | * Prints the contents of the SchemaDescriptor |
281 | * |
282 | * @return The contents as a String |
283 | */ |
284 | public String toString() |
285 | { |
286 | return name; |
287 | } |
288 | |
289 | // Methods so that we can put SchemaDescriptors on hashed lists |
290 | |
291 | /** |
292 | * Determine if two SchemaDescriptors are the same. |
293 | * |
294 | * @param otherObject other schemadescriptor |
295 | * |
296 | * @return true if they are the same, false otherwise |
297 | */ |
298 | |
299 | public boolean equals(Object otherObject) |
300 | { |
301 | if (!(otherObject instanceof SchemaDescriptor)) |
302 | return false; |
303 | |
304 | SchemaDescriptor other = (SchemaDescriptor) otherObject; |
305 | |
306 | if ((oid != null) && (other.oid != null)) |
307 | return oid.equals( other.oid); |
308 | |
309 | return name.equals(other.name); |
310 | } |
311 | |
312 | /** |
313 | * Indicate whether this is a system schema or not |
314 | * |
315 | * Examples of system schema's include: |
316 | * SYS, SYSIBM, SYSCAT, SYSFUN, SYSPROC, SYSSTAT, and SYSCS_DIAG |
317 | * |
318 | * @return true/false |
319 | */ |
320 | public boolean isSystemSchema() |
321 | { |
322 | return(isSystem); |
323 | } |
324 | |
325 | /** |
326 | * Indicate whether this is a system schema with grantable routines |
327 | * |
328 | * @return true/false |
329 | */ |
330 | public boolean isSchemaWithGrantableRoutines() |
331 | { |
332 | if (!isSystem) |
333 | return true; |
334 | |
335 | if (name.equals(STD_SQLJ_SCHEMA_NAME) || name.equals(STD_SYSTEM_UTIL_SCHEMA_NAME)) |
336 | return true; |
337 | |
338 | return false; |
339 | } |
340 | |
341 | public boolean isSYSIBM() |
342 | { |
343 | return isSYSIBM; |
344 | } |
345 | |
346 | /** |
347 | * Get a hashcode for this SchemaDescriptor |
348 | * |
349 | * @return hashcode |
350 | */ |
351 | public int hashCode() |
352 | { |
353 | return oid.hashCode(); |
354 | } |
355 | |
356 | /** @see TupleDescriptor#getDescriptorName */ |
357 | public String getDescriptorName() |
358 | { |
359 | return name; |
360 | } |
361 | |
362 | /** @see TupleDescriptor#getDescriptorType */ |
363 | public String getDescriptorType() |
364 | { |
365 | return "Schema"; |
366 | } |
367 | } |