KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > upgrade > TunnelsUpgrade


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.upgrade;
21
22 import java.io.File JavaDoc;
23 import java.sql.Connection JavaDoc;
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.ResultSet JavaDoc;
26 import java.sql.Statement JavaDoc;
27
28 public class TunnelsUpgrade extends AbstractDatabaseUpgrade {
29
30     TunnelsUpgrade(File JavaDoc oldDbDir, File JavaDoc newDbDir) {
31         super("SSL Tunnels", "Copies all SSL Tunnels to the new installation. "
32                         + "Any user created tunnels are also copied (with the owner "
33                         + "username appended to the new resource name). The resource " + "will not be attached to any policies.",
34                         true, "explorer_configuration", "explorer_configuration", oldDbDir, newDbDir);
35     }
36
37     public void doUpgrade(Upgrader upgrader, Connection JavaDoc oldConx, Connection JavaDoc newConx) throws Exception JavaDoc {
38         // // Auth Schemes
39
upgrader.info("Migrating all SSL tunnels");
40         Statement JavaDoc stmt = oldConx.createStatement();
41         try {
42             ResultSet JavaDoc rs = stmt.executeQuery("SELECT * FROM TUNNELS");
43             try {
44                 while (rs.next()) {
45                     int tunnelId = rs.getInt("TUNNEL_ID");
46                     PreparedStatement JavaDoc ps = newConx.prepareStatement("INSERT INTO TUNNELS (NAME,"
47                                     + "DESCRIPTION, TYPE, TRANSPORT, USERNAME, SOURCE_PORT,"
48                                     + " DESTINATION_PORT, DESTINATION_HOST, AUTO_START, "
49                                     + "ALLOW_EXTERNAL_HOSTS, PARENT_RESOURCE_PERMISSION, "
50                                     + "DATE_CREATED, DATE_AMENDED) VALUES (?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW())");
51                     try {
52                         upgrader.info(" " + tunnelId);
53                         String JavaDoc resourceName = "Tunnel ID " + tunnelId;
54                         String JavaDoc username = rs.getString("USERNAME");
55                         if (username.equals("")) {
56                             resourceName += " (System)";
57                         } else {
58                             resourceName += " (" + username + ")";
59                         }
60                         ps.setString(1, resourceName);
61                         ps.setString(2, resourceName);
62                         ps.setInt(3, rs.getInt("TYPE"));
63                         ps.setString(4, rs.getString("TRANSPORT"));
64                         ps.setString(5, rs.getString("USERNAME"));
65                         ps.setInt(6, rs.getInt("SOURCE_PORT"));
66                         ps.setInt(7, rs.getInt("DESTINATION_PORT"));
67                         ps.setString(8, rs.getString("DESTINATION_HOST"));
68                         ps.setInt(9, rs.getInt("AUTO_START"));
69                         ps.setInt(10, rs.getInt("ALLOW_EXTERNAL_HOSTS"));
70                         ps.setInt(11, 0);
71                         try {
72                             ps.execute();
73                         } catch (Exception JavaDoc e) {
74                             upgrader.warn("Failed to insert tunnel " + tunnelId + ". Probably already exists.");
75                         }
76                     } finally {
77                         ps.close();
78                     }
79                 }
80             } finally {
81                 rs.close();
82             }
83         } finally {
84             stmt.close();
85         }
86
87     }
88
89 }
90
Popular Tags