Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseFeatureStore.java |
— | — | @@ -85,6 +85,8 @@ |
86 | 86 | } |
87 | 87 | |
88 | 88 | 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 | + |
89 | 91 | String sql = "SELECT concept, feature, normal_weight FROM " +featureTable.getSQLName()+" as F "; |
90 | 92 | sql += " WHERE concept = "+concept; |
91 | 93 | if (maxConceptFeatures>0) sql += " ORDER BY normal_weight DESC LIMIT "+maxConceptFeatures; |
— | — | @@ -143,8 +145,10 @@ |
144 | 146 | Map<Integer, ConceptFeatures<T, Integer>> features = new HashMap<Integer, ConceptFeatures<T, Integer>>(); |
145 | 147 | |
146 | 148 | try { |
147 | | - while (!rs.isAfterLast()) { |
| 149 | + while (!rs.isAfterLast()) { // JDBC sais isAfterLast() returns false for empty sets. WTF?? |
148 | 150 | ConceptFeatures<T, Integer> f = readConceptFeatures(rs, conceptField, nameField, cardinalityField, relevanceField, keyField, valueField); |
| 151 | + if ( f == null ) break; //result set was empty. |
| 152 | + |
149 | 153 | features.put(f.getId(), f); |
150 | 154 | } |
151 | 155 | |
— | — | @@ -161,7 +165,8 @@ |
162 | 166 | String conceptField, String nameField, String cardinalityField, String relevanceField, |
163 | 167 | String keyField, String valueField) throws PersistenceException { |
164 | 168 | try { |
165 | | - rs.next(); //TODO: return what iof this fails?? |
| 169 | + if ( !rs.next() ) return null; |
| 170 | + |
166 | 171 | int id = DatabaseUtil.asInt(rs.getObject(conceptField)); |
167 | 172 | String n = nameField == null ? null : DatabaseUtil.asString(rs.getObject(nameField)); |
168 | 173 | int c = cardinalityField == null ? 1 : DatabaseUtil.asInt(rs.getObject(cardinalityField)); |