r67527 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67526‎ | r67527 | r67528 >
Date:13:26, 7 June 2010
Author:daniel
Status:deferred
Tags:
Comment:
fixed handling of empty feature sets
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseFeatureStore.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseFeatureStore.java
@@ -85,6 +85,8 @@
8686 }
8787
8888 public ConceptFeatures<T, Integer> getConceptFeatures(int concept) throws PersistenceException {
 89+ if (concept == 0) return new ConceptFeatures<T, Integer>(newConcept(concept, null, ConceptType.UNKNOWN, 0, 0), ConceptFeatures.newIntFeaturVector(1));
 90+
8991 String sql = "SELECT concept, feature, normal_weight FROM " +featureTable.getSQLName()+" as F ";
9092 sql += " WHERE concept = "+concept;
9193 if (maxConceptFeatures>0) sql += " ORDER BY normal_weight DESC LIMIT "+maxConceptFeatures;
@@ -143,8 +145,10 @@
144146 Map<Integer, ConceptFeatures<T, Integer>> features = new HashMap<Integer, ConceptFeatures<T, Integer>>();
145147
146148 try {
147 - while (!rs.isAfterLast()) {
 149+ while (!rs.isAfterLast()) { // JDBC sais isAfterLast() returns false for empty sets. WTF??
148150 ConceptFeatures<T, Integer> f = readConceptFeatures(rs, conceptField, nameField, cardinalityField, relevanceField, keyField, valueField);
 151+ if ( f == null ) break; //result set was empty.
 152+
149153 features.put(f.getId(), f);
150154 }
151155
@@ -161,7 +165,8 @@
162166 String conceptField, String nameField, String cardinalityField, String relevanceField,
163167 String keyField, String valueField) throws PersistenceException {
164168 try {
165 - rs.next(); //TODO: return what iof this fails??
 169+ if ( !rs.next() ) return null;
 170+
166171 int id = DatabaseUtil.asInt(rs.getObject(conceptField));
167172 String n = nameField == null ? null : DatabaseUtil.asString(rs.getObject(nameField));
168173 int c = cardinalityField == null ? 1 : DatabaseUtil.asInt(rs.getObject(cardinalityField));

Status & tagging log