001: /*
002:
003: Derby - Class org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.sql.dictionary;
023:
024: import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
025: import org.apache.derby.iapi.error.StandardException;
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027:
028: import org.apache.derby.iapi.services.monitor.Monitor;
029:
030: import org.apache.derby.catalog.UUID;
031:
032: import java.util.Iterator;
033: import java.util.ArrayList;
034:
035: public class ConglomerateDescriptorList extends ArrayList {
036:
037: /**
038: * Get a conglomerate descriptor by its number
039: *
040: * @param conglomerateNumber The number of the conglomerate we're looking for
041: *
042: * @return The ConglomerateDescriptor if found in this list,
043: * null if not found.
044: */
045: public ConglomerateDescriptor getConglomerateDescriptor(
046: long conglomerateNumber) {
047: ConglomerateDescriptor conglomerateDescriptor;
048: ConglomerateDescriptor returnValue = null;
049:
050: int size = size();
051: for (int index = 0; index < size; index++) {
052: conglomerateDescriptor = (ConglomerateDescriptor) get(index);
053: if (conglomerateNumber == conglomerateDescriptor
054: .getConglomerateNumber()) {
055: returnValue = conglomerateDescriptor;
056: break;
057: }
058: }
059:
060: return returnValue;
061: }
062:
063: /**
064: * Get an array of conglomerate descriptors with the given conglomerate
065: * number. We get more than one descriptors if duplicate indexes share
066: * one conglomerate.
067: *
068: * @param conglomerateNumber The number of the conglomerate
069: *
070: * @return Array of ConglomerateDescriptors if found in this list,
071: * size 0 array if not found.
072: */
073: public ConglomerateDescriptor[] getConglomerateDescriptors(
074: long conglomerateNumber) {
075: ConglomerateDescriptor conglomerateDescriptor;
076:
077: int size = size(), j = 0;
078: ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size];
079:
080: for (int index = 0; index < size; index++) {
081: conglomerateDescriptor = (ConglomerateDescriptor) get(index);
082: if (conglomerateNumber == conglomerateDescriptor
083: .getConglomerateNumber())
084: draft[j++] = conglomerateDescriptor;
085: }
086:
087: if (j == size)
088: return draft;
089: ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j];
090: for (int i = 0; i < j; i++)
091: returnValue[i] = draft[i];
092:
093: return returnValue;
094: }
095:
096: /**
097: * Get a conglomerate descriptor by its Name
098: *
099: * @param conglomerateName The Name of the conglomerate we're looking for
100: *
101: * @return The ConglomerateDescriptor if found in this list,
102: * null if not found.
103: */
104:
105: public ConglomerateDescriptor getConglomerateDescriptor(
106: String conglomerateName) {
107: ConglomerateDescriptor conglomerateDescriptor;
108: ConglomerateDescriptor returnValue = null;
109:
110: int size = size();
111: for (int index = 0; index < size; index++) {
112: conglomerateDescriptor = (ConglomerateDescriptor) get(index);
113: if (conglomerateName.equals(conglomerateDescriptor
114: .getConglomerateName())) {
115: returnValue = conglomerateDescriptor;
116: break;
117: }
118: }
119:
120: return returnValue;
121: }
122:
123: /**
124: * Get a conglomerate descriptor by its UUID String
125: *
126: * @param uuid The UUID of the conglomerate we're looking for
127: *
128: * @return The ConglomerateDescriptor if found in this list,
129: * null if not found.
130: * @exception StandardException thrown on failure
131: */
132:
133: public ConglomerateDescriptor getConglomerateDescriptor(UUID uuid)
134: throws StandardException {
135: ConglomerateDescriptor conglomerateDescriptor;
136: ConglomerateDescriptor returnValue = null;
137:
138: int size = size();
139: for (int index = 0; index < size; index++) {
140: conglomerateDescriptor = (ConglomerateDescriptor) get(index);
141:
142: if (uuid.equals(conglomerateDescriptor.getUUID())) {
143: returnValue = conglomerateDescriptor;
144: break;
145: }
146: }
147:
148: return returnValue;
149: }
150:
151: /**
152: * Get an array of conglomerate descriptors by a UUID String. We get
153: * more than one descriptors if duplicate indexes share one conglomerate.
154: *
155: * @param uuid The UUID of the conglomerate
156: *
157: * @return Array of ConglomerateDescriptors if found in this list,
158: * size 0 array if not found.
159: */
160: public ConglomerateDescriptor[] getConglomerateDescriptors(UUID uuid) {
161: ConglomerateDescriptor conglomerateDescriptor;
162:
163: int size = size(), j = 0;
164: ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size];
165:
166: for (int index = 0; index < size; index++) {
167: conglomerateDescriptor = (ConglomerateDescriptor) get(index);
168: if (uuid.equals(conglomerateDescriptor.getUUID()))
169: draft[j++] = conglomerateDescriptor;
170: }
171:
172: if (j == size)
173: return draft;
174: ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j];
175: for (int i = 0; i < j; i++)
176: returnValue[i] = draft[i];
177:
178: return returnValue;
179: }
180:
181: /**
182: * Remove the specified conglomerate descriptor from the
183: * conglomerate descriptor list. If the descriptor
184: * is not found, no errors are issued.
185: *
186: * @param tableID table uuid, ignored
187: * @param cgDesc the conglomerate
188: *
189: * @exception StandardException thrown on failure
190: */
191: public void dropConglomerateDescriptor(UUID tableID,
192: ConglomerateDescriptor cgDesc) throws StandardException {
193: for (Iterator iterator = iterator(); iterator.hasNext();) {
194: ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator
195: .next();
196: if (localCgDesc.getConglomerateNumber() == cgDesc
197: .getConglomerateNumber()
198: && localCgDesc.getConglomerateName().equals(
199: cgDesc.getConglomerateName())
200: && localCgDesc.getSchemaID().equals(
201: cgDesc.getSchemaID())) {
202: iterator.remove();
203: break;
204: }
205: }
206: }
207:
208: /**
209: * Remove the specified conglomerate descriptor from the
210: * conglomerate descriptor list. If the descriptor
211: * is not found, no errors are issued.
212: *
213: * @param conglomerateID table uuid, ignored
214: *
215: * @exception StandardException thrown on failure
216: */
217: public void dropConglomerateDescriptorByUUID(UUID conglomerateID)
218: throws StandardException {
219: for (Iterator iterator = iterator(); iterator.hasNext();) {
220: ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator
221: .next();
222: if (conglomerateID.equals(localCgDesc.getUUID())) {
223: iterator.remove();
224: break;
225: }
226: }
227: }
228: }
|