use of org.springframework.data.mapping.PropertyPath in project spring-data-couchbase by spring-projects.
the class CouchbasePartTree method maybeInitDistinctFields.
private void maybeInitDistinctFields(String methodName, Class<?> domainType) {
if (isDistinct()) {
Matcher grp = DISTINCT_TEMPLATE.matcher(methodName);
if (grp.matches()) {
String grp3 = grp.group(3);
String[] names = grp.group(3).split("And");
int parameterCount = names.length;
distinctFields = new String[names.length];
for (int i = 0; i < parameterCount; ++i) {
Part.Type type = Part.Type.fromProperty(names[i]);
PropertyPath path = PropertyPath.from(type.extractProperty(names[i]), domainType);
distinctFields[i] = path.toDotPath();
}
} else {
distinctFields = new String[0];
}
}
}
use of org.springframework.data.mapping.PropertyPath in project spring-data-jpa by spring-projects.
the class QueryUtilsIntegrationTests method reusesExistingJoinForExpression.
// DATAJPA-403
@Test
void reusesExistingJoinForExpression() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<User> query = builder.createQuery(User.class);
Root<User> from = query.from(User.class);
PropertyPath managerFirstname = PropertyPath.from("manager.firstname", User.class);
PropertyPath managerLastname = PropertyPath.from("manager.lastname", User.class);
QueryUtils.toExpressionRecursively(from, managerLastname);
QueryUtils.toExpressionRecursively(from, managerFirstname);
assertThat(from.getJoins()).hasSize(1);
}
use of org.springframework.data.mapping.PropertyPath in project spring-data-jpa by spring-projects.
the class Querydsl method buildOrderPropertyPathFrom.
/**
* Creates an {@link Expression} for the given {@link Order} property.
*
* @param order must not be {@literal null}.
* @return
*/
private Expression<?> buildOrderPropertyPathFrom(Order order) {
Assert.notNull(order, "Order must not be null!");
PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
Expression<?> sortPropertyExpression = builder;
while (path != null) {
sortPropertyExpression = //
!path.hasNext() && order.isIgnoreCase() && String.class.equals(path.getType()) ? //
Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower() : Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
path = path.next();
}
return sortPropertyExpression;
}
use of org.springframework.data.mapping.PropertyPath in project spring-data-jpa by spring-projects.
the class QueryUtils method toExpressionRecursively.
/**
* Creates an expression with proper inner and left joins by recursively navigating the path
*
* @param from the {@link From}
* @param property the property path
* @param isForSelection is the property navigated for the selection or ordering part of the query?
* @param hasRequiredOuterJoin has a parent already required an outer join?
* @param <T> the type of the expression
* @return the expression
*/
@SuppressWarnings("unchecked")
static <T> Expression<T> toExpressionRecursively(From<?, ?> from, PropertyPath property, boolean isForSelection, boolean hasRequiredOuterJoin) {
String segment = property.getSegment();
boolean isLeafProperty = !property.hasNext();
boolean requiresOuterJoin = requiresOuterJoin(from, property, isForSelection, hasRequiredOuterJoin);
// if it does not require an outer join and is a leaf, simply get the segment
if (!requiresOuterJoin && isLeafProperty) {
return from.get(segment);
}
// get or create the join
JoinType joinType = requiresOuterJoin ? JoinType.LEFT : JoinType.INNER;
Join<?, ?> join = getOrCreateJoin(from, segment, joinType);
// if it's a leaf, return the join
if (isLeafProperty) {
return (Expression<T>) join;
}
PropertyPath nextProperty = Objects.requireNonNull(property.next(), "An element of the property path is null!");
// recurse with the next property
return toExpressionRecursively(join, nextProperty, isForSelection, requiresOuterJoin);
}
use of org.springframework.data.mapping.PropertyPath in project redis-om-spring by redis.
the class RediSearchQuery method processPartTree.
private void processPartTree(PartTree pt) {
pt.stream().forEach(orPart -> {
List<Pair<String, QueryClause>> orPartParts = new ArrayList<Pair<String, QueryClause>>();
orPart.iterator().forEachRemaining(part -> {
PropertyPath propertyPath = part.getProperty();
List<PropertyPath> path = StreamSupport.stream(propertyPath.spliterator(), false).collect(Collectors.toList());
orPartParts.addAll(extractQueryFields(domainType, part, path));
});
queryOrParts.add(orPartParts);
});
}
Aggregations