- Timestamp:
- 2004-12-21T12:11:00+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
r8798 r8867 54 54 */ 55 55 private void addSubscription(Subscription subscription) { 56 // TODO change to lists57 56 List documentIdPredicate = subscription.getPredicateList("documentID"); 58 57 List collectionIdPredicate = subscription.getPredicateList("collectionID"); … … 237 236 return matchedSubscriptions; 238 237 } 239 //240 // public String toString() {241 // Set allSubscriptions = getAllSubscriptions();242 //243 // StringBuffer buffer = new StringBuffer();244 //245 // for (Iterator iter = allSubscriptions.iterator(); iter.hasNext();) {246 // Subscription sub = (Subscription) iter.next();247 // buffer.append(sub);248 // buffer.append("\n");249 // }250 //251 // return buffer.toString();252 // }253 //254 // /**255 // * @return256 // */257 // public Set getAllSubscriptions() {258 // Set allSubscriptions = new TreeSet();259 // allSubscriptions.addAll(noEqualsSubscriptions);260 //261 // for(Iterator iter = docIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {262 // Set values = (Set) iter.next();263 // allSubscriptions.addAll(values);264 // }265 //266 // for(Iterator iter = docCollectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {267 // Set values = (Set) iter.next();268 // allSubscriptions.addAll(values);269 // }270 //271 // for(Iterator iter = collectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {272 // Set values = (Set) iter.next();273 // allSubscriptions.addAll(values);274 // }275 // return Collections.unmodifiableSet(allSubscriptions);276 // }277 238 278 239 … … 289 250 /** 290 251 * @param subscriptionID 291 */ 292 public void deleteSubscription(String subscriptionID) { 293 // delete row from subscriptions table 294 // for each predicate: 295 // delete row from subs_to_predicates 296 // if there aren't any other subscriptions using this predicate, delete predicate 297 // TODO Auto-generated method stub 252 * @throws DatabaseException 253 * @throws SQLException 254 */ 255 public void deleteSubscription(String subscriptionID) throws DatabaseException, SQLException { 256 Integer subID = new Integer(subscriptionID); 257 System.out.println("deleting subscription " + subscriptionID); 258 if (!subscriptions.containsKey(subID)) { 259 return; 260 } 261 Subscription sub = (Subscription) subscriptions.get(subID); 262 for (Iterator iter = dontCareSubscriptions.values().iterator(); iter.hasNext();) { 263 Set entry = (Set) iter.next(); 264 if (entry.contains(subID)) 265 entry.remove(subID); 266 } 267 if (noEqualsSubscriptions.contains(subID)) 268 noEqualsSubscriptions.remove(subID); 269 for (Iterator iter = sub.getPredicates().iterator(); iter.hasNext();) { 270 Predicate pred = (Predicate) iter.next(); 271 pred.removeSubscription(subID); 272 } 273 274 subscriptions.remove(subID); 275 276 277 Connection conn = DatabaseManager.getInstance().getDatabaseConnection(); 278 279 Statement statement = conn.createStatement(); 280 281 String sqlString = "DELETE FROM subscriptions WHERE id = " + subscriptionID; 282 statement.executeUpdate(sqlString); 283 284 sqlString = "SELECT predicate FROM subs_to_predicates " + 285 "WHERE subscription = " + subscriptionID; 286 ResultSet predicates = statement.executeQuery(sqlString); 287 while (predicates.next()) { 288 // if there aren't any other subscriptions using this predicate, delete predicate 289 int predicateID = predicates.getInt("predicate"); 290 291 } 292 298 293 299 294 } … … 344 339 return result; 345 340 } 341 342 /** 343 * 344 */ 345 public void restoreFromDatabase() { 346 try { 347 Connection conn = DatabaseManager.getInstance().getDatabaseConnection(); 348 Statement statement = conn.createStatement(); 349 String sqlString = "SELECT * FROM subscriptions"; 350 ResultSet subs = statement.executeQuery(sqlString); 351 while (subs.next()) { 352 // construct map for all predicates 353 int id = subs.getInt("id"); 354 Map map = new TreeMap(); 355 map.put("username", subs.getString("user")); 356 map.put("email", subs.getString("email")); 357 map.put("subscription_name", subs.getString("name")); 358 Vector ways = new Vector(); 359 if (subs.getInt("rss") != 0) { 360 ways.add("rss"); 361 } 362 if (subs.getInt("page") != 0) { 363 ways.add("page"); 364 } 365 map.put("way", ways); 366 Statement stmnt = conn.createStatement(); 367 sqlString = "SELECT p.type, p.field, p.value from subs_to_predicates stp join predicates p on(stp.predicate = p.id) where stp.subscription = " + id + ";"; 368 ResultSet predicates = stmnt.executeQuery(sqlString); 369 while (predicates.next()) { 370 String type = predicates.getString("type"); 371 String field = predicates.getString("field"); 372 if (type.equals(SubstringMatchPredicate.class.getName())) { 373 if (field.equals("colletionID")) { 374 field = "collection_query"; 375 } else if (field.equals("hostID")) { 376 field = "host_query"; 377 } 378 } 379 String value = predicates.getString("value"); 380 if (type.equals(IdEqualsPredicate.class.getName())) { 381 if (!map.containsKey(field)) { 382 map.put(field, new Vector()); 383 } 384 ((List) map.get(field)).add(value); 385 } else { 386 map.put(field, value); 387 } 388 } 389 try { 390 createSubscription(map); 391 } catch (Exception e1) { 392 // TODO Auto-generated catch block 393 e1.printStackTrace(); 394 } 395 } 396 } catch (SQLException e) { 397 // TODO Auto-generated catch block 398 e.printStackTrace(); 399 } catch (DatabaseException e) { 400 // TODO Auto-generated catch block 401 e.printStackTrace(); 402 } 403 } 346 404 347 405 }
Note:
See TracChangeset
for help on using the changeset viewer.