Package org.mongodb.morphia.mapping.validation

Examples of org.mongodb.morphia.mapping.validation.ConstraintViolation


*/
public class EmbeddedAndId implements ClassConstraint {

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


public class EmbeddedAndValue implements ClassConstraint {

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

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

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

public class MultipleVersions implements ClassConstraint {

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

public class EntityAndEmbed implements ClassConstraint {

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

    if (mc.getEntityAnnotation() != null && mc.getEmbeddedAnnotation() != null) {
      new ConstraintViolation(Level.FATAL, mc, 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(final MappedClass mc, final Set<ConstraintViolation> ve) {
    if (mc.getIdField() == null && mc.getEmbeddedAnnotation() == null) {
      ve.add(new ConstraintViolation(Level.FATAL, mc, getClass(), "No field is annotated with @Id; but it is required"));
    }
  }
View Full Code Here

  public void check(final MappedClass mc, final Set<ConstraintViolation> ve) {
    final Set<String> foundNames = new HashSet<String>();
    for (final MappedField mappedField : mc.getPersistenceFields()) {
      for (final String name : mappedField.getLoadNames()) {
        if (!foundNames.add(name)) {
          ve.add(new ConstraintViolation(Level.FATAL, mc, mappedField, getClass(),
            "Mapping to MongoDB field name '" + name + "' is duplicated; you cannot map different java fields to the same MongoDB field."));
        }
      }
    }
  }
View Full Code Here

public class EntityCannotBeMapOrIterable implements ClassConstraint {

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

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

  }
View Full Code Here

TOP

Related Classes of org.mongodb.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.