1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor |
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.error.StandardException; |
24 | |
25 | import org.apache.derby.catalog.UUID; |
26 | import org.apache.derby.iapi.services.sanity.SanityManager; |
27 | /** |
28 | * This interface is used to get information from a KeyConstraintDescriptor. |
29 | * A KeyConstraintDescriptor can represent a primary/unique/foreign key |
30 | * constraint. |
31 | * |
32 | * @version 0.1 |
33 | * @author Jerry Brenner |
34 | */ |
35 | |
36 | public abstract class KeyConstraintDescriptor extends ConstraintDescriptor |
37 | { |
38 | /** interface to this class: |
39 | <ol> |
40 | <li>public UUID getIndexId();</li> |
41 | <li>public ConglomerateDescriptor getIndexConglomerateDescriptor(DataDictionary dd)</li> |
42 | throws StandardException;</li> |
43 | <li>public String getIndexUUIDString();</li> |
44 | <li>public int[] getKeyColumns();</li> |
45 | </ol> |
46 | */ |
47 | |
48 | // implementation |
49 | UUID indexId; |
50 | |
51 | private ConglomerateDescriptor indexConglom; |
52 | |
53 | /** |
54 | * Constructor for a KeyConstraintDescriptor |
55 | * |
56 | * @param dataDictionary The data dictionary that this descriptor lives in |
57 | * @param table The descriptor of the table the constraint is on |
58 | * @param constraintName The name of the constraint. |
59 | * @param deferrable If the constraint can be deferred. |
60 | * @param initiallyDeferred If the constraint starts life deferred. |
61 | * @param referencedColumns columns that the constraint references |
62 | * @param constraintId UUID of constraint |
63 | * @param indexId The UUID for the backing index |
64 | * @param schemaDesc The SchemaDescriptor for the constraint |
65 | * @param isEnabled is this constraint enabled |
66 | */ |
67 | KeyConstraintDescriptor( |
68 | DataDictionary dataDictionary, |
69 | TableDescriptor table, |
70 | String constraintName, |
71 | boolean deferrable, |
72 | boolean initiallyDeferred, |
73 | int[] referencedColumns, |
74 | UUID constraintId, |
75 | UUID indexId, |
76 | SchemaDescriptor schemaDesc, |
77 | boolean isEnabled |
78 | ) |
79 | { |
80 | super(dataDictionary, table, constraintName, deferrable, |
81 | initiallyDeferred, referencedColumns, |
82 | constraintId, schemaDesc, isEnabled); |
83 | this.indexId = indexId; |
84 | } |
85 | |
86 | /** |
87 | * Gets the UUID of the backing index for the constraint. |
88 | * |
89 | * @return The UUID of the backing index for the constraint. |
90 | */ |
91 | public UUID getIndexId() |
92 | { |
93 | return indexId; |
94 | } |
95 | |
96 | /** |
97 | * Gets the index conglomerate descriptor |
98 | * |
99 | * @return the index conglomerate descriptor |
100 | * |
101 | * @exception StandardException on error |
102 | */ |
103 | public ConglomerateDescriptor getIndexConglomerateDescriptor(DataDictionary dd) |
104 | throws StandardException |
105 | { |
106 | if (indexConglom == null) |
107 | { |
108 | indexConglom = getTableDescriptor().getConglomerateDescriptor(indexId); |
109 | } |
110 | return indexConglom; |
111 | } |
112 | |
113 | /** |
114 | * Gets the UUID String of the backing index for the constraint. |
115 | * |
116 | * @return The UUID String of the backing index for the constraint. |
117 | */ |
118 | public String getIndexUUIDString() |
119 | { |
120 | return indexId.toString(); |
121 | } |
122 | |
123 | /** |
124 | * Does this constraint have a backing index? |
125 | * |
126 | * @return boolean Whether or not there is a backing index for this constraint. |
127 | */ |
128 | public boolean hasBackingIndex() |
129 | { |
130 | return true; |
131 | } |
132 | |
133 | /** |
134 | * Get the UUID of the backing index, if one exists. |
135 | * |
136 | * @return The UUID of the backing index, if one exists, else null. |
137 | */ |
138 | public UUID getConglomerateId() |
139 | { |
140 | return indexId; |
141 | } |
142 | |
143 | /** |
144 | * Convert the SubConstraintDescriptor to a String. |
145 | * |
146 | * @return A String representation of this SubConstraintDescriptor |
147 | */ |
148 | |
149 | public String toString() |
150 | { |
151 | if (SanityManager.DEBUG) |
152 | { |
153 | return "indexId: " + indexId + "\n" + |
154 | super.toString(); |
155 | } |
156 | else |
157 | { |
158 | return ""; |
159 | } |
160 | } |
161 | |
162 | } |