1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList |
4 | |
5 | Copyright 2001, 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.dictionary.ConglomerateDescriptor; |
24 | import org.apache.derby.iapi.error.StandardException; |
25 | import org.apache.derby.iapi.services.sanity.SanityManager; |
26 | |
27 | import org.apache.derby.iapi.services.monitor.Monitor; |
28 | |
29 | import org.apache.derby.catalog.UUID; |
30 | |
31 | import java.util.Iterator; |
32 | import java.util.ArrayList; |
33 | |
34 | public class ConglomerateDescriptorList extends ArrayList |
35 | { |
36 | |
37 | /** |
38 | * Get a conglomerate descriptor by its number |
39 | * |
40 | * @param conglomerateNumber The number of the conglomerate we're looking for |
41 | * |
42 | * @return The ConglomerateDescriptor if found in this list, |
43 | * null if not found. |
44 | */ |
45 | public ConglomerateDescriptor getConglomerateDescriptor(long conglomerateNumber) |
46 | { |
47 | ConglomerateDescriptor conglomerateDescriptor; |
48 | ConglomerateDescriptor returnValue = null; |
49 | |
50 | int size = size(); |
51 | for (int index = 0; index < size; index++) |
52 | { |
53 | conglomerateDescriptor = (ConglomerateDescriptor) get(index); |
54 | if (conglomerateNumber == conglomerateDescriptor.getConglomerateNumber()) |
55 | { |
56 | returnValue = conglomerateDescriptor; |
57 | break; |
58 | } |
59 | } |
60 | |
61 | return returnValue; |
62 | } |
63 | |
64 | /** |
65 | * Get an array of conglomerate descriptors with the given conglomerate |
66 | * number. We get more than one descriptors if duplicate indexes share |
67 | * one conglomerate. |
68 | * |
69 | * @param conglomerateNumber The number of the conglomerate |
70 | * |
71 | * @return Array of ConglomerateDescriptors if found in this list, |
72 | * size 0 array if not found. |
73 | */ |
74 | public ConglomerateDescriptor[] getConglomerateDescriptors(long conglomerateNumber) |
75 | { |
76 | ConglomerateDescriptor conglomerateDescriptor; |
77 | |
78 | int size = size(), j = 0; |
79 | ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size]; |
80 | |
81 | for (int index = 0; index < size; index++) |
82 | { |
83 | conglomerateDescriptor = (ConglomerateDescriptor) get(index); |
84 | if (conglomerateNumber == conglomerateDescriptor.getConglomerateNumber()) |
85 | draft[j++] = conglomerateDescriptor; |
86 | } |
87 | |
88 | if (j == size) |
89 | return draft; |
90 | ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j]; |
91 | for (int i = 0; i < j; i++) |
92 | returnValue[i] = draft[i]; |
93 | |
94 | return returnValue; |
95 | } |
96 | |
97 | |
98 | /** |
99 | * Get a conglomerate descriptor by its Name |
100 | * |
101 | * @param conglomerateName The Name of the conglomerate we're looking for |
102 | * |
103 | * @return The ConglomerateDescriptor if found in this list, |
104 | * null if not found. |
105 | */ |
106 | |
107 | public ConglomerateDescriptor getConglomerateDescriptor(String conglomerateName) |
108 | { |
109 | ConglomerateDescriptor conglomerateDescriptor; |
110 | ConglomerateDescriptor returnValue = null; |
111 | |
112 | int size = size(); |
113 | for (int index = 0; index < size; index++) |
114 | { |
115 | conglomerateDescriptor = (ConglomerateDescriptor) get(index); |
116 | if (conglomerateName.equals(conglomerateDescriptor.getConglomerateName())) |
117 | { |
118 | returnValue = conglomerateDescriptor; |
119 | break; |
120 | } |
121 | } |
122 | |
123 | return returnValue; |
124 | } |
125 | |
126 | /** |
127 | * Get a conglomerate descriptor by its UUID String |
128 | * |
129 | * @param uuid The UUID of the conglomerate we're looking for |
130 | * |
131 | * @return The ConglomerateDescriptor if found in this list, |
132 | * null if not found. |
133 | * @exception StandardException thrown on failure |
134 | */ |
135 | |
136 | public ConglomerateDescriptor getConglomerateDescriptor(UUID uuid) |
137 | throws StandardException |
138 | { |
139 | ConglomerateDescriptor conglomerateDescriptor; |
140 | ConglomerateDescriptor returnValue = null; |
141 | |
142 | int size = size(); |
143 | for (int index = 0; index < size; index++) |
144 | { |
145 | conglomerateDescriptor = (ConglomerateDescriptor) get(index); |
146 | |
147 | if (uuid.equals(conglomerateDescriptor.getUUID())) |
148 | { |
149 | returnValue = conglomerateDescriptor; |
150 | break; |
151 | } |
152 | } |
153 | |
154 | return returnValue; |
155 | } |
156 | |
157 | /** |
158 | * Get an array of conglomerate descriptors by a UUID String. We get |
159 | * more than one descriptors if duplicate indexes share one conglomerate. |
160 | * |
161 | * @param uuid The UUID of the conglomerate |
162 | * |
163 | * @return Array of ConglomerateDescriptors if found in this list, |
164 | * size 0 array if not found. |
165 | */ |
166 | public ConglomerateDescriptor[] getConglomerateDescriptors(UUID uuid) |
167 | { |
168 | ConglomerateDescriptor conglomerateDescriptor; |
169 | |
170 | int size = size(), j = 0; |
171 | ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size]; |
172 | |
173 | for (int index = 0; index < size; index++) |
174 | { |
175 | conglomerateDescriptor = (ConglomerateDescriptor) get(index); |
176 | if (uuid.equals(conglomerateDescriptor.getUUID())) |
177 | draft[j++] = conglomerateDescriptor; |
178 | } |
179 | |
180 | if (j == size) |
181 | return draft; |
182 | ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j]; |
183 | for (int i = 0; i < j; i++) |
184 | returnValue[i] = draft[i]; |
185 | |
186 | return returnValue; |
187 | } |
188 | |
189 | /** |
190 | * Remove the specified conglomerate descriptor from the |
191 | * conglomerate descriptor list. If the descriptor |
192 | * is not found, no errors are issued. |
193 | * |
194 | * @param tableID table uuid, ignored |
195 | * @param cgDesc the conglomerate |
196 | * |
197 | * @exception StandardException thrown on failure |
198 | */ |
199 | public void dropConglomerateDescriptor(UUID tableID, ConglomerateDescriptor cgDesc) |
200 | throws StandardException |
201 | { |
202 | for (Iterator iterator = iterator(); iterator.hasNext(); ) |
203 | { |
204 | ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator.next(); |
205 | if (localCgDesc.getConglomerateNumber() == cgDesc.getConglomerateNumber() && |
206 | localCgDesc.getConglomerateName().equals(cgDesc.getConglomerateName()) && |
207 | localCgDesc.getSchemaID().equals(cgDesc.getSchemaID())) |
208 | { |
209 | iterator.remove(); |
210 | break; |
211 | } |
212 | } |
213 | } |
214 | |
215 | /** |
216 | * Remove the specified conglomerate descriptor from the |
217 | * conglomerate descriptor list. If the descriptor |
218 | * is not found, no errors are issued. |
219 | * |
220 | * @param conglomerateID table uuid, ignored |
221 | * |
222 | * @exception StandardException thrown on failure |
223 | */ |
224 | public void dropConglomerateDescriptorByUUID(UUID conglomerateID) |
225 | throws StandardException |
226 | { |
227 | for (Iterator iterator = iterator(); iterator.hasNext(); ) |
228 | { |
229 | ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator.next(); |
230 | if ( conglomerateID.equals( localCgDesc.getUUID() ) ) |
231 | { |
232 | iterator.remove(); |
233 | break; |
234 | } |
235 | } |
236 | } |
237 | } |