Source Code Cross Referenced for DB_Jar.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_Jar
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:
030:        import java.util.HashMap;
031:
032:        import java.io.File;
033:        import java.io.FileOutputStream;
034:        import java.io.FileInputStream;
035:        import java.io.FileNotFoundException;
036:        import java.io.IOException;
037:
038:        import org.apache.derby.tools.dblook;
039:
040:        public class DB_Jar {
041:
042:            /* ************************************************
043:             * Generate the DDL for all jars in a given
044:             * database.
045:             * @param dbName Name of the database (for locating the jar).
046:             * @param conn Connection to the source database.
047:             * @return The DDL for the jars has been written
048:             *  to output via Logs.java.
049:             ****/
050:
051:            public static void doJars(String dbName, Connection conn)
052:                    throws SQLException {
053:
054:                String separator = System.getProperty("file.separator");
055:                Statement stmt = conn.createStatement();
056:                ResultSet rs = stmt.executeQuery("SELECT FILENAME, SCHEMAID, "
057:                        + "GENERATIONID FROM SYS.SYSFILES");
058:
059:                boolean firstTime = true;
060:                while (rs.next()) {
061:
062:                    String jarName = dblook.addQuotes(dblook
063:                            .expandDoubleQuotes(rs.getString(1)));
064:                    String schemaId = rs.getString(2);
065:                    String schemaName = dblook.lookupSchemaId(schemaId);
066:                    if (dblook.isIgnorableSchema(schemaName))
067:                        continue;
068:
069:                    if (firstTime) {
070:                        Logs
071:                                .reportString("----------------------------------------------");
072:                        Logs.reportMessage("DBLOOK_JarsHeader");
073:                        Logs.reportMessage("DBLOOK_Jar_Note");
074:                        Logs
075:                                .reportString("----------------------------------------------\n");
076:                    }
077:
078:                    String genID = rs.getString(3);
079:
080:                    String schemaWithoutQuotes = dblook.stripQuotes(schemaName);
081:                    StringBuffer jarFullName = new StringBuffer(separator);
082:                    jarFullName.append(dblook.stripQuotes(jarName));
083:                    jarFullName.append(".jar.G");
084:                    jarFullName.append(genID);
085:
086:                    StringBuffer oldJarPath = new StringBuffer();
087:                    oldJarPath.append(dbName);
088:                    oldJarPath.append(separator);
089:                    oldJarPath.append("jar");
090:                    oldJarPath.append(separator);
091:                    oldJarPath.append(schemaWithoutQuotes);
092:                    oldJarPath.append(jarFullName);
093:
094:                    // Copy jar file to DBJARS directory.
095:                    String absJarDir = null;
096:                    try {
097:
098:                        // Create the DBJARS directory.
099:                        File jarDir = new File(System.getProperty("user.dir")
100:                                + separator + "DBJARS" + separator
101:                                + schemaWithoutQuotes);
102:                        absJarDir = jarDir.getAbsolutePath();
103:                        jarDir.mkdirs();
104:
105:                        // Create streams.
106:                        FileInputStream oldJarFile = new FileInputStream(
107:                                oldJarPath.toString());
108:                        FileOutputStream newJarFile = new FileOutputStream(
109:                                absJarDir + jarFullName);
110:
111:                        // Copy.
112:                        int st = 0;
113:                        while (true) {
114:                            if (oldJarFile.available() == 0)
115:                                break;
116:                            byte[] bAr = new byte[oldJarFile.available()];
117:                            oldJarFile.read(bAr);
118:                            newJarFile.write(bAr);
119:                        }
120:
121:                        newJarFile.close();
122:                        oldJarFile.close();
123:
124:                    } catch (Exception e) {
125:                        Logs.debug("DBLOOK_FailedToLoadJar", absJarDir
126:                                + jarFullName.toString());
127:                        Logs.debug(e);
128:                        firstTime = false;
129:                        continue;
130:                    }
131:
132:                    // Now, add the DDL to read the jar from DBJARS.
133:                    StringBuffer loadJarString = new StringBuffer();
134:                    loadJarString.append("CALL SQLJ.INSTALL_JAR('file:");
135:                    loadJarString.append(absJarDir);
136:                    loadJarString.append(jarFullName);
137:                    loadJarString.append("', '");
138:                    loadJarString.append(schemaName);
139:                    loadJarString.append(".");
140:                    loadJarString.append(jarName);
141:                    loadJarString.append("', 0)");
142:
143:                    Logs.writeToNewDDL(loadJarString.toString());
144:                    Logs.writeStmtEndToNewDDL();
145:                    Logs.writeNewlineToNewDDL();
146:                    firstTime = false;
147:
148:                }
149:
150:                stmt.close();
151:                rs.close();
152:
153:            }
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.