Source Code Cross Referenced for DB_Alias.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » tools » dblook » 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.tools.dblook 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.tools.dblook.DB_Alias
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.tools.dblook;
023:
024:        import java.sql.Connection;
025:        import java.sql.Statement;
026:        import java.sql.PreparedStatement;
027:        import java.sql.ResultSet;
028:        import java.sql.SQLException;
029:        import java.sql.DatabaseMetaData;
030:
031:        import java.util.HashMap;
032:        import org.apache.derby.tools.dblook;
033:
034:        public class DB_Alias {
035:
036:            // Prepared statements use throughout the DDL
037:            // generation process.
038:
039:            /* ************************************************
040:             * Generate the DDL for all stored procedures and
041:             * functions in a given database and write it to
042:             * output via Logs.java.
043:             * @param conn Connection to the source database.
044:             ****/
045:
046:            public static void doProceduresAndFunctions(Connection conn)
047:                    throws SQLException {
048:
049:                // First do stored procedures.
050:                Statement stmt = conn.createStatement();
051:                ResultSet rs = stmt
052:                        .executeQuery("SELECT ALIAS, ALIASINFO, "
053:                                + "ALIASID, SCHEMAID, JAVACLASSNAME, SYSTEMALIAS FROM SYS.SYSALIASES "
054:                                + "WHERE ALIASTYPE='P'");
055:                generateDDL(rs, 'P'); // 'P' => for PROCEDURES
056:
057:                // Now do functions.
058:                rs = stmt
059:                        .executeQuery("SELECT ALIAS, ALIASINFO, "
060:                                + "ALIASID, SCHEMAID, JAVACLASSNAME, SYSTEMALIAS FROM SYS.SYSALIASES "
061:                                + "WHERE ALIASTYPE='F'");
062:                generateDDL(rs, 'F'); // 'F' => for FUNCTIONS
063:
064:                rs.close();
065:                stmt.close();
066:                return;
067:
068:            }
069:
070:            /* ************************************************
071:             * Generate the DDL for either stored procedures or
072:             * functions in a given database, depending on the
073:             * the received aliasType.
074:             * @param rs Result set holding either stored procedures
075:             *  or functions.
076:             * @param aliasType Indication of whether we're generating
077:             *  stored procedures or functions.
078:             ****/
079:            private static void generateDDL(ResultSet rs, char aliasType)
080:                    throws SQLException {
081:
082:                boolean firstTime = true;
083:                while (rs.next()) {
084:
085:                    if (rs.getBoolean(6))
086:                        // it's a system alias, so we ignore it.
087:                        continue;
088:
089:                    String procSchema = dblook.lookupSchemaId(rs.getString(4));
090:                    if (dblook.isIgnorableSchema(procSchema))
091:                        continue;
092:
093:                    if (firstTime) {
094:                        Logs
095:                                .reportString("----------------------------------------------");
096:                        Logs
097:                                .reportMessage((aliasType == 'P') ? "DBLOOK_StoredProcHeader"
098:                                        : "DBLOOK_FunctionHeader");
099:                        Logs
100:                                .reportString("----------------------------------------------\n");
101:                    }
102:
103:                    String aliasName = rs.getString(1);
104:                    String fullName = dblook.addQuotes(dblook
105:                            .expandDoubleQuotes(aliasName));
106:                    fullName = procSchema + "." + fullName;
107:
108:                    String creationString = createProcOrFuncString(fullName,
109:                            rs, aliasType);
110:                    Logs.writeToNewDDL(creationString);
111:                    Logs.writeStmtEndToNewDDL();
112:                    Logs.writeNewlineToNewDDL();
113:                    firstTime = false;
114:
115:                }
116:
117:            }
118:
119:            /* ************************************************
120:             * Generate DDL for a specific stored procedure or
121:             * function.
122:             * @param aliasName Name of the current procedure/function
123:             * @param aliasInfo Info about the current procedure/function
124:             * @param aliasType Indicator of whether we're generating
125:             *  a stored procedure or a function.
126:             * @return DDL for the current stored procedure is
127:             *   returned, as a String.
128:             ****/
129:
130:            private static String createProcOrFuncString(String aliasName,
131:                    ResultSet aliasInfo, char aliasType) throws SQLException {
132:
133:                StringBuffer alias = new StringBuffer("CREATE ");
134:                if (aliasType == 'P')
135:                    alias.append("PROCEDURE ");
136:                else if (aliasType == 'F')
137:                    alias.append("FUNCTION ");
138:                alias.append(aliasName);
139:                alias.append(" ");
140:
141:                String params = aliasInfo.getString(2);
142:
143:                // Just grab the parameter part; we'll get the method name later.
144:                alias.append(params.substring(params.indexOf("("), params
145:                        .length()));
146:                alias.append(" ");
147:
148:                // Now add the external name.
149:                alias.append("EXTERNAL NAME '");
150:                alias.append(aliasInfo.getString(5));
151:                alias.append(".");
152:                // Get method name from parameter string fetched above.
153:                alias.append(params.substring(0, params.indexOf("(")));
154:                alias.append("' ");
155:
156:                return alias.toString();
157:
158:            }
159:
160:            /* ************************************************
161:             * Generate the DDL for all synonyms in a given
162:             * database. On successul return, the DDL for the
163:             * synonyms has been written to output via Logs.java.
164:             * @param conn Connection to the source database.
165:             * @return 
166:             ****/
167:            public static void doSynonyms(Connection conn) throws SQLException {
168:                Statement stmt = conn.createStatement();
169:                ResultSet rs = stmt
170:                        .executeQuery("SELECT ALIAS, SCHEMAID, "
171:                                + "ALIASINFO, SYSTEMALIAS FROM SYS.SYSALIASES A WHERE ALIASTYPE='S'");
172:
173:                boolean firstTime = true;
174:                while (rs.next()) {
175:                    if (rs.getBoolean(4))
176:                        // it's a system alias, so we ignore it.
177:                        continue;
178:
179:                    String aliasSchema = dblook.lookupSchemaId(rs.getString(2));
180:                    if (dblook.isIgnorableSchema(aliasSchema))
181:                        continue;
182:
183:                    if (firstTime) {
184:                        Logs
185:                                .reportString("----------------------------------------------");
186:                        Logs.reportMessage("DBLOOK_SynonymHeader");
187:                        Logs
188:                                .reportString("----------------------------------------------\n");
189:                    }
190:
191:                    String aliasName = rs.getString(1);
192:                    String aliasFullName = dblook.addQuotes(dblook
193:                            .expandDoubleQuotes(aliasName));
194:                    aliasFullName = aliasSchema + "." + aliasFullName;
195:
196:                    Logs.writeToNewDDL("CREATE SYNONYM " + aliasFullName
197:                            + " FOR " + rs.getString(3));
198:                    Logs.writeStmtEndToNewDDL();
199:                    Logs.writeNewlineToNewDDL();
200:                    firstTime = false;
201:                }
202:
203:                rs.close();
204:                stmt.close();
205:                return;
206:
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.