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

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


*/
public class EmbeddedAndId implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {
        if (mc.getEmbeddedAnnotation() != null && mc.getIdField() != null) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "@" + Embedded.class.getSimpleName()
                    + " classes cannot specify a @Id field"));
        }
    }
View Full Code Here


public class EmbeddedAndValue implements ClassConstraint {

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

        if (mc.getEmbeddedAnnotation() != null && !mc.getEmbeddedAnnotation().value().equals(Mapper.IGNORED_FIELDNAME)) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "@" + Embedded.class.getSimpleName()
                    + " classes cannot specify a fieldName value(); this is on applicable on fields"));
        }
    }
View Full Code Here

        for (Class<?> clazz : classesToInspect) {
            if (alreadyInspectedClasses.contains(clazz)) {
                continue;
            }
            if (hasTypeFieldAnnotation(clazz, Id.class) || hasTypeFieldAnnotation(clazz, javax.persistence.Id.class)) {
                ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(),
                        "You cannot use @Id on any field of an Embedded/Property object"));
            }
            alreadyInspectedClasses.add(clazz);
            Set<Class<?>> extraClassesToInspect = new HashSet<Class<?>>();
            for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(clazz, true)) {
View Full Code Here

public class MultipleVersions implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {
        List<MappedField> versionFields = mc.getFieldsAnnotatedWith(Version.class);
        if (versionFields.size() > 1)
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "Multiple @" + Version.class
                    + " annotations are not allowed. (" + new FieldEnumString(versionFields)));
    }
View Full Code Here

public class EntityAndEmbed implements ClassConstraint {

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

        if (mc.getEntityAnnotation() != null && mc.getEmbeddedAnnotation() != null) {
            new ConstraintViolation(Level.FATAL, mc, this.getClass(), "Cannot have both @" + Entity.class.getSimpleName() + " and @"
                    + Embedded.class.getSimpleName() + " annotation at class level.");
        }

    }
View Full Code Here

*/
public class NoId implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {
        if (mc.getIdField() == null && mc.getEmbeddedAnnotation() == null) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(),
                    "No field is annotated with @Id; but it is required"));
        }
    }
View Full Code Here

            for (String name : mappedField.getLoadNames()) {
//        if (duplicates.contains(name)) {
//          continue;
//        }
                if (!foundNames.add(name)) {
                    ve.add(new ConstraintViolation(Level.FATAL, mc, mappedField, this.getClass(), "Mapping to MongoDB field name '" + name
                            + "' is duplicated; you cannot map different java fields to the same MongoDB field."));
                    duplicates.add(name);
                }
            }
        }
View Full Code Here

public class EntityCannotBeMapOrIterable implements ClassConstraint {

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

        if (mc.getEntityAnnotation() != null && (Map.class.isAssignableFrom(mc.getClazz()) || Iterable.class.isAssignableFrom(mc.getClazz()))) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "Entities cannot implement Map/Iterable"));
        }

    }
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.