KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList
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.error.StandardException;
25 import org.apache.derby.iapi.services.sanity.SanityManager;
26
27 import org.apache.derby.catalog.UUID;
28
29 import org.apache.derby.iapi.error.StandardException;
30 import org.apache.derby.iapi.services.sanity.SanityManager;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 /**
36  * This represents a list of column descriptors.
37  */

38
39 public class ColumnDescriptorList extends ArrayList JavaDoc
40 {
41     /**
42      * Add the column. Currently, the table id is ignored.
43      *
44      * @param tableID the table id (ignored)
45      * @param column the column to add
46      */

47     public void add(UUID tableID, ColumnDescriptor column)
48     {
49         /*
50         ** RESOLVE: The interface includes tableID because presumably
51         ** the primary key for the columns table will be tableID +
52         ** columnID (or possibly tableID + column name - both column
53         ** name and ID must be unique within a table). However, the
54         ** ColumnDescriptor contains a reference to a tableID, so it
55         ** seems like we don't need the parameter here. I am going
56         ** to leave it here just in case we decide we need it later.
57         */

58         add(column);
59     }
60
61     /**
62      * Get the column descriptor
63      *
64      * @param tableID the table id (ignored)
65      * @param columnName the column get
66      *
67      * @return the column descriptor if found
68      */

69     public ColumnDescriptor getColumnDescriptor(UUID tableID,
70                             String JavaDoc columnName)
71     {
72         ColumnDescriptor returnValue = null;
73
74         for (Iterator JavaDoc iterator = iterator(); iterator.hasNext(); )
75         {
76             ColumnDescriptor columnDescriptor = (ColumnDescriptor) iterator.next();
77
78             if ( columnName.equals( columnDescriptor.getColumnName() ) &&
79                 tableID.equals( columnDescriptor.getReferencingUUID() ) )
80             {
81                 returnValue = columnDescriptor;
82                 break;
83             }
84         }
85
86         return returnValue;
87     }
88
89     /**
90      * Get the column descriptor
91      *
92      * @param tableID the table id (ignored)
93      * @param columnID the column id
94      *
95      * @return the column descriptor if found
96      */

97     public ColumnDescriptor getColumnDescriptor(UUID tableID, int columnID)
98     {
99         ColumnDescriptor returnValue = null;
100
101         for (Iterator JavaDoc iterator = iterator(); iterator.hasNext(); )
102         {
103             ColumnDescriptor columnDescriptor = (ColumnDescriptor) iterator.next();
104             if ( ( columnID == columnDescriptor.getPosition() ) &&
105                 tableID.equals( columnDescriptor.getReferencingUUID() ) )
106             {
107                 returnValue = columnDescriptor;
108                 break;
109             }
110         }
111
112         return returnValue;
113     }
114
115     /**
116      * Return the nth (0-based) element in the list.
117      *
118      * @param n Which element to return.
119      *
120      * @return The nth element in the list.
121      */

122     public ColumnDescriptor elementAt(int n)
123     {
124         return (ColumnDescriptor) get(n);
125     }
126
127     /**
128      * Get an array of strings for all the columns
129      * in this CDL.
130      *
131      * @return the array of strings
132      */

133     public String JavaDoc[] getColumnNames()
134     {
135         String JavaDoc strings[] = new String JavaDoc[size()];
136
137         int size = size();
138
139         for (int index = 0; index < size; index++)
140         {
141             ColumnDescriptor columnDescriptor = elementAt(index);
142             strings[index] = columnDescriptor.getColumnName();
143         }
144         return strings;
145     }
146 }
147
Popular Tags