Package org.mongodb.morphia

Examples of org.mongodb.morphia.Datastore


    public void testMin() {
        final IndexedEntity a = new IndexedEntity("a");
        final IndexedEntity b = new IndexedEntity("b");
        final IndexedEntity c = new IndexedEntity("c");

        Datastore ds = getDs();

        ds.save(a);
        ds.save(b);
        ds.save(c);

        Assert.assertEquals("last", b.id, ds.createQuery(IndexedEntity.class).order("id")
                                            .lowerIndexBound(new BasicDBObject("testField", "b")).get().id);
    }
View Full Code Here


        final IndexedEntity b1 = new IndexedEntity("b");
        final IndexedEntity b2 = new IndexedEntity("b");
        final IndexedEntity c1 = new IndexedEntity("c");
        final IndexedEntity c2 = new IndexedEntity("c");

        Datastore ds = getDs();

        ds.save(a1);
        ds.save(a2);
        ds.save(b1);
        ds.save(b2);
        ds.save(c1);
        ds.save(c2);

        Query<IndexedEntity> min = ds.createQuery(IndexedEntity.class).order("testField, id")
                                     .lowerIndexBound(new BasicDBObject("testField", "b").append("_id", b1.id));
        List<IndexedEntity> l = min.asList();

        Assert.assertEquals("size", 4, l.size());
        Assert.assertEquals("item", b1.id, l.get(0).id);
View Full Code Here

        }

        final DBRef dbRef = idOnly ? null : (DBRef) ref;
        final Key key = mapper.createKey(mf.isSingleValue() ? mf.getType() : mf.getSubClass(),
                                         idOnly ? ref : dbRef.getId());
        final Datastore ds = idOnly ? mapper.getDatastoreProvider().get() : null;

        final Object cached = cache.getEntity(key);
        if (cached != null) {
            return cached;
        }

        //TODO: if _db is null, set it?
        final DBObject refDbObject = idOnly ? ds.getCollection(key.getKindClass()).findOne(ref) : dbRef.fetch();

        if (refDbObject != null) {
            Object refObj = mapper.getOptions().getObjectFactory().createInstance(mapper, mf, refDbObject);
            refObj = mapper.fromDb(refDbObject, refObj, cache);
            cache.putEntity(key, refObj);
View Full Code Here

    @Test
    public void shouldNotCreateAnIndexWhenAnIndexedEntityIsMarkedAsNotSaved() {
        // given
        getMorphia().map(IndexOnValue.class, NoIndexes.class);
        Datastore ds = getDs();

        // when
        ds.ensureIndexes();
        ds.save(new IndexOnValue());
        ds.save(new NoIndexes());

        // then
        List<DBObject> indexes = getDb().getCollection("NoIndexes").getIndexInfo();
        assertEquals(1, indexes.size());
    }
View Full Code Here

TOP

Related Classes of org.mongodb.morphia.Datastore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.