KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList
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.sql.dictionary.ConglomerateDescriptor;
25 import org.apache.derby.iapi.error.StandardException;
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.services.monitor.Monitor;
29
30 import org.apache.derby.catalog.UUID;
31
32 import java.util.Iterator JavaDoc;
33 import java.util.ArrayList JavaDoc;
34
35 public class ConglomerateDescriptorList extends ArrayList JavaDoc
36 {
37
38     /**
39      * Get a conglomerate descriptor by its number
40      *
41      * @param conglomerateNumber The number of the conglomerate we're looking for
42      *
43      * @return The ConglomerateDescriptor if found in this list,
44      * null if not found.
45      */

46     public ConglomerateDescriptor getConglomerateDescriptor(long conglomerateNumber)
47     {
48         ConglomerateDescriptor conglomerateDescriptor;
49         ConglomerateDescriptor returnValue = null;
50
51         int size = size();
52         for (int index = 0; index < size; index++)
53         {
54             conglomerateDescriptor = (ConglomerateDescriptor) get(index);
55             if (conglomerateNumber == conglomerateDescriptor.getConglomerateNumber())
56             {
57                 returnValue = conglomerateDescriptor;
58                 break;
59             }
60         }
61
62         return returnValue;
63     }
64
65     /**
66      * Get an array of conglomerate descriptors with the given conglomerate
67      * number. We get more than one descriptors if duplicate indexes share
68      * one conglomerate.
69      *
70      * @param conglomerateNumber The number of the conglomerate
71      *
72      * @return Array of ConglomerateDescriptors if found in this list,
73      * size 0 array if not found.
74      */

75     public ConglomerateDescriptor[] getConglomerateDescriptors(long conglomerateNumber)
76     {
77         ConglomerateDescriptor conglomerateDescriptor;
78
79         int size = size(), j = 0;
80         ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size];
81
82         for (int index = 0; index < size; index++)
83         {
84             conglomerateDescriptor = (ConglomerateDescriptor) get(index);
85             if (conglomerateNumber == conglomerateDescriptor.getConglomerateNumber())
86                 draft[j++] = conglomerateDescriptor;
87         }
88
89         if (j == size)
90             return draft;
91         ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j];
92         for (int i = 0; i < j; i++)
93             returnValue[i] = draft[i];
94
95         return returnValue;
96     }
97
98
99     /**
100      * Get a conglomerate descriptor by its Name
101      *
102      * @param conglomerateName The Name of the conglomerate we're looking for
103      *
104      * @return The ConglomerateDescriptor if found in this list,
105      * null if not found.
106      */

107
108     public ConglomerateDescriptor getConglomerateDescriptor(String JavaDoc conglomerateName)
109     {
110         ConglomerateDescriptor conglomerateDescriptor;
111         ConglomerateDescriptor returnValue = null;
112
113         int size = size();
114         for (int index = 0; index < size; index++)
115         {
116             conglomerateDescriptor = (ConglomerateDescriptor) get(index);
117             if (conglomerateName.equals(conglomerateDescriptor.getConglomerateName()))
118             {
119                 returnValue = conglomerateDescriptor;
120                 break;
121             }
122         }
123
124         return returnValue;
125     }
126
127     /**
128      * Get a conglomerate descriptor by its UUID String
129      *
130      * @param uuid The UUID of the conglomerate we're looking for
131      *
132      * @return The ConglomerateDescriptor if found in this list,
133      * null if not found.
134      * @exception StandardException thrown on failure
135      */

136
137     public ConglomerateDescriptor getConglomerateDescriptor(UUID uuid)
138                         throws StandardException
139     {
140         ConglomerateDescriptor conglomerateDescriptor;
141         ConglomerateDescriptor returnValue = null;
142
143         int size = size();
144         for (int index = 0; index < size; index++)
145         {
146             conglomerateDescriptor = (ConglomerateDescriptor) get(index);
147
148             if (uuid.equals(conglomerateDescriptor.getUUID()))
149             {
150                 returnValue = conglomerateDescriptor;
151                 break;
152             }
153         }
154
155         return returnValue;
156     }
157
158     /**
159      * Get an array of conglomerate descriptors by a UUID String. We get
160      * more than one descriptors if duplicate indexes share one conglomerate.
161      *
162      * @param uuid The UUID of the conglomerate
163      *
164      * @return Array of ConglomerateDescriptors if found in this list,
165      * size 0 array if not found.
166      */

167     public ConglomerateDescriptor[] getConglomerateDescriptors(UUID uuid)
168     {
169         ConglomerateDescriptor conglomerateDescriptor;
170
171         int size = size(), j = 0;
172         ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size];
173
174         for (int index = 0; index < size; index++)
175         {
176             conglomerateDescriptor = (ConglomerateDescriptor) get(index);
177             if (uuid.equals(conglomerateDescriptor.getUUID()))
178                 draft[j++] = conglomerateDescriptor;
179         }
180
181         if (j == size)
182             return draft;
183         ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j];
184         for (int i = 0; i < j; i++)
185             returnValue[i] = draft[i];
186
187         return returnValue;
188     }
189
190     /**
191      * Remove the specified conglomerate descriptor from the
192      * conglomerate descriptor list. If the descriptor
193      * is not found, no errors are issued.
194      *
195      * @param tableID table uuid, ignored
196      * @param cgDesc the conglomerate
197      *
198      * @exception StandardException thrown on failure
199      */

200     public void dropConglomerateDescriptor(UUID tableID, ConglomerateDescriptor cgDesc)
201                         throws StandardException
202     {
203         for (Iterator JavaDoc iterator = iterator(); iterator.hasNext(); )
204         {
205             ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator.next();
206             if (localCgDesc.getConglomerateNumber() == cgDesc.getConglomerateNumber() &&
207                 localCgDesc.getConglomerateName().equals(cgDesc.getConglomerateName()) &&
208                 localCgDesc.getSchemaID().equals(cgDesc.getSchemaID()))
209             {
210                 iterator.remove();
211                 break;
212             }
213         }
214     }
215
216     /**
217      * Remove the specified conglomerate descriptor from the
218      * conglomerate descriptor list. If the descriptor
219      * is not found, no errors are issued.
220      *
221      * @param conglomerateID table uuid, ignored
222      *
223      * @exception StandardException thrown on failure
224      */

225     public void dropConglomerateDescriptorByUUID(UUID conglomerateID)
226                         throws StandardException
227     {
228         for (Iterator JavaDoc iterator = iterator(); iterator.hasNext(); )
229         {
230             ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator.next();
231             if ( conglomerateID.equals( localCgDesc.getUUID() ) )
232             {
233                 iterator.remove();
234                 break;
235             }
236         }
237     }
238 }
239
Popular Tags