Skip to content

Commit

Permalink
and and or merges
Browse files Browse the repository at this point in the history
  • Loading branch information
tombaeyens committed Jul 3, 2015
1 parent 9787e33 commit ebb550e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
19 changes: 17 additions & 2 deletions effektif-mongo/src/main/java/com/effektif/mongo/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ public Query or(BasicDBList clauses) {
if (clauses==null || clauses.size()==0) {
return this;
}
query.append("$or", clauses);
if (query.containsField("$or")) {
BasicDBList andClauses = new BasicDBList();
andClauses.add(new BasicDBObject("$or", query.remove("$or")));
andClauses.add(new BasicDBObject("$or", clauses));
and(andClauses);
} else if (query.containsField("$and")) {
BasicDBList andClauses = (BasicDBList) query.get("$and");
andClauses.add(clauses);
} else {
query.append("$or", clauses);
}
return this;
}

Expand Down Expand Up @@ -185,7 +195,12 @@ public Query and(BasicDBList clauses) {
if (clauses==null || clauses.size()==0) {
return this;
}
query.append("$and", clauses);
if (query.containsField("$and")) {
BasicDBList existingAndClauses = (BasicDBList) query.get("$and");
existingAndClauses.add(clauses);
} else {
query.append("$and", clauses);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An API for serialising values to JSON.
*
* @author Tom Baeyens
*/
public abstract class JsonWriter {

private static final Logger log = LoggerFactory.getLogger(JsonWriter.class);
// private static final Logger log = LoggerFactory.getLogger(JsonWriter.class);

Mappings mappings;
List<Object> loopCheckBeans = new ArrayList<>();
Expand All @@ -53,7 +50,7 @@ public void writeObject(Object o) {
if (o!=null) {
Class<?> clazz = o.getClass();
JsonTypeMapper jsonTypeMapper = mappings.getTypeMapper(clazz);
log.debug("using type mapper "+jsonTypeMapper.getClass().getSimpleName()+" to write object "+o+" ("+o.getClass().getSimpleName()+")");
// log.debug("using type mapper "+jsonTypeMapper.getClass().getSimpleName()+" to write object "+o+" ("+o.getClass().getSimpleName()+")");
jsonTypeMapper.write(o, this);
} else {
writeNull();
Expand Down

0 comments on commit ebb550e

Please sign in to comment.