List of usage examples for org.springframework.data.repository.query.parser Part getType
public Part.Type getType()
From source file:com._4dconcept.springframework.data.marklogic.repository.query.MarklogicQueryCreator.java
/** * Populates the given {@link CriteriaDefinition} depending on the {@link Part} given. * * @param part the current method part// ww w.j a v a 2 s . c o m * @param property the resolve entity property * @param parameters the method parameters iterator * @return the build criteria */ private Criteria from(Part part, MarklogicPersistentProperty property, Iterator<Object> parameters) { Part.Type type = part.getType(); switch (type) { // case AFTER: // case GREATER_THAN: // case GREATER_THAN_EQUAL: // case BEFORE: // case LESS_THAN: // case LESS_THAN_EQUAL: // case BETWEEN: // case IS_NOT_NULL: // case IS_NULL: // case NOT_IN: // case LIKE: // case STARTING_WITH: // case ENDING_WITH: case IN: case CONTAINING: return computeContainingCriteria(property.getQName(), parameters.next()); // case NOT_CONTAINING: // case REGEX: // case EXISTS: case TRUE: return computeSimpleCriteria(property.getQName(), true); case FALSE: return computeSimpleCriteria(property.getQName(), false); // case NEAR: // case WITHIN: // case NEGATING_SIMPLE_PROPERTY: case SIMPLE_PROPERTY: return computeSimpleCriteria(property.getQName(), parameters.next()); default: throw new IllegalArgumentException("Unsupported keyword : " + type); } }
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));//from ww w . 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); }// ww w. jav a 2 s. c o 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); }// w ww .ja va2 s . c o 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 . j a v a 2 s.com 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 w w w. j a v a2 s .c o 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 a2s. 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 ww .j a va2 s .c o m*/ 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)); }