Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / sql / dictionary / ColumnDescriptorList.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/sql/dictionary/ColumnDescriptorList.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/sql/dictionary/ColumnDescriptorList.java
new file mode 100644 (file)
index 0000000..a62d982
--- /dev/null
@@ -0,0 +1,146 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList\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.error.StandardException;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+\r
+/**\r
+ * This represents a list of column descriptors. \r
+ */\r
+\r
+public class ColumnDescriptorList extends ArrayList\r
+{\r
+       /**\r
+        * Add the column.  Currently, the table id is ignored.\r
+        *\r
+        * @param tableID the table id (ignored)\r
+        * @param column the column to add\r
+        */     \r
+       public void add(UUID tableID, ColumnDescriptor column)\r
+       {\r
+               /*\r
+               ** RESOLVE: The interface includes tableID because presumably\r
+               ** the primary key for the columns table will be tableID +\r
+               ** columnID (or possibly tableID + column name - both column\r
+               ** name and ID must be unique within a table).  However, the\r
+               ** ColumnDescriptor contains a reference to a tableID, so it\r
+               ** seems like we don't need the parameter here.  I am going\r
+               ** to leave it here just in case we decide we need it later.\r
+               */\r
+               add(column);\r
+       }\r
+\r
+       /**\r
+        * Get the column descriptor\r
+        *\r
+        * @param tableID the table id (ignored)\r
+        * @param columnName the column get\r
+        *\r
+        * @return the column descriptor if found\r
+        */     \r
+       public ColumnDescriptor getColumnDescriptor(UUID tableID,\r
+                                                       String columnName)\r
+       {\r
+               ColumnDescriptor        returnValue = null;\r
+\r
+               for (Iterator iterator = iterator(); iterator.hasNext(); )\r
+               {\r
+                       ColumnDescriptor columnDescriptor = (ColumnDescriptor) iterator.next();\r
+\r
+                       if ( columnName.equals( columnDescriptor.getColumnName() ) &&\r
+                           tableID.equals( columnDescriptor.getReferencingUUID() ) )\r
+                       {\r
+                               returnValue = columnDescriptor;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               return returnValue;\r
+       }\r
+\r
+       /**\r
+        * Get the column descriptor\r
+        *\r
+        * @param tableID the table id (ignored)\r
+        * @param columnID the column id\r
+        *\r
+        * @return the column descriptor if found\r
+        */     \r
+       public ColumnDescriptor getColumnDescriptor(UUID tableID, int columnID)\r
+       {\r
+               ColumnDescriptor        returnValue = null;\r
+\r
+               for (Iterator iterator = iterator(); iterator.hasNext(); )\r
+               {\r
+                       ColumnDescriptor columnDescriptor = (ColumnDescriptor) iterator.next();\r
+                       if ( ( columnID == columnDescriptor.getPosition() ) &&\r
+                               tableID.equals( columnDescriptor.getReferencingUUID() ) )\r
+                       {\r
+                               returnValue = columnDescriptor;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               return returnValue;\r
+       }\r
+\r
+       /**\r
+        * Return the nth (0-based) element in the list.\r
+        *\r
+        * @param n     Which element to return.\r
+        *\r
+        * @return The nth element in the list.\r
+        */\r
+       public ColumnDescriptor elementAt(int n)\r
+       {\r
+               return (ColumnDescriptor) get(n);\r
+       }\r
+\r
+       /**\r
+        * Get an array of strings for all the columns\r
+        * in this CDL.\r
+        *\r
+        * @return the array of strings\r
+        */\r
+       public String[] getColumnNames()\r
+       {\r
+               String strings[] = new String[size()];\r
+\r
+               int size = size();\r
+\r
+               for (int index = 0; index < size; index++)\r
+               {\r
+                       ColumnDescriptor columnDescriptor = elementAt(index);\r
+                       strings[index] = columnDescriptor.getColumnName();\r
+               }\r
+               return strings;\r
+       }\r
+}\r