Changeset 8867 for trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java
- 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/profiles/Predicate.java
r8798 r8867 119 119 String query = "SELECT id FROM predicates " + 120 120 "WHERE field = '" + field + 121 "' AND value = '" + value + "';"; 121 "' AND value = '" + value + 122 "' AND type = '" + this.getClass().getName() + "';"; 122 123 Statement statement = DatabaseManager.getInstance().getDatabaseConnection().createStatement(); 123 124 System.out.println(query); 124 125 ResultSet result = statement.executeQuery(query); 125 126 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; 128 130 } 129 131 // 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 + "');"; 132 134 System.out.println(insert); 133 135 statement.execute(insert); … … 141 143 142 144 /** 143 * @return144 */145 public List getValueList() {146 throw new UnsupportedOperationException("you can only call this method for multi-valued predicates");147 }148 149 /**150 145 * @param key 151 146 * @return … … 154 149 return ArrayHelper.contains(singleValueFields, key) || ArrayHelper.contains(multiValueFields, key); 155 150 } 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 } 156 172 157 173 }
Note:
See TracChangeset
for help on using the changeset viewer.