Package org.springframework.data.mapping.model

Examples of org.springframework.data.mapping.model.MappingException


    if (typeToUse.isMap()) {
      return (S) readMap(typeToUse, dbo, path);
    }

    if (dbo instanceof BasicDBList) {
      throw new MappingException(String.format(INCOMPATIBLE_TYPES, dbo, BasicDBList.class, typeToUse.getType(), path));
    }

    // Retrieve persistent entity info
    MongoPersistentEntity<S> persistentEntity = (MongoPersistentEntity<S>) mappingContext
        .getPersistentEntity(typeToUse);
    if (persistentEntity == null) {
      throw new MappingException("No mapping metadata found for " + rawType.getName());
    }

    return read(persistentEntity, dbo, path);
  }
View Full Code Here


    if (obj == null) {
      return;
    }

    if (null == entity) {
      throw new MappingException("No mapping metadata found for entity of type " + obj.getClass().getName());
    }

    final BeanWrapper<Object> wrapper = BeanWrapper.create(obj, conversionService);
    final MongoPersistentProperty idProperty = entity.getIdProperty();
View Full Code Here

        String simpleKey = potentiallyEscapeMapKey(key.toString());
        dbObject.put(simpleKey, value != null ? createDBRef(value, property) : null);

      } else {
        throw new MappingException("Cannot use a complex object as a key value.");
      }
    }

    return dbObject;
  }
View Full Code Here

              : ClassTypeInformation.OBJECT;
          writeInternal(val, newDbo, valueTypeInfo);
          dbo.put(simpleKey, newDbo);
        }
      } else {
        throw new MappingException("Cannot use a complex object as a key value.");
      }
    }

    return dbo;
  }
View Full Code Here

    if (!source.contains(".")) {
      return source;
    }

    if (mapKeyDotReplacement == null) {
      throw new MappingException(String.format("Map key %s contains dots but no replacement was configured! Make "
          + "sure map keys don't contain dots in the first place or configure an appropriate replacement!", source));
    }

    return source.replaceAll("\\.", mapKeyDotReplacement);
  }
View Full Code Here

    MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass());
    targetEntity = targetEntity == null ? targetEntity = mappingContext.getPersistentEntity(property) : targetEntity;

    if (null == targetEntity) {
      throw new MappingException("No mapping metadata found for " + target.getClass());
    }

    MongoPersistentProperty idProperty = targetEntity.getIdProperty();

    if (idProperty == null) {
      throw new MappingException("No id property found on class " + targetEntity.getType());
    }

    Object id = null;

    if (target.getClass().equals(idProperty.getType())) {
      id = target;
    } else {
      BeanWrapper<Object> wrapper = BeanWrapper.create(target, conversionService);
      id = wrapper.getProperty(idProperty, Object.class);
    }

    if (null == id) {
      throw new MappingException("Cannot create a reference to an object with a NULL id.");
    }

    return dbRefResolver.createDbRef(property == null ? null : property.getDBRef(), targetEntity,
        idMapper.convertId(id));
  }
View Full Code Here

            associationDetected = true;
            continue;
          }

          if (associationDetected && !property.isIdProperty()) {
            throw new MappingException(String.format(INVALID_ASSOCIATION_REFERENCE, pathExpression));
          }
        }

        return propertyPath;
      } catch (PropertyReferenceException e) {
View Full Code Here

    @SuppressWarnings("null")
    Field currentIdPropertyField = currentIdProperty.getField();

    if (newIdPropertyIsExplicit && currentIdPropertyIsExplicit) {
      throw new MappingException(String.format(
          "Attempt to add explicit id property %s but already have an property %s registered "
              + "as explicit id. Check your mapping configuration!", property.getField(), currentIdPropertyField));

    } else if (newIdPropertyIsExplicit && !currentIdPropertyIsExplicit) {
      // explicit id property takes precedence over implicit id property
      return property;

    } else if (!newIdPropertyIsExplicit && currentIdPropertyIsExplicit) {
      // no id property override - current property is explicitly defined

    } else {
      throw new MappingException(String.format(
          "Attempt to add id property %s but already have an property %s registered "
              + "as id. Check your mapping configuration!", property.getField(), currentIdPropertyField));
    }

    return null;
View Full Code Here

      String fieldName = property.getFieldName();
      MongoPersistentProperty existingProperty = properties.get(fieldName);

      if (existingProperty != null) {
        throw new MappingException(String.format(AMBIGUOUS_FIELD_MAPPING, property.toString(),
            existingProperty.toString(), fieldName));
      }

      properties.put(fieldName, property);
    }
View Full Code Here

        if (ClassUtils.isAssignable(potentialMatch, persistentProperty.getActualType())) {
          return;
        }
      }

      throw new MappingException(String.format("Missmatching types for %s. Found %s expected one of %s.",
          persistentProperty.getField(), persistentProperty.getActualType(),
          StringUtils.arrayToCommaDelimitedString(validMatches)));
    }
View Full Code Here

TOP

Related Classes of org.springframework.data.mapping.model.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.