Package com.github.jmkgreen.morphia.mapping

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


     */
    public <T> DBRef createRef(T entity) {
        entity = ProxyHelper.unwrap(entity);
        Object id = mapr.getId(entity);
        if (id == null)
            throw new MappingException("Could not get id for " + entity.getClass().getName());
        return createRef(entity.getClass(), id);
    }
View Full Code Here


     * @return
     */
    public <T> WriteResult delete(T entity, WriteConcern wc) {
        entity = ProxyHelper.unwrap(entity);
        if (entity instanceof Class<?>)
            throw new MappingException("Did you mean to delete all documents? -- delete(ds.createQuery(???.class))");
        try {
            Object id = mapr.getId(entity);
            return delete(entity.getClass(), id, wc);

        } catch (Exception e) {
View Full Code Here

     */
    public <T> T get(T entity) {
        entity = ProxyHelper.unwrap(entity);
        Object id = mapr.getId(entity);
        if (id == null)
            throw new MappingException("Could not get id for " + entity.getClass().getName());
        return (T) get(entity.getClass(), id);
    }
View Full Code Here

    public Key<?> exists(Object entityOrKey) {
        entityOrKey = ProxyHelper.unwrap(entityOrKey);
        Key<?> key = mapr.getKey(entityOrKey);
        Object id = key.getId();
        if (id == null)
            throw new MappingException("Could not get id for " + entityOrKey.getClass().getName());

        String collName = key.getKind();
        if (collName == null)
            collName = getCollection(key.getKindClass()).getName();
View Full Code Here

        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

    /**
     * call postSaveOperations and returns Key for entity.
     */
    protected <T> Key<T> postSaveGetKey(T entity, DBObject dbObj, DBCollection dbColl, Map<Object, DBObject> involvedObjects) {
        if (dbObj.get(Mapper.ID_KEY) == null)
            throw new MappingException("Missing _id after save!");

        postSaveOperations(entity, dbObj, involvedObjects);
        Key<T> key = new Key<T>(dbColl.getName(), mapr.getId(entity));
        key.setKindClass((Class<? extends T>) entity.getClass());

View Full Code Here

     * @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>();
View Full Code Here

        DBObject dbObj = mapr.toDBObject(entity, involvedObjects);
        Key<T> key = mapr.getKey(entity);
        entity = ProxyHelper.unwrap(entity);
        Object id = mapr.getId(entity);
        if (id == null)
            throw new MappingException("Could not get id for " + entity.getClass().getName());

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

        WriteResult wr = null;
View Full Code Here

TOP

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

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.