KickJava   Java API By Example, From Geeks To Geeks.

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


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

66
67 public class SYSCONSTRAINTSRowFactory extends CatalogRowFactory
68 {
69     private static final String JavaDoc TABLENAME_STRING = "SYSCONSTRAINTS";
70
71     protected static final int SYSCONSTRAINTS_COLUMN_COUNT = 7;
72     protected static final int SYSCONSTRAINTS_CONSTRAINTID = 1;
73     protected static final int SYSCONSTRAINTS_TABLEID = 2;
74     protected static final int SYSCONSTRAINTS_CONSTRAINTNAME = 3;
75     protected static final int SYSCONSTRAINTS_TYPE = 4;
76     protected static final int SYSCONSTRAINTS_SCHEMAID = 5;
77     protected static final int SYSCONSTRAINTS_STATE = ConstraintDescriptor.SYSCONSTRAINTS_STATE_FIELD;
78     protected static final int SYSCONSTRAINTS_REFERENCECOUNT = 7;
79
80     protected static final int SYSCONSTRAINTS_INDEX1_ID = 0;
81     protected static final int SYSCONSTRAINTS_INDEX2_ID = 1;
82     protected static final int SYSCONSTRAINTS_INDEX3_ID = 2;
83
84     private static final boolean[] uniqueness = {
85                                                        true,
86                                                        true,
87                                                        false
88                                                      };
89
90     private static final int[][] indexColumnPositions =
91     {
92         {SYSCONSTRAINTS_CONSTRAINTID},
93         {SYSCONSTRAINTS_CONSTRAINTNAME, SYSCONSTRAINTS_SCHEMAID},
94         {SYSCONSTRAINTS_TABLEID}
95     };
96
97     private static final String JavaDoc[] uuids =
98     {
99          "8000002f-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
100
,"80000036-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
101
,"80000031-00d0-fd77-3ed8-000a0a0b1900" // SYSCONSTRAINTS_INDEX1
102
,"80000033-00d0-fd77-3ed8-000a0a0b1900" // SYSCONSTRAINTS_INDEX2
103
,"80000035-00d0-fd77-3ed8-000a0a0b1900" // SYSCONSTRAINTS_INDEX3
104
};
105
106     /////////////////////////////////////////////////////////////////////////////
107
//
108
// CONSTRUCTORS
109
//
110
/////////////////////////////////////////////////////////////////////////////
111

112     public SYSCONSTRAINTSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf,
113                                  boolean convertIdToLower)
114     {
115         super(uuidf,ef,dvf,convertIdToLower);
116         initInfo(SYSCONSTRAINTS_COLUMN_COUNT, TABLENAME_STRING,
117                  indexColumnPositions, uniqueness, uuids );
118     }
119
120     /////////////////////////////////////////////////////////////////////////////
121
//
122
// METHODS
123
//
124
/////////////////////////////////////////////////////////////////////////////
125

126   /**
127      * Make a SYSCONTRAINTS row
128      *
129      * @return Row suitable for inserting into SYSCONTRAINTS.
130      *
131      * @exception StandardException thrown on failure
132      */

133     public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
134                     throws StandardException
135     {
136         DataValueDescriptor col;
137         ExecRow row;
138         int constraintIType;
139         UUID oid;
140         String JavaDoc constraintSType = null;
141         String JavaDoc constraintID = null;
142         String JavaDoc tableID = null;
143         String JavaDoc constraintName = null;
144         String JavaDoc schemaID = null;
145         boolean isEnabled = true;
146         int referenceCount = 0;
147
148         if (td != null)
149         {
150             ConstraintDescriptor constraint = (ConstraintDescriptor)td;
151             /*
152             ** We only allocate a new UUID if the descriptor doesn't already have one.
153             ** For descriptors replicated from a Source system, we already have an UUID.
154             */

155             oid = constraint.getUUID();
156             constraintID = oid.toString();
157
158             oid = constraint.getTableId();
159             tableID = oid.toString();
160
161             constraintName = constraint.getConstraintName();
162
163             constraintIType = constraint.getConstraintType();
164             switch (constraintIType)
165             {
166                 case DataDictionary.PRIMARYKEY_CONSTRAINT:
167                     constraintSType = "P";
168                     break;
169
170                 case DataDictionary.UNIQUE_CONSTRAINT:
171                     constraintSType = "U";
172                     break;
173
174                 case DataDictionary.CHECK_CONSTRAINT:
175                     constraintSType = "C";
176                     break;
177
178                 case DataDictionary.FOREIGNKEY_CONSTRAINT:
179                     constraintSType = "F";
180                     break;
181
182                 default:
183                     if (SanityManager.DEBUG)
184                     {
185                         SanityManager.THROWASSERT("invalid constraint type");
186                     }
187             }
188
189             schemaID = constraint.getSchemaDescriptor().getUUID().toString();
190             isEnabled = constraint.isEnabled();
191             referenceCount = constraint.getReferenceCount();
192         }
193
194         /* Insert info into sysconstraints */
195
196         /* RESOLVE - It would be nice to require less knowledge about sysconstraints
197          * and have this be more table driven.
198          */

199
200         /* Build the row to insert */
201         row = getExecutionFactory().getValueRow(SYSCONSTRAINTS_COLUMN_COUNT);
202
203         /* 1st column is CONSTRAINTID (UUID - char(36)) */
204         row.setColumn(SYSCONSTRAINTS_CONSTRAINTID, dvf.getCharDataValue(constraintID));
205
206         /* 2nd column is TABLEID (UUID - char(36)) */
207         row.setColumn(SYSCONSTRAINTS_TABLEID, dvf.getCharDataValue(tableID));
208
209         /* 3rd column is NAME (varchar(128)) */
210         row.setColumn(SYSCONSTRAINTS_CONSTRAINTNAME, dvf.getVarcharDataValue(constraintName));
211
212         /* 4th column is TYPE (char(1)) */
213         row.setColumn(SYSCONSTRAINTS_TYPE, dvf.getCharDataValue(constraintSType));
214
215         /* 5th column is SCHEMAID (UUID - char(36)) */
216         row.setColumn(SYSCONSTRAINTS_SCHEMAID, dvf.getCharDataValue(schemaID));
217
218         /* 6th column is STATE (char(1)) */
219         row.setColumn(SYSCONSTRAINTS_STATE, dvf.getCharDataValue(isEnabled ? "E" : "D"));
220
221         /* 7th column is REFERENCED */
222         row.setColumn(SYSCONSTRAINTS_REFERENCECOUNT, dvf.getDataValue(referenceCount));
223
224         return row;
225     }
226
227
228     ///////////////////////////////////////////////////////////////////////////
229
//
230
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
231
//
232
///////////////////////////////////////////////////////////////////////////
233

234     /**
235      * Make a ConstraintDescriptor out of a SYSCONSTRAINTS row
236      *
237      * @param row a SYSCONSTRAINTS row
238      * @param parentTupleDescriptor Subconstraint descriptor with auxiliary info.
239      * @param dd dataDictionary
240      *
241      * @exception StandardException thrown on failure
242      */

243     public TupleDescriptor buildDescriptor(
244         ExecRow row,
245         TupleDescriptor parentTupleDescriptor,
246         DataDictionary dd )
247                     throws StandardException
248     {
249         ConstraintDescriptor constraintDesc = null;
250
251         if (SanityManager.DEBUG)
252         {
253             SanityManager.ASSERT(
254                 row.nColumns() == SYSCONSTRAINTS_COLUMN_COUNT,
255                 "Wrong number of columns for a SYSCONSTRAINTS row");
256         }
257
258         DataValueDescriptor col;
259         ConglomerateDescriptor conglomDesc;
260         DataDescriptorGenerator ddg;
261         TableDescriptor td = null;
262         int constraintIType = -1;
263         int[] keyColumns = null;
264         UUID constraintUUID;
265         UUID schemaUUID;
266         UUID tableUUID;
267         UUID referencedConstraintId = null;
268         SchemaDescriptor schema;
269         String JavaDoc tableUUIDString;
270         String JavaDoc constraintName;
271         String JavaDoc constraintSType;
272         String JavaDoc constraintStateStr;
273         boolean constraintEnabled;
274         int referenceCount;
275         String JavaDoc constraintUUIDString;
276         String JavaDoc schemaUUIDString;
277         SubConstraintDescriptor scd;
278
279         if (SanityManager.DEBUG)
280         {
281             if (!(parentTupleDescriptor instanceof SubConstraintDescriptor))
282             {
283                 SanityManager.THROWASSERT(
284                     "parentTupleDescriptor expected to be instanceof " +
285                     "SubConstraintDescriptor, not " +
286                     parentTupleDescriptor.getClass().getName());
287             }
288         }
289
290         scd = (SubConstraintDescriptor) parentTupleDescriptor;
291
292         ddg = dd.getDataDescriptorGenerator();
293
294         /* 1st column is CONSTRAINTID (UUID - char(36)) */
295         col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTID);
296         constraintUUIDString = col.getString();
297         constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
298
299         /* 2nd column is TABLEID (UUID - char(36)) */
300         col = row.getColumn(SYSCONSTRAINTS_TABLEID);
301         tableUUIDString = col.getString();
302         tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
303
304         /* Get the TableDescriptor.
305          * It may be cached in the SCD,
306          * otherwise we need to go to the
307          * DD.
308          */

309         if (scd != null)
310         {
311             td = scd.getTableDescriptor();
312         }
313         if (td == null)
314         {
315             td = dd.getTableDescriptor(tableUUID);
316         }
317
318         /* 3rd column is NAME (varchar(128)) */
319         col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTNAME);
320         constraintName = col.getString();
321
322         /* 4th column is TYPE (char(1)) */
323         col = row.getColumn(SYSCONSTRAINTS_TYPE);
324         constraintSType = col.getString();
325         if (SanityManager.DEBUG)
326         {
327             SanityManager.ASSERT(constraintSType.length() == 1,
328                 "Fourth column type incorrect");
329         }
330
331         boolean typeSet = false;
332         switch (constraintSType.charAt(0))
333         {
334             case 'P' :
335                 constraintIType = DataDictionary.PRIMARYKEY_CONSTRAINT;
336                 typeSet = true;
337                 // fall through
338

339             case 'U' :
340                 if (! typeSet)
341                 {
342                     constraintIType = DataDictionary.UNIQUE_CONSTRAINT;
343                     typeSet = true;
344                 }
345                 // fall through
346

347             case 'F' :
348                 if (! typeSet)
349                     constraintIType = DataDictionary.FOREIGNKEY_CONSTRAINT;
350                 if (SanityManager.DEBUG)
351                 {
352                     if (!(parentTupleDescriptor instanceof SubKeyConstraintDescriptor))
353                     {
354                         SanityManager.THROWASSERT(
355                         "parentTupleDescriptor expected to be instanceof " +
356                         "SubKeyConstraintDescriptor, not " +
357                         parentTupleDescriptor.getClass().getName());
358                     }
359                 }
360                 conglomDesc = td.getConglomerateDescriptor(
361                                         ((SubKeyConstraintDescriptor)
362                                             parentTupleDescriptor).getIndexId());
363                 /* Take care the rare case of conglomDesc being null. The
364                  * reason is that our "td" is out of date. Another thread
365                  * which was adding a constraint committed between the moment
366                  * we got the table descriptor (conglomerate list) and the
367                  * moment we scanned and got the constraint desc list. Since
368                  * that thread just added a new row to SYSCONGLOMERATES,
369                  * SYSCONSTRAINTS, etc. We wouldn't have wanted to lock the
370                  * system tables just to prevent other threads from adding new
371                  * rows.
372                  */

373                 if (conglomDesc == null)
374                 {
375                     // we can't be getting td from cache because if we are
376
// here, we must have been in dd's ddl mode (that's why
377
// the ddl thread went through), we are not done yet, the
378
// dd ref count is not 0, hence it couldn't have turned
379
// into COMPILE_ONLY mode
380
td = dd.getTableDescriptor(tableUUID);
381                     if (scd != null)
382                         scd.setTableDescriptor(td);
383                     // try again now
384
conglomDesc = td.getConglomerateDescriptor(
385                                     ((SubKeyConstraintDescriptor)
386                                         parentTupleDescriptor).getIndexId());
387                 }
388
389                 if (SanityManager.DEBUG)
390                 {
391                     SanityManager.ASSERT(conglomDesc != null,
392                     "conglomDesc is expected to be non-null for backing index");
393                 }
394                 keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
395                 referencedConstraintId = ((SubKeyConstraintDescriptor)
396                                             parentTupleDescriptor).getKeyConstraintId();
397                 keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
398                 break;
399
400             case 'C' :
401                 constraintIType = DataDictionary.CHECK_CONSTRAINT;
402                 if (SanityManager.DEBUG)
403                 {
404                     if (!(parentTupleDescriptor instanceof SubCheckConstraintDescriptor))
405                     {
406                         SanityManager.THROWASSERT("parentTupleDescriptor expected to be instanceof " +
407                         "SubCheckConstraintDescriptor, not " +
408                         parentTupleDescriptor.getClass().getName());
409                     }
410                 }
411                 break;
412
413             default:
414                 if (SanityManager.DEBUG)
415                 {
416                     SanityManager.THROWASSERT("Fourth column value invalid");
417                 }
418         }
419
420         /* 5th column is SCHEMAID (UUID - char(36)) */
421         col = row.getColumn(SYSCONSTRAINTS_SCHEMAID);
422         schemaUUIDString = col.getString();
423         schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
424
425         schema = dd.getSchemaDescriptor(schemaUUID, null);
426
427         /* 6th column is STATE (char(1)) */
428         col = row.getColumn(SYSCONSTRAINTS_STATE);
429         constraintStateStr = col.getString();
430         if (SanityManager.DEBUG)
431         {
432             SanityManager.ASSERT(constraintStateStr.length() == 1,
433                 "Sixth column (state) type incorrect");
434         }
435
436         switch (constraintStateStr.charAt(0))
437         {
438             case 'E':
439                 constraintEnabled = true;
440                 break;
441             case 'D':
442                 constraintEnabled = false;
443                 break;
444             default:
445                 constraintEnabled = true;
446                 if (SanityManager.DEBUG)
447                 {
448                     SanityManager.THROWASSERT("Invalidate state value '"
449                             +constraintStateStr+ "' for constraint");
450                 }
451         }
452
453         /* 7th column is REFERENCECOUNT, boolean */
454         col = row.getColumn(SYSCONSTRAINTS_REFERENCECOUNT);
455         referenceCount = col.getInt();
456         
457         /* now build and return the descriptor */
458
459         switch (constraintIType)
460         {
461             case DataDictionary.PRIMARYKEY_CONSTRAINT :
462                 constraintDesc = ddg.newPrimaryKeyConstraintDescriptor(
463                                         td,
464                                         constraintName,
465                                         false, //deferable,
466
false, //initiallyDeferred,
467
keyColumns,//genReferencedColumns(dd, td), //int referencedColumns[],
468
constraintUUID,
469                                         ((SubKeyConstraintDescriptor)
470                                             parentTupleDescriptor).getIndexId(),
471                                         schema,
472                                         constraintEnabled,
473                                         referenceCount);
474                 break;
475
476             case DataDictionary.UNIQUE_CONSTRAINT :
477                 constraintDesc = ddg.newUniqueConstraintDescriptor(
478                                         td,
479                                         constraintName,
480                                         false, //deferable,
481
false, //initiallyDeferred,
482
keyColumns,//genReferencedColumns(dd, td), //int referencedColumns[],
483
constraintUUID,
484                                         ((SubKeyConstraintDescriptor)
485                                             parentTupleDescriptor).getIndexId(),
486                                         schema,
487                                         constraintEnabled,
488                                         referenceCount);
489                 break;
490
491             case DataDictionary.FOREIGNKEY_CONSTRAINT :
492                 if (SanityManager.DEBUG)
493                 {
494                     SanityManager.ASSERT(referenceCount == 0,
495                         "REFERENCECOUNT column is nonzero for fk constraint");
496                 }
497                     
498                 constraintDesc = ddg.newForeignKeyConstraintDescriptor(
499                                         td,
500                                         constraintName,
501                                         false, //deferable,
502
false, //initiallyDeferred,
503
keyColumns,//genReferencedColumns(dd, td), //int referencedColumns[],
504
constraintUUID,
505                                         ((SubKeyConstraintDescriptor)
506                                             parentTupleDescriptor).getIndexId(),
507                                         schema,
508                                         referencedConstraintId,
509                                         constraintEnabled,
510                                         ((SubKeyConstraintDescriptor)
511                                             parentTupleDescriptor).getRaDeleteRule(),
512                                         ((SubKeyConstraintDescriptor)
513                                             parentTupleDescriptor).getRaUpdateRule()
514                                         );
515                 break;
516
517             case DataDictionary.CHECK_CONSTRAINT :
518                 if (SanityManager.DEBUG)
519                 {
520                     SanityManager.ASSERT(referenceCount == 0,
521                         "REFERENCECOUNT column is nonzero for check constraint");
522                 }
523                     
524                 constraintDesc = ddg.newCheckConstraintDescriptor(
525                                         td,
526                                         constraintName,
527                                         false, //deferable,
528
false, //initiallyDeferred,
529
constraintUUID,
530                                         ((SubCheckConstraintDescriptor)
531                                             parentTupleDescriptor).getConstraintText(),
532                                         ((SubCheckConstraintDescriptor)
533                                             parentTupleDescriptor).getReferencedColumnsDescriptor(),
534                                         schema,
535                                         constraintEnabled);
536                 break;
537         }
538         return constraintDesc;
539     }
540
541     /**
542      * Get the constraint ID of the row.
543      *
544      * @param row The row from sysconstraints
545      *
546      * @return UUID The constraint id
547      *
548      * @exception StandardException thrown on failure
549      */

550      protected UUID getConstraintId(ExecRow row)
551          throws StandardException
552      {
553         DataValueDescriptor col;
554         String JavaDoc constraintUUIDString;
555
556         /* 1st column is CONSTRAINTID (UUID - char(36)) */
557         col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTID);
558         constraintUUIDString = col.getString();
559         return getUUIDFactory().recreateUUID(constraintUUIDString);
560      }
561
562     /**
563      * Get the constraint name of the row.
564      *
565      * @param row The row from sysconstraints
566      *
567      * @return UUID The constraint name
568      *
569      * @exception StandardException thrown on failure
570      */

571      protected String JavaDoc getConstraintName(ExecRow row)
572          throws StandardException
573      {
574         DataValueDescriptor col;
575         String JavaDoc constraintName;
576
577         /* 3rd column is CONSTRAINTNAME (char(128)) */
578         col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTNAME);
579         constraintName = col.getString();
580         return constraintName;
581      }
582
583     /**
584      * Get the schema ID of the row.
585      *
586      * @param row The row from sysconstraints
587      *
588      * @return UUID The schema
589      *
590      * @exception StandardException thrown on failure
591      */

592      protected UUID getSchemaId(ExecRow row)
593          throws StandardException
594      {
595         DataValueDescriptor col;
596         String JavaDoc schemaUUIDString;
597
598         /* 5th column is SCHEMAID (UUID - char(36)) */
599         col = row.getColumn(SYSCONSTRAINTS_SCHEMAID);
600         schemaUUIDString =col.getString();
601         return getUUIDFactory().recreateUUID(schemaUUIDString);
602      }
603
604     /**
605      * Get the table ID of the row.
606      *
607      * @param row The row from sysconstraints
608      *
609      * @return UUID The table id
610      *
611      * @exception StandardException thrown on failure
612      */

613      protected UUID getTableId(ExecRow row)
614          throws StandardException
615      {
616         DataValueDescriptor col;
617         String JavaDoc tableUUIDString;
618
619         /* 2nd column is TABLEID (UUID - char(36)) */
620         col = row.getColumn(SYSCONSTRAINTS_TABLEID);
621         tableUUIDString = col.getString();
622         return getUUIDFactory().recreateUUID(tableUUIDString);
623      }
624
625     /**
626      * Get the constraint type out of the row.
627      *
628      * @param row The row from sysconstraints
629      *
630      * @return int The constraint type as an int
631      *
632      * @exception StandardException thrown on failure
633      */

634      protected int getConstraintType(ExecRow row)
635          throws StandardException
636      {
637         DataValueDescriptor col;
638         int constraintIType;
639         String JavaDoc constraintSType;
640
641         /* 4th column is TYPE (char(1)) */
642         col = row.getColumn(SYSCONSTRAINTS_TYPE);
643         constraintSType = col.getString();
644         if (SanityManager.DEBUG)
645         {
646             SanityManager.ASSERT(constraintSType.length() == 1,
647                 "Fourth column type incorrect");
648         }
649
650         switch (constraintSType.charAt(0))
651         {
652             case 'P' :
653                 constraintIType = DataDictionary.PRIMARYKEY_CONSTRAINT;
654                 break;
655
656             case 'U' :
657                 constraintIType = DataDictionary.UNIQUE_CONSTRAINT;
658                 break;
659
660             case 'C' :
661                 constraintIType = DataDictionary.CHECK_CONSTRAINT;
662                 break;
663
664             case 'F' :
665                 constraintIType = DataDictionary.FOREIGNKEY_CONSTRAINT;
666                 break;
667
668             default:
669                 if (SanityManager.DEBUG)
670                 {
671                     SanityManager.THROWASSERT("Fourth column value invalid");
672                 }
673                 constraintIType = -1;
674         }
675
676         return constraintIType;
677      }
678
679     /**
680      * Builds a list of columns suitable for creating this Catalog.
681      *
682      *
683      * @return array of SystemColumn suitable for making this catalog.
684      */

685     public SystemColumn[] buildColumnList()
686     {
687         int index = 0;
688         SystemColumn[] columnList = new SystemColumn[SYSCONSTRAINTS_COLUMN_COUNT];
689
690         // describe columns
691

692         columnList[index++] =
693                     new SystemColumnImpl(
694                             convertIdCase( "CONSTRAINTID"), // column name
695
SYSCONSTRAINTS_CONSTRAINTID, // column number
696
0, // precision
697
0, // scale
698
false, // nullability
699
"CHAR", // dataType
700
true, // built-in type
701
36 // maxLength
702
);
703
704         columnList[index++] =
705                     new SystemColumnImpl(
706                             convertIdCase( "TABLEID"), // column name
707
SYSCONSTRAINTS_TABLEID, // column number
708
0, // precision
709
0, // scale
710
false, // nullability
711
"CHAR", // dataType
712
true, // built-in type
713
36 // maxLength
714
);
715
716         columnList[index++] =
717                     new SystemColumnImpl( // SQL IDENTIFIER
718
convertIdCase( "CONSTRAINTNAME"), // column name
719
SYSCONSTRAINTS_CONSTRAINTNAME,
720                             false // nullability
721
);
722
723         columnList[index++] =
724                     new SystemColumnImpl(
725                             convertIdCase( "TYPE"), // column name
726
SYSCONSTRAINTS_TYPE, // column number
727
0, // precision
728
0, // scale
729
false, // nullability
730
"CHAR", // dataType
731
true, // built-in type
732
1 // maxLength
733
);
734
735
736         columnList[index++] =
737                     new SystemColumnImpl(
738                             convertIdCase( "SCHEMAID"), // column name
739
SYSCONSTRAINTS_SCHEMAID, // column number
740
0, // precision
741
0, // scale
742
false, // nullability
743
"CHAR", // dataType
744
true, // built-in type
745
36 // maxLength
746
);
747
748         columnList[index++] =
749                     new SystemColumnImpl(
750                             convertIdCase( "STATE"), // column name
751
SYSCONSTRAINTS_STATE, // column number
752
0, // precision
753
0, // scale
754
false, // nullability
755
"CHAR", // dataType
756
true, // built-in type
757
1 // maxLength
758
);
759
760         columnList[index++] =
761                     new SystemColumnImpl(
762                             convertIdCase( "REFERENCECOUNT"), // column name
763
SYSCONSTRAINTS_REFERENCECOUNT, // column number
764
0, // precision
765
0, // scale
766
false, // nullability
767
"INTEGER", // dataType
768
true, // built-in type
769
1 // maxLength
770
);
771         return columnList;
772     }
773
774 }
775
Popular Tags