1 19 20 package com.sslexplorer.upgrade; 21 22 import java.io.File ; 23 import java.sql.Connection ; 24 import java.sql.PreparedStatement ; 25 import java.sql.ResultSet ; 26 import java.sql.Statement ; 27 28 public class ReplacementsUpgrade extends AbstractDatabaseUpgrade { 29 30 ReplacementsUpgrade(File oldDbDir, File newDbDir) { 31 super( 32 "Replacements", 33 "Copies replacement patterns used by the replacement " + 34 "proxy web forwards (previously known as Secure Proxy). " + 35 "All new replacements will be deleted and the ones from " + 36 "your old installation will be copied across. Only " + 37 "global replacements will be copied. DO NOT SELECT " + 38 "THIS UPGRADE UNLESS YOU HAVE CREATED " + 39 "CUSTOM REPLACEMENTS AND WISH TO KEEP THEM. ", 40 false, "explorer_configuration", "explorer_configuration", oldDbDir, newDbDir); 41 } 42 43 public void doUpgrade(Upgrader upgrader, Connection oldConx, Connection newConx) throws Exception { 44 upgrader.info("Migrating all replacements"); 46 Statement stmt = oldConx.createStatement(); 47 try { 48 ResultSet rs = stmt.executeQuery("SELECT * FROM REPLACEMENTS"); 49 try { 50 while (rs.next()) { 51 Statement stmt2 = newConx.createStatement(); 52 try { 53 stmt2.execute("DELETE FROM REPLACEMENTS"); 54 } 55 finally { 56 stmt2.close(); 57 } 58 59 PreparedStatement ps = newConx.prepareStatement( 60 "INSERT INTO REPLACEMENTS (USERNAME," 61 + "SITE_PATTERN,MIME_TYPE,SEQUENCE,MATCH_PATTERN,REPLACE_PATTERN,REPLACE_TYPE) VALUES (?,?,?,?,?,?,?)"); 62 try { 63 String username =rs.getString("USERNAME"); 64 int seq = rs.getInt("SEQUENCE"); 65 if(username.equals("")) { 66 ps.setString(1, username); 67 ps.setString(2, rs.getString("SITE_PATTERN")); 68 ps.setString(3, rs.getString("MIME_TYPE")); 69 ps.setInt(4, seq); 70 ps.setString(5, rs.getString("MATCH_PATTERN")); 71 ps.setString(6, rs.getString("REPLACE_PATTERN")); 72 ps.setInt(7, rs.getInt("REPLACE_TYPE")); 73 try { 74 ps.execute(); 75 } catch (Exception e) { 76 upgrader.warn("Failed to insert IP restriction for sequence " + seq + ". Probably already exists."); 77 } 78 } 79 else { 80 upgrader.warn("Skipping user replacement for user '" + username + "'."); 81 } 82 } finally { 83 ps.close(); 84 } 85 } 86 } finally { 87 rs.close(); 88 } 89 } finally { 90 stmt.close(); 91 } 92 93 } 94 95 } 96 | Popular Tags |