/** * Return whether the given {@link From} contains a fetch declaration for the attribute with the given name. * * @param from the {@link From} to check for fetches. * @param attribute the attribute name to check. * @return */ private static boolean isAlreadyFetched(From<?, ?> from, String attribute) { for (Fetch<?, ?> fetch : from.getFetches()) { boolean sameName = fetch.getAttribute().getName().equals(attribute); if (sameName && fetch.getJoinType().equals(JoinType.LEFT)) { return true; } } return false; }
private static boolean hasFetches(From<?, ?> from) { return from.getFetches().stream().anyMatch(fetch -> fetch instanceof Path) || (from instanceof EclipseLinkRoot && ((EclipseLinkRoot<?>) from).hasPostponedFetches()); }
@SuppressWarnings("unchecked") protected void fetchToJoin(final From<?, ?> from, final Set<Fetch<?, ?>> fetches) { if (fetches != null && !fetches.isEmpty()) { for (final Fetch<?, ?> fetch : fetches) { @SuppressWarnings("rawtypes") final Join join = (Join) fetch; final Set<Fetch<?, ?>> fs = (Set<Fetch<?, ?>>) ((Set<?>) fetch.getFetches()); if (fs.isEmpty()) { try { from.getJoins().add(join); } catch (UnsupportedOperationException e) { } } else { fetchToJoin(join, fs); } } from.getFetches().clear(); } } }
/** * Return whether the given {@link From} contains a fetch declaration for the attribute with the given name. * * @param from the {@link From} to check for fetches. * @param attribute the attribute name to check. * @return */ private static boolean isAlreadyFetched(From<?, ?> from, String attribute) { for (Fetch<?, ?> fetch : from.getFetches()) { boolean sameName = fetch.getAttribute().getName().equals(attribute); if (sameName && fetch.getJoinType().equals(JoinType.LEFT)) { return true; } } return false; }
/** * Copy Joins * * @param from source Join * @param to destination Join */ public static void copyJoins(From<?, ?> from, From<?, ?> to) { for (Join<?, ?> j : from.getJoins()) { Join<?, ?> toJoin = to.join(j.getAttribute().getName(), j.getJoinType()); toJoin.alias(getOrCreateAlias(j)); copyJoins(j, toJoin); } for (Fetch<?, ?> f : from.getFetches()) { Fetch<?, ?> toFetch = to.fetch(f.getAttribute().getName()); copyFetches(f, toFetch); } }