KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > dictionary > SchemaDescriptor


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.SchemaDescriptor
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.iapi.sql.dictionary;
23
24 import org.apache.derby.iapi.sql.depend.Provider;
25 import org.apache.derby.catalog.DependableFinder;
26 import org.apache.derby.iapi.services.io.StoredFormatIds;
27 import org.apache.derby.iapi.reference.Property;
28 import org.apache.derby.catalog.UUID;
29 import org.apache.derby.catalog.Dependable;
30
31 /**
32  * This class represents a schema descriptor
33  *
34  * @version 0.1
35  * @author Jeff Lichtman
36  */

37
38 public final class SchemaDescriptor extends TupleDescriptor
39     implements UniqueTupleDescriptor, Provider
40 {
41     
42     /*
43     ** When we boot, we put the system tables in
44     ** in 'SYS', owned by user DBA.
45     ** '92 talks about two system schemas:
46     **
47     ** Information Schema: literal name is
48     ** SYS. This schema contains
49     ** a series of well defined views that reference
50     ** actual base tables from the Definition Schema.
51     **
52     ** Definition Schema: literal name is
53     ** DEFINITION_SCHEMA. This schema contains
54     ** system tables that can be in any shape or
55     ** form.
56     **
57     ** SYS is owned by SA_USER_NAME (or DBA).
58     */

59     /**
60      * STD_SYSTEM_SCHEMA_NAME is the name of the system schema in databases that
61      * use ANSI standard identifier casing. In LSA and in Cloudscape target
62      * databases the name will use the same case as the source database
63      * identifiers.
64      *
65      * See org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext#getSystemSchemaName
66      */

67     public static final String JavaDoc STD_SYSTEM_SCHEMA_NAME = "SYS";
68
69     public static final String JavaDoc IBM_SYSTEM_SCHEMA_NAME = "SYSIBM";
70
71     /*
72      * Names of system schemas.
73      * The following schemas exist in a standard empty DB2 database. For
74      * now creating them in the cloudscape database but not actually putting
75      * any objects in them. Users should not be able to create any objects
76      * in these schemas.
77      **/

78     public static final String JavaDoc IBM_SYSTEM_CAT_SCHEMA_NAME = "SYSCAT";
79     public static final String JavaDoc IBM_SYSTEM_FUN_SCHEMA_NAME = "SYSFUN";
80     public static final String JavaDoc IBM_SYSTEM_PROC_SCHEMA_NAME = "SYSPROC";
81     public static final String JavaDoc IBM_SYSTEM_STAT_SCHEMA_NAME = "SYSSTAT";
82     public static final String JavaDoc IBM_SYSTEM_NULLID_SCHEMA_NAME = "NULLID";
83
84     /**
85      * This schema is used for jar handling procedures.
86      **/

87     public static final String JavaDoc STD_SQLJ_SCHEMA_NAME = "SQLJ";
88      
89     /**
90      * This schema is for cloudscape specific system diagnostic procedures and
91      * functions which are not available in DB2.
92      **/

93     public static final String JavaDoc STD_SYSTEM_DIAG_SCHEMA_NAME = "SYSCS_DIAG";
94
95     /**
96      * This schema is for cloudscape specific system diagnostic procedures and
97      * functions which are not available in DB2.
98      **/

99     public static final String JavaDoc STD_SYSTEM_UTIL_SCHEMA_NAME = "SYSCS_UTIL";
100
101     /**
102      * STD_DEFAULT_SCHEMA_NAME is the name of the default schema in databases
103      * that use ANSI standard identifier casing. In LSA and in Cloudscape
104      * target databases the name will use the same case as the source database
105      * identifiers.
106      *
107      * See org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext#getDefaultSchemaName
108      */

109     public static final String JavaDoc STD_DEFAULT_SCHEMA_NAME = Property.DEFAULT_USER_NAME;
110
111
112     /**
113      * UUID's used as key's in the SYSSCHEMA catalog for the system schema's
114      **/

115     public static final String JavaDoc SYSCAT_SCHEMA_UUID =
116         "c013800d-00fb-2641-07ec-000000134f30";
117     public static final String JavaDoc SYSFUN_SCHEMA_UUID =
118         "c013800d-00fb-2642-07ec-000000134f30";
119     public static final String JavaDoc SYSPROC_SCHEMA_UUID =
120         "c013800d-00fb-2643-07ec-000000134f30";
121     public static final String JavaDoc SYSSTAT_SCHEMA_UUID =
122         "c013800d-00fb-2644-07ec-000000134f30";
123     public static final String JavaDoc SYSCS_DIAG_SCHEMA_UUID =
124         "c013800d-00fb-2646-07ec-000000134f30";
125     public static final String JavaDoc SYSCS_UTIL_SCHEMA_UUID =
126         "c013800d-00fb-2649-07ec-000000134f30";
127     public static final String JavaDoc NULLID_SCHEMA_UUID =
128         "c013800d-00fb-2647-07ec-000000134f30";
129     public static final String JavaDoc SQLJ_SCHEMA_UUID =
130         "c013800d-00fb-2648-07ec-000000134f30";
131     public static final String JavaDoc SYSTEM_SCHEMA_UUID =
132         "8000000d-00d0-fd77-3ed8-000a0a0b1900";
133     public static final String JavaDoc SYSIBM_SCHEMA_UUID =
134         "c013800d-00f8-5b53-28a9-00000019ed88";
135     public static final String JavaDoc DEFAULT_SCHEMA_UUID =
136         "80000000-00d2-b38f-4cda-000a0a412c00";
137
138
139
140     public static final String JavaDoc STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME = "SESSION";
141     public static final String JavaDoc DEFAULT_USER_NAME = Property.DEFAULT_USER_NAME;
142     public static final String JavaDoc SA_USER_NAME = "DBA";
143
144
145     /** the public interface for this system:
146         <ol>
147         <li>public String getSchemaName();
148         <li>public String getAuthorizationId();
149         <li>public void setUUID(UUID uuid);
150         <li>public boolean isSystemSchema();
151         </ol>
152     */

153
154     //// Implementation
155
private final String JavaDoc name;
156     private UUID oid;
157     private final String JavaDoc aid;
158
159     private final boolean isSystem;
160     private final boolean isSYSIBM;
161
162     /**
163      * Constructor for a SchemaDescriptor.
164      *
165      * @param dataDictionary
166      * @param name The schema descriptor for this table.
167      * @param oid The object id
168      * @param aid The authorizatin id
169      * @param isSystem boolean, true iff this is a system schema, like SYS,
170      * SYSIBM, SYSCAT, SYSFUN, ....
171      */

172     public SchemaDescriptor(
173     DataDictionary dataDictionary,
174     String JavaDoc name,
175     String JavaDoc aid,
176     UUID oid,
177     boolean isSystem)
178     {
179         super (dataDictionary);
180
181         this.name = name;
182         this.aid = aid;
183         this.oid = oid;
184         this.isSystem = isSystem;
185         isSYSIBM = isSystem && 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc getDescriptorName()
358     {
359         return name;
360     }
361     
362     /** @see TupleDescriptor#getDescriptorType */
363     public String JavaDoc getDescriptorType()
364     {
365         return "Schema";
366     }
367 }
368
Popular Tags