Search in sources :

Example 1 with CustomId

use of org.mongodb.morphia.TestMapper.CustomId in project morphia by mongodb.

the class TestQuery method testComplexIdQuery.

@Test
public void testComplexIdQuery() {
    final CustomId cId = new CustomId();
    cId.setId(new ObjectId());
    cId.setType("banker");
    final UsesCustomIdObject object = new UsesCustomIdObject();
    object.setId(cId);
    object.setText("hllo");
    getDs().save(object);
    assertNotNull(getDs().find(UsesCustomIdObject.class).filter("_id.type", "banker").get());
    assertNotNull(getDs().find(UsesCustomIdObject.class).field("_id").hasAnyOf(singletonList(cId)).get());
}
Also used : ObjectId(org.bson.types.ObjectId) CustomId(org.mongodb.morphia.TestMapper.CustomId) UsesCustomIdObject(org.mongodb.morphia.TestMapper.UsesCustomIdObject) Test(org.junit.Test)

Example 2 with CustomId

use of org.mongodb.morphia.TestMapper.CustomId in project morphia by mongodb.

the class TestQuery method testComplexIdQueryWithRenamedField.

@Test
public void testComplexIdQueryWithRenamedField() {
    final CustomId cId = new CustomId();
    cId.setId(new ObjectId());
    cId.setType("banker");
    final UsesCustomIdObject object = new UsesCustomIdObject();
    object.setId(cId);
    object.setText("hllo");
    getDs().save(object);
    assertNotNull(getDs().find(UsesCustomIdObject.class).filter("_id.t", "banker").get());
}
Also used : ObjectId(org.bson.types.ObjectId) CustomId(org.mongodb.morphia.TestMapper.CustomId) UsesCustomIdObject(org.mongodb.morphia.TestMapper.UsesCustomIdObject) Test(org.junit.Test)

Example 3 with CustomId

use of org.mongodb.morphia.TestMapper.CustomId in project morphia by mongodb.

the class TestQuery method testQBE.

@Test
public void testQBE() {
    final CustomId cId = new CustomId();
    cId.setId(new ObjectId());
    cId.setType("banker");
    final UsesCustomIdObject object = new UsesCustomIdObject();
    object.setId(cId);
    object.setText("hllo");
    getDs().save(object);
    final UsesCustomIdObject loaded;
    // Add back if/when query by example for embedded fields is supported (require dotting each field).
    // CustomId exId = new CustomId();
    // exId.type = cId.type;
    // loaded = getDs().find(UsesCustomIdObject.class, "_id", exId).get();
    // assertNotNull(loaded);
    final UsesCustomIdObject ex = new UsesCustomIdObject();
    ex.setText(object.getText());
    loaded = getDs().queryByExample(ex).get();
    assertNotNull(loaded);
}
Also used : ObjectId(org.bson.types.ObjectId) CustomId(org.mongodb.morphia.TestMapper.CustomId) UsesCustomIdObject(org.mongodb.morphia.TestMapper.UsesCustomIdObject) Test(org.junit.Test)

Aggregations

ObjectId (org.bson.types.ObjectId)3 Test (org.junit.Test)3 CustomId (org.mongodb.morphia.TestMapper.CustomId)3 UsesCustomIdObject (org.mongodb.morphia.TestMapper.UsesCustomIdObject)3