Ignore:
Timestamp:
2004-12-21T12:11:00+13:00 (19 years ago)
Author:
schweer
Message:

fixed BTS 12: restore subscriptions/predicates from database

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java

    r8798 r8867  
    7878        rssNotification = valueMap.containsKey("way") && ((List)valueMap.get("way")).contains("rss");
    7979        eventsSincePageNotification = valueMap.containsKey("way") && ((List)valueMap.get("way")).contains("page");
    80         id = saveToDatabase(true);
     80        id = saveToDatabase();
    8181       
    8282        for (Iterator iter = getPredicates().iterator(); iter.hasNext();) {
     
    157157    }
    158158   
    159     private int saveToDatabase(boolean initial) throws DatabaseException, SQLException {
     159    private int saveToDatabase() throws DatabaseException, SQLException {
    160160        Connection conn = DatabaseManager.getInstance().getDatabaseConnection();
    161161        Statement statement = conn.createStatement();
    162162        String sqlString;
     163        boolean initial = true;
     164       
     165        sqlString = "SELECT id FROM subscriptions WHERE name like '" + name +
     166                    "' AND email like '" + email + "' AND rss=" + (rssNotification ? 1 : 0)
     167                    + " AND page=" + (eventsSincePageNotification ? 1 : 0) + " AND user like '" +
     168                    username + "';";
     169        ResultSet result = statement.executeQuery(sqlString);
     170        if (result.next()) {
     171            initial = false;
     172            this.id = result.getInt("id");
     173        }
     174       
    163175        if (initial) {
    164176            sqlString = "INSERT INTO subscriptions (name, email, rss, page, user) " +
     
    168180            sqlString = "UPDATE subscriptions SET name='" + name + "', email='" +
    169181                    email + "', rss=" + (rssNotification ? 1 : 0) + ",page=" +
    170                     (eventsSincePageNotification ? 1 : 0)+ "WHERE id=" + id + ";";
     182                    (eventsSincePageNotification ? 1 : 0)+ " WHERE id=" + this.id + ";";
    171183            // cannot change user
    172184        }
     
    178190                    username + "';";
    179191        System.out.println(sqlString);
    180         ResultSet result = statement.executeQuery(sqlString);
    181         int id;
     192        result = statement.executeQuery(sqlString);
     193       
    182194        if (result.next()) {
    183195            id = result.getInt("id");
Note: See TracChangeset for help on using the changeset viewer.