Java源码示例:org.springframework.data.mapping.PropertyPath
示例1
private Expression<?> buildOrderPropertyPathFrom(Sort.Order order) {
Assert.notNull(order, "Order must not be null!");
PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
Expression<?> sortPropertyExpression = builder;
while (path != null) {
if (!path.hasNext() && order.isIgnoreCase()) {
// if order is ignore-case we have to treat the last path segment as a String.
sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
} else {
sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
}
path = path.next();
}
return sortPropertyExpression;
}
示例2
private Expression<?> buildOrderPropertyPathFrom(Sort.Order order) {
Assert.notNull(order, "Order must not be null!");
PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
Expression<?> sortPropertyExpression = builder;
while (path != null) {
if (!path.hasNext() && order.isIgnoreCase()) {
// if order is ignore-case we have to treat the last path segment as a String.
sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
} else {
sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
}
path = path.next();
}
return sortPropertyExpression;
}
示例3
/**
* Creates an {@link Expression} for the given {@link Order} property.
*
* @param order must not be {@literal null}.
* @param builder must not be {@literal null}.
* @return
*/
private static Expression<?> buildOrderPropertyPathFrom(Order order, PathBuilder<?> builder) {
Assert.notNull(order, "Order must not be null!");
Assert.notNull(builder, "Builder must not be null!");
PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
Expression<?> sortPropertyExpression = builder;
while (path != null) {
if (!path.hasNext() && order.isIgnoreCase()) {
// if order is ignore-case we have to treat the last path segment as a String.
sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
} else {
sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
}
path = path.next();
}
return sortPropertyExpression;
}
示例4
private void collectWithCollections(final PropertyPath propertyPath) {
propertyPath.stream().map(property -> {
return property.isCollection() ? property.getTypeInformation().getComponentType()
: property.getTypeInformation();
}).map(type -> {
return context.getPersistentEntity(type);
}).filter(entity -> {
return entity != null;
}).map(entity -> {
return AqlUtils.buildCollectionName(entity.getCollection());
}).forEach(withCollections::add);
}
示例5
private List<DatastorePersistentProperty> getPropertiesChain(Part part) {
Iterable<PropertyPath> iterable = () -> part.getProperty().iterator();
return StreamSupport.stream(iterable.spliterator(), false)
.map(propertyPath ->
this.datastoreMappingContext
.getPersistentEntity(propertyPath.getOwningType())
.getPersistentProperty(propertyPath.getSegment())
).collect(Collectors.toList());
}
示例6
private String buildName(Part part) {
Iterable<PropertyPath> iterable = () -> part.getProperty().iterator();
return StreamSupport
.stream(iterable.spliterator(), false)
.map(propertyPath -> {
FirestorePersistentEntity<?> persistentEntity = this.mappingContext.getPersistentEntity(propertyPath.getOwningType());
return persistentEntity.getPersistentProperty(propertyPath.getSegment()).getFieldName();
})
.collect(Collectors.joining("."));
}
示例7
protected TypedQuery<Tuple> getTupleQuery(@Nullable Specification spec, Sort sort, ReturnedType returnedType) {
if (!returnedType.needsCustomConstruction()){
return getQuery(spec,sort);
}
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> query = builder.createQuery(Tuple.class);
Root<T> root = this.applySpecificationToCriteria(spec, getDomainClass(), query);
Predicate predicate = spec.toPredicate(root, query, builder);
if (predicate != null) {
query.where(predicate);
}
if (returnedType.needsCustomConstruction()) {
List<Selection<?>> selections = new ArrayList<>();
for (String property : returnedType.getInputProperties()) {
PropertyPath path = PropertyPath.from(property, returnedType.getReturnedType());
selections.add(toExpressionRecursively(root, path, true).alias(property));
}
query.multiselect(selections);
} else {
throw new IllegalArgumentException("only except projection");
}
if (sort.isSorted()) {
query.orderBy(QueryUtils.toOrders(sort, root, builder));
}
return this.applyRepositoryMethodMetadata(this.entityManager.createQuery(query));
}
示例8
static <T> Expression<T> toExpressionRecursively(From<?, ?> from, PropertyPath property, boolean isForSelection) {
Bindable<?> propertyPathModel;
Bindable<?> model = from.getModel();
String segment = property.getSegment();
if (model instanceof ManagedType) {
/*
* Required to keep support for EclipseLink 2.4.x. TODO: Remove once we drop that (probably Dijkstra M1)
* See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=413892
*/
propertyPathModel = (Bindable<?>) ((ManagedType<?>) model).getAttribute(segment);
} else {
propertyPathModel = from.get(segment).getModel();
}
if (requiresJoin(propertyPathModel, model instanceof PluralAttribute, !property.hasNext(), isForSelection)
&& !isAlreadyFetched(from, segment)) {
Join<?, ?> join = getOrCreateJoin(from, segment);
return (Expression<T>) (property.hasNext() ? toExpressionRecursively(join, property.next(), isForSelection)
: join);
} else {
Path<Object> path = from.get(segment);
return (Expression<T>) (property.hasNext() ? toExpressionRecursively(path, property.next()) : path);
}
}
示例9
/**
* Builds a Ebean {@link Expression} from the underlying {@link Part}.
*
* @return
*/
public Expression build() {
PropertyPath property = part.getProperty();
Part.Type type = part.getType();
switch (type) {
case BETWEEN:
ParameterMetadataProvider.ParameterMetadata<Comparable> first = provider.next(part);
ParameterMetadataProvider.ParameterMetadata<Comparable> second = provider.next(part);
return Expr.between(property.toDotPath(), first.getParameterValue(), second.getParameterValue());
case AFTER:
case GREATER_THAN:
return Expr.gt(property.toDotPath(), provider.next(part).getParameterValue());
case GREATER_THAN_EQUAL:
return Expr.ge(property.toDotPath(), provider.next(part).getParameterValue());
case BEFORE:
case LESS_THAN:
return Expr.lt(property.toDotPath(), provider.next(part).getParameterValue());
case LESS_THAN_EQUAL:
return Expr.le(property.toDotPath(), provider.next(part).getParameterValue());
case IS_NULL:
return Expr.isNull(property.toDotPath());
case IS_NOT_NULL:
return Expr.isNotNull(property.toDotPath());
case NOT_IN:
ParameterMetadataProvider.ParameterMetadata<? extends Collection> pmNotIn = provider.next(part, Collection.class);
return Expr.not(Expr.in(property.toDotPath(), ParameterMetadataProvider.ParameterMetadata.toCollection(pmNotIn.getParameterValue())));
case IN:
ParameterMetadataProvider.ParameterMetadata<? extends Collection> pmIn = provider.next(part, Collection.class);
return Expr.in(property.toDotPath(), ParameterMetadataProvider.ParameterMetadata.toCollection(pmIn.getParameterValue()));
case STARTING_WITH:
return Expr.startsWith(property.toDotPath(), (String) provider.next(part).getParameterValue());
case ENDING_WITH:
return Expr.endsWith(property.toDotPath(), (String) provider.next(part).getParameterValue());
case CONTAINING:
return Expr.contains(property.toDotPath(), (String) provider.next(part).getParameterValue());
case NOT_CONTAINING:
return Expr.not(Expr.contains(property.toDotPath(), (String) provider.next(part).getParameterValue()));
case LIKE:
return Expr.like(property.toDotPath(), (String) provider.next(part).getParameterValue());
case NOT_LIKE:
return Expr.not(Expr.like(property.toDotPath(), (String) provider.next(part).getParameterValue()));
case TRUE:
return Expr.eq(property.toDotPath(), true);
case FALSE:
return Expr.eq(property.toDotPath(), false);
case SIMPLE_PROPERTY:
ParameterMetadataProvider.ParameterMetadata<Object> pmEquals = provider.next(part);
return pmEquals.isIsNullParameter() ? Expr.isNull(property.toDotPath())
: Expr.eq(property.toDotPath(), pmEquals.getParameterValue());
case NEGATING_SIMPLE_PROPERTY:
ParameterMetadataProvider.ParameterMetadata<Object> pmNot = provider.next(part);
return pmNot.isIsNullParameter() ? Expr.isNull(property.toDotPath())
: Expr.ne(property.toDotPath(), pmNot.getParameterValue());
// case IS_EMPTY:
// return Expr.isEmpty(property.toDotPath());
// case IS_NOT_EMPTY:
// return Expr.isNotEmpty(property.toDotPath());
default:
throw new IllegalArgumentException("Unsupported keyword " + type);
}
}
示例10
static Expression<Object> toExpressionRecursively(Path<Object> path, PropertyPath property) {
Path<Object> result = path.get(property.getSegment());
return property.hasNext() ? toExpressionRecursively(result, property.next()) : result;
}
示例11
private boolean canUpperCase(PropertyPath path) {
return String.class.equals(path.getType());
}
示例12
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);
}
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());
}
}