KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.DefaultDescriptor
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.sql.depend.Provider;
25 import org.apache.derby.iapi.sql.depend.Dependent;
26
27 import org.apache.derby.iapi.reference.SQLState;
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29 import org.apache.derby.iapi.sql.StatementType;
30 import org.apache.derby.catalog.DependableFinder;
31 import org.apache.derby.catalog.Dependable;
32 import org.apache.derby.iapi.services.io.StoredFormatIds;
33 import org.apache.derby.iapi.error.StandardException;
34 import org.apache.derby.iapi.sql.depend.DependencyManager;
35 import org.apache.derby.iapi.sql.depend.Dependent;
36 import org.apache.derby.iapi.sql.depend.Dependency;
37 import org.apache.derby.iapi.sql.depend.Provider;
38 import org.apache.derby.iapi.services.i18n.MessageService;
39 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
40 import org.apache.derby.catalog.UUID;
41
42 /**
43  * This interface is used to get information from a DefaultDescriptor.
44  *
45  * @author Jerry
46  */

47
48 public final class DefaultDescriptor
49     extends TupleDescriptor
50     implements UniqueTupleDescriptor, Provider, Dependent
51 {
52     private final int columnNumber;
53     private final UUID defaultUUID;
54     private final UUID tableUUID;
55
56     /**
57      * Constructor for a DefaultDescriptor
58      *
59      * @param dataDictionary the DD
60      * @param defaultUUID The UUID of the default
61      * @param tableUUID The UUID of the table
62      * @param columnNumber The column number of the column that the default is for
63      */

64
65     public DefaultDescriptor(DataDictionary dataDictionary, UUID defaultUUID, UUID tableUUID, int columnNumber)
66     {
67         super( dataDictionary );
68
69         this.defaultUUID = defaultUUID;
70         this.tableUUID = tableUUID;
71         this.columnNumber = columnNumber;
72     }
73
74     /**
75      * Get the UUID of the default.
76      *
77      * @return The UUID of the default.
78      */

79     public UUID getUUID()
80     {
81         return defaultUUID;
82     }
83
84     /**
85      * Get the UUID of the table.
86      *
87      * @return The UUID of the table.
88      */

89     public UUID getTableUUID()
90     {
91         return tableUUID;
92     }
93
94     /**
95      * Get the column number of the column.
96      *
97      * @return The column number of the column.
98      */

99     public int getColumnNumber()
100     {
101         return columnNumber;
102     }
103
104     /**
105      * Convert the DefaultDescriptor to a String.
106      *
107      * @return A String representation of this DefaultDescriptor
108      */

109
110     public String JavaDoc toString()
111     {
112         if (SanityManager.DEBUG)
113         {
114             /*
115             ** NOTE: This does not format table, because table.toString()
116             ** formats columns, leading to infinite recursion.
117             */

118             return "defaultUUID: " + defaultUUID + "\n" +
119                 "tableUUID: " + tableUUID + "\n" +
120                 "columnNumber: " + columnNumber + "\n";
121         }
122         else
123         {
124             return "";
125         }
126     }
127
128     ////////////////////////////////////////////////////////////////////
129
//
130
// PROVIDER INTERFACE
131
//
132
////////////////////////////////////////////////////////////////////
133

134     /**
135         @return the stored form of this provider
136
137             @see Dependable#getDependableFinder
138      */

139     public DependableFinder getDependableFinder()
140     {
141         return getDependableFinder(StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID);
142     }
143
144     /**
145      * Return the name of this Provider. (Useful for errors.)
146      *
147      * @return String The name of this provider.
148      */

149     public String JavaDoc getObjectName()
150     {
151         return "default";
152     }
153
154     /**
155      * Get the provider's UUID
156      *
157      * @return The provider's UUID
158      */

159     public UUID getObjectID()
160     {
161         return defaultUUID;
162     }
163
164     /**
165      * Get the provider's type.
166      *
167      * @return char The provider's type.
168      */

169     public String JavaDoc getClassType()
170     {
171         return Dependable.DEFAULT;
172     }
173
174     //////////////////////////////////////////////////////
175
//
176
// DEPENDENT INTERFACE
177
//
178
//////////////////////////////////////////////////////
179
/**
180      * Check that all of the dependent's dependencies are valid.
181      *
182      * @return true if the dependent is currently valid
183      */

184     public synchronized boolean isValid()
185     {
186         return true;
187     }
188
189     /**
190      * Prepare to mark the dependent as invalid (due to at least one of
191      * its dependencies being invalid).
192      *
193      * @param action The action causing the invalidation
194      * @param p the provider
195      *
196      * @exception StandardException thrown if unable to make it invalid
197      */

198     public void prepareToInvalidate(Provider p, int action,
199                     LanguageConnectionContext lcc)
200         throws StandardException
201     {
202         DependencyManager dm = getDataDictionary().getDependencyManager();
203
204         switch (action)
205         {
206             /*
207             ** Currently, the only thing we are depenedent
208             ** on is an alias.
209             */

210             default:
211                 DataDictionary dd = getDataDictionary();
212                 ColumnDescriptor cd = dd.getColumnDescriptorByDefaultId(defaultUUID);
213                 TableDescriptor td = dd.getTableDescriptor(cd.getReferencingUUID());
214
215                 throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
216                                     dm.getActionString(action),
217                                     p.getObjectName(),
218                                     MessageService.getTextMessage(
219                                         SQLState.LANG_COLUMN_DEFAULT
220                                     ),
221                                     td.getQualifiedName() + "." +
222                                     cd.getColumnName());
223         }
224     }
225
226     /**
227      * Mark the dependent as invalid (due to at least one of
228      * its dependencies being invalid). Always an error
229      * for a constraint -- should never have gotten here.
230      *
231      * @param action The action causing the invalidation
232      *
233      * @exception StandardException thrown if called in sanity mode
234      */

235     public void makeInvalid(int action, LanguageConnectionContext lcc)
236         throws StandardException
237     {
238         /*
239         ** We should never get here, we should have barfed on
240         ** prepareToInvalidate().
241         */

242         if (SanityManager.DEBUG)
243         {
244             DependencyManager dm;
245     
246             dm = getDataDictionary().getDependencyManager();
247
248             SanityManager.THROWASSERT("makeInvalid("+
249                 dm.getActionString(action)+
250                 ") not expected to get called");
251         }
252     }
253
254     /**
255      * Attempt to revalidate the dependent. Meaningless
256      * for defaults.
257      */

258     public void makeValid(LanguageConnectionContext lcc)
259     {
260     }
261
262 }
263
Popular Tags