changed null handling to be compatible with Nullable cases

This commit is contained in:
Timo Westkämper 2010-09-22 14:49:01 +00:00
parent 0305cfc361
commit adc7917cc3
2 changed files with 11 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import java.util.List;
import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.google.code.morphia.mapping.cache.DefaultEntityCache;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
@ -37,6 +38,8 @@ import com.mysema.query.types.Predicate;
public class MongodbQuery<K> implements SimpleQuery<MongodbQuery<K>>,
SimpleProjectable<K> {
private static final MongodbSerializer serializer = new MongodbSerializer();
private final QueryMixin<MongodbQuery<K>> queryMixin;
private final EntityPath<K> ePath;
@ -47,8 +50,6 @@ public class MongodbQuery<K> implements SimpleQuery<MongodbQuery<K>>,
private final DBCollection coll;
private final MongodbSerializer serializer = new MongodbSerializer();
private final DefaultEntityCache cache = new DefaultEntityCache();
public MongodbQuery(Morphia morphiaParam, Datastore datastore,
@ -175,7 +176,12 @@ public class MongodbQuery<K> implements SimpleQuery<MongodbQuery<K>>,
private DBObject createQuery() {
QueryMetadata metadata = queryMixin.getMetadata();
return (DBObject) serializer.handle(metadata.getWhere());
if (metadata.getWhere() != null){
return (DBObject) serializer.handle(metadata.getWhere());
}else{
return new BasicDBObject();
}
}
@Override

View File

@ -23,8 +23,8 @@ import com.mysema.query.types.*;
*/
public class MongodbSerializer implements Visitor<Object, Void> {
public Object handle(Expression<?> where) {
return where != null ? where.accept(this, null) : new BasicDBObject();
public Object handle(Expression<?> expression) {
return expression.accept(this, null);
}
public DBObject toSort(List<OrderSpecifier<?>> orderBys) {