Package com.github.jmkgreen.morphia.mapping

Examples of com.github.jmkgreen.morphia.mapping.MappedClass


    private <T> Iterable<Key<T>> insert(DBCollection dbColl, Iterable<T> entities, WriteConcern wc) {
        ArrayList<DBObject> ents = entities instanceof List ? new ArrayList<DBObject>(((List<T>) entities).size()) : new ArrayList<DBObject>();

        Map<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>();
        for (T ent : entities) {
            MappedClass mc = mapr.getMappedClass(ent);
            if (mc.getAnnotation(NotSaved.class) != null)
                throw new MappingException("Entity type: " + mc.getClazz().getName() + " is marked as NotSaved which means you should not try to save it!");
            ents.add(entityToDBObj(ent, involvedObjects));
        }

        WriteResult wr = null;
View Full Code Here


     * @param wc
     * @param <T>
     * @return
     */
    protected <T> Key<T> save(DBCollection dbColl, T entity, WriteConcern wc) {
        MappedClass mc = mapr.getMappedClass(entity);
        if (mc.getAnnotation(NotSaved.class) != null)
            throw new MappingException("Entity type: " + mc.getClazz().getName() + " is marked as NotSaved which means you should not try to save it!");

        WriteResult wr = null;

        //involvedObjects is used not only as a cache but also as a list of what needs to be called for life-cycle methods at the end.
        LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>();
        DBObject dbObj = entityToDBObj(entity, involvedObjects);

        //try to do an update if there is a @Version field
        if (mc.hasVersioning()) {
            wr = tryVersionedUpdate(dbColl, entity, dbObj, wc, db, mc);
        } else {
            if (wc == null)
                wr = dbColl.save(dbObj);
            else
View Full Code Here

     */
    public <T> UpdateResults<T> update(T ent, UpdateOperations<T> ops) {
        if (ent instanceof Query)
            return update((Query<T>) ent, ops);

        MappedClass mc = mapr.getMappedClass(ent);
        Query<T> q = (Query<T>) createQuery(mc.getClazz());
        q.disableValidation().filter(Mapper.ID_KEY, mapr.getId(ent));

        if (mc.getFieldsAnnotatedWith(Version.class).size() > 0) {
            MappedField versionMF = mc.getFieldsAnnotatedWith(Version.class).get(0);
            Long oldVer = (Long) versionMF.getFieldValue(ent);
            q.filter(versionMF.getNameToStore(), oldVer);
            ops.set(versionMF.getNameToStore(), VersionHelper.nextValue(oldVer));
        }

View Full Code Here

        //remove (immutable) _id field for update.
        dbObj.removeField(Mapper.ID_KEY);

        WriteResult wr = null;

        MappedClass mc = mapr.getMappedClass(entity);
        DBCollection dbColl = getCollection(entity);

        //try to do an update if there is a @Version field
        if (mc.hasVersioning()) {
            wr = tryVersionedUpdate(dbColl, entity, dbObj, wc, db, mc);
        } else {
            Query<T> query = (Query<T>) createQuery(entity.getClass()).filter(Mapper.ID_KEY, id);
            wr = update(query, new BasicDBObject("$set", dbObj), false, false, wc).getWriteResult();
        }
View Full Code Here

        //call PostPersist on all involved entities (including the entity)
        for (Map.Entry<Object, DBObject> e : involvedObjects.entrySet()) {
            Object ent = e.getKey();
            DBObject dbO = e.getValue();
            MappedClass mc = mapr.getMappedClass(ent);
            mc.callLifecycleMethods(PostPersist.class, ent, dbO, mapr);
        }
    }
View Full Code Here

TOP

Related Classes of com.github.jmkgreen.morphia.mapping.MappedClass

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.