KickJava   Java API By Example, From Geeks To Geeks.

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


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 IPRestrictionsUpgrade extends AbstractDatabaseUpgrade {
29
30     IPRestrictionsUpgrade(File JavaDoc oldDbDir, File JavaDoc 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 JavaDoc oldConx, Connection JavaDoc newConx) throws Exception JavaDoc {
36         // // Auth Schemes
37
upgrader.info("Migrating all IP restrictions");
38         Statement JavaDoc stmt = oldConx.createStatement();
39         try {
40             ResultSet JavaDoc rs = stmt.executeQuery("SELECT * FROM IP_RESTRICTIONS");
41             try {
42                 while (rs.next()) {
43                     int restrictionId = rs.getInt("RESTRICTION_ID");
44                     PreparedStatement JavaDoc 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 JavaDoc 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