KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > catalog > SYSCONGLOMERATESRowFactory


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.SYSCONGLOMERATESRowFactory
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.impl.sql.catalog;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.types.TypeId;
27 import org.apache.derby.iapi.sql.dictionary.SystemColumn;
28 import org.apache.derby.catalog.TypeDescriptor;
29
30 import org.apache.derby.iapi.types.DataValueDescriptor;
31
32 import org.apache.derby.iapi.types.DataValueFactory;
33
34 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
35 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
36 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
37 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
38 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;
39 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
40 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
41
42 import org.apache.derby.iapi.types.RowLocation;
43
44 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
45 import org.apache.derby.iapi.sql.execute.ExecRow;
46 import org.apache.derby.iapi.sql.execute.ExecutionContext;
47 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
48
49 import org.apache.derby.iapi.error.StandardException;
50
51 import org.apache.derby.iapi.services.uuid.UUIDFactory;
52 import org.apache.derby.catalog.UUID;
53
54 import org.apache.derby.catalog.IndexDescriptor;
55
56 import java.util.Properties JavaDoc;
57
58 /**
59  * Factory for creating a SYSCONGLOMERATES row.
60  *
61  * @author ames
62  */

63
64 public class SYSCONGLOMERATESRowFactory extends CatalogRowFactory
65 {
66     private static final String JavaDoc TABLENAME_STRING = "SYSCONGLOMERATES";
67
68     protected static final int SYSCONGLOMERATES_COLUMN_COUNT = 8;
69     protected static final int SYSCONGLOMERATES_SCHEMAID = 1;
70     protected static final int SYSCONGLOMERATES_TABLEID = 2;
71     protected static final int SYSCONGLOMERATES_CONGLOMERATENUMBER = 3;
72     protected static final int SYSCONGLOMERATES_CONGLOMERATENAME = 4;
73     protected static final int SYSCONGLOMERATES_ISINDEX = 5;
74     protected static final int SYSCONGLOMERATES_DESCRIPTOR = 6;
75     protected static final int SYSCONGLOMERATES_ISCONSTRAINT = 7;
76     protected static final int SYSCONGLOMERATES_CONGLOMERATEID = 8;
77
78     protected static final int SYSCONGLOMERATES_INDEX1_ID = 0;
79     protected static final int SYSCONGLOMERATES_INDEX2_ID = 1;
80     protected static final int SYSCONGLOMERATES_INDEX3_ID = 2;
81
82     private static final boolean[] uniqueness = {
83                                                        false,
84                                                        true,
85                                                        false
86                                                      };
87
88     private static final int[][] indexColumnPositions =
89     {
90         {SYSCONGLOMERATES_CONGLOMERATEID},
91         {SYSCONGLOMERATES_CONGLOMERATENAME, SYSCONGLOMERATES_SCHEMAID},
92         {SYSCONGLOMERATES_TABLEID}
93     };
94
95     private static final String JavaDoc[] uuids =
96     {
97          "80000010-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
98
,"80000027-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
99
,"80000012-00d0-fd77-3ed8-000a0a0b1900" // SYSCONGLOMERATES_INDEX1
100
,"80000014-00d0-fd77-3ed8-000a0a0b1900" // SYSCONGLOMERATES_INDEX2
101
,"80000016-00d0-fd77-3ed8-000a0a0b1900" // SYSCONGLOMERATES_INDEX3
102
};
103
104     SYSCONGLOMERATESRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf,
105                                  boolean convertIdToLower)
106     {
107         super(uuidf,ef,dvf,convertIdToLower);
108         initInfo(SYSCONGLOMERATES_COLUMN_COUNT,
109                  TABLENAME_STRING, indexColumnPositions,
110                  uniqueness, uuids );
111     }
112
113   /**
114      * Make a SYSCONGLOMERATES row
115      *
116      * @return Row suitable for inserting into SYSCONGLOMERATES.
117      *
118      * @exception StandardException thrown on failure
119      */

120     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
121                     throws StandardException
122     {
123         ExecRow row;
124         DataValueDescriptor col;
125         String JavaDoc tabID =null;
126         Long JavaDoc conglomNumber = null;
127         String JavaDoc conglomName = null;
128         Boolean JavaDoc supportsIndex = null;
129         IndexRowGenerator indexRowGenerator = null;
130         Boolean JavaDoc supportsConstraint = null;
131         String JavaDoc conglomUUIDString = null;
132         String JavaDoc schemaID = null;
133         ConglomerateDescriptor conglomerate = (ConglomerateDescriptor)td;
134
135         /* Insert info into sysconglomerates */
136
137         if (td != null)
138         {
139             /* Sometimes the SchemaDescriptor is non-null and sometimes it
140              * is null. (We can't just rely on getting the schema id from
141              * the ConglomerateDescriptor because it can be null when
142              * we are creating a new conglomerate.
143              */

144             if (parent != null)
145             {
146                 SchemaDescriptor sd = (SchemaDescriptor)parent;
147                 schemaID = sd.getUUID().toString();
148             }
149             else
150             {
151                 schemaID = conglomerate.getSchemaID().toString();
152             }
153             tabID = conglomerate.getTableID().toString();
154             conglomNumber = new Long JavaDoc( conglomerate.getConglomerateNumber() );
155             conglomName = conglomerate.getConglomerateName();
156             conglomUUIDString = conglomerate.getUUID().toString();
157
158             supportsIndex = new Boolean JavaDoc( conglomerate.isIndex() );
159             indexRowGenerator = conglomerate.getIndexDescriptor();
160             supportsConstraint = new Boolean JavaDoc( conglomerate.isConstraint() );
161         }
162
163         /* RESOLVE - It would be nice to require less knowledge about sysconglomerates
164          * and have this be more table driven.
165          */

166
167         /* Build the row to insert */
168         row = getExecutionFactory().getValueRow(SYSCONGLOMERATES_COLUMN_COUNT);
169
170         /* 1st column is SCHEMAID (UUID - char(36)) */
171         row.setColumn(1, dvf.getCharDataValue(schemaID));
172
173         /* 2nd column is TABLEID (UUID - char(36)) */
174         row.setColumn(2, dvf.getCharDataValue(tabID));
175
176         /* 3rd column is CONGLOMERATENUMBER (long) */
177         row.setColumn(3, dvf.getDataValue(conglomNumber));
178
179         /* 4th column is CONGLOMERATENAME (varchar(128))
180         ** If null, use the tableid so we always
181         ** have a unique column
182         */

183         row.setColumn(4, (conglomName == null) ?
184                 dvf.getVarcharDataValue(tabID):
185                 dvf.getVarcharDataValue(conglomName));
186
187         /* 5th column is ISINDEX (boolean) */
188         row.setColumn(5, dvf.getDataValue(supportsIndex));
189
190         /* 6th column is DESCRIPTOR
191         * (user type org.apache.derby.catalog.IndexDescriptor)
192         */

193         row.setColumn(6,
194             dvf.getDataValue(
195                         (indexRowGenerator == null ?
196                             (IndexDescriptor) null :
197                             indexRowGenerator.getIndexDescriptor()
198                         )
199                     )
200                 );
201
202         /* 7th column is ISCONSTRAINT (boolean) */
203         row.setColumn(7, dvf.getDataValue(supportsConstraint));
204
205         /* 8th column is CONGLOMERATEID (UUID - char(36)) */
206         row.setColumn(8, dvf.getCharDataValue(conglomUUIDString));
207
208         return row;
209     }
210
211     public ExecRow makeEmptyRow() throws StandardException
212     {
213         return makeRow(null, null);
214     }
215
216
217     /**
218      * Get the Properties associated with creating the heap.
219      *
220      * @return The Properties associated with creating the heap.
221      */

222     public Properties JavaDoc getCreateHeapProperties()
223     {
224         Properties JavaDoc properties = new Properties JavaDoc();
225         // keep page size at 4K since its a big table
226
properties.put("derby.storage.pageSize","4096");
227         // default properties for system tables:
228
properties.put("derby.storage.pageReservedSpace","0");
229         properties.put("derby.storage.minimumRecordSize","1");
230         return properties;
231     }
232
233     /**
234      * Get the Properties associated with creating the specified index.
235      *
236      * @param indexNumber The specified index number.
237      *
238      * @return The Properties associated with creating the specified index.
239      */

240     public Properties JavaDoc getCreateIndexProperties(int indexNumber)
241     {
242         Properties JavaDoc properties = new Properties JavaDoc();
243         // keep page size for all indexes at 4K since its a big table
244
properties.put("derby.storage.pageSize","4096");
245         return properties;
246     }
247
248     ///////////////////////////////////////////////////////////////////////////
249
//
250
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
251
//
252
///////////////////////////////////////////////////////////////////////////
253

254     /**
255      *
256      * @param row a SYSCOLUMNS row
257      * @param parentTupleDescriptor Null for this kind of descriptor.
258      * @param dd dataDictionary
259      *
260      * @return a conglomerate descriptor equivalent to a SYSCONGOMERATES row
261      *
262      * @exception StandardException thrown on failure
263      */

264
265     public TupleDescriptor buildDescriptor(
266         ExecRow row,
267         TupleDescriptor parentTupleDescriptor,
268         DataDictionary dd )
269                     throws StandardException
270     {
271         if (SanityManager.DEBUG)
272         SanityManager.ASSERT(
273             row.nColumns() == SYSCONGLOMERATES_COLUMN_COUNT,
274             "Wrong number of columns for a SYSCONGLOMERATES row");
275
276         DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
277         long conglomerateNumber;
278         String JavaDoc name;
279         boolean isConstraint;
280         boolean isIndex;
281         IndexRowGenerator indexRowGenerator;
282         DataValueDescriptor col;
283         ConglomerateDescriptor conglomerateDesc;
284         String JavaDoc conglomUUIDString;
285         UUID conglomUUID;
286         String JavaDoc schemaUUIDString;
287         UUID schemaUUID;
288         String JavaDoc tableUUIDString;
289         UUID tableUUID;
290
291         /* 1st column is SCHEMAID (UUID - char(36)) */
292         col = row.getColumn(1);
293         schemaUUIDString = col.getString();
294         schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
295
296         /* 2nd column is TABLEID (UUID - char(36)) */
297         col = row.getColumn(2);
298         tableUUIDString = col.getString();
299         tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
300
301
302         /* 3nd column is CONGLOMERATENUMBER (long) */
303         col = row.getColumn(3);
304         conglomerateNumber = col.getLong();
305
306         /* 4rd column is CONGLOMERATENAME (varchar(128)) */
307         col = row.getColumn(4);
308         name = col.getString();
309
310         /* 5th column is ISINDEX (boolean) */
311         col = row.getColumn(5);
312         isIndex = col.getBoolean();
313
314         /* 6th column is DESCRIPTOR */
315         col = row.getColumn(6);
316         indexRowGenerator = new IndexRowGenerator(
317             (IndexDescriptor) col.getObject());
318
319         /* 7th column is ISCONSTRAINT (boolean) */
320         col = row.getColumn(7);
321         isConstraint = col.getBoolean();
322
323         /* 8th column is CONGLOMERATEID (UUID - char(36)) */
324         col = row.getColumn(8);
325         conglomUUIDString = col.getString();
326         conglomUUID = getUUIDFactory().recreateUUID(conglomUUIDString);
327
328         /* now build and return the descriptor */
329         conglomerateDesc = ddg.newConglomerateDescriptor(conglomerateNumber,
330                                                          name,
331                                                          isIndex,
332                                                          indexRowGenerator,
333                                                          isConstraint,
334                                                          conglomUUID,
335                                                          tableUUID,
336                                                          schemaUUID);
337         return conglomerateDesc;
338     }
339
340     /**
341      * Get the conglomerate's UUID of the row.
342      *
343      * @param row The row from sysconglomerates
344      *
345      * @return UUID The conglomerates UUID
346      *
347      * @exception StandardException thrown on failure
348      */

349      protected UUID getConglomerateUUID(ExecRow row)
350          throws StandardException
351      {
352         DataValueDescriptor col;
353         String JavaDoc conglomerateUUIDString;
354
355         /* 8th column is CONGLOMERATEID (UUID - char(36)) */
356         col = row.getColumn(SYSCONGLOMERATES_CONGLOMERATEID);
357         conglomerateUUIDString = col.getString();
358         return getUUIDFactory().recreateUUID(conglomerateUUIDString);
359      }
360
361     /**
362      * Get the table's UUID from the row.
363      *
364      * @param row The row from sysconglomerates
365      *
366      * @return UUID The table's UUID
367      *
368      * @exception StandardException thrown on failure
369      */

370      protected UUID getTableUUID(ExecRow row)
371          throws StandardException
372      {
373         DataValueDescriptor col;
374         String JavaDoc tableUUIDString;
375
376         /* 2nd column is TABLEID (UUID - char(36)) */
377         col = row.getColumn(SYSCONGLOMERATES_TABLEID);
378         tableUUIDString = col.getString();
379         return getUUIDFactory().recreateUUID(tableUUIDString);
380      }
381
382     /**
383      * Get the schema's UUID from the row.
384      *
385      * @param row The row from sysconglomerates
386      *
387      * @return UUID The schema's UUID
388      *
389      * @exception StandardException thrown on failure
390      */

391      protected UUID getSchemaUUID(ExecRow row)
392          throws StandardException
393      {
394         DataValueDescriptor col;
395         String JavaDoc schemaUUIDString;
396
397         /* 1st column is SCHEMAID (UUID - char(36)) */
398         col = row.getColumn(SYSCONGLOMERATES_SCHEMAID);
399         schemaUUIDString = col.getString();
400         return getUUIDFactory().recreateUUID(schemaUUIDString);
401      }
402
403     /**
404      * Get the conglomerate's name of the row.
405      *
406      * @param row The row from sysconglomerates
407      *
408      * @return String The conglomerates name
409      *
410      * @exception StandardException thrown on failure
411      */

412      protected String JavaDoc getConglomerateName(ExecRow row)
413          throws StandardException
414      {
415         DataValueDescriptor col;
416
417         /* 4th column is CONGLOMERATENAME (varchar(128)) */
418         col = row.getColumn(SYSCONGLOMERATES_CONGLOMERATENAME);
419         return col.getString();
420      }
421
422     /**
423      * Builds a list of columns suitable for creating this Catalog.
424      *
425      *
426      * @return array of SystemColumn suitable for making this catalog.
427      */

428     public SystemColumn[] buildColumnList()
429     {
430         int index = 0;
431         SystemColumn[] columnList = new SystemColumn[SYSCONGLOMERATES_COLUMN_COUNT];
432
433         // describe columns
434

435
436         columnList[index++] =
437                     new SystemColumnImpl(
438                             convertIdCase( "SCHEMAID"), // column name
439
SYSCONGLOMERATES_SCHEMAID, // column number
440
0, // precision
441
0, // scale
442
false, // nullability
443
"CHAR", // dataType
444
true, // built-in type
445
36 // maxLength
446
);
447
448         columnList[index++] =
449                     new SystemColumnImpl(
450                             convertIdCase( "TABLEID"), // column name
451
SYSCONGLOMERATES_TABLEID, // column number
452
0, // precision
453
0, // scale
454
false, // nullability
455
"CHAR", // dataType
456
true, // built-in type
457
36 // maxLength
458
);
459         columnList[index++] =
460                     new SystemColumnImpl(
461                             convertIdCase( "CONGLOMERATENUMBER"), // column name
462
SYSCONGLOMERATES_CONGLOMERATENUMBER, // column number
463
0, // precision
464
0, // scale
465
false, // nullability
466
"BIGINT", // dataType
467
true, // built-in type
468
TypeId.LONGINT_MAXWIDTH // maxLength
469
);
470
471         columnList[index++] =
472                     new SystemColumnImpl( // SQL IDENTIFIER
473
convertIdCase( "CONGLOMERATENAME"), // column name
474
SYSCONGLOMERATES_CONGLOMERATENAME,
475                             true // nullability
476
);
477
478         columnList[index++] =
479                     new SystemColumnImpl(
480                             convertIdCase( "ISINDEX"), // column name
481
SYSCONGLOMERATES_ISINDEX, // column number
482
0, // precision
483
0, // scale
484
false, // nullability
485
"BOOLEAN", // dataType
486
true, // built-in type
487
1 // maxLength
488
);
489
490         columnList[index++] =
491                     new SystemColumnImpl(
492                             convertIdCase( "DESCRIPTOR"), // column name
493
SYSCONGLOMERATES_DESCRIPTOR,
494                             0, // precision
495
0, // scale
496
true, // nullability
497
"org.apache.derby.catalog.IndexDescriptor", // datatype
498
false, // built-in type
499
TypeDescriptor.MAXIMUM_WIDTH_UNKNOWN
500                                                 // maxLength
501
);
502
503         columnList[index++] =
504                     new SystemColumnImpl(
505                             convertIdCase( "ISCONSTRAINT"), // column name
506
SYSCONGLOMERATES_ISCONSTRAINT,
507                             0, // precision
508
0, // scale
509
true, // nullability
510
"BOOLEAN", // datatype
511
true, // built-in type
512
1 // maxLength
513
);
514
515         columnList[index++] =
516                     new SystemColumnImpl(
517                             convertIdCase( "CONGLOMERATEID"), // column name
518
SYSCONGLOMERATES_CONGLOMERATEID,
519                             0, // precision
520
0, // scale
521
false, // nullability
522
"CHAR", // datatype
523
true, // built-in type
524
36 // maxLength
525
);
526
527         return columnList;
528
529     }
530 }
531
Popular Tags