/** * Gets the path full name, including any parent path, separated by a dot <code>.</code> character. * @param nameMapper The function to use to obtain the path name (not null) * @return Path full name */ default String fullName(Function<Path<?>, String> nameMapper) { ObjectUtils.argumentNotNull(nameMapper, "Path name mapper function must be not null"); return getParent().map(pr -> stream().map(p -> nameMapper.apply(p)) .collect(LinkedList<String>::new, LinkedList::addFirst, (a, b) -> a.addAll(0, b)).stream() .collect(Collectors.joining("."))).orElse(getName()); }
/** * Gets the <em>relative</em> path name, separated by a dot <code>.</code> character, i.e. exclude any * {@link FinalPath} path instance from path name composition. * @param nameMapper The function to use to obtain the path name (not null) * @return Path relative name, en empty String if this Path is a {@link FinalPath} itself. */ default String relativeName(Function<Path<?>, String> nameMapper) { ObjectUtils.argumentNotNull(nameMapper, "Path name mapper function must be not null"); return getParent() .map(pr -> stream().filter(p -> !FinalPath.class.isAssignableFrom(p.getClass())) .map(p -> nameMapper.apply(p)) .collect(LinkedList<String>::new, LinkedList::addFirst, (a, b) -> a.addAll(0, b)).stream() .collect(Collectors.joining("."))) .orElse(FinalPath.class.isAssignableFrom(this.getClass()) ? "" : getName()); }
private static Optional<com.querydsl.core.types.Path<?>> getParentRootPath(Path<?> path, QueryDslResolutionContext context) { Optional<DataTarget> target = path.stream().filter(p -> DataTarget.class.isAssignableFrom(p.getClass())) .map(p -> (DataTarget) p).findFirst(); if (target.isPresent()) { JpaEntity<?> entity = context.resolve(target.get(), JpaEntity.class) .orElseThrow(() -> new InvalidExpressionException("Failed to resolve target [" + target.get() + "] declared as parent of path [" + path + "]")); QueryDslResolutionContext ctx = context; while (ctx != null) { final List<JoinExpression> joins = ctx.getQueryMetadata().map(q -> q.getJoins()) .orElseThrow(() -> new InvalidExpressionException("Missing context query metadata")); if (joins != null) { for (JoinExpression join : joins) { if (join.getTarget() != null && EntityPath.class.isAssignableFrom(join.getTarget().getClass()) && entity.getEntityClass() == join.getTarget().getType()) { return Optional.of((EntityPath<?>) join.getTarget()); } } } // parent ctx = ctx.getParent().orElse(null); } throw new InvalidExpressionException("None of the query joins corresponds to the target [" + target.get() + "] declared as parent of path [" + path + "]"); } return Optional.empty(); }