Package com.github.jmkgreen.morphia

Examples of com.github.jmkgreen.morphia.Key


            }
            MappedClass mappedClass = mapr.getMappedClass(entity);
            Object id = mappedClass.getIdField().get(entity);
            if (id == null)
                throw new MappingException("@Id field cannot be null!");
            Key key = new Key(mappedClass.getCollectionName(), id);
            return key;
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        }
    }
View Full Code Here


            mf.setFieldValue(entity, references);
        }
    }

    boolean exists(Class c, final DBRef dbRef, EntityCache cache, Mapper mapr) {
        Key key = mapr.refToKey(dbRef);
        Boolean cached = cache.exists(key);
        if (cached != null)
            return cached;

        Datastore dsi = mapr.getDatastoreProvider().get();
View Full Code Here

    Object resolveObject(final DBRef dbRef, final MappedField mf, EntityCache cache, Mapper mapr) {
        if (dbRef == null)
            return null;

        Key key = mapr.createKey(mf.isSingleValue() ? mf.getType() : mf.getSubClass(), dbRef.getId());

        Object cached = cache.getEntity(key);
        if (cached != null)
            return cached;
View Full Code Here

        }
        mf.setFieldValue(entity, m);
    }

    private Object createOrReuseProxy(final Class referenceObjClass, final DBRef dbRef, EntityCache cache, Mapper mapr) {
        Key key = mapr.refToKey(dbRef);
        Object proxyAlreadyCreated = cache.getProxy(key);
        if (proxyAlreadyCreated != null) {
            return proxyAlreadyCreated;
        }
        Object newProxy = mapr.getProxyFactory().createProxy(referenceObjClass, key, mapr.getDatastoreProvider());
View Full Code Here

        // check the history key (a key is the namespace + id)

        if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null
                && getMappedClass(entity).getEntityAnnotation() != null) {
            Key key = new Key(entity.getClass(), dbObject.get(ID_KEY));
            Object cachedInstance = cache.getEntity(key);
            if (cachedInstance != null)
                return cachedInstance;
            else
                cache.putEntity(key, entity); // to avoid stackOverflow in recursive refs
        }

        MappedClass mc = getMappedClass(entity);

        dbObject = (DBObject) mc.callLifecycleMethods(PreLoad.class, entity, dbObject, this);
        try {
            for (MappedField mf : mc.getMappedFields()) {
                readMappedField(dbObject, mf, entity, cache);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
            Key key = new Key(entity.getClass(), dbObject.get(ID_KEY));
            cache.putEntity(key, entity);
        }
        mc.callLifecycleMethods(PostLoad.class, entity, dbObject, this);
        return entity;
    }
View Full Code Here

TOP

Related Classes of com.github.jmkgreen.morphia.Key

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.