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 NetworkPlacesUpgrade extends AbstractDatabaseUpgrade { 29 30 NetworkPlacesUpgrade(File oldDbDir, File newDbDir) { 31 super("Network Places", "Copies all network places to the new format. " 32 + "All are assumed to be SMB mounts. Any user created network " 33 + "places are also copied (with the owner username appended to " 34 + "the new resource name). The resource will not be attached to " + "any policies.", true, 35 "explorer_configuration", "explorer_configuration", oldDbDir, newDbDir); 36 } 37 38 public void doUpgrade(Upgrader upgrader, Connection oldConx, Connection newConx) throws Exception { 39 upgrader.info("Migrating all network places"); 41 Statement stmt = oldConx.createStatement(); 42 try { 43 ResultSet rs = stmt.executeQuery("SELECT * FROM NETWORK_PLACES"); 44 try { 45 while (rs.next()) { 46 String shortName = rs.getString("SHORT_NAME"); 47 String username = rs.getString("username"); 48 String uri = rs.getString("uri"); 49 if (uri.equals("/fs/cifs") || uri.equals("/fs/cifs/")) { 50 upgrader.warn(" Skipping network neighbourhood network place, no longer supported."); 51 } else { 52 shortName = shortName + " (" + (username.equals("") ? "System" : username) + ")"; 53 PreparedStatement ps = newConx.prepareStatement("SELECT * FROM NETWORK_PLACES WHERE SHORT_NAME = ?"); 54 boolean found = false; 55 try { 56 ps.setString(1, shortName); 57 ResultSet rs2 = ps.executeQuery(); 58 try { 59 if (rs2.next()) { 60 found = true; 61 } 62 } finally { 63 rs2.close(); 64 } 65 } finally { 66 ps.close(); 67 } 68 69 if (found) { 70 upgrader.warn(" Network place '" + shortName + "' already exists, skipping"); 71 } else { 72 insertNetworkPlace(upgrader, newConx, uri, shortName); 73 } 74 } 75 } 76 } finally { 77 rs.close(); 78 } 79 } finally { 80 stmt.close(); 81 } 82 83 } 84 85 void insertNetworkPlace(Upgrader upgrader, Connection newConx, String uri, String shortName) throws Exception { 86 87 PreparedStatement ps = newConx.prepareStatement("INSERT INTO NETWORK_PLACES (SHORT_NAME," 88 + "DESCRIPTION, PATH, READ_ONLY, ALLOW_RESURSIVE, " 89 + "NO_DELETE, SHOW_HIDDEN, PARENT_RESOURCE_PERMISSION, " + "DATE_CREATED, DATE_AMENDED,SCHEME) VALUES " 90 + "(?,?,?,?,?,?,?,?,NOW(),NOW(),?)"); 91 try { 92 upgrader.info(" " + shortName); 93 ps.setString(1, shortName); 94 ps.setString(2, shortName); 95 if (uri.equals("/fs/cifs")) { 96 uri = "smb://"; 97 } else if (uri.startsWith("\\\\")) { 98 uri = "smb:" + uri.replace('\\', '/'); 99 } else { 100 uri = "smb:/" + uri.substring(8); 101 } 102 ps.setString(3, uri); 103 ps.setBoolean(4, false); 104 ps.setBoolean(5, true); 105 ps.setBoolean(6, false); 106 ps.setBoolean(7, true); 107 ps.setInt(8, 0); 108 ps.setString(9, "smb"); 109 try { 110 ps.execute(); 111 } catch (Exception e) { 112 upgrader.warn("Failed to insert network place " + shortName + ". Probably already exists."); 113 } 114 } finally { 115 ps.close(); 116 } 117 } 118 119 } 120 | Popular Tags |