1 21 22 package org.apache.derby.impl.tools.dblook; 23 24 import java.sql.Connection ; 25 import java.sql.Statement ; 26 import java.sql.PreparedStatement ; 27 import java.sql.ResultSet ; 28 import java.sql.SQLException ; 29 30 import java.util.HashMap ; 31 32 import java.io.File ; 33 import java.io.FileOutputStream ; 34 import java.io.FileInputStream ; 35 import java.io.FileNotFoundException ; 36 import java.io.IOException ; 37 38 import org.apache.derby.tools.dblook; 39 40 public class DB_Jar { 41 42 50 51 public static void doJars(String dbName, Connection conn) 52 throws SQLException 53 { 54 55 String separator = System.getProperty("file.separator"); 56 Statement stmt = conn.createStatement(); 57 ResultSet rs = stmt.executeQuery("SELECT FILENAME, SCHEMAID, " + 58 "GENERATIONID FROM SYS.SYSFILES"); 59 60 boolean firstTime = true; 61 while (rs.next()) { 62 63 String jarName = dblook.addQuotes( 64 dblook.expandDoubleQuotes(rs.getString(1))); 65 String schemaId = rs.getString(2); 66 String schemaName = dblook.lookupSchemaId(schemaId); 67 if (dblook.isIgnorableSchema(schemaName)) 68 continue; 69 70 if (firstTime) { 71 Logs.reportString("----------------------------------------------"); 72 Logs.reportMessage("DBLOOK_JarsHeader"); 73 Logs.reportMessage("DBLOOK_Jar_Note"); 74 Logs.reportString("----------------------------------------------\n"); 75 } 76 77 String genID = rs.getString(3); 78 79 String schemaWithoutQuotes = dblook.stripQuotes(schemaName); 80 StringBuffer jarFullName = new StringBuffer (separator); 81 jarFullName.append(dblook.stripQuotes(jarName)); 82 jarFullName.append(".jar.G"); 83 jarFullName.append(genID); 84 85 StringBuffer oldJarPath = new StringBuffer (); 86 oldJarPath.append(dbName); 87 oldJarPath.append(separator); 88 oldJarPath.append("jar"); 89 oldJarPath.append(separator); 90 oldJarPath.append(schemaWithoutQuotes); 91 oldJarPath.append(jarFullName); 92 93 String absJarDir = null; 95 try { 96 97 File jarDir = new File (System.getProperty("user.dir") + 99 separator + "DBJARS" + separator + schemaWithoutQuotes); 100 absJarDir = jarDir.getAbsolutePath(); 101 jarDir.mkdirs(); 102 103 FileInputStream oldJarFile = 105 new FileInputStream (oldJarPath.toString()); 106 FileOutputStream newJarFile = 107 new FileOutputStream (absJarDir + jarFullName); 108 109 int st = 0; 111 while (true) { 112 if (oldJarFile.available() == 0) 113 break; 114 byte[] bAr = new byte[oldJarFile.available()]; 115 oldJarFile.read(bAr); 116 newJarFile.write(bAr); 117 } 118 119 newJarFile.close(); 120 oldJarFile.close(); 121 122 } catch (Exception e) { 123 Logs.debug("DBLOOK_FailedToLoadJar", 124 absJarDir + jarFullName.toString()); 125 Logs.debug(e); 126 firstTime = false; 127 continue; 128 } 129 130 StringBuffer loadJarString = new StringBuffer (); 132 loadJarString.append("CALL SQLJ.INSTALL_JAR('file:"); 133 loadJarString.append(absJarDir); 134 loadJarString.append(jarFullName); 135 loadJarString.append("', '"); 136 loadJarString.append(schemaName); 137 loadJarString.append("."); 138 loadJarString.append(jarName); 139 loadJarString.append("', 0)"); 140 141 Logs.writeToNewDDL(loadJarString.toString()); 142 Logs.writeStmtEndToNewDDL(); 143 Logs.writeNewlineToNewDDL(); 144 firstTime = false; 145 146 } 147 148 stmt.close(); 149 rs.close(); 150 151 } 152 153 } 154 | Popular Tags |