KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor
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
26 import org.apache.derby.catalog.UUID;
27 import org.apache.derby.iapi.reference.SQLState;
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29 import org.apache.derby.iapi.sql.StatementType;
30 import org.apache.derby.catalog.DependableFinder;
31 import org.apache.derby.catalog.Dependable;
32 import org.apache.derby.iapi.services.io.StoredFormatIds;
33
34 import org.apache.derby.iapi.services.uuid.UUIDFactory;
35 import org.apache.derby.iapi.services.monitor.Monitor;
36
37 /**
38  * The ConglomerateDescriptor class is used to get information about
39  * conglomerates for the purpose of optimization.
40  *
41  * NOTE: The language module does not have to know much about conglomerates
42  * with this architecture. To get the cost of using a conglomerate, all it
43  * has to do is pass the ConglomerateDescriptor to the access methods, along
44  * with the predicate. What the access methods need from a
45  * ConglomerateDescriptor remains to be seen.
46  *
47  * @version 0.1
48  * @author Jeff Lichtman
49  */

50
51 public final class ConglomerateDescriptor extends TupleDescriptor
52     implements UniqueTupleDescriptor, Provider
53 {
54     // Implementation
55
private long conglomerateNumber;
56     private String JavaDoc name;
57     private String JavaDoc[] columnNames;
58     private final boolean indexable;
59     private final boolean forConstraint;
60     private final IndexRowGenerator indexRowGenerator;
61     private final UUID uuid;
62     private final UUID tableID;
63     private final UUID schemaID;
64
65     /**
66      * Constructor for a conglomerate descriptor.
67      *
68      * @param dataDictionary The data dictionary that this descriptor lives in
69      * @param conglomerateNumber The number for the conglomerate
70      * we're interested in
71      * @param name The name of the conglomerate, if any
72      * @param indexable TRUE means the conglomerate is indexable,
73      * FALSE means it isn't
74      * @param indexRowGenerator The descriptor of the index if it's not a
75      * heap
76      * @param forConstraint TRUE means the conglomerate is an index backing up
77      * a constraint, FALSE means it isn't
78      * @param uuid UUID for this conglomerate
79      * @param tableID UUID for the table that this conglomerate belongs to
80      * @param schemaID UUID for the schema that this conglomerate belongs to
81      */

82     ConglomerateDescriptor(DataDictionary dataDictionary,
83                                long conglomerateNumber,
84                                String JavaDoc name,
85                                boolean indexable,
86                                IndexRowGenerator indexRowGenerator,
87                                boolean forConstraint,
88                                UUID uuid,
89                                UUID tableID,
90                                UUID schemaID)
91     {
92         super( dataDictionary );
93
94         this.conglomerateNumber = conglomerateNumber;
95         this.name = name;
96         this.indexable = indexable;
97         this.indexRowGenerator = indexRowGenerator;
98         this.forConstraint = forConstraint;
99         if (uuid == null)
100         {
101             UUIDFactory uuidFactory = Monitor.getMonitor().getUUIDFactory();
102             uuid = uuidFactory.createUUID();
103         }
104         this.uuid = uuid;
105         this.tableID = tableID;
106         this.schemaID = schemaID;
107     }
108
109     /**
110      * Gets the number for the conglomerate.
111      *
112      * @return A long identifier for the conglomerate
113      */

114     public long getConglomerateNumber()
115     {
116         return conglomerateNumber;
117     }
118
119     /**
120      * Set the conglomerate number.
121      * This is useful when swapping conglomerates, like for bulkInsert.
122      *
123      * @param conglomerateNumber The new conglomerate number.
124      */

125     public void setConglomerateNumber(long conglomerateNumber)
126     {
127         this.conglomerateNumber = conglomerateNumber;
128     }
129
130     /**
131      * Gets the UUID String for the conglomerate.
132      *
133      * @return The UUID String for the conglomerate
134      */

135     public UUID getUUID()
136     {
137         return uuid;
138     }
139
140     /**
141      * Gets the UUID for the table that the conglomerate belongs to.
142      *
143      * @return The UUID String for the conglomerate
144      */

145     public UUID getTableID()
146     {
147         return tableID;
148     }
149
150     /**
151      * Gets the UUID for the schema that the conglomerate belongs to.
152      *
153      * @return The UUID String for the schema that the conglomerate belongs to
154      */

155     public UUID getSchemaID()
156     {
157         return schemaID;
158     }
159
160     /**
161      * Tells whether the conglomerate can be used as an index.
162      *
163      * @return TRUE if the conglomerate can be used as an index, FALSE if not
164      */

165     public boolean isIndex()
166     {
167         return indexable;
168     }
169
170     /**
171      * Tells whether the conglomerate is an index backing up a constraint.
172      *
173      * @return TRUE if the conglomerate is an index backing up a constraint, FALSE if not
174      */

175     public boolean isConstraint()
176     {
177         return forConstraint;
178     }
179
180     /**
181      * Gets the name of the conglomerate. For heaps, this is null. For
182      * indexes, it is the index name.
183      *
184      * @return The name of the conglomerate, null if it's the heap for a table.
185      */

186     public String JavaDoc getConglomerateName()
187     {
188         return name;
189     }
190
191     /**
192      * Set the name of the conglomerate. Used only by rename index.
193      *
194      * @param newName The new name of the conglomerate.
195      */

196     public void setConglomerateName(String JavaDoc newName)
197     {
198         name = newName;
199     }
200
201     /**
202      * Gets the index row generator for this conglomerate, null if the
203      * conglomerate is not an index.
204      *
205      * @return The index descriptor for this conglomerate, if any.
206      */

207     public IndexRowGenerator getIndexDescriptor()
208     {
209         return indexRowGenerator;
210     }
211
212     /**
213      * Set the column names for this conglomerate descriptor.
214      * This is useful for tracing the optimizer.
215      *
216      * @param columnNames 0-based array of column names.
217      */

218     public void setColumnNames(String JavaDoc[] columnNames)
219     {
220         this.columnNames = columnNames;
221     }
222
223     /**
224      * Get the column names for this conglomerate descriptor.
225      * This is useful for tracing the optimizer.
226      *
227      * @return the column names for the conglomerate descriptor.
228      */

229     public String JavaDoc[] getColumnNames()
230     {
231         return columnNames;
232     }
233
234     //
235
// Provider interface
236
//
237

238     /**
239         @return the stored form of this provider
240      */

241     public DependableFinder getDependableFinder()
242     {
243         return getDependableFinder(StoredFormatIds.CONGLOMERATE_DESCRIPTOR_FINDER_V01_ID);
244     }
245
246     /**
247      * Return the name of this Provider. (Useful for errors.)
248      *
249      * @return String The name of this provider.
250      */

251     public String JavaDoc getObjectName()
252     {
253         if (SanityManager.DEBUG)
254         {
255             SanityManager.ASSERT(name != null,
256                 "ConglomerateDescriptor only expected to be provider for indexes");
257         }
258         return name;
259     }
260
261     /**
262      * Get the provider's UUID
263      *
264      * @return The provider's UUID
265      */

266     public UUID getObjectID()
267     {
268         return uuid;
269     }
270
271     /**
272      * Get the provider's type.
273      *
274      * @return char The provider's type.
275      */

276     public String JavaDoc getClassType()
277     {
278         if (indexable)
279         {
280             return Dependable.INDEX;
281         }
282         else
283         {
284             return Dependable.HEAP;
285         }
286     }
287
288     /**
289      * Convert the conglomerate descriptor to a String
290      *
291      * @return The conglomerate descriptor as a String
292      */

293
294     public String JavaDoc toString()
295     {
296         if (SanityManager.DEBUG)
297         {
298             String JavaDoc keyString = "";
299
300             if (indexable && columnNames != null )
301             {
302                 int[] keyColumns = indexRowGenerator.baseColumnPositions();
303
304                 keyString = ", key columns = {" + columnNames[keyColumns[0] - 1];
305                 for (int index = 1; index < keyColumns.length; index++)
306                 {
307                     keyString = keyString + ", " + columnNames[keyColumns[index] - 1];
308                 }
309                 keyString = keyString + "}";
310             }
311
312             return "ConglomerateDescriptor: conglomerateNumber = " + conglomerateNumber +
313                 " name = " + name +
314                 " uuid = " + uuid +
315                 " indexable = " + indexable + keyString;
316         }
317         else
318         {
319             return "";
320         }
321     }
322
323     /** @see TupleDescriptor#getDescriptorType */
324     public String JavaDoc getDescriptorType()
325     {
326         if (indexable)
327             return "Index";
328         else
329             return "Table";
330     }
331
332     /** @see TupleDescriptor#getDescriptorName */
333     public String JavaDoc getDescriptorName() { return name; }
334     
335 }
336
Popular Tags