Search in sources :

Example 1 with QueryImpl

use of org.mongodb.morphia.query.QueryImpl in project morphia by mongodb.

the class EmbeddedReferenceType method testQueryFormat.

@Test
@SuppressWarnings("deprecation")
public void testQueryFormat() {
    Assume.assumeTrue("This test requires Java 8", JAVA_8);
    Query<ReferenceType> query = getDs().find(ReferenceType.class).field("id").equal(new ObjectId(0, 0, (short) 0, 0)).field("referenceType").equal(new ReferenceType(2, "far")).field("embeddedType").equal(new EmbeddedReferenceType(3, "strikes")).field("string").equal("some value").field("embeddedArray").elemMatch(getDs().find(EmbeddedReferenceType.class).filter("number", 3).filter("text", "strikes")).field("embeddedSet").elemMatch(getDs().find(EmbeddedReferenceType.class).filter("number", 3).filter("text", "strikes")).field("embeddedList").elemMatch(getDs().find(EmbeddedReferenceType.class).filter("number", 3).filter("text", "strikes")).field("map.bar").equal(new EmbeddedReferenceType(1, "chance")).field("mapOfList.bar").in(singletonList(new EmbeddedReferenceType(1, "chance"))).field("mapOfList.foo").elemMatch(getDs().find(EmbeddedReferenceType.class).filter("number", 1).filter("text", "chance")).field("selfReference").equal(new ReferenceType(1, "blah")).field("mixedTypeList").elemMatch(getDs().find(EmbeddedReferenceType.class).filter("number", 3).filter("text", "strikes")).field("mixedTypeList").in(singletonList(new EmbeddedReferenceType(1, "chance"))).field("mixedTypeMap.foo").equal(new ReferenceType(3, "strikes")).field("mixedTypeMap.bar").equal(new EmbeddedReferenceType(3, "strikes")).field("mixedTypeMapOfList.bar").in(singletonList(new EmbeddedReferenceType(1, "chance"))).field("mixedTypeMapOfList.foo").elemMatch(getDs().find(EmbeddedReferenceType.class).filter("number", 3).filter("text", "strikes")).field("referenceMap.foo").equal(new ReferenceType(1, "chance")).field("referenceMap.bar").equal(new EmbeddedReferenceType(1, "chance"));
    DBObject dbObject = ((QueryImpl) query).getQueryObject();
    Assert.assertEquals(BasicDBObject.parse(readFully("/QueryStructure.json")), dbObject);
}
Also used : QueryImpl(org.mongodb.morphia.query.QueryImpl) ObjectId(org.bson.types.ObjectId) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 ObjectId (org.bson.types.ObjectId)1 Test (org.junit.Test)1 QueryImpl (org.mongodb.morphia.query.QueryImpl)1