1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.sql.dictionary; |
22 | |
23 | import org.apache.derby.iapi.error.StandardException; |
24 | import org.apache.derby.iapi.services.sanity.SanityManager; |
25 | |
26 | import org.apache.derby.catalog.UUID; |
27 | |
28 | import org.apache.derby.iapi.error.StandardException; |
29 | import org.apache.derby.iapi.services.sanity.SanityManager; |
30 | |
31 | import java.util.ArrayList; |
32 | import java.util.Iterator; |
33 | |
34 | /** |
35 | * This represents a list of column descriptors. |
36 | */ |
37 | |
38 | public class ColumnDescriptorList extends ArrayList |
39 | { |
40 | /** |
41 | * Add the column. Currently, the table id is ignored. |
42 | * |
43 | * @param tableID the table id (ignored) |
44 | * @param column the column to add |
45 | */ |
46 | public void add(UUID tableID, ColumnDescriptor column) |
47 | { |
48 | /* |
49 | ** RESOLVE: The interface includes tableID because presumably |
50 | ** the primary key for the columns table will be tableID + |
51 | ** columnID (or possibly tableID + column name - both column |
52 | ** name and ID must be unique within a table). However, the |
53 | ** ColumnDescriptor contains a reference to a tableID, so it |
54 | ** seems like we don't need the parameter here. I am going |
55 | ** to leave it here just in case we decide we need it later. |
56 | */ |
57 | add(column); |
58 | } |
59 | |
60 | /** |
61 | * Get the column descriptor |
62 | * |
63 | * @param tableID the table id (ignored) |
64 | * @param columnName the column get |
65 | * |
66 | * @return the column descriptor if found |
67 | */ |
68 | public ColumnDescriptor getColumnDescriptor(UUID tableID, |
69 | String columnName) |
70 | { |
71 | ColumnDescriptor returnValue = null; |
72 | |
73 | for (Iterator iterator = iterator(); iterator.hasNext(); ) |
74 | { |
75 | ColumnDescriptor columnDescriptor = (ColumnDescriptor) iterator.next(); |
76 | |
77 | if ( columnName.equals( columnDescriptor.getColumnName() ) && |
78 | tableID.equals( columnDescriptor.getReferencingUUID() ) ) |
79 | { |
80 | returnValue = columnDescriptor; |
81 | break; |
82 | } |
83 | } |
84 | |
85 | return returnValue; |
86 | } |
87 | |
88 | /** |
89 | * Get the column descriptor |
90 | * |
91 | * @param tableID the table id (ignored) |
92 | * @param columnID the column id |
93 | * |
94 | * @return the column descriptor if found |
95 | */ |
96 | public ColumnDescriptor getColumnDescriptor(UUID tableID, int columnID) |
97 | { |
98 | ColumnDescriptor returnValue = null; |
99 | |
100 | for (Iterator iterator = iterator(); iterator.hasNext(); ) |
101 | { |
102 | ColumnDescriptor columnDescriptor = (ColumnDescriptor) iterator.next(); |
103 | if ( ( columnID == columnDescriptor.getPosition() ) && |
104 | tableID.equals( columnDescriptor.getReferencingUUID() ) ) |
105 | { |
106 | returnValue = columnDescriptor; |
107 | break; |
108 | } |
109 | } |
110 | |
111 | return returnValue; |
112 | } |
113 | |
114 | /** |
115 | * Return the nth (0-based) element in the list. |
116 | * |
117 | * @param n Which element to return. |
118 | * |
119 | * @return The nth element in the list. |
120 | */ |
121 | public ColumnDescriptor elementAt(int n) |
122 | { |
123 | return (ColumnDescriptor) get(n); |
124 | } |
125 | |
126 | /** |
127 | * Get an array of strings for all the columns |
128 | * in this CDL. |
129 | * |
130 | * @return the array of strings |
131 | */ |
132 | public String[] getColumnNames() |
133 | { |
134 | String strings[] = new String[size()]; |
135 | |
136 | int size = size(); |
137 | |
138 | for (int index = 0; index < size; index++) |
139 | { |
140 | ColumnDescriptor columnDescriptor = elementAt(index); |
141 | strings[index] = columnDescriptor.getColumnName(); |
142 | } |
143 | return strings; |
144 | } |
145 | } |