Package com.github.jmkgreen.morphia.mapping

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


    @Override
    protected void check(MappedClass mc, MappedField mf, Set<ConstraintViolation> ve) {
        if (mf.hasAnnotation(Reference.class)) {
            Class realType = (mf.isSingleValue()) ? mf.getType() : mf.getSubClass();

            if (realType == null) throw new MappingException("Type is null for this MappedField: " + mf);

            if ((!realType.isInterface() && mc.getMapper().getMappedClass(realType).getIdField() == null))
                ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), mf.getFullName() + " is annotated as a @"
                        + Reference.class.getSimpleName() + " but the " + mf.getType().getName()
                        + " class is missing the @" + Id.class.getSimpleName() + " annotation"));
View Full Code Here


                } else {
                    if (paramType instanceof TypeVariable) {
                        // TODO: Figure out what to do... Walk back up the to
                        // the parent class and try to get the variable type
                        // from the T/V/X
                        throw new MappingException("Generic Typed Class not supported:  <" + ((TypeVariable) paramType).getName() + "> = "
                                + ((TypeVariable) paramType).getBounds()[0]);
                    } else if (paramType instanceof Class) {
                        return (Class) paramType;
                    } else {
                        throw new MappingException("Unknown type... pretty bad... call for help, wave your hands... yeah!");
                    }
                }
            }
        }
        return null;
View Full Code Here

//            throw new MappingException("Generic Typed Class not supported:  <" + ((TypeVariable) paramType).getName() + "> = " + ((TypeVariable) paramType).getBounds()[0]);
                        return paramType;
                    } else if (paramType instanceof Class) {
                        return (Class) paramType;
                    } else {
                        throw new MappingException("Unknown type... pretty bad... call for help, wave your hands... yeah!");
                    }
                }
            }
        }
        return null;
View Full Code Here

        String l = fromDBObject.toString();
        try {
            return Class.forName(l);
        } catch (ClassNotFoundException e) {
            throw new MappingException("Cannot create class from Name '" + l + "'", e);
        }
    }
View Full Code Here

            TypeConverter enc = getEncoder(mf);
            Object decodedValue = enc.decode(mf.getType(), object, mf);
            try {
                mf.setFieldValue(targetEntity, decodedValue);
            } catch (IllegalArgumentException e) {
                throw new MappingException("Error setting value from converter (" +
                        enc.getClass().getSimpleName() + ") for " + mf.getFullName() + " to " + decodedValue);
            }
        }
    }
View Full Code Here

    @Override
    public Object decode(Class targetClass, Object fromDBObject, MappedField f) throws MappingException {
        if (fromDBObject == null) return null;

        if (!((fromDBObject instanceof Binary) || (fromDBObject instanceof byte[]))) {
            throw new MappingException("The stored data is not a DBBinary or byte[] instance for " + f.getFullName()
                    + " ; it is a " + fromDBObject.getClass().getName());
        }

        try {
            boolean useCompression = !f.getAnnotation(Serialized.class).disableCompression();
            return Serializer.deserialize(fromDBObject, useCompression);
        } catch (IOException e) {
            throw new MappingException("While deserializing to " + f.getFullName(), e);
        } catch (ClassNotFoundException e) {
            throw new MappingException("While deserializing to " + f.getFullName(), e);
        }
    }
View Full Code Here

                    }
                }
            }
            return this;
        } catch (IOException ioex) {
            throw new MappingException("Could not get map classes from package " + packageName, ioex);
        } catch (ClassNotFoundException cnfex) {
            throw new MappingException("Could not get map classes from package " + packageName, cnfex);
        }
    }
View Full Code Here

     * @throws MappingException
     * @see Mapper#fromDBObject(Class, com.mongodb.DBObject, com.github.jmkgreen.morphia.mapping.cache.EntityCache)
     */
    public <T> T fromDBObject(Class<T> entityClass, DBObject dbObject, EntityCache cache) {
        if (!entityClass.isInterface() && !mapper.isMapped(entityClass)) {
            throw new MappingException("Trying to map to an unmapped class: " + entityClass.getName());
        }
        try {
            return (T) mapper.fromDBObject(entityClass, dbObject, cache);
        } catch (Exception e) {
            throw new MappingException("Could not map entity from DBObject", e);
        }
    }
View Full Code Here

     */
    public DBObject toDBObject(Object entity) {
        try {
            return mapper.toDBObject(entity);
        } catch (Exception e) {
            throw new MappingException("Could not map entity to DBObject", e);
        }
    }
View Full Code Here

     * @param <V>
     * @return
     */
    public <T, V> DBRef createRef(Class<T> clazz, V id) {
        if (id == null)
            throw new MappingException("Could not get id for " + clazz.getName());
        return new DBRef(getDB(), getCollection(clazz).getName(), id);
    }
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.