Example usage for org.springframework.data.mapping MappingException MappingException

List of usage examples for org.springframework.data.mapping MappingException MappingException

Introduction

In this page you can find the example usage for org.springframework.data.mapping MappingException MappingException.

Prototype

public MappingException(@Nullable String s) 

Source Link

Usage

From source file:com._4dconcept.springframework.data.marklogic.core.mapping.BasicMarklogicPersistentEntity.java

@Override
protected MarklogicPersistentProperty returnPropertyIfBetterIdPropertyCandidateOrNull(
        MarklogicPersistentProperty property) {
    if (!property.isIdProperty()) {
        return null; // Not a potential id property. Early exit
    }/*from   ww w.  j av a  2  s.c  o m*/

    MarklogicPersistentProperty currentIdProperty = getIdProperty();

    if (currentIdProperty != null && currentIdProperty.isExplicitIdProperty()) {
        return null; // An explicit Id property is already set
    } else if (property.isExplicitIdProperty()) {
        return property; // Use this explicit id property
    } else if (currentIdProperty == null) {
        return property;
    }

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

From source file:io.twipple.springframework.data.clusterpoint.convert.DefaultClusterpointEntityConverter.java

/**
 * Read an incoming {@link ClusterpointDocument} into the target entity.
 *
 * @param type   the type information of the target entity.
 * @param source the document to convert.
 * @param parent an optional parent object.
 * @param <R>    the entity type./*from w  w w .  j  a  v a  2  s.  c om*/
 * @return the converted entity.
 */
@NotNull
@SuppressWarnings("unchecked")
protected <R> R read(@NotNull TypeInformation<R> type, @NotNull ClusterpointDocument source, Object parent) {

    Assert.notNull(type);
    Assert.notNull(source);

    TypeInformation<? extends R> typeToUse = typeMapper.readType(source, type);
    Class<? extends R> rawType = typeToUse.getType();

    // TODO: handle custom conversions for DOMDocument and DOMElement.
    // Since ClusterpointDocument is a holder of a DOMDocument, it might happen that there is a custom conversion
    // for either DOMDocument or the root DOMElement.
    if (conversions.hasCustomReadTarget(source.getClass(), rawType)) {
        return conversionService.convert(source, rawType);
    }

    if (typeToUse.isMap()) {
        return (R) readMap(typeToUse, source, parent);
    }

    if (typeToUse.isCollectionLike()) {
        return (R) readCollection(typeToUse, source, parent);
    }

    ClusterpointPersistentEntity<R> entity = (ClusterpointPersistentEntity<R>) mappingContext
            .getPersistentEntity(typeToUse);
    if (entity == null) {
        throw new MappingException("No mapping metadata found for " + rawType.getName());
    }
    return read(entity, source, parent);
}

From source file:io.twipple.springframework.data.clusterpoint.convert.DefaultClusterpointEntityConverter.java

/**
 * Potentially convert simple values like ENUMs.
 *
 * @param value  the value to convert.//from   ww  w.j ava  2 s.com
 * @param target the target object.
 * @return the potentially converted object.
 */
@SuppressWarnings("unchecked")
private Object getPotentiallyConvertedSimpleRead(Object value, Class<?> target) {
    if (value == null || target == null) {
        return value;
    }

    if (conversions.hasCustomReadTarget(value.getClass(), target)) {
        return conversionService.convert(value, target);
    }

    if (Enum.class.isAssignableFrom(target)) {
        return Enum.valueOf((Class<Enum>) target, value.toString());
    }

    if (Class.class.isAssignableFrom(target)) {
        try {
            return Class.forName(value.toString());
        } catch (ClassNotFoundException e) {
            throw new MappingException("Unable to create class from " + value.toString());
        }
    }

    return target.isAssignableFrom(value.getClass()) ? value : conversionService.convert(value, target);
}

From source file:com._4dconcept.springframework.data.marklogic.core.MarklogicTemplate.java

private MarklogicIdentifier resolveMarklogicIdentifier(Object id, MarklogicPersistentProperty idProperty) {
    if (MarklogicTypeUtils.isSimpleType(idProperty.getType())) {
        return new MarklogicIdentifier() {
            @Override/* ww  w  . ja  va  2 s  . c om*/
            public QName qname() {
                return idProperty.getQName();
            }

            @Override
            public String value() {
                return id.toString();
            }
        };
    }

    ConversionService conversionService = marklogicConverter.getConversionService();
    if (conversionService.canConvert(idProperty.getType(), MarklogicIdentifier.class)) {
        MarklogicIdentifier convert = conversionService.convert(id, MarklogicIdentifier.class);
        if (convert == null) {
            throw new ConversionFailedException(TypeDescriptor.forObject(id),
                    TypeDescriptor.valueOf(MarklogicIdentifier.class), id,
                    new NullPointerException("Conversion result is not expected to be null"));
        }

        return convert;
    }

    throw new MappingException("Unexpected identifier type " + idProperty.getClass());
}