- Timestamp:
- 2004-12-06T11:44:03+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java
r8609 r8738 9 9 package org.greenstone.gsdlas.profiles; 10 10 11 import java.sql.*; 12 import java.sql.SQLException; 13 import java.sql.Statement; 11 14 import java.util.*; 12 15 import java.util.Set; 13 16 import java.util.TreeSet; 17 18 import org.greenstone.gsdlas.database.DatabaseException; 19 import org.greenstone.gsdlas.database.DatabaseManager; 20 import org.greenstone.gsdlas.util.ArrayHelper; 14 21 15 22 /** … … 26 33 protected int id; 27 34 28 public void addSubscription(Subscription sub) { 29 subscriptions.add(sub); 35 36 public static final String[] singleValueFields = new String[] { 37 "document_title", 38 "document_content", 39 "metadata_has_field", 40 "host_query", 41 "collection_query" }; 42 public static final String[] multiValueFields = new String[] { 43 "type", 44 "host", 45 "collection" }; 46 47 public void addSubscription(int subscriptionID) { 48 subscriptions.add(new Integer(subscriptionID)); 49 // TODO save to db 30 50 } 31 51 … … 33 53 * @see org.greenstone.gsdlas.profiles.Predicate#getSubscriptions() 34 54 */ 35 public Set getSubscription s() {55 public Set getSubscriptionIDs() { 36 56 return Collections.unmodifiableSet(subscriptions); 37 57 } … … 74 94 75 95 public abstract boolean isSatisfied(Map event); 96 97 /** 98 * @param key 99 * @return 100 */ 101 public static boolean isSingleValued(String key) { 102 return ArrayHelper.contains(singleValueFields, key); 103 } 104 105 /** 106 * @param key 107 * @return 108 */ 109 public static boolean isMultiValued(String key) { 110 return ArrayHelper.contains(singleValueFields, key); 111 } 112 113 /** 114 * @return 115 * @throws DatabaseException 116 * @throws SQLException 117 */ 118 int saveToDatabase() throws SQLException, DatabaseException { 119 // TODO handle multi-valued predicate (in subclass?) 120 String query = "SELECT id FROM predicates " + 121 "WHERE type='single' AND field = '" + field + 122 "' AND singleValue = '" + value + "';"; 123 Statement statement = DatabaseManager.getInstance().getDatabaseConnection().createStatement(); 124 System.out.println(query); 125 ResultSet result = statement.executeQuery(query); 126 if (result.next()) { // predicate already exists in database 127 System.out.println("predicate " + id + " already exists"); 128 return result.getInt("id"); 129 } 130 // predicate has been newly created 131 String insert = "INSERT INTO predicates (type, field, singleValue) " + 132 "VALUES ('single', '" + field + "', '" + value + "');"; 133 System.out.println(insert); 134 statement.execute(insert); 135 result = statement.executeQuery(query); 136 if (result.next()) { 137 return result.getInt("id"); 138 } else { 139 throw new DatabaseException("could not save predicate"); 140 } 141 } 76 142 77 143 }
Note:
See TracChangeset
for help on using the changeset viewer.