Source Code Cross Referenced for DDdependableFinder.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » sql » catalog » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.sql.catalog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.sql.catalog.DDdependableFinder
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.impl.sql.catalog;
023:
024:        import org.apache.derby.iapi.services.context.ContextManager;
025:        import org.apache.derby.iapi.services.context.ContextService;
026:
027:        import org.apache.derby.iapi.services.monitor.Monitor;
028:
029:        import org.apache.derby.iapi.services.sanity.SanityManager;
030:
031:        import org.apache.derby.iapi.services.io.StoredFormatIds;
032:        import org.apache.derby.iapi.services.io.Formatable;
033:
034:        import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
035:        import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;
036:        import org.apache.derby.iapi.sql.dictionary.DefaultDescriptor;
037:        import org.apache.derby.iapi.sql.dictionary.DataDictionary;
038:        import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
039:        import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
040:
041:        import org.apache.derby.iapi.error.StandardException;
042:        import org.apache.derby.iapi.error.PublicAPI;
043:
044:        import org.apache.derby.iapi.services.i18n.MessageService;
045:
046:        import org.apache.derby.iapi.services.uuid.UUIDFactory;
047:
048:        import org.apache.derby.catalog.UUID;
049:        import org.apache.derby.catalog.Dependable;
050:        import org.apache.derby.catalog.DependableFinder;
051:
052:        import org.apache.derby.iapi.reference.SQLState;
053:
054:        import java.io.ObjectOutput;
055:        import java.io.ObjectInput;
056:        import java.io.IOException;
057:
058:        /**
059:         *	Class for all DependableFinders in the core DataDictionary
060:         *
061:         *
062:         * @author Rick
063:         */
064:
065:        public class DDdependableFinder implements  DependableFinder, Formatable {
066:            ////////////////////////////////////////////////////////////////////////
067:            //
068:            //	STATE
069:            //
070:            ////////////////////////////////////////////////////////////////////////
071:
072:            private transient DataDictionary dataDictionary;
073:            private transient UUIDFactory uuidFactory;
074:
075:            private final int formatId;
076:
077:            ////////////////////////////////////////////////////////////////////////
078:            //
079:            //	CONSTRUCTORS
080:            //
081:            ////////////////////////////////////////////////////////////////////////
082:
083:            /**
084:             *	Public constructor for Formatable hoo-hah.
085:             */
086:            public DDdependableFinder(int formatId) {
087:                this .formatId = formatId;
088:            }
089:
090:            //////////////////////////////////////////////////////////////////
091:            //
092:            //	OBJECT SUPPORT
093:            //
094:            //////////////////////////////////////////////////////////////////
095:
096:            public String toString() {
097:                return getSQLObjectType();
098:            }
099:
100:            //////////////////////////////////////////////////////////////////
101:            //
102:            //	VACUOUS FORMATABLE INTERFACE. ALL THAT A VACUOUSDEPENDABLEFINDER
103:            //	NEEDS TO DO IS STAMP ITS FORMAT ID ONTO THE OUTPUT STREAM.
104:            //
105:            //////////////////////////////////////////////////////////////////
106:
107:            /**
108:             * Read this object from a stream of stored objects. Nothing to
109:             * do. Our persistent representation is just a 2-byte format id.
110:             *
111:             * @param in read this.
112:             */
113:            public void readExternal(ObjectInput in) throws IOException,
114:                    ClassNotFoundException {
115:            }
116:
117:            /**
118:             * Write this object to a stream of stored objects. Again, nothing
119:             * to do. We just stamp the output stream with our Format id.
120:             *
121:             * @param out write bytes here.
122:             */
123:            public void writeExternal(ObjectOutput out) throws IOException {
124:            }
125:
126:            /**
127:             * Get the formatID which corresponds to this class.
128:             *
129:             *	@return	the formatID of this class
130:             */
131:            public final int getTypeFormatId() {
132:                return formatId;
133:            }
134:
135:            ////////////////////////////////////////////////////////////////////////
136:            //
137:            //	DDdependable METHODS
138:            //
139:            ////////////////////////////////////////////////////////////////////////
140:
141:            /**
142:             * Gets the in-memory object associated with the passed-in object ID.
143:             *
144:             * @param	dependableObjectID the UUID of the Dependable as a String.
145:             * 			Used to locate that Dependable
146:             *
147:             * @return	the associated Dependable
148:             *
149:             * @exception java.sql.SQLException		thrown on error
150:             */
151:            public final Dependable getDependable(String dependableObjectID)
152:                    throws java.sql.SQLException {
153:                /*
154:                 ** Call the specific implementation of getDependable
155:                 ** to do the work
156:                 */
157:                return getDependable(recreateUUID(dependableObjectID));
158:            }
159:
160:            /**
161:             *	Gets the AliasDescriptor associated with the passed-in object ID.
162:             *
163:             *	@param	dependableObjectID	the object ID of an Alias. Used to locate its AliasDescriptor
164:             *
165:             *	@return	the associated AliasDescriptor
166:             * @exception java.sql.SQLException		thrown on error
167:             */
168:            public final Dependable getDependable(UUID dependableObjectID)
169:                    throws java.sql.SQLException {
170:                try {
171:                    return getDependable(getDataDictionary(),
172:                            dependableObjectID);
173:                } catch (StandardException se) {
174:                    throw PublicAPI.wrapStandardException(se);
175:                }
176:            }
177:
178:            /**
179:             * @see DependableFinder#getSQLObjectName
180:             * @exception java.sql.SQLException		thrown on error
181:             */
182:            public final String getSQLObjectName(String idString)
183:                    throws java.sql.SQLException {
184:
185:                try {
186:
187:                    // This should really be getDependable(idString).getObjectName()
188:                    // and then the sub-classes would not have to provide a getSQLObjectName
189:                    // method. Currently getDependable(idString).getObjectName() would
190:                    // not always return the same result - fix in main.
191:
192:                    return getSQLObjectName(getDataDictionary(),
193:                            recreateUUID(idString));
194:                } catch (StandardException se) {
195:                    throw PublicAPI.wrapStandardException(se);
196:                }
197:            }
198:
199:            /**
200:             * @see DependableFinder#getSQLObjectType
201:             */
202:            public String getSQLObjectType() {
203:                switch (formatId) {
204:                case StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID:
205:                    return Dependable.ALIAS;
206:
207:                case StoredFormatIds.CONGLOMERATE_DESCRIPTOR_FINDER_V01_ID:
208:                    return Dependable.CONGLOMERATE;
209:
210:                case StoredFormatIds.CONSTRAINT_DESCRIPTOR_FINDER_V01_ID:
211:                    return Dependable.CONSTRAINT;
212:
213:                case StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID:
214:                    return Dependable.DEFAULT;
215:
216:                case StoredFormatIds.FILE_INFO_FINDER_V01_ID:
217:                    return Dependable.FILE;
218:
219:                case StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID:
220:                    return Dependable.SCHEMA;
221:
222:                case StoredFormatIds.SPS_DESCRIPTOR_FINDER_V01_ID:
223:                    return Dependable.STORED_PREPARED_STATEMENT;
224:
225:                case StoredFormatIds.TABLE_DESCRIPTOR_FINDER_V01_ID:
226:                    return Dependable.TABLE;
227:
228:                case StoredFormatIds.COLUMN_DESCRIPTOR_FINDER_V01_ID:
229:                    return Dependable.COLUMNS_IN_TABLE;
230:
231:                case StoredFormatIds.TRIGGER_DESCRIPTOR_FINDER_V01_ID:
232:                    return Dependable.TRIGGER;
233:
234:                case StoredFormatIds.VIEW_DESCRIPTOR_FINDER_V01_ID:
235:                    return Dependable.VIEW;
236:
237:                case StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID:
238:                    return Dependable.TABLE_PERMISSION;
239:
240:                case StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID:
241:                    return Dependable.COLUMNS_PERMISSION;
242:
243:                case StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID:
244:                    return Dependable.ROUTINE_PERMISSION;
245:
246:                default:
247:                    if (SanityManager.DEBUG) {
248:                        SanityManager
249:                                .THROWASSERT("getSQLObjectType() called with unexpeced formatId = "
250:                                        + formatId);
251:                    }
252:                    return null;
253:                }
254:            }
255:
256:            /**
257:             *	Gets the datadictionary for this connection.
258:             *
259:             *	@return	the data dictionary for this connection
260:             *
261:             * @exception StandardException		Thrown on failure
262:             */
263:            private DataDictionary getDataDictionary() throws StandardException {
264:                if (dataDictionary == null) {
265:                    ContextManager cm = ContextService.getFactory()
266:                            .getCurrentContextManager();
267:                    DataDictionaryContext ddc = (DataDictionaryContext) (cm
268:                            .getContext(DataDictionaryContext.CONTEXT_ID));
269:                    dataDictionary = ddc.getDataDictionary();
270:                }
271:                return dataDictionary;
272:            }
273:
274:            /**
275:             * Get the UUID for the given string
276:             *
277:             * @param idString the string
278:             *
279:             * @return the UUID
280:             */
281:            private UUID recreateUUID(String idString) {
282:                if (uuidFactory == null) {
283:                    uuidFactory = Monitor.getMonitor().getUUIDFactory();
284:                }
285:                return uuidFactory.recreateUUID(idString);
286:            }
287:
288:            /**
289:            	Get the dependable for the given UUID
290:            	@exception StandardException thrown on error
291:             */
292:            protected Dependable getDependable(DataDictionary dd,
293:                    UUID dependableObjectID) throws StandardException {
294:                switch (formatId) {
295:                case StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID:
296:                    return dd.getAliasDescriptor(dependableObjectID);
297:
298:                case StoredFormatIds.CONGLOMERATE_DESCRIPTOR_FINDER_V01_ID:
299:                    return dd.getConglomerateDescriptor(dependableObjectID);
300:
301:                case StoredFormatIds.CONSTRAINT_DESCRIPTOR_FINDER_V01_ID:
302:                    return dd.getConstraintDescriptor(dependableObjectID);
303:
304:                case StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID:
305:                    ColumnDescriptor cd = dd
306:                            .getColumnDescriptorByDefaultId(dependableObjectID);
307:                    DefaultDescriptor ddi = new DefaultDescriptor(dd, cd
308:                            .getDefaultUUID(), cd.getReferencingUUID(), cd
309:                            .getPosition());
310:                    return ddi;
311:
312:                case StoredFormatIds.FILE_INFO_FINDER_V01_ID:
313:                    return dd.getFileInfoDescriptor(dependableObjectID);
314:
315:                case StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID:
316:                    return dd.getSchemaDescriptor(dependableObjectID, null);
317:
318:                case StoredFormatIds.SPS_DESCRIPTOR_FINDER_V01_ID:
319:                    return dd.getSPSDescriptor(dependableObjectID);
320:
321:                case StoredFormatIds.TABLE_DESCRIPTOR_FINDER_V01_ID:
322:                    return dd.getTableDescriptor(dependableObjectID);
323:
324:                case StoredFormatIds.TRIGGER_DESCRIPTOR_FINDER_V01_ID:
325:                    return dd.getTriggerDescriptor(dependableObjectID);
326:
327:                case StoredFormatIds.VIEW_DESCRIPTOR_FINDER_V01_ID:
328:                    return dd.getViewDescriptor(dependableObjectID);
329:
330:                case StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID:
331:                    return dd.getColumnPermissions(dependableObjectID);
332:
333:                case StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID:
334:                    return dd.getTablePermissions(dependableObjectID);
335:
336:                case StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID:
337:                    return dd.getRoutinePermissions(dependableObjectID);
338:
339:                default:
340:                    if (SanityManager.DEBUG) {
341:                        SanityManager
342:                                .THROWASSERT("getDependable() called with unexpeced formatId = "
343:                                        + formatId);
344:                    }
345:                    return null;
346:                }
347:            }
348:
349:            /**
350:            	Get the SQL object name for the given UUID
351:            	@exception StandardException thrown on error
352:             */
353:            protected String getSQLObjectName(DataDictionary dd,
354:                    UUID dependableObjectID) throws StandardException {
355:                switch (formatId) {
356:                case StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID:
357:                    return dd.getAliasDescriptor(dependableObjectID)
358:                            .getDescriptorName();
359:
360:                case StoredFormatIds.CONGLOMERATE_DESCRIPTOR_FINDER_V01_ID:
361:                    return dd.getConglomerateDescriptor(dependableObjectID)
362:                            .getConglomerateName();
363:
364:                case StoredFormatIds.CONSTRAINT_DESCRIPTOR_FINDER_V01_ID:
365:                    return dd.getConstraintDescriptor(dependableObjectID)
366:                            .getConstraintName();
367:
368:                case StoredFormatIds.DEFAULT_DESCRIPTOR_FINDER_V01_ID:
369:                    ColumnDescriptor columnDescriptor = dd
370:                            .getColumnDescriptorByDefaultId(dependableObjectID);
371:                    TableDescriptor tableDescriptor = dd
372:                            .getTableDescriptor(columnDescriptor
373:                                    .getReferencingUUID());
374:
375:                    return MessageService.getTextMessage(
376:                            SQLState.LANG_COLUMN_DEFAULT, tableDescriptor
377:                                    .getQualifiedName()
378:                                    + "." + columnDescriptor.getColumnName());
379:
380:                case StoredFormatIds.FILE_INFO_FINDER_V01_ID:
381:                    return dd.getFileInfoDescriptor(dependableObjectID)
382:                            .getName();
383:
384:                case StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID:
385:                    return dd.getSchemaDescriptor(dependableObjectID, null)
386:                            .getSchemaName();
387:
388:                case StoredFormatIds.SPS_DESCRIPTOR_FINDER_V01_ID:
389:                    return dd.getSPSDescriptor(dependableObjectID).getName();
390:
391:                case StoredFormatIds.TABLE_DESCRIPTOR_FINDER_V01_ID:
392:                case StoredFormatIds.COLUMN_DESCRIPTOR_FINDER_V01_ID:
393:                    return getDependable(dd, dependableObjectID)
394:                            .getObjectName();
395:
396:                case StoredFormatIds.TRIGGER_DESCRIPTOR_FINDER_V01_ID:
397:                    return dd.getTriggerDescriptor(dependableObjectID)
398:                            .getName();
399:
400:                case StoredFormatIds.VIEW_DESCRIPTOR_FINDER_V01_ID:
401:                    return dd.getTableDescriptor(dependableObjectID).getName();
402:
403:                case StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID:
404:                    return dd.getColumnPermissions(dependableObjectID)
405:                            .getObjectName();
406:
407:                case StoredFormatIds.TABLE_PERMISSION_FINDER_V01_ID:
408:                    return dd.getTablePermissions(dependableObjectID)
409:                            .getObjectName();
410:
411:                case StoredFormatIds.ROUTINE_PERMISSION_FINDER_V01_ID:
412:                    return dd.getRoutinePermissions(dependableObjectID)
413:                            .getObjectName();
414:
415:                default:
416:                    if (SanityManager.DEBUG) {
417:                        SanityManager
418:                                .THROWASSERT("getSQLObjectName() called with unexpeced formatId = "
419:                                        + formatId);
420:                    }
421:                    return null;
422:                }
423:            }
424:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.