Package org.mongodb.morphia.mapping.cache

Examples of org.mongodb.morphia.mapping.cache.DefaultEntityCache


    private final EntityCache cache;

    private final Datastore datastore;

    public MorphiaQuery(Morphia morphia, Datastore datastore, EntityPath<K> entityPath) {
        this(morphia, datastore, new DefaultEntityCache(), entityPath);
    }
View Full Code Here


        User user = new User();
        user.id = 1;

        user.userObject = "just a String";
        DBObject dbObject = mapper.toDBObject(user);
        Object object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());
        Assert.assertEquals(user.userObject, ((User) object).userObject);
       
        user.userObject = 33;
        dbObject = mapper.toDBObject(user);
        object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());
        Assert.assertEquals(user.userObject, ((User) object).userObject);

        user.userObject = 33.3;
        dbObject = mapper.toDBObject(user);
        object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());
        Assert.assertEquals(user.userObject, ((User) object).userObject);
    }
View Full Code Here

        user.id = 1;
        user.userObject = new SerializableObject();

        // when
        DBObject dbObject = mapper.toDBObject(user);
        User object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());

        // then
        assertThat(object.userObject, is(user.userObject));
    }
View Full Code Here

        cRef.rect = new DBRef(getDb(), (String) rDbObject.get("_ns"), rDbObject.get("_id"));
        final DBObject cRefDbObject = getMorphia().toDBObject(cRef);
        stuff.save(cRefDbObject);
        final BasicDBObject cRefDbObjectLoaded = (BasicDBObject) stuff.findOne(BasicDBObjectBuilder.start("_id", cRefDbObject.get("_id"))
                                                                                                   .get());
        final ContainsRef cRefLoaded = getMorphia().fromDBObject(ContainsRef.class, cRefDbObjectLoaded, new DefaultEntityCache());
        assertNotNull(cRefLoaded);
        assertNotNull(cRefLoaded.rect);
        assertNotNull(cRefLoaded.rect.getId());
        assertNotNull(cRefLoaded.rect.getRef());
        assertEquals(cRefLoaded.rect.getId(), cRef.rect.getId());
View Full Code Here

        assertTrue(!(((DBObject) ((List) hotelDbObj.get("phoneNumbers")).get(0)).containsField(Mapper.CLASS_NAME_FIELDNAME)));


        hotels.save(hotelDbObj);

        Hotel borgLoaded = getMorphia().fromDBObject(Hotel.class, hotelDbObj, new DefaultEntityCache());

        assertEquals(borg.getName(), borgLoaded.getName());
        assertEquals(borg.getStars(), borgLoaded.getStars());
        assertEquals(borg.getStartDate(), borgLoaded.getStartDate());
        assertEquals(borg.getType(), borgLoaded.getType());
        assertEquals(borg.getAddress().getStreet(), borgLoaded.getAddress().getStreet());
        assertEquals(borg.getTags().size(), borgLoaded.getTags().size());
        assertEquals(borg.getTags(), borgLoaded.getTags());
        assertEquals(borg.getPhoneNumbers().size(), borgLoaded.getPhoneNumbers().size());
        assertEquals(borg.getPhoneNumbers().get(1), borgLoaded.getPhoneNumbers().get(1));
        assertNull(borgLoaded.getTemp());
        assertTrue(borgLoaded.getPhoneNumbers() instanceof Vector);
        assertNotNull(borgLoaded.getId());

        final TravelAgency agency = new TravelAgency();
        agency.setName("Lastminute.com");
        agency.getHotels().add(borgLoaded);

        final BasicDBObject agencyDbObj = (BasicDBObject) getMorphia().toDBObject(agency);
        agencies.save(agencyDbObj);

        final TravelAgency agencyLoaded = getMorphia().fromDBObject(TravelAgency.class,
                                                                    agencies.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                       agencyDbObj.get(Mapper.ID_KEY))),
                                                                    new DefaultEntityCache());

        assertEquals(agency.getName(), agencyLoaded.getName());
        assertEquals(1, agency.getHotels().size());
        assertEquals(agency.getHotels().get(0).getName(), borg.getName());

        // try clearing values
        borgLoaded.setAddress(null);
        borgLoaded.getPhoneNumbers().clear();
        borgLoaded.setName(null);

        hotelDbObj = (BasicDBObject) getMorphia().toDBObject(borgLoaded);
        hotels.save(hotelDbObj);

        hotelDbObj = (BasicDBObject) hotels.findOne(new BasicDBObject(Mapper.ID_KEY, hotelDbObj.get(Mapper.ID_KEY)));

        borgLoaded = getMorphia().fromDBObject(Hotel.class, hotelDbObj, new DefaultEntityCache());
        assertNull(borgLoaded.getAddress());
        assertEquals(0, borgLoaded.getPhoneNumbers().size());
        assertNull(borgLoaded.getName());
    }
View Full Code Here

        articles.save(relatedDbObj);

        final Article relatedLoaded = getMorphia().fromDBObject(Article.class,
                                                                articles.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                   relatedDbObj.get(Mapper.ID_KEY))),
                                                                new DefaultEntityCache());

        final Article article = new Article();
        article.setTranslation("en", new Translation("Hello World", "Just a test"));
        article.setTranslation("is", new Translation("Halló heimur", "Bara aĆ° prófa"));

        article.setAttribute("myDate", new Date());
        article.setAttribute("myString", "Test");
        article.setAttribute("myInt", 123);

        article.putRelated("test", relatedLoaded);

        final BasicDBObject articleDbObj = (BasicDBObject) getMorphia().toDBObject(article);
        articles.save(articleDbObj);

        final Article articleLoaded = getMorphia().fromDBObject(Article.class,
                                                                articles.findOne(
                                                                                    new BasicDBObject(Mapper.ID_KEY,
                                                                                                      articleDbObj.get(Mapper.ID_KEY))),
                                                                new DefaultEntityCache());

        assertEquals(article.getTranslations().size(), articleLoaded.getTranslations().size());
        assertEquals(article.getTranslation("en").getTitle(), articleLoaded.getTranslation("en").getTitle());
        assertEquals(article.getTranslation("is").getBody(), articleLoaded.getTranslation("is").getBody());
        assertEquals(article.getAttributes().size(), articleLoaded.getAttributes().size());
View Full Code Here

        stuff.save(childDbObj);

        final RecursiveParent parentLoaded = getMorphia().fromDBObject(RecursiveParent.class,
                                                                       stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                       parentDbObj.get(Mapper.ID_KEY))),
                                                                       new DefaultEntityCache());
        final RecursiveChild childLoaded = getMorphia().fromDBObject(RecursiveChild.class,
                                                                     stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                     childDbObj.get(Mapper.ID_KEY))),
                                                                     new DefaultEntityCache());

        parentLoaded.setChild(childLoaded);
        childLoaded.setParent(parentLoaded);

        stuff.save(getMorphia().toDBObject(parentLoaded));
        stuff.save(getMorphia().toDBObject(childLoaded));

        final RecursiveParent finalParentLoaded = getMorphia().fromDBObject(RecursiveParent.class,
                                                                            stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                            parentDbObj.get(Mapper
                                                                                                                                .ID_KEY))),
                                                                            new DefaultEntityCache());
        final RecursiveChild finalChildLoaded = getMorphia().fromDBObject(RecursiveChild.class,
                                                                          stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                          childDbObj.get(Mapper.ID_KEY))),
                                                                          new DefaultEntityCache());

        assertNotNull(finalParentLoaded.getChild());
        assertNotNull(finalChildLoaded.getParent());
    }
View Full Code Here

        final long start = System.nanoTime();
        final List<DBObject> list = getDs().getDB().getCollection("Address")
                                        .find()
                                        .sort(new BasicDBObject("name", 1))
                                        .toArray();
        final EntityCache entityCache = new DefaultEntityCache();
        final List<Address> resultList = new LinkedList<Address>();
        for (final DBObject dbObject : list) {
            final Address address = getMorphia().fromDBObject(Address.class, dbObject, entityCache);
            resultList.add(address);
        }
View Full Code Here

    public DefaultConverters getConverters() {
        return converters;
    }

    public EntityCache createEntityCache() {
        return new DefaultEntityCache();
    }
View Full Code Here

        final DBObject rectangleDbObj = getMorphia().toDBObject(rectangle);
        shapes.save(rectangleDbObj);

        final BasicDBObject rectangleDbObjLoaded = (BasicDBObject) shapes.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                    rectangleDbObj.get(Mapper.ID_KEY)));
        final Shape rectangleLoaded = getMorphia().fromDBObject(Shape.class, rectangleDbObjLoaded, new DefaultEntityCache());

        assertTrue(rectangle.getArea() == rectangleLoaded.getArea());
        assertTrue(rectangleLoaded instanceof Rectangle);

        final ShapeShifter shifter = new ShapeShifter();
        shifter.setReferencedShape(rectangleLoaded);
        shifter.setMainShape(new Circle(2.2));
        shifter.getAvailableShapes().add(new Rectangle(3, 3));
        shifter.getAvailableShapes().add(new Circle(4.4));

        final DBObject shifterDbObj = getMorphia().toDBObject(shifter);
        shapeshifters.save(shifterDbObj);

        final BasicDBObject shifterDbObjLoaded = (BasicDBObject) shapeshifters.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                         shifterDbObj.get(Mapper.ID_KEY)));
        final ShapeShifter shifterLoaded = getMorphia().fromDBObject(ShapeShifter.class, shifterDbObjLoaded, new DefaultEntityCache());

        assertNotNull(shifterLoaded);
        assertNotNull(shifterLoaded.getReferencedShape());
        assertNotNull(shifterLoaded.getReferencedShape().getArea());
        assertNotNull(rectangle);
View Full Code Here

TOP

Related Classes of org.mongodb.morphia.mapping.cache.DefaultEntityCache

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.