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/Predicate.java

    r8798 r8867  
    119119        String query = "SELECT id FROM predicates " +
    120120                "WHERE field = '" + field +
    121                 "' AND value = '" + value + "';";
     121                "' AND value = '" + value +
     122                "' AND type = '" + this.getClass().getName() + "';";
    122123        Statement statement = DatabaseManager.getInstance().getDatabaseConnection().createStatement();
    123124        System.out.println(query);
    124125        ResultSet result = statement.executeQuery(query);
    125126        if (result.next()) { // predicate already exists in database
    126             System.out.println("predicate " + id + " already exists");
    127             return result.getInt("id");
     127            int id = result.getInt("id");
     128            System.out.println("predicate already exists with id " + id);
     129            return id;
    128130        }
    129131        // predicate has been newly created
    130         String insert = "INSERT INTO predicates (field, value) " +
    131         "VALUES ('" + field + "', '" + value + "');";
     132        String insert = "INSERT INTO predicates (field, type, value) " +
     133        "VALUES ('" + field + "', '" + this.getClass().getName() + "', '" + value + "');";
    132134        System.out.println(insert);
    133135        statement.execute(insert);
     
    141143
    142144    /**
    143      * @return
    144      */
    145     public List getValueList() {
    146         throw new UnsupportedOperationException("you can only call this method for multi-valued predicates");
    147     }
    148 
    149     /**
    150145     * @param key
    151146     * @return
     
    154149        return ArrayHelper.contains(singleValueFields, key) || ArrayHelper.contains(multiValueFields, key);
    155150    }
     151
     152    /**
     153     * @param subID
     154     * @throws DatabaseException
     155     * @throws SQLException
     156     */
     157    public void removeSubscription(Integer subID) throws SQLException, DatabaseException {
     158        subscriptions.remove(subID);
     159
     160        Statement statement = DatabaseManager.getInstance().getDatabaseConnection().createStatement();
     161        String sqlString = "DELETE FROM subs_to_predicates " +
     162            "WHERE subscription = " + subID +
     163            " AND predicate = " + id;
     164        statement.executeUpdate(sqlString);
     165       
     166        if (subscriptions.isEmpty()) {
     167            PredicateFactory.deletePredicate(this);
     168            sqlString = "DELETE FROM predicates WHERE id = " + id;
     169            statement.executeUpdate(sqlString);
     170        }
     171    }
    156172   
    157173}
Note: See TracChangeset for help on using the changeset viewer.