Example usage for org.springframework.data.repository.query.parser Part getProperty

List of usage examples for org.springframework.data.repository.query.parser Part getProperty

Introduction

In this page you can find the example usage for org.springframework.data.repository.query.parser Part getProperty.

Prototype

public PropertyPath getProperty() 

Source Link

Usage

From source file:com._4dconcept.springframework.data.marklogic.repository.query.MarklogicQueryCreator.java

@Override
protected Criteria create(Part part, Iterator<Object> iterator) {
    PersistentPropertyPath<MarklogicPersistentProperty> path = context
            .getPersistentPropertyPath(part.getProperty());
    MarklogicPersistentProperty property = path.getLeafProperty();

    if (property == null) {
        throw new TypeMismatchDataAccessException(
                String.format("No persistent pntity information found for the path %s", path));
    }/*from w  w w.jav  a  2  s.  c  om*/

    return from(part, property, iterator);
}

From source file:com.frank.search.solr.repository.query.SolrQueryCreator.java

@Override
protected Query create(Part part, Iterator<Object> iterator) {
    PersistentPropertyPath<SolrPersistentProperty> path = context.getPersistentPropertyPath(part.getProperty());
    return new SimpleQuery(from(part.getType(),
            new Criteria(path.toDotPath(SolrPersistentProperty.PropertyToFieldNameConverter.INSTANCE)),
            iterator));//w ww .j  av a 2 s  .  c  om
}

From source file:com.frank.search.solr.repository.query.SolrQueryCreator.java

@Override
protected Query and(Part part, Query base, Iterator<Object> iterator) {
    if (base == null) {
        return create(part, iterator);
    }/* w  w  w .  ja  v  a  2 s  . co  m*/
    PersistentPropertyPath<SolrPersistentProperty> path = context.getPersistentPropertyPath(part.getProperty());
    return base.addCriteria(from(part.getType(),
            new Criteria(path.toDotPath(SolrPersistentProperty.PropertyToFieldNameConverter.INSTANCE)),
            iterator));
}

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);
    }//from www  .  ja v  a2s . co  m

    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());
    }

}

From source file:org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBQueryCreator.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<?> propertyType = part.getProperty().getType();

    switch (part.getType()) {
    case IN://from  ww w  . ja va2 s.c o m
        Object in = iterator.next();
        Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '"
                + part.getProperty().getSegment() + "'");
        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(part.getProperty().getSegment(), iterable, propertyType);
    case CONTAINING:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.CONTAINS,
                iterator.next(), propertyType);
    case STARTING_WITH:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.BEGINS_WITH,
                iterator.next(), propertyType);
    case BETWEEN:
        Object first = iterator.next();
        Object second = iterator.next();
        return criteria.withPropertyBetween(part.getProperty().getSegment(), first, second, propertyType);
    case AFTER:
    case GREATER_THAN:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GT,
                iterator.next(), propertyType);
    case BEFORE:
    case LESS_THAN:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LT,
                iterator.next(), propertyType);
    case GREATER_THAN_EQUAL:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GE,
                iterator.next(), propertyType);
    case LESS_THAN_EQUAL:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LE,
                iterator.next(), propertyType);
    case IS_NULL:
        return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NULL);
    case IS_NOT_NULL:
        return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NOT_NULL);
    case TRUE:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ,
                Boolean.TRUE, propertyType);
    case FALSE:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ,
                Boolean.FALSE, propertyType);
    case SIMPLE_PROPERTY:
        return criteria.withPropertyEquals(part.getProperty().getSegment(), iterator.next(), propertyType);
    case NEGATING_SIMPLE_PROPERTY:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.NE,
                iterator.next(), propertyType);
    default:
        throw new IllegalArgumentException("Unsupported keyword " + part.getType());
    }

}

From source file:org.springframework.data.document.mongodb.repository.MongoQueryCreator.java

@Override
protected Query create(Part part, Iterator<Object> iterator) {

    Criteria criteria = from(part.getType(), where(part.getProperty().toDotPath()),
            (PotentiallyConvertingIterator) iterator);

    return new Query(criteria);
}

From source file:org.springframework.data.document.mongodb.repository.MongoQueryCreator.java

@Override
protected Query and(Part part, Query base, Iterator<Object> iterator) {

    Criteria criteria = from(part.getType(), where(part.getProperty().toDotPath()),
            (PotentiallyConvertingIterator) iterator);
    return base.addCriteria(criteria);
}

From source file:org.springframework.data.mongodb.repository.query.MongoQueryCreator.java

@Override
protected Criteria create(Part part, Iterator<Object> iterator) {

    if (isGeoNearQuery && part.getType().equals(Type.NEAR)) {
        return null;
    }/*from ww w .  j  a  v  a 2s  . co m*/

    PersistentPropertyPath<MongoPersistentProperty> path = context
            .getPersistentPropertyPath(part.getProperty());
    Criteria criteria = from(part.getType(),
            where(path.toDotPath(MongoPersistentProperty.PropertyToFieldNameConverter.INSTANCE)),
            (PotentiallyConvertingIterator) iterator);

    return criteria;
}

From source file:org.springframework.data.mongodb.repository.query.MongoQueryCreator.java

@Override
protected Criteria and(Part part, Criteria base, Iterator<Object> iterator) {

    if (base == null) {
        return create(part, iterator);
    }//from   w w  w .  j  a  v  a2 s .  co  m

    PersistentPropertyPath<MongoPersistentProperty> path = context
            .getPersistentPropertyPath(part.getProperty());

    return new Criteria().andOperator(base,
            from(part.getType(),
                    where(path.toDotPath(MongoPersistentProperty.PropertyToFieldNameConverter.INSTANCE)),
                    (PotentiallyConvertingIterator) iterator));
}

From source file:org.springframework.data.mongodb.repository.support.IndexEnsuringQueryCreationListener.java

public void onCreation(PartTreeMongoQuery query) {

    PartTree tree = query.getTree();/*from w w  w .  j a v a2  s .com*/
    Index index = new Index();
    index.named(query.getQueryMethod().getName());
    Sort sort = tree.getSort();

    for (Part part : tree.getParts()) {
        if (GEOSPATIAL_TYPES.contains(part.getType())) {
            return;
        }
        String property = part.getProperty().toDotPath();
        Order order = toOrder(sort, property);
        index.on(property, order);
    }

    // Add fixed sorting criteria to index
    if (sort != null) {
        for (Sort.Order order : sort) {
            index.on(order.getProperty(), QueryUtils.toOrder(order));
        }
    }

    MongoEntityInformation<?, ?> metadata = query.getQueryMethod().getEntityInformation();
    operations.indexOps(metadata.getCollectionName()).ensureIndex(index);
    LOG.debug(String.format("Created %s!", index));
}