Search in sources :

Example 1 with ContainsPic

use of dev.morphia.test.query.TestLegacyQuery.ContainsPic in project morphia by mongodb.

the class TestQueriesOnReferences method testQueryOverReference.

@Test
public void testQueryOverReference() {
    final ContainsPic cpk = new ContainsPic();
    final Pic p = new Pic();
    getDs().save(p);
    cpk.setPic(p);
    getDs().save(cpk);
    final Query<ContainsPic> query = getDs().find(ContainsPic.class);
    final ContainsPic object = query.filter(eq("pic", p)).iterator(new FindOptions().limit(1)).tryNext();
    assertNotNull(object);
}
Also used : FindOptions(dev.morphia.query.FindOptions) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) Pic(dev.morphia.test.query.TestLegacyQuery.Pic) Test(org.testng.annotations.Test)

Example 2 with ContainsPic

use of dev.morphia.test.query.TestLegacyQuery.ContainsPic in project morphia by mongodb.

the class TestQueriesOnReferences method testQueryOverLazyReference.

@Test
public void testQueryOverLazyReference() {
    final ContainsPic cpk = new ContainsPic();
    final Pic p = new Pic();
    getDs().save(p);
    final PicWithObjectId withObjectId = new PicWithObjectId();
    getDs().save(withObjectId);
    cpk.setLazyPic(p);
    cpk.setLazyObjectIdPic(withObjectId);
    getDs().save(cpk);
    Query<ContainsPic> query = getDs().find(ContainsPic.class);
    assertNotNull(query.filter(eq("lazyPic", p)).iterator(new FindOptions().limit(1)).tryNext());
    query = getDs().find(ContainsPic.class);
    assertNotNull(query.filter(eq("lazyObjectIdPic", withObjectId)).iterator(new FindOptions().limit(1)).tryNext());
}
Also used : FindOptions(dev.morphia.query.FindOptions) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) Pic(dev.morphia.test.query.TestLegacyQuery.Pic) PicWithObjectId(dev.morphia.test.query.TestLegacyQuery.PicWithObjectId) Test(org.testng.annotations.Test)

Example 3 with ContainsPic

use of dev.morphia.test.query.TestLegacyQuery.ContainsPic in project morphia by mongodb.

the class TestQueriesOnReferences method testMissingReferences.

@Test(expectedExceptions = ReferenceException.class)
public void testMissingReferences() {
    final ContainsPic cpk = new ContainsPic();
    final Pic p = new Pic();
    cpk.setPic(p);
    getDs().save(p);
    getDs().save(cpk);
    getDs().delete(p);
    getDs().find(ContainsPic.class).iterator().toList();
}
Also used : ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) Pic(dev.morphia.test.query.TestLegacyQuery.Pic) Test(org.testng.annotations.Test)

Example 4 with ContainsPic

use of dev.morphia.test.query.TestLegacyQuery.ContainsPic in project morphia by mongodb.

the class TestQueriesOnReferences method testKeyExists.

@Test
public void testKeyExists() {
    final ContainsPic cpk = new ContainsPic();
    final Pic p = new Pic();
    cpk.setPic(p);
    getDs().save(p);
    getDs().save(cpk);
    assertNotNull(getDs().find(ContainsPic.class).filter(exists("pic")).iterator(new FindOptions().projection().include("pic").limit(1)).tryNext());
    assertNull(getDs().find(ContainsPic.class).filter(exists("pic").not()).iterator(new FindOptions().projection().include("pic").limit(1)).tryNext());
}
Also used : FindOptions(dev.morphia.query.FindOptions) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) Pic(dev.morphia.test.query.TestLegacyQuery.Pic) Test(org.testng.annotations.Test)

Example 5 with ContainsPic

use of dev.morphia.test.query.TestLegacyQuery.ContainsPic in project morphia by mongodb.

the class TestQueriesOnReferences method testWithKeyQuery.

@Test
public void testWithKeyQuery() {
    final ContainsPic cpk = new ContainsPic();
    final Pic p = new Pic();
    cpk.setPic(p);
    getDs().save(p);
    getDs().save(cpk);
    Query<ContainsPic> query = getDs().find(ContainsPic.class).filter(eq("pic", new Key<>(Pic.class, "pic", p.getId())));
    assertEquals(query.first(new FindOptions().logQuery().limit(1)).getId(), cpk.getId(), query.getLoggedQuery());
}
Also used : FindOptions(dev.morphia.query.FindOptions) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) Pic(dev.morphia.test.query.TestLegacyQuery.Pic) Key(dev.morphia.Key) Test(org.testng.annotations.Test)

Aggregations

ContainsPic (dev.morphia.test.query.TestLegacyQuery.ContainsPic)6 Pic (dev.morphia.test.query.TestLegacyQuery.Pic)6 Test (org.testng.annotations.Test)6 FindOptions (dev.morphia.query.FindOptions)4 Key (dev.morphia.Key)1 PicWithObjectId (dev.morphia.test.query.TestLegacyQuery.PicWithObjectId)1