Skip to content

Commit

Permalink
fix for delivering wrong result set in case of a missing/misspleled p…
Browse files Browse the repository at this point in the history
…roperty. Throws now an Exception.
  • Loading branch information
Erich Nachbar committed Mar 4, 2010
1 parent c63577e commit 3af01e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
9 changes: 6 additions & 3 deletions src/java/meetup/beeno/ScanByIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import meetup.beeno.mapping.EntityInfo;
import meetup.beeno.mapping.IndexMapping;
import meetup.beeno.mapping.MappingException;
import meetup.beeno.util.HUtil;
import meetup.beeno.util.PBUtil;

Expand Down Expand Up @@ -151,9 +152,10 @@ protected ResultScanner getIndexScanner(String tablename,
* for the query.
* @param expressions
* @return
* @throws MappingException
*/
protected Criteria.PropertyExpression selectIndexedExpression(EntityInfo info,
List<Criteria.Expression> expressions) {
List<Criteria.Expression> expressions) throws MappingException {
// first look for a direct match expression
for (Criteria.Expression e : expressions) {
if (e instanceof Criteria.RequireExpression)
Expand All @@ -179,8 +181,9 @@ protected Criteria.PropertyExpression selectIndexedExpression(EntityInfo info,
return propExpr;
}
}

return null;
// not property match found
// notifying user to avoid returning wrong result set
throw new MappingException(info.getClass(), "Can't find property " + expressions);
}


Expand Down
35 changes: 25 additions & 10 deletions test/java/meetup/beeno/BasicOrmPersistanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void setUpBeforeClass() throws Exception {

// create tables
HTableDescriptor by_photoId_idx = new HTableDescriptor(
"test_simple-by_photoId");
"test_simple-by_photoId");
by_photoId_idx.addFamily(new HColumnDescriptor("__idx__"));
by_photoId_idx.addFamily(new HColumnDescriptor("props"));
admin.createTable(by_photoId_idx);
Expand Down Expand Up @@ -94,7 +94,7 @@ public void tearDown() throws Exception {
public void testCreationAndCriteriaRetrieval() throws HBaseException {

EntityService<SimpleEntity> service = EntityService
.create(SimpleEntity.class);
.create(SimpleEntity.class);

for (int i = 0; i < 10; i++) {
SimpleEntity se = new SimpleEntity();
Expand All @@ -106,8 +106,7 @@ public void testCreationAndCriteriaRetrieval() throws HBaseException {
}

// query rows
Query query = service.query().using(
Criteria.eq("photoIdProperty", "PHOTOID5"));
Query query = service.query().using(Criteria.eq("photoIdProperty", "PHOTOID5"));
List<SimpleEntity> items = query.execute();
for (SimpleEntity e : items) {
System.out.println("items: " + ((SimpleEntity) e).getId());
Expand All @@ -121,13 +120,29 @@ public void testCreationAndNonExistantCriteriaRetrieval() throws HBaseException
EntityService<SimpleEntity> service = EntityService.create(SimpleEntity.class);

// query rows
Query query = service.query().using(
Criteria.eq("IDONTEXISTFORSURE", "PHOTOID5"));
List<SimpleEntity> items = query.execute();
for (SimpleEntity e : items) {
System.out.println("items: " + ((SimpleEntity) e).getId());
try{
Query query = service.query().using(Criteria.eq("IDONTEXISTFORSURE", "PHOTOID5"));
List<SimpleEntity> items = query.execute();
fail("Should have gotten a QueryException for the missing properties.");
} catch(QueryException e){
//Sweet! Got our expected exception.
}
}

@Test
public void testCreationOfMixedExistingAndNonExistantCriteriaRetrieval() throws HBaseException {

EntityService<SimpleEntity> service = EntityService.create(SimpleEntity.class);

// query rows
try{
Query query = service.query().using(Criteria.eq("IDONTEXISTFORSURE", "PHOTOID5")).where(Criteria.eq("photoIdProperty", "PHOTOID5"));
List<SimpleEntity> items = query.execute();
fail("Should have gotten a QueryException for the missing properties.");
} catch(QueryException e){
//Sweet! Got our expected exception.
}
assertEquals(0, items.size());
}


}

0 comments on commit 3af01e8

Please sign in to comment.