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 IPRestrictionsUpgrade extends AbstractDatabaseUpgrade { 29 30 IPRestrictionsUpgrade(File oldDbDir, File newDbDir) { 31 super("IP Restrictions", "Copies IP restrictions to the new installation.", true, "explorer_configuration", 32 "explorer_configuration", oldDbDir, newDbDir); 33 } 34 35 public void doUpgrade(Upgrader upgrader, Connection oldConx, Connection newConx) throws Exception { 36 upgrader.info("Migrating all IP restrictions"); 38 Statement stmt = oldConx.createStatement(); 39 try { 40 ResultSet rs = stmt.executeQuery("SELECT * FROM IP_RESTRICTIONS"); 41 try { 42 while (rs.next()) { 43 int restrictionId = rs.getInt("RESTRICTION_ID"); 44 PreparedStatement ps = newConx.prepareStatement("INSERT INTO IP_RESTRICTIONS (RESTRICTION_ID," 45 + "ADDRESS, TYPE) VALUES (?,?,?)"); 46 try { 47 upgrader.info(" " + restrictionId); 48 ps.setInt(1, restrictionId); 49 ps.setString(2, rs.getString("ADDRESS")); 50 ps.setInt(3, rs.getInt("TYPE")); 51 try { 52 ps.execute(); 53 } catch (Exception e) { 54 upgrader.warn("Failed to insert IP restriction " + restrictionId + ". Probably already exists."); 55 } 56 } finally { 57 ps.close(); 58 } 59 } 60 } finally { 61 rs.close(); 62 } 63 } finally { 64 stmt.close(); 65 } 66 67 } 68 69 } 70 | Popular Tags |