1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.sql.dictionary.DefaultDescriptor |
4 | |
5 | Copyright 1999, 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.sql.depend.Provider; |
24 | import org.apache.derby.iapi.sql.depend.Dependent; |
25 | |
26 | import org.apache.derby.iapi.reference.SQLState; |
27 | import org.apache.derby.iapi.services.sanity.SanityManager; |
28 | import org.apache.derby.iapi.sql.StatementType; |
29 | import org.apache.derby.catalog.DependableFinder; |
30 | import org.apache.derby.catalog.Dependable; |
31 | import org.apache.derby.iapi.services.io.StoredFormatIds; |
32 | import org.apache.derby.iapi.error.StandardException; |
33 | import org.apache.derby.iapi.sql.depend.DependencyManager; |
34 | import org.apache.derby.iapi.sql.depend.Dependent; |
35 | import org.apache.derby.iapi.sql.depend.Dependency; |
36 | import org.apache.derby.iapi.sql.depend.Provider; |
37 | import org.apache.derby.iapi.services.i18n.MessageService; |
38 | import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; |
39 | import org.apache.derby.catalog.UUID; |
40 | |
41 | /** |
42 | * This interface is used to get information from a DefaultDescriptor. |
43 | * |
44 | * @author Jerry |
45 | */ |
46 | |
47 | public class DefaultDescriptor |
48 | extends TupleDescriptor |
49 | implements UniqueTupleDescriptor, Provider, Dependent |
50 | { |
51 | /** public interface to this class |
52 | <ol> |
53 | <li>public void setDefaultUUID(UUID defaultUUID); |
54 | <li>public UUID getTableUUID(); |
55 | </ol> |
56 | */ |
57 | |
58 | // implementation |
59 | |
60 | int columnNumber; |
61 | UUID defaultUUID; |
62 | UUID tableUUID; |
63 | |
64 | /** |
65 | * Constructor for a DefaultDescriptor |
66 | * |
67 | * @param dataDictionary the DD |
68 | * @param defaultUUID The UUID of the default |
69 | * @param tableUUID The UUID of the table |
70 | * @param columnNumber The column number of the column that the default is for |
71 | */ |
72 | |
73 | public DefaultDescriptor(DataDictionary dataDictionary, UUID defaultUUID, UUID tableUUID, int columnNumber) |
74 | { |
75 | super( dataDictionary ); |
76 | |
77 | this.defaultUUID = defaultUUID; |
78 | this.tableUUID = tableUUID; |
79 | this.columnNumber = columnNumber; |
80 | } |
81 | |
82 | /** |
83 | * Get the UUID of the default. |
84 | * |
85 | * @return The UUID of the default. |
86 | */ |
87 | public UUID getUUID() |
88 | { |
89 | return defaultUUID; |
90 | } |
91 | |
92 | /** |
93 | * Set the UUID of the default. |
94 | * |
95 | * @param defaultUUID The new UUID for the default. |
96 | */ |
97 | public void setDefaultUUID(UUID defaultUUID) |
98 | { |
99 | this.defaultUUID = defaultUUID; |
100 | } |
101 | |
102 | /** |
103 | * Get the UUID of the table. |
104 | * |
105 | * @return The UUID of the table. |
106 | */ |
107 | public UUID getTableUUID() |
108 | { |
109 | return tableUUID; |
110 | } |
111 | |
112 | /** |
113 | * Get the column number of the column. |
114 | * |
115 | * @return The column number of the column. |
116 | */ |
117 | public int getColumnNumber() |
118 | { |
119 | return columnNumber; |
120 | } |
121 | |
122 | /** |
123 | * Convert the DefaultDescriptor to a String. |
124 | * |
125 | * @return A String representation of this DefaultDescriptor |
126 | */ |
127 | |
128 | public String toString() |
129 | { |
130 | if (SanityManager.DEBUG) |
131 | { |
132 | /* |
133 | ** NOTE: This does not format table, because table.toString() |
134 | ** formats columns, leading to infinite recursion. |
135 | */ |
136 | return "defaultUUID: " + defaultUUID + "\n" + |
137 | "tableUUID: " + tableUUID + "\n" + |
138 | "columnNumber: " + columnNumber + "\n"; |
139 | } |
140 | else |
141 | { |
142 | return ""; |
143 | } |
144 | } |
145 | |
146 | //////////////////////////////////////////////////////////////////// |
147 | // |
148 | // PROVIDER INTERFACE |
149 | // |
150 | //////////////////////////////////////////////////////////////////// |
151 | |
152 | /** |
153 | @return the stored form of this provider |
154 | |
155 | @see Dependable#getDependableFinder |
156 | */ |
157 | public DependableFinder getDependableFinder() |
158 | { |
159 | return getDependableFinder(StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID); |
160 | } |
161 | |
162 | /** |
163 | * Return the name of this Provider. (Useful for errors.) |
164 | * |
165 | * @return String The name of this provider. |
166 | */ |
167 | public String getObjectName() |
168 | { |
169 | return "default"; |
170 | } |
171 | |
172 | /** |
173 | * Get the provider's UUID |
174 | * |
175 | * @return The provider's UUID |
176 | */ |
177 | public UUID getObjectID() |
178 | { |
179 | return defaultUUID; |
180 | } |
181 | |
182 | /** |
183 | * Get the provider's type. |
184 | * |
185 | * @return char The provider's type. |
186 | */ |
187 | public String getClassType() |
188 | { |
189 | return Dependable.DEFAULT; |
190 | } |
191 | |
192 | ////////////////////////////////////////////////////// |
193 | // |
194 | // DEPENDENT INTERFACE |
195 | // |
196 | ////////////////////////////////////////////////////// |
197 | /** |
198 | * Check that all of the dependent's dependencies are valid. |
199 | * |
200 | * @return true if the dependent is currently valid |
201 | */ |
202 | public synchronized boolean isValid() |
203 | { |
204 | return true; |
205 | } |
206 | |
207 | /** |
208 | * Prepare to mark the dependent as invalid (due to at least one of |
209 | * its dependencies being invalid). |
210 | * |
211 | * @param action The action causing the invalidation |
212 | * @param p the provider |
213 | * |
214 | * @exception StandardException thrown if unable to make it invalid |
215 | */ |
216 | public void prepareToInvalidate(Provider p, int action, |
217 | LanguageConnectionContext lcc) |
218 | throws StandardException |
219 | { |
220 | DependencyManager dm = getDataDictionary().getDependencyManager(); |
221 | |
222 | switch (action) |
223 | { |
224 | /* |
225 | ** Currently, the only thing we are depenedent |
226 | ** on is an alias. |
227 | */ |
228 | default: |
229 | DataDictionary dd = getDataDictionary(); |
230 | ColumnDescriptor cd = dd.getColumnDescriptorByDefaultId(defaultUUID); |
231 | TableDescriptor td = dd.getTableDescriptor(cd.getReferencingUUID()); |
232 | |
233 | throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT, |
234 | dm.getActionString(action), |
235 | p.getObjectName(), |
236 | MessageService.getTextMessage( |
237 | SQLState.LANG_COLUMN_DEFAULT |
238 | ), |
239 | td.getQualifiedName() + "." + |
240 | cd.getColumnName()); |
241 | } |
242 | } |
243 | |
244 | /** |
245 | * Mark the dependent as invalid (due to at least one of |
246 | * its dependencies being invalid). Always an error |
247 | * for a constraint -- should never have gotten here. |
248 | * |
249 | * @param action The action causing the invalidation |
250 | * |
251 | * @exception StandardException thrown if called in sanity mode |
252 | */ |
253 | public void makeInvalid(int action, LanguageConnectionContext lcc) |
254 | throws StandardException |
255 | { |
256 | /* |
257 | ** We should never get here, we should have barfed on |
258 | ** prepareToInvalidate(). |
259 | */ |
260 | if (SanityManager.DEBUG) |
261 | { |
262 | DependencyManager dm; |
263 | |
264 | dm = getDataDictionary().getDependencyManager(); |
265 | |
266 | SanityManager.THROWASSERT("makeInvalid("+ |
267 | dm.getActionString(action)+ |
268 | ") not expected to get called"); |
269 | } |
270 | } |
271 | |
272 | /** |
273 | * Attempt to revalidate the dependent. Meaningless |
274 | * for defaults. |
275 | */ |
276 | public void makeValid(LanguageConnectionContext lcc) |
277 | { |
278 | } |
279 | |
280 | } |