mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Fix isNotEmpty bug in mongodb serialization
This commit is contained in:
parent
41c2c02eee
commit
fbf2d23c62
@ -127,6 +127,11 @@ public abstract class MongodbSerializer implements Visitor<Object, Void> {
|
||||
if (subOp == Ops.IN) {
|
||||
return visit(OperationImpl.create(Boolean.class, Ops.NOT_IN, subOperation.getArg(0),
|
||||
subOperation.getArg(1)), context);
|
||||
} else if (subOp == Ops.COL_IS_EMPTY) {
|
||||
DBObject visit = (DBObject)visit(OperationImpl.create(Boolean.class, Ops.COL_IS_EMPTY, subOperation.getArg(0)), context);
|
||||
Object existingOperator = visit.removeField("$or");
|
||||
visit.put("$nor", existingOperator);
|
||||
return visit;
|
||||
} else if (subOp != Ops.EQ && subOp != Ops.STRING_IS_EMPTY) {
|
||||
return asDBObject(key, asDBObject("$not", arg.get(key)));
|
||||
} else {
|
||||
@ -309,4 +314,4 @@ public abstract class MongodbSerializer implements Visitor<Object, Void> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,6 +97,26 @@ public class MongodbSerializerTest {
|
||||
assertQuery(user.addresses.any().street.eq("Aakatu"), dbo("addresses.street","Aakatu"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void CollectionIsEmpty() {
|
||||
BasicDBObject expected = dbo("$or",
|
||||
dblist(
|
||||
dbo("addresses", dblist()),
|
||||
dbo("addresses",
|
||||
dbo("$exists", false))));
|
||||
assertQuery(QUser.user.addresses.isEmpty(), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void CollectionIsNotEmpty() {
|
||||
BasicDBObject expected = dbo("$nor",
|
||||
dblist(
|
||||
dbo("addresses", dblist()),
|
||||
dbo("addresses",
|
||||
dbo("$exists", false))));
|
||||
assertQuery(QUser.user.addresses.isNotEmpty(), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Equals() {
|
||||
assertQuery(title.eq("A"), dbo("title","A"));
|
||||
@ -131,7 +151,6 @@ public class MongodbSerializerTest {
|
||||
|
||||
@Test
|
||||
public void Between() {
|
||||
System.err.println(dbo("year", dbo("$gte", 1).append("$lte", 10)));
|
||||
assertQuery(year.between(1, 10), dbo("year", dbo("$gte", 1).append("$lte", 10)));
|
||||
}
|
||||
|
||||
@ -161,6 +180,12 @@ public class MongodbSerializerTest {
|
||||
assertQuery(year.in(1,2,3), dbo("year", dbo("$in", 1,2,3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void NotIn() {
|
||||
assertQuery(year.in(1,2,3).not(), dbo("year", dbo("$nin", 1,2,3)));
|
||||
assertQuery(year.notIn(1,2,3), dbo("year", dbo("$nin", 1,2,3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void OrderBy() {
|
||||
DBObject orderBy = serializer.toSort(sortList(year.asc()));
|
||||
@ -242,7 +267,6 @@ public class MongodbSerializerTest {
|
||||
}
|
||||
return new BasicDBObject(key, value);
|
||||
}
|
||||
|
||||
public static BasicDBList dblist(Object... contents) {
|
||||
BasicDBList list = new BasicDBList();
|
||||
list.addAll(Arrays.asList(contents));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user