KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor
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.error.StandardException;
25
26 import org.apache.derby.catalog.UUID;
27 import org.apache.derby.iapi.services.sanity.SanityManager;
28 /**
29  * This interface is used to get information from a KeyConstraintDescriptor.
30  * A KeyConstraintDescriptor can represent a primary/unique/foreign key
31  * constraint.
32  *
33  * @version 0.1
34  * @author Jerry Brenner
35  */

36
37 public abstract class KeyConstraintDescriptor extends ConstraintDescriptor
38 {
39     /** interface to this class:
40         <ol>
41         <li>public UUID getIndexId();</li>
42         <li>public ConglomerateDescriptor getIndexConglomerateDescriptor(DataDictionary dd)</li>
43         throws StandardException;</li>
44         <li>public String getIndexUUIDString();</li>
45         <li>public int[] getKeyColumns();</li>
46         </ol>
47     */

48
49     // implementation
50
UUID indexId;
51
52     private ConglomerateDescriptor indexConglom;
53
54     /**
55      * Constructor for a KeyConstraintDescriptor
56      *
57      * @param dataDictionary The data dictionary that this descriptor lives in
58      * @param table The descriptor of the table the constraint is on
59      * @param constraintName The name of the constraint.
60      * @param deferrable If the constraint can be deferred.
61      * @param initiallyDeferred If the constraint starts life deferred.
62      * @param referencedColumns columns that the constraint references
63      * @param constraintId UUID of constraint
64      * @param indexId The UUID for the backing index
65      * @param schemaDesc The SchemaDescriptor for the constraint
66      * @param isEnabled is this constraint enabled
67      */

68     KeyConstraintDescriptor(
69             DataDictionary dataDictionary,
70             TableDescriptor table,
71             String JavaDoc constraintName,
72             boolean deferrable,
73             boolean initiallyDeferred,
74             int[] referencedColumns,
75             UUID constraintId,
76             UUID indexId,
77             SchemaDescriptor schemaDesc,
78             boolean isEnabled
79             )
80     {
81         super(dataDictionary, table, constraintName, deferrable,
82               initiallyDeferred, referencedColumns,
83               constraintId, schemaDesc, isEnabled);
84         this.indexId = indexId;
85     }
86
87     /**
88      * Gets the UUID of the backing index for the constraint.
89      *
90      * @return The UUID of the backing index for the constraint.
91      */

92     public UUID getIndexId()
93     {
94         return indexId;
95     }
96
97     /**
98      * Gets the index conglomerate descriptor
99      *
100      * @return the index conglomerate descriptor
101      *
102      * @exception StandardException on error
103      */

104     public ConglomerateDescriptor getIndexConglomerateDescriptor(DataDictionary dd)
105         throws StandardException
106     {
107         if (indexConglom == null)
108         {
109             indexConglom = getTableDescriptor().getConglomerateDescriptor(indexId);
110         }
111         return indexConglom;
112     }
113     
114     /**
115      * Gets the UUID String of the backing index for the constraint.
116      *
117      * @return The UUID String of the backing index for the constraint.
118      */

119     public String JavaDoc getIndexUUIDString()
120     {
121         return indexId.toString();
122     }
123
124     /**
125      * Does this constraint have a backing index?
126      *
127      * @return boolean Whether or not there is a backing index for this constraint.
128      */

129     public boolean hasBackingIndex()
130     {
131         return true;
132     }
133
134     /**
135      * Get the UUID of the backing index, if one exists.
136      *
137      * @return The UUID of the backing index, if one exists, else null.
138      */

139     public UUID getConglomerateId()
140     {
141         return indexId;
142     }
143
144     /**
145      * Convert the SubConstraintDescriptor to a String.
146      *
147      * @return A String representation of this SubConstraintDescriptor
148      */

149
150     public String JavaDoc toString()
151     {
152         if (SanityManager.DEBUG)
153         {
154             return "indexId: " + indexId + "\n" +
155                 super.toString();
156         }
157         else
158         {
159             return "";
160         }
161     }
162
163 }
164
Popular Tags