Example usage for org.springframework.data.mapping PropertyPath toDotPath

List of usage examples for org.springframework.data.mapping PropertyPath toDotPath

Introduction

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

Prototype

public String toDotPath() 

Source Link

Document

Returns the PropertyPath in dot notation.

Usage

From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCreator.java

protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part,
        Iterator<Object> iterator) {
    if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS))
        throw new UnsupportedOperationException("Case insensitivity not supported");

    Class<?> leafNodePropertyType = part.getProperty().getLeafProperty().getType();

    PropertyPath leafNodePropertyPath = part.getProperty().getLeafProperty();
    String leafNodePropertyName = leafNodePropertyPath.toDotPath();
    if (leafNodePropertyName.indexOf(".") != -1) {
        int index = leafNodePropertyName.lastIndexOf(".");
        leafNodePropertyName = leafNodePropertyName.substring(index);
    }//ww  w. j a  v  a2 s .  c  om

    switch (part.getType()) {

    case IN:
        Object in = iterator.next();
        Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '"
                + leafNodePropertyName + "'");
        boolean isIterable = ClassUtils.isAssignable(in.getClass(), Iterable.class);
        boolean isArray = ObjectUtils.isArray(in);
        Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters");
        Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in));
        return criteria.withPropertyIn(leafNodePropertyName, iterable, leafNodePropertyType);
    case CONTAINING:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.CONTAINS,
                iterator.next(), leafNodePropertyType);
    case STARTING_WITH:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.BEGINS_WITH,
                iterator.next(), leafNodePropertyType);
    case BETWEEN:
        Object first = iterator.next();
        Object second = iterator.next();
        return criteria.withPropertyBetween(leafNodePropertyName, first, second, leafNodePropertyType);
    case AFTER:
    case GREATER_THAN:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GT, iterator.next(),
                leafNodePropertyType);
    case BEFORE:
    case LESS_THAN:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LT, iterator.next(),
                leafNodePropertyType);
    case GREATER_THAN_EQUAL:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GE, iterator.next(),
                leafNodePropertyType);
    case LESS_THAN_EQUAL:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LE, iterator.next(),
                leafNodePropertyType);
    case IS_NULL:
        return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NULL);
    case IS_NOT_NULL:
        return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NOT_NULL);
    case TRUE:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.TRUE,
                leafNodePropertyType);
    case FALSE:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.FALSE,
                leafNodePropertyType);
    case SIMPLE_PROPERTY:
        return criteria.withPropertyEquals(leafNodePropertyName, iterator.next(), leafNodePropertyType);
    case NEGATING_SIMPLE_PROPERTY:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.NE, iterator.next(),
                leafNodePropertyType);
    default:
        throw new IllegalArgumentException("Unsupported keyword " + part.getType());
    }

}