KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator
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.services.monitor.Monitor;
25 import org.apache.derby.iapi.error.StandardException;
26
27 import org.apache.derby.iapi.sql.dictionary.*;
28
29 import org.apache.derby.iapi.types.TypeId;
30 import org.apache.derby.iapi.sql.depend.Dependent;
31 import org.apache.derby.iapi.sql.depend.Provider;
32 import org.apache.derby.iapi.reference.SQLState;
33 import org.apache.derby.iapi.sql.execute.ConstantAction;
34 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement;
35 import org.apache.derby.iapi.services.uuid.UUIDFactory;
36 import org.apache.derby.iapi.services.io.FormatableBitSet;
37
38 import org.apache.derby.catalog.AliasInfo;
39 import org.apache.derby.catalog.DefaultInfo;
40 import org.apache.derby.catalog.Dependable;
41 import org.apache.derby.catalog.DependableFinder;
42 import org.apache.derby.catalog.ReferencedColumns;
43 import org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl;
44 import org.apache.derby.catalog.UUID;
45 import org.apache.derby.catalog.Statistics;
46 import java.sql.Timestamp JavaDoc;
47 import java.io.InputStream JavaDoc;
48
49 /**
50  * This is an implementation of the DataDescriptorGenerator interface
51  * that lives in the DataDictionary protocol. See that interface for
52  * a description of what this class is supposed to do.
53  *
54  * @version 0.1
55  * @author Jeff Lichtman
56  */

57
58 public class DataDescriptorGenerator
59 {
60     private UUIDFactory uuidf;
61
62     protected final DataDictionary dataDictionary; // the data dictionary that this generator operates on
63

64     /**
65       * Make a generator. Specify the data dictionary that it operates on.
66       *
67       * @param dataDictionary the data dictionary that this generator makes objects for
68       */

69     public DataDescriptorGenerator( DataDictionary dataDictionary )
70     {
71         this.dataDictionary = dataDictionary;
72     }
73
74     /**
75      * Create a descriptor for the named schema with a null UUID.
76      *
77      * @param schemaName The name of the schema we're interested in.
78      * If the name is NULL, get the descriptor for the
79      * current schema.
80      * @param aid The authorization ID associated with the schema.
81      * The owner of the schema.
82      *
83      * @param oid The object ID
84      *
85      * @return The descriptor for the schema.
86      * @exception StandardException Thrown on failure
87      */

88     public SchemaDescriptor newSchemaDescriptor(String JavaDoc schemaName,
89         String JavaDoc aid, UUID oid)
90         throws StandardException
91     {
92         return new SchemaDescriptor(
93             dataDictionary, schemaName, aid, oid,
94             dataDictionary.isSystemSchemaName(schemaName));
95     }
96
97     /**
98      * Create a descriptor for the named table within the given schema.
99      * If the schema parameter is NULL, it creates a schema descriptor
100      * using the current default schema.
101      *
102      * @param tableName The name of the table to get the descriptor for
103      * @param schema The descriptor for the schema the table lives in.
104      * If null, use the current (default) schema.
105      * @param tableType The type of the table: base table or view.
106      * @param lockGranularity The lock granularity.
107      *
108      * @return The descriptor for the table.
109      */

110     public TableDescriptor newTableDescriptor
111     (
112         String JavaDoc tableName,
113         SchemaDescriptor schema,
114         int tableType,
115         char lockGranularity
116     )
117     {
118         return new TableDescriptor
119             (dataDictionary, tableName, schema, tableType, lockGranularity);
120     }
121
122     /**
123      * Create a descriptor for the temporary table within the given schema.
124      *
125      * @param tableName The name of the temporary table to get the descriptor for
126      * @param schema The descriptor for the schema the table lives in.
127      * @param tableType The type of the table: temporary table
128      * @param onCommitDeleteRows If true, on commit delete rows else on commit preserve rows of temporary table.
129      * @param onRollbackDeleteRows If true, on rollback, delete rows from temp tables which were logically modified. true is the only supported value
130      *
131      * @return The descriptor for the table.
132      */

133     public TableDescriptor newTableDescriptor
134     (
135         String JavaDoc tableName,
136         SchemaDescriptor schema,
137         int tableType,
138         boolean onCommitDeleteRows,
139         boolean onRollbackDeleteRows
140     )
141     {
142         return new TableDescriptor
143             (dataDictionary, tableName, schema, tableType, onCommitDeleteRows, onRollbackDeleteRows);
144     }
145
146     /**
147      * Create a viewDescriptor for the view with the given UUID.
148      *
149      * @param viewID the UUID for the view.
150      * @param viewName the name of the view
151      * @param viewText the text of the view's query.
152      * @param checkOption int for check option type
153      * @param compSchemaId the UUID of the schema this was compiled in
154      *
155      * @return A descriptor for the view
156      */

157     public ViewDescriptor newViewDescriptor(UUID viewID,
158                 String JavaDoc viewName, String JavaDoc viewText, int checkOption,
159                 UUID compSchemaId)
160     {
161         return new ViewDescriptor(dataDictionary, viewID, viewName,
162                 viewText, checkOption, compSchemaId);
163     }
164
165
166     /**
167      * @see DataDescriptorGenerator#newUniqueConstraintDescriptor
168      */

169     public ReferencedKeyConstraintDescriptor newUniqueConstraintDescriptor(
170                         TableDescriptor table,
171                         String JavaDoc constraintName,
172                         boolean deferrable,
173                         boolean initiallyDeferred,
174                         int[] referencedColumns,
175                         UUID constraintId,
176                         UUID indexId,
177                         SchemaDescriptor schemaDesc,
178                         boolean isEnabled,
179                         int referenceCount
180                         )
181     {
182         return new ReferencedKeyConstraintDescriptor(DataDictionary.UNIQUE_CONSTRAINT,
183             dataDictionary, table, constraintName,
184                 deferrable, initiallyDeferred,
185                 referencedColumns, constraintId,
186                 indexId, schemaDesc, isEnabled, referenceCount);
187     }
188
189     /**
190      * @see DataDescriptorGenerator#newPrimaryKeyConstraintDescriptor
191      */

192     public ReferencedKeyConstraintDescriptor newPrimaryKeyConstraintDescriptor(
193                         TableDescriptor table,
194                         String JavaDoc constraintName,
195                         boolean deferrable,
196                         boolean initiallyDeferred,
197                         int[] referencedColumns,
198                         UUID constraintId,
199                         UUID indexId,
200                         SchemaDescriptor schemaDesc,
201                         boolean isEnabled,
202                         int referenceCount
203                         )
204     {
205         return new ReferencedKeyConstraintDescriptor(DataDictionary.PRIMARYKEY_CONSTRAINT,
206             dataDictionary, table, constraintName,
207                 deferrable, initiallyDeferred,
208                 referencedColumns, constraintId,
209                 indexId, schemaDesc, isEnabled, referenceCount);
210     }
211
212     /**
213      * @see DataDescriptorGenerator#newForeignKeyConstraintDescriptor
214      */

215     public ForeignKeyConstraintDescriptor newForeignKeyConstraintDescriptor(
216                         TableDescriptor table,
217                         String JavaDoc constraintName,
218                         boolean deferrable,
219                         boolean initiallyDeferred,
220                         int[] fkColumns,
221                         UUID constraintId,
222                         UUID indexId,
223                         SchemaDescriptor schemaDesc,
224                         ReferencedKeyConstraintDescriptor referencedConstraintDescriptor,
225                         boolean isEnabled,
226                         int raDeleteRule,
227                         int raUpdateRule
228                         )
229     {
230         return new ForeignKeyConstraintDescriptor(dataDictionary, table, constraintName,
231                 deferrable, initiallyDeferred,
232                 fkColumns, constraintId,
233                 indexId, schemaDesc,
234                 referencedConstraintDescriptor, isEnabled, raDeleteRule, raUpdateRule);
235     }
236
237
238     /**
239      * @see DataDescriptorGenerator#newForeignKeyConstraintDescriptor
240      */

241     public ForeignKeyConstraintDescriptor newForeignKeyConstraintDescriptor(
242                         TableDescriptor table,
243                         String JavaDoc constraintName,
244                         boolean deferrable,
245                         boolean initiallyDeferred,
246                         int[] fkColumns,
247                         UUID constraintId,
248                         UUID indexId,
249                         SchemaDescriptor schemaDesc,
250                         UUID referencedConstraintId,
251                         boolean isEnabled,
252                         int raDeleteRule,
253                         int raUpdateRule
254                         )
255     {
256         return new ForeignKeyConstraintDescriptor(dataDictionary, table, constraintName,
257                 deferrable, initiallyDeferred,
258                 fkColumns, constraintId,
259                 indexId, schemaDesc,
260                 referencedConstraintId, isEnabled, raDeleteRule, raUpdateRule);
261     }
262
263     /**
264      * @see DataDescriptorGenerator#newCheckConstraintDescriptor
265      */

266     public CheckConstraintDescriptor newCheckConstraintDescriptor(
267                         TableDescriptor table,
268                         String JavaDoc constraintName,
269                         boolean deferrable,
270                         boolean initiallyDeferred,
271                         UUID constraintId,
272                         String JavaDoc constraintText,
273                         ReferencedColumns referencedColumns,
274                         SchemaDescriptor schemaDesc,
275                         boolean isEnabled
276                         )
277     {
278         return new CheckConstraintDescriptor(dataDictionary, table, constraintName,
279                 deferrable, initiallyDeferred,
280                 constraintId,
281                 constraintText, referencedColumns, schemaDesc, isEnabled);
282     }
283
284     public CheckConstraintDescriptor newCheckConstraintDescriptor(
285                         TableDescriptor table,
286                         String JavaDoc constraintName,
287                         boolean deferrable,
288                         boolean initiallyDeferred,
289                         UUID constraintId,
290                         String JavaDoc constraintText,
291                         int[] refCols,
292                         SchemaDescriptor schemaDesc,
293                         boolean isEnabled
294                         )
295     {
296         ReferencedColumns referencedColumns = new ReferencedColumnsDescriptorImpl(refCols);
297         return new CheckConstraintDescriptor(dataDictionary, table, constraintName,
298                 deferrable, initiallyDeferred,
299                 constraintId,
300                 constraintText, referencedColumns, schemaDesc, isEnabled);
301     }
302
303     /**
304      * Create a conglomerate descriptor for the given conglomerate id.
305      *
306      * @param conglomerateId The identifier for the conglomerate
307      * we're interested in
308      * @param name The name of the conglomerate, if any
309      * @param indexable TRUE means the conglomerate is indexable,
310      * FALSE means it isn't
311      * @param indexRowGenerator The IndexRowGenerator for the conglomerate,
312      * null if it's a heap
313      * @param isConstraint TRUE means the conglomerate is an index backing
314      * up a constraint, FALSE means it isn't
315      *
316      * @param uuid UUID for this conglomerate
317      * @param tableID UUID for the table that this conglomerate belongs to
318      * @param schemaID UUID for the schema that conglomerate belongs to
319      *
320      * @return A ConglomerateDescriptor describing the
321      * conglomerate.
322      */

323     public ConglomerateDescriptor newConglomerateDescriptor(
324                         long conglomerateId,
325                         String JavaDoc name,
326                         boolean indexable,
327                         IndexRowGenerator indexRowGenerator,
328                         boolean isConstraint,
329                         UUID uuid,
330                         UUID tableID,
331                         UUID schemaID
332                         )
333     {
334         return (ConglomerateDescriptor)
335                 new ConglomerateDescriptor(dataDictionary, conglomerateId,
336                                                 name,
337                                                 indexable,
338                                                 indexRowGenerator,
339                                                 isConstraint,
340                                                 uuid,
341                                                 tableID,
342                                                 schemaID);
343     }
344
345     /**
346      * Create a new trigger descriptor.
347      *
348      * @param sd the schema descriptor for this trigger
349      * @param uuid the trigger id
350      * @param name the trigger name
351      * @param eventMask TriggerDescriptor.TRIGGER_EVENT_XXXX
352      * @param isBefore is this a before (as opposed to after) trigger
353      * @param isRow is this a row trigger or statement trigger
354      * @param isEnabled is this trigger enabled or disabled
355      * @param td the table upon which this trigger is defined
356      * @param whenSPSId the sps id for the when clause (may be null)
357      * @param actionSPSId the spsid for the trigger action (may be null)
358      * @param creationTimestamp when was this trigger created?
359      * @param referencedCols what columns does this trigger reference (may be null)
360      * @param triggerDefinition The original user text of the trigger action
361      * @param referencingOld whether or not OLD appears in REFERENCING clause
362      * @param referencingNew whether or not NEW appears in REFERENCING clause
363      * @param oldReferencingName old referencing table name, if any, that appears in REFERCING clause
364      * @param newReferencingName new referencing table name, if any, that appears in REFERCING clause
365      *
366      * @exception StandardException on error
367      */

368     public TriggerDescriptor newTriggerDescriptor
369     (
370         SchemaDescriptor sd,
371         UUID uuid,
372         String JavaDoc name,
373         int eventMask,
374         boolean isBefore,
375         boolean isRow,
376         boolean isEnabled,
377         TableDescriptor td,
378         UUID whenSPSId,
379         UUID actionSPSId,
380         Timestamp JavaDoc creationTimestamp,
381         int[] referencedCols,
382         String JavaDoc triggerDefinition,
383         boolean referencingOld,
384         boolean referencingNew,
385         String JavaDoc oldReferencingName,
386         String JavaDoc newReferencingName
387     ) throws StandardException
388     {
389         return new TriggerDescriptor(
390                     dataDictionary,
391                     sd,
392                     uuid,
393                     name,
394                     eventMask,
395                     isBefore,
396                     isRow,
397                     isEnabled,
398                     td,
399                     whenSPSId,
400                     actionSPSId,
401                     creationTimestamp,
402                     referencedCols,
403                     triggerDefinition,
404                     referencingOld,
405                     referencingNew,
406                     oldReferencingName,
407                     newReferencingName
408                     );
409     }
410         
411     /*
412       get a UUIDFactory. This uses the Monitor to get one the
413       first time and holds onto it for later.
414       */

415     protected UUIDFactory getUUIDFactory()
416     {
417         if (uuidf == null)
418             uuidf = Monitor.getMonitor().getUUIDFactory();
419         return uuidf;
420     }
421
422     /**
423       @see DataDescriptorGenerator#newFileInfoDescriptor
424       */

425     public FileInfoDescriptor newFileInfoDescriptor(
426                                 UUID id,
427                                 SchemaDescriptor sd,
428                                 String JavaDoc SQLName,
429                                 long generationId
430                                 )
431     {
432         if (id == null) id = getUUIDFactory().createUUID();
433         return new FileInfoDescriptor(dataDictionary, id,sd,SQLName,generationId);
434     }
435         
436     public TablePermsDescriptor newTablePermsDescriptor( TableDescriptor td,
437                                                          String JavaDoc selectPerm,
438                                                          String JavaDoc deletePerm,
439                                                          String JavaDoc insertPerm,
440                                                          String JavaDoc updatePerm,
441                                                          String JavaDoc referencesPerm,
442                                                          String JavaDoc triggerPerm,
443                                                          String JavaDoc grantor)
444     throws StandardException
445     {
446         if( "N".equals( selectPerm) && "N".equals( deletePerm) && "N".equals( insertPerm)
447             && "N".equals( updatePerm) && "N".equals( referencesPerm) && "N".equals( triggerPerm))
448             return null;
449         
450         return new TablePermsDescriptor( dataDictionary,
451                                          (String JavaDoc) null,
452                                          grantor,
453                                          td.getUUID(),
454                                          selectPerm,
455                                          deletePerm,
456                                          insertPerm,
457                                          updatePerm,
458                                          referencesPerm,
459                                          triggerPerm);
460     }
461
462     /**
463      * Manufacture a new ColPermsDescriptor.
464      *
465      * @param td The descriptor of the table.
466      * @param type The action type:
467      *<ol>
468      *<li>"s" - select without grant
469      *<li>"S" - select with grant
470      *<li>"u" - update without grant
471      *<li>"U" - update with grant
472      *<li>"r" - references without grant
473      *<li>"R" - references with grant
474      *</ol>
475      * @param columns the set of columns
476      */

477     public ColPermsDescriptor newColPermsDescriptor( TableDescriptor td,
478                                                      String JavaDoc type,
479                                                      FormatableBitSet columns,
480                                                      String JavaDoc grantor) throws StandardException
481     {
482         return new ColPermsDescriptor( dataDictionary,
483                                        (String JavaDoc) null,
484                                        grantor,
485                                        td.getUUID(),
486                                        type,
487                                        columns);
488     }
489
490     /**
491      * Create a new routine permissions descriptor
492      *
493      * @param ad The routine's alias descriptor
494      * @param grantor
495      */

496     public RoutinePermsDescriptor newRoutinePermsDescriptor( AliasDescriptor ad, String JavaDoc grantor)
497     throws StandardException
498     {
499         return new RoutinePermsDescriptor( dataDictionary,
500                                            (String JavaDoc) null,
501                                            grantor,
502                                            ad.getUUID());
503     }
504 }
505
Popular Tags