Skip to content

Commit

Permalink
Completed Query.filterBy with QueryOp
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmx committed Jan 31, 2011
1 parent e6bb9c5 commit 6945d2a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/main/java/org/mongoste/query/DefaultQuery.java
Expand Up @@ -99,7 +99,19 @@ public Query limit(Integer maxResults) {
*/
@Override
public Query filterBy(QueryField field,Object value) {
return filterBy(field,new QueryFilter(QueryOp.EQ,value));
return filterBy(field,QueryOp.EQ,value);
}


/**
* Sets a filter to a single field with an operation
* @param field Field to filter by
* @param operation Filter operation
* @param value Value to apply
* @return
*/
public Query filterBy(QueryField field,QueryOp operation,Object value) {
return filterBy(field,new QueryFilter(operation,value));
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/mongoste/query/Query.java
Expand Up @@ -64,6 +64,15 @@ public interface Query extends Serializable {
*/
Query filterBy(QueryField field, Object value);

/**
* Sets a filter to a single field with an operation
* @param field Field to filter by
* @param operation Filter operation
* @param value Value to apply
* @return
*/
Query filterBy(QueryField field, QueryOp operation, Object value);

/**
* Sets a filter to a single field
* @param field Field to filter by
Expand Down
Expand Up @@ -45,6 +45,7 @@
import java.util.Properties;
import java.text.ParseException;
import org.mongoste.query.Query;
import org.mongoste.query.QueryOp;
import org.mongoste.query.RequiredQueryFieldException;

/**
Expand Down Expand Up @@ -682,9 +683,11 @@ public void testGetMultiTargetActionCount() throws Exception {
System.out.println("result:"+result);
//TODO check collection
List<String> targets = Arrays.asList(event.getTarget());
//query.filterBy(QueryField.TARGET,QueryOp.IN,targets)
//query.filterBy(QueryField.TARGET).in(targets)

query.filterBy(QueryField.TARGET,QueryOp.IN,targets);
result = query.getMultiTargetActionCount();
assertNotNull(result);
assertEquals(1,result.size());
System.out.println("result:"+result);
}

/**
Expand Down

0 comments on commit 6945d2a

Please sign in to comment.