@Override public <E> Path<List<E>> createListPath(Class<E> elementType, PathMetadata metadata) { return Expressions.listPath(elementType, EntityPathBase.class, metadata); }
@SuppressWarnings("rawtypes") private static <T> Path<T> replaceParent(Path<T> path, Path<?> parent) { PathMetadata metadata = new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType()); if (path instanceof CollectionExpression) { CollectionExpression<?,?> col = (CollectionExpression<?,?>) path; return (Path<T>) Expressions.listPath(col.getParameter(0), SimplePath.class, metadata); } else { return ExpressionUtils.path(path.getType(), metadata); } }
@Override public <E> Path<List<E>> createListPath(Class<E> elementType, PathMetadata metadata) { return Expressions.listPath(elementType, EntityPathBase.class, metadata); }
@SuppressWarnings("rawtypes") private static <T> Path<T> replaceParent(Path<T> path, Path<?> parent) { PathMetadata metadata = new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType()); if (path instanceof CollectionExpression) { CollectionExpression<?,?> col = (CollectionExpression<?,?>) path; return (Path<T>) Expressions.listPath(col.getParameter(0), SimplePath.class, metadata); } else { return ExpressionUtils.path(path.getType(), metadata); } }
@SuppressWarnings("unchecked") @Override protected Predicate exists(Context c, Predicate condition) { JPAQueryMixin<?> query = new JPAQueryMixin<Object>(); query.setProjection(Expressions.ONE); for (int i = 0; i < c.paths.size(); i++) { Path<?> child = c.paths.get(i).getMetadata().getParent(); EntityPath<Object> replacement = (EntityPath<Object>) c.replacements.get(i); if (c.paths.get(i).getType().isAnnotationPresent(Entity.class)) { query.addJoin(i == 0 ? JoinType.DEFAULT : JoinType.INNERJOIN, Expressions.as( Expressions.listPath((Class) c.paths.get(i).getType(), SimplePath.class, child.getMetadata()), replacement)); } else { // join via parent Path<?> parent = child.getMetadata().getParent(); EntityPathBase<Object> newParent = new EntityPathBase<Object>(parent.getType(), ExpressionUtils.createRootVariable(parent, Math.abs(condition.hashCode()))); EntityPath<Object> newChild = new EntityPathBase<Object>(child.getType(), PathMetadataFactory.forProperty(newParent, child.getMetadata().getName())); query.from(newParent); query.addJoin(JoinType.INNERJOIN, Expressions.as(newChild, replacement)); query.where(ExpressionUtils.eq(newParent, parent)); } } c.clear(); query.where(condition); return ExpressionUtils.predicate(Ops.EXISTS, asExpression(query.getMetadata())); }