Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / sql / dictionary / ConglomerateDescriptorList.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptorList.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptorList.java
new file mode 100644 (file)
index 0000000..9b62dce
--- /dev/null
@@ -0,0 +1,238 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.sql.dictionary;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.services.monitor.Monitor;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import java.util.Iterator;\r
+import java.util.ArrayList;\r
+\r
+public class ConglomerateDescriptorList extends ArrayList\r
+{\r
+\r
+       /**\r
+        * Get a conglomerate descriptor by its number\r
+        *\r
+        * @param conglomerateNumber    The number of the conglomerate we're looking for\r
+        *\r
+        * @return      The ConglomerateDescriptor if found in this list,\r
+        *              null if not found.\r
+        */\r
+       public ConglomerateDescriptor getConglomerateDescriptor(long conglomerateNumber)\r
+       {\r
+               ConglomerateDescriptor conglomerateDescriptor;\r
+               ConglomerateDescriptor  returnValue = null;\r
+\r
+               int size = size();\r
+               for (int index = 0; index < size; index++)\r
+               {\r
+                       conglomerateDescriptor = (ConglomerateDescriptor) get(index);\r
+                       if (conglomerateNumber == conglomerateDescriptor.getConglomerateNumber())\r
+                       {\r
+                               returnValue = conglomerateDescriptor;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               return returnValue;\r
+       }\r
+\r
+       /**\r
+        * Get an array of conglomerate descriptors with the given conglomerate\r
+        * number.  We get more than one descriptors if duplicate indexes share\r
+        * one conglomerate.\r
+        *\r
+        * @param conglomerateNumber    The number of the conglomerate\r
+        *\r
+        * @return      Array of ConglomerateDescriptors if found in this list,\r
+        *              size 0 array if not found.\r
+        */\r
+       public ConglomerateDescriptor[] getConglomerateDescriptors(long conglomerateNumber)\r
+       {\r
+               ConglomerateDescriptor conglomerateDescriptor;\r
+\r
+               int size = size(), j = 0;\r
+               ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size];\r
+\r
+               for (int index = 0; index < size; index++)\r
+               {\r
+                       conglomerateDescriptor = (ConglomerateDescriptor) get(index);\r
+                       if (conglomerateNumber == conglomerateDescriptor.getConglomerateNumber())\r
+                               draft[j++] = conglomerateDescriptor;\r
+               }\r
+\r
+               if (j == size)\r
+                       return draft;\r
+               ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j];\r
+               for (int i = 0; i < j; i++)\r
+                       returnValue[i] = draft[i];\r
+\r
+               return returnValue;\r
+       }\r
+\r
+\r
+       /**\r
+        * Get a conglomerate descriptor by its Name\r
+        *\r
+        * @param conglomerateName      The Name of the conglomerate we're looking for\r
+        *\r
+        * @return      The ConglomerateDescriptor if found in this list,\r
+        *              null if not found.\r
+        */\r
+\r
+       public ConglomerateDescriptor getConglomerateDescriptor(String conglomerateName)\r
+       {\r
+               ConglomerateDescriptor conglomerateDescriptor;\r
+               ConglomerateDescriptor  returnValue = null;\r
+\r
+               int size = size();\r
+               for (int index = 0; index < size; index++)\r
+               {\r
+                       conglomerateDescriptor = (ConglomerateDescriptor) get(index);\r
+                       if (conglomerateName.equals(conglomerateDescriptor.getConglomerateName()))\r
+                       {\r
+                               returnValue = conglomerateDescriptor;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               return returnValue;\r
+       }\r
+\r
+       /**\r
+        * Get a conglomerate descriptor by its UUID String\r
+        *\r
+        * @param uuid  The UUID of the conglomerate we're looking for\r
+        *\r
+        * @return      The ConglomerateDescriptor if found in this list,\r
+        *              null if not found.\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+\r
+       public ConglomerateDescriptor getConglomerateDescriptor(UUID uuid)\r
+                                               throws StandardException\r
+       {\r
+               ConglomerateDescriptor conglomerateDescriptor;\r
+               ConglomerateDescriptor  returnValue = null;\r
+\r
+               int size = size();\r
+               for (int index = 0; index < size; index++)\r
+               {\r
+                       conglomerateDescriptor = (ConglomerateDescriptor) get(index);\r
+\r
+                       if (uuid.equals(conglomerateDescriptor.getUUID()))\r
+                       {\r
+                               returnValue = conglomerateDescriptor;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               return returnValue;\r
+       }\r
+\r
+       /**\r
+        * Get an array of conglomerate descriptors by a UUID String.  We get\r
+        * more than one descriptors if duplicate indexes share one conglomerate.\r
+        *\r
+        * @param uuid  The UUID of the conglomerate\r
+        *\r
+        * @return      Array of ConglomerateDescriptors if found in this list,\r
+        *              size 0 array if not found.\r
+        */\r
+       public ConglomerateDescriptor[] getConglomerateDescriptors(UUID uuid)\r
+       {\r
+               ConglomerateDescriptor conglomerateDescriptor;\r
+\r
+               int size = size(), j = 0;\r
+               ConglomerateDescriptor[] draft = new ConglomerateDescriptor[size];\r
+\r
+               for (int index = 0; index < size; index++)\r
+               {\r
+                       conglomerateDescriptor = (ConglomerateDescriptor) get(index);\r
+                       if (uuid.equals(conglomerateDescriptor.getUUID()))\r
+                               draft[j++] = conglomerateDescriptor;\r
+               }\r
+\r
+               if (j == size)\r
+                       return draft;\r
+               ConglomerateDescriptor[] returnValue = new ConglomerateDescriptor[j];\r
+               for (int i = 0; i < j; i++)\r
+                       returnValue[i] = draft[i];\r
+\r
+               return returnValue;\r
+       }\r
+\r
+       /**\r
+        * Remove the specified conglomerate descriptor from the\r
+        * conglomerate descriptor list.  If the descriptor\r
+        * is not found, no errors are issued.\r
+        *\r
+        * @param tableID table uuid, ignored\r
+        * @param cgDesc the conglomerate\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+       public void dropConglomerateDescriptor(UUID tableID, ConglomerateDescriptor cgDesc) \r
+                                               throws StandardException\r
+       {\r
+               for (Iterator iterator = iterator(); iterator.hasNext(); )\r
+               {\r
+                       ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator.next();\r
+                       if (localCgDesc.getConglomerateNumber() == cgDesc.getConglomerateNumber() &&\r
+                               localCgDesc.getConglomerateName().equals(cgDesc.getConglomerateName()) &&\r
+                               localCgDesc.getSchemaID().equals(cgDesc.getSchemaID()))\r
+                       {\r
+                               iterator.remove();\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Remove the specified conglomerate descriptor from the\r
+        * conglomerate descriptor list.  If the descriptor\r
+        * is not found, no errors are issued.\r
+        *\r
+        * @param conglomerateID table uuid, ignored\r
+        *\r
+        * @exception   StandardException thrown on failure\r
+        */\r
+       public void dropConglomerateDescriptorByUUID(UUID conglomerateID) \r
+                                               throws StandardException\r
+       {\r
+               for (Iterator iterator = iterator(); iterator.hasNext(); )\r
+               {\r
+                       ConglomerateDescriptor localCgDesc = (ConglomerateDescriptor) iterator.next();\r
+                       if ( conglomerateID.equals( localCgDesc.getUUID() ) )\r
+                       {\r
+                               iterator.remove();\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+}\r