Package com.github.jmkgreen.morphia.mapping.validation

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation


    }

    @Override
    protected final void check(MappedClass mc, MappedField mf, Set<ConstraintViolation> ve) {
        if (mf.hasAnnotation(a1) && mf.hasAnnotation(a2))
            ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), "A field can be either annotated with @"
                    + a1.getSimpleName() + " OR @" + a2.getSimpleName() + ", but not both."));
    }
View Full Code Here


    @Override
    protected void check(MappedClass mc, MappedField mf, Set<ConstraintViolation> ve) {
        if (mf.isMap() && (!mf.hasAnnotation(Serialized.class))) {
            Class<?> parameterizedClass = ReflectionUtils.getParameterizedClass(mf.getField(), 0);
            if (parameterizedClass == null) {
                ve.add(new ConstraintViolation(Level.WARNING, mc, mf, this.getClass(),
                        "Maps cannot be keyed by Object (Map<Object,?>); Use a parametrized type that is supported " + supportedExample));
            } else if (!parameterizedClass.equals(String.class) && !parameterizedClass.equals(ObjectId.class) && !ReflectionUtils.isPrimitiveLike(parameterizedClass))
                ve
                        .add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(),
                                "Maps must be keyed by a simple type " + supportedExample + "; " + parameterizedClass + " is not supported as a map key type."));
        }
    }
View Full Code Here

    protected void check(MappedClass mc, MappedField mf, Set<ConstraintViolation> ve) {
        // a field can be a Value, Reference, or Embedded
        if (mf.hasAnnotation(Property.class)) {
            // make sure that the property type is supported
            if (mf.isSingleValue() && !mf.isTypeMongoCompatible() && !mc.getMapper().getConverters().hasSimpleValueConverter(mf)) {
                ve.add(new ConstraintViolation(Level.WARNING, mc, mf, this.getClass(), mf.getFullName() + " is annotated as @"
                        + Property.class.getSimpleName() + " but is a type that cannot be mapped simply (type is "
                        + mf.getType().getName() + ")."));
            }
        }
    }
View Full Code Here

                Object testInstance = DefaultCreator.createInst(mc.getClazz());

                // check initial value
                if (Long.class.equals(type)) {
                    if (mf.getFieldValue(testInstance) != null)
                        ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), "When using @" + Version.class.getSimpleName()
                                + " on a Long field, it must be initialized to null."));
                } else if (long.class.equals(type)) {
                    if ((Long) mf.getFieldValue(testInstance) != 0L)
                        ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), "When using @" + Version.class.getSimpleName()
                                + " on a long field, it must be initialized to 0."));
                }
            } else
                ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), "@" + Version.class.getSimpleName() + " can only be used on a Long/long field."));
        }
    }
View Full Code Here

    protected void check(MappedClass mc, MappedField mf, Set<ConstraintViolation> ve) {
        Reference ref = mf.getAnnotation(Reference.class);
        if (ref != null) {
            if (ref.lazy()) {
                if (!LazyFeatureDependencies.testDependencyFullFilled())
                    ve.add(new ConstraintViolation(Level.SEVERE, mc, mf, this.getClass(),
                            "Lazy references need CGLib and Proxytoys in the classpath."));
            }
        }
    }
View Full Code Here

    protected void check(MappedClass mc, MappedField mf, Set<ConstraintViolation> ve) {
        Reference ref = mf.getAnnotation(Reference.class);
        if (ref != null && ref.lazy()) {
            Class type = mf.getType();
            if (type.isArray())
                ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(),
                        "The lazy attribute cannot be used for an Array. If you need a lazy array please use ArrayList instead."));
        }
    }
View Full Code Here

            if (mf.hasAnnotation(Serialized.class)) {
                Class<?> keyClass = ReflectionUtils.getParameterizedClass(mf.getField(), 0);
                Class<?> valueClass = ReflectionUtils.getParameterizedClass(mf.getField(), 1);
                if (keyClass != null) {
                    if (!Serializable.class.isAssignableFrom(keyClass))
                        ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), "Key class (" + keyClass.getName()
                                + ") is not Serializable"));
                }
                if (valueClass != null) {
                    if (!Serializable.class.isAssignableFrom(keyClass))
                        ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), "Value class (" + valueClass.getName()
                                + ") is not Serializable"));
                }
            }
        }
    }
View Full Code Here

    @Override
    protected void check(MappedClass mc, MappedField mf, Set<ConstraintViolation> ve) {
        // an @Id field can not be a Value, Reference, or Embedded
        if (mf.hasAnnotation(Id.class))
            if (mf.hasAnnotation(Reference.class) || mf.hasAnnotation(Embedded.class) || mf.hasAnnotation(Property.class))
                ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), mf.getFullName() + " is annotated as @"
                        + Id.class.getSimpleName() + " and cannot be mixed with other annotations (like @Reference)"));
    }
View Full Code Here

            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

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {

        List<MappedField> idFields = mc.getFieldsAnnotatedWith(Id.class, javax.persistence.Id.class);

        if (idFields.size() > 1) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "More than one @" + Id.class.getSimpleName()
                    + " Field found (" + new FieldEnumString(idFields)
                    + ")."));
        }
    }
View Full Code Here

TOP

Related Classes of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

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.