001: /*
002:
003: Derby - Class org.apache.derby.iapi.sql.dictionary.DefaultDescriptor
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.sql.dictionary;
023:
024: import org.apache.derby.iapi.sql.depend.Provider;
025: import org.apache.derby.iapi.sql.depend.Dependent;
026:
027: import org.apache.derby.iapi.reference.SQLState;
028: import org.apache.derby.iapi.services.sanity.SanityManager;
029: import org.apache.derby.iapi.sql.StatementType;
030: import org.apache.derby.catalog.DependableFinder;
031: import org.apache.derby.catalog.Dependable;
032: import org.apache.derby.iapi.services.io.StoredFormatIds;
033: import org.apache.derby.iapi.error.StandardException;
034: import org.apache.derby.iapi.sql.depend.DependencyManager;
035: import org.apache.derby.iapi.sql.depend.Dependent;
036: import org.apache.derby.iapi.sql.depend.Dependency;
037: import org.apache.derby.iapi.sql.depend.Provider;
038: import org.apache.derby.iapi.services.i18n.MessageService;
039: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
040: import org.apache.derby.catalog.UUID;
041:
042: /**
043: * This interface is used to get information from a DefaultDescriptor.
044: *
045: * @author Jerry
046: */
047:
048: public final class DefaultDescriptor extends TupleDescriptor implements
049: UniqueTupleDescriptor, Provider, Dependent {
050: private final int columnNumber;
051: private final UUID defaultUUID;
052: private final UUID tableUUID;
053:
054: /**
055: * Constructor for a DefaultDescriptor
056: *
057: * @param dataDictionary the DD
058: * @param defaultUUID The UUID of the default
059: * @param tableUUID The UUID of the table
060: * @param columnNumber The column number of the column that the default is for
061: */
062:
063: public DefaultDescriptor(DataDictionary dataDictionary,
064: UUID defaultUUID, UUID tableUUID, int columnNumber) {
065: super (dataDictionary);
066:
067: this .defaultUUID = defaultUUID;
068: this .tableUUID = tableUUID;
069: this .columnNumber = columnNumber;
070: }
071:
072: /**
073: * Get the UUID of the default.
074: *
075: * @return The UUID of the default.
076: */
077: public UUID getUUID() {
078: return defaultUUID;
079: }
080:
081: /**
082: * Get the UUID of the table.
083: *
084: * @return The UUID of the table.
085: */
086: public UUID getTableUUID() {
087: return tableUUID;
088: }
089:
090: /**
091: * Get the column number of the column.
092: *
093: * @return The column number of the column.
094: */
095: public int getColumnNumber() {
096: return columnNumber;
097: }
098:
099: /**
100: * Convert the DefaultDescriptor to a String.
101: *
102: * @return A String representation of this DefaultDescriptor
103: */
104:
105: public String toString() {
106: if (SanityManager.DEBUG) {
107: /*
108: ** NOTE: This does not format table, because table.toString()
109: ** formats columns, leading to infinite recursion.
110: */
111: return "defaultUUID: " + defaultUUID + "\n" + "tableUUID: "
112: + tableUUID + "\n" + "columnNumber: "
113: + columnNumber + "\n";
114: } else {
115: return "";
116: }
117: }
118:
119: ////////////////////////////////////////////////////////////////////
120: //
121: // PROVIDER INTERFACE
122: //
123: ////////////////////////////////////////////////////////////////////
124:
125: /**
126: @return the stored form of this provider
127:
128: @see Dependable#getDependableFinder
129: */
130: public DependableFinder getDependableFinder() {
131: return getDependableFinder(StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID);
132: }
133:
134: /**
135: * Return the name of this Provider. (Useful for errors.)
136: *
137: * @return String The name of this provider.
138: */
139: public String getObjectName() {
140: return "default";
141: }
142:
143: /**
144: * Get the provider's UUID
145: *
146: * @return The provider's UUID
147: */
148: public UUID getObjectID() {
149: return defaultUUID;
150: }
151:
152: /**
153: * Get the provider's type.
154: *
155: * @return char The provider's type.
156: */
157: public String getClassType() {
158: return Dependable.DEFAULT;
159: }
160:
161: //////////////////////////////////////////////////////
162: //
163: // DEPENDENT INTERFACE
164: //
165: //////////////////////////////////////////////////////
166: /**
167: * Check that all of the dependent's dependencies are valid.
168: *
169: * @return true if the dependent is currently valid
170: */
171: public synchronized boolean isValid() {
172: return true;
173: }
174:
175: /**
176: * Prepare to mark the dependent as invalid (due to at least one of
177: * its dependencies being invalid).
178: *
179: * @param action The action causing the invalidation
180: * @param p the provider
181: *
182: * @exception StandardException thrown if unable to make it invalid
183: */
184: public void prepareToInvalidate(Provider p, int action,
185: LanguageConnectionContext lcc) throws StandardException {
186: DependencyManager dm = getDataDictionary()
187: .getDependencyManager();
188:
189: switch (action) {
190: /*
191: ** Currently, the only thing we are depenedent
192: ** on is an alias.
193: */
194: default:
195: DataDictionary dd = getDataDictionary();
196: ColumnDescriptor cd = dd
197: .getColumnDescriptorByDefaultId(defaultUUID);
198: TableDescriptor td = dd.getTableDescriptor(cd
199: .getReferencingUUID());
200:
201: throw StandardException
202: .newException(
203: SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
204: dm.getActionString(action),
205: p.getObjectName(),
206: MessageService
207: .getTextMessage(SQLState.LANG_COLUMN_DEFAULT),
208: td.getQualifiedName() + "."
209: + cd.getColumnName());
210: }
211: }
212:
213: /**
214: * Mark the dependent as invalid (due to at least one of
215: * its dependencies being invalid). Always an error
216: * for a constraint -- should never have gotten here.
217: *
218: * @param action The action causing the invalidation
219: *
220: * @exception StandardException thrown if called in sanity mode
221: */
222: public void makeInvalid(int action, LanguageConnectionContext lcc)
223: throws StandardException {
224: /*
225: ** We should never get here, we should have barfed on
226: ** prepareToInvalidate().
227: */
228: if (SanityManager.DEBUG) {
229: DependencyManager dm;
230:
231: dm = getDataDictionary().getDependencyManager();
232:
233: SanityManager.THROWASSERT("makeInvalid("
234: + dm.getActionString(action)
235: + ") not expected to get called");
236: }
237: }
238:
239: /**
240: * Attempt to revalidate the dependent. Meaningless
241: * for defaults.
242: */
243: public void makeValid(LanguageConnectionContext lcc) {
244: }
245:
246: }
|