1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor |
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 | |
25 | import org.apache.derby.catalog.UUID; |
26 | import org.apache.derby.iapi.reference.SQLState; |
27 | import org.apache.derby.iapi.services.sanity.SanityManager; |
28 | import org.apache.derby.iapi.sql.StatementType; |
29 | import org.apache.derby.catalog.DependableFinder; |
30 | import org.apache.derby.catalog.Dependable; |
31 | import org.apache.derby.iapi.services.io.StoredFormatIds; |
32 | |
33 | import org.apache.derby.iapi.services.uuid.UUIDFactory; |
34 | import org.apache.derby.iapi.services.monitor.Monitor; |
35 | |
36 | /** |
37 | * The ConglomerateDescriptor class is used to get information about |
38 | * conglomerates for the purpose of optimization. |
39 | * |
40 | * NOTE: The language module does not have to know much about conglomerates |
41 | * with this architecture. To get the cost of using a conglomerate, all it |
42 | * has to do is pass the ConglomerateDescriptor to the access methods, along |
43 | * with the predicate. What the access methods need from a |
44 | * ConglomerateDescriptor remains to be seen. |
45 | * |
46 | * @version 0.1 |
47 | * @author Jeff Lichtman |
48 | */ |
49 | |
50 | public class ConglomerateDescriptor extends TupleDescriptor |
51 | implements UniqueTupleDescriptor, Provider |
52 | { |
53 | // Implementation |
54 | long conglomerateNumber; |
55 | String name; |
56 | String[] columnNames; |
57 | boolean indexable; |
58 | boolean forConstraint; |
59 | IndexRowGenerator indexRowGenerator; |
60 | UUID uuid; |
61 | UUID tableID; |
62 | UUID schemaID; |
63 | |
64 | /** |
65 | * Constructor for a conglomerate descriptor. |
66 | * |
67 | * @param dataDictionary The data dictionary that this descriptor lives in |
68 | * @param conglomerateNumber The number for the conglomerate |
69 | * we're interested in |
70 | * @param name The name of the conglomerate, if any |
71 | * @param indexable TRUE means the conglomerate is indexable, |
72 | * FALSE means it isn't |
73 | * @param indexRowGenerator The descriptor of the index if it's not a |
74 | * heap |
75 | * @param forConstraint TRUE means the conglomerate is an index backing up |
76 | * a constraint, FALSE means it isn't |
77 | * @param uuid UUID for this conglomerate |
78 | * @param tableID UUID for the table that this conglomerate belongs to |
79 | * @param schemaID UUID for the schema that this conglomerate belongs to |
80 | */ |
81 | ConglomerateDescriptor(DataDictionary dataDictionary, |
82 | long conglomerateNumber, |
83 | String name, |
84 | boolean indexable, |
85 | IndexRowGenerator indexRowGenerator, |
86 | boolean forConstraint, |
87 | UUID uuid, |
88 | UUID tableID, |
89 | UUID schemaID) |
90 | { |
91 | super( dataDictionary ); |
92 | |
93 | this.conglomerateNumber = conglomerateNumber; |
94 | this.name = name; |
95 | this.indexable = indexable; |
96 | this.indexRowGenerator = indexRowGenerator; |
97 | this.forConstraint = forConstraint; |
98 | if (uuid == null) |
99 | { |
100 | UUIDFactory uuidFactory = Monitor.getMonitor().getUUIDFactory(); |
101 | uuid = uuidFactory.createUUID(); |
102 | } |
103 | this.uuid = uuid; |
104 | this.tableID = tableID; |
105 | this.schemaID = schemaID; |
106 | } |
107 | |
108 | /** |
109 | * Gets the number for the conglomerate. |
110 | * |
111 | * @return A long identifier for the conglomerate |
112 | */ |
113 | public long getConglomerateNumber() |
114 | { |
115 | return conglomerateNumber; |
116 | } |
117 | |
118 | /** |
119 | * Set the conglomerate number. |
120 | * This is useful when swapping conglomerates, like for bulkInsert. |
121 | * |
122 | * @param conglomerateNumber The new conglomerate number. |
123 | */ |
124 | public void setConglomerateNumber(long conglomerateNumber) |
125 | { |
126 | this.conglomerateNumber = conglomerateNumber; |
127 | } |
128 | |
129 | /** |
130 | * Gets the UUID String for the conglomerate. |
131 | * |
132 | * @return The UUID String for the conglomerate |
133 | */ |
134 | public UUID getUUID() |
135 | { |
136 | return uuid; |
137 | } |
138 | |
139 | /** |
140 | * Gets the UUID for the table that the conglomerate belongs to. |
141 | * |
142 | * @return The UUID String for the conglomerate |
143 | */ |
144 | public UUID getTableID() |
145 | { |
146 | return tableID; |
147 | } |
148 | |
149 | /** |
150 | * Gets the UUID for the schema that the conglomerate belongs to. |
151 | * |
152 | * @return The UUID String for the schema that the conglomerate belongs to |
153 | */ |
154 | public UUID getSchemaID() |
155 | { |
156 | return schemaID; |
157 | } |
158 | |
159 | /** |
160 | * Tells whether the conglomerate can be used as an index. |
161 | * |
162 | * @return TRUE if the conglomerate can be used as an index, FALSE if not |
163 | */ |
164 | public boolean isIndex() |
165 | { |
166 | return indexable; |
167 | } |
168 | |
169 | /** |
170 | * Tells whether the conglomerate is an index backing up a constraint. |
171 | * |
172 | * @return TRUE if the conglomerate is an index backing up a constraint, FALSE if not |
173 | */ |
174 | public boolean isConstraint() |
175 | { |
176 | return forConstraint; |
177 | } |
178 | |
179 | /** |
180 | * Gets the name of the conglomerate. For heaps, this is null. For |
181 | * indexes, it is the index name. |
182 | * |
183 | * @return The name of the conglomerate, null if it's the heap for a table. |
184 | */ |
185 | public String getConglomerateName() |
186 | { |
187 | return name; |
188 | } |
189 | |
190 | /** |
191 | * Set the name of the conglomerate. Used only by rename index. |
192 | * |
193 | * @param newName The new name of the conglomerate. |
194 | */ |
195 | public void setConglomerateName(String newName) |
196 | { |
197 | name = newName; |
198 | } |
199 | |
200 | /** |
201 | * Gets the index row generator for this conglomerate, null if the |
202 | * conglomerate is not an index. |
203 | * |
204 | * @return The index descriptor for this conglomerate, if any. |
205 | */ |
206 | public IndexRowGenerator getIndexDescriptor() |
207 | { |
208 | return indexRowGenerator; |
209 | } |
210 | |
211 | /** |
212 | * Set the column names for this conglomerate descriptor. |
213 | * This is useful for tracing the optimizer. |
214 | * |
215 | * @param columnNames 0-based array of column names. |
216 | */ |
217 | public void setColumnNames(String[] columnNames) |
218 | { |
219 | this.columnNames = columnNames; |
220 | } |
221 | |
222 | /** |
223 | * Get the column names for this conglomerate descriptor. |
224 | * This is useful for tracing the optimizer. |
225 | * |
226 | * @return the column names for the conglomerate descriptor. |
227 | */ |
228 | public String[] getColumnNames() |
229 | { |
230 | return columnNames; |
231 | } |
232 | |
233 | // |
234 | // Provider interface |
235 | // |
236 | |
237 | /** |
238 | @return the stored form of this provider |
239 | */ |
240 | public DependableFinder getDependableFinder() |
241 | { |
242 | return getDependableFinder(StoredFormatIds.CONGLOMERATE_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 | if (SanityManager.DEBUG) |
253 | { |
254 | SanityManager.ASSERT(name != null, |
255 | "ConglomerateDescriptor only expected to be provider for indexes"); |
256 | } |
257 | return name; |
258 | } |
259 | |
260 | /** |
261 | * Get the provider's UUID |
262 | * |
263 | * @return The provider's UUID |
264 | */ |
265 | public UUID getObjectID() |
266 | { |
267 | return uuid; |
268 | } |
269 | |
270 | /** |
271 | * Get the provider's type. |
272 | * |
273 | * @return char The provider's type. |
274 | */ |
275 | public String getClassType() |
276 | { |
277 | if (indexable) |
278 | { |
279 | return Dependable.INDEX; |
280 | } |
281 | else |
282 | { |
283 | return Dependable.HEAP; |
284 | } |
285 | } |
286 | |
287 | /** |
288 | * Convert the conglomerate descriptor to a String |
289 | * |
290 | * @return The conglomerate descriptor as a String |
291 | */ |
292 | |
293 | public String toString() |
294 | { |
295 | if (SanityManager.DEBUG) |
296 | { |
297 | String keyString = ""; |
298 | |
299 | if (indexable && columnNames != null ) |
300 | { |
301 | int[] keyColumns = indexRowGenerator.baseColumnPositions(); |
302 | |
303 | keyString = ", key columns = {" + columnNames[keyColumns[0] - 1]; |
304 | for (int index = 1; index < keyColumns.length; index++) |
305 | { |
306 | keyString = keyString + ", " + columnNames[keyColumns[index] - 1]; |
307 | } |
308 | keyString = keyString + "}"; |
309 | } |
310 | |
311 | return "ConglomerateDescriptor: conglomerateNumber = " + conglomerateNumber + |
312 | " name = " + name + |
313 | " uuid = " + uuid + |
314 | " indexable = " + indexable + keyString; |
315 | } |
316 | else |
317 | { |
318 | return ""; |
319 | } |
320 | } |
321 | |
322 | /** @see TupleDescriptor#getDescriptorType */ |
323 | public String getDescriptorType() |
324 | { |
325 | if (indexable) |
326 | return "Index"; |
327 | else |
328 | return "Table"; |
329 | } |
330 | |
331 | /** @see TupleDescriptor#getDescriptorName */ |
332 | public String getDescriptorName() { return name; } |
333 | |
334 | } |