@SuppressWarnings("unchecked") private <X, T, V extends T, K extends JoinImplementor> K treat( Join<X, T> join, Class<V> type, BiFunction<Join<X, T>, Class<V>, K> f) { final Set<Join<X, ?>> joins = join.getParent().getJoins(); final K treatAs = f.apply( join, type ); joins.add( treatAs ); return treatAs; } }
/** * Returns an existing join for the given attribute if one already exists or creates a new one if not. * * @param from the {@link From} to get the current joins from. * @param attribute the {@link Attribute} to look for in the current joins. * @return will never be {@literal null}. */ private static Join<?, ?> getOrCreateJoin(From<?, ?> from, String attribute) { for (Join<?, ?> join : from.getJoins()) { boolean sameName = join.getAttribute().getName().equals(attribute); if (sameName && join.getJoinType().equals(JoinType.LEFT)) { return join; } } return from.join(attribute, JoinType.LEFT); }
for( Join<F, ?> join : grandparentJoin.getJoins() ) { if( join.getJavaType().equals(toAttrJoinType) ) { if( join.getAttribute().equals(parentJoinAttr) ) {
private static boolean hasJoins(From<?, ?> from) { return !from.getJoins().isEmpty() || hasFetches(from); }
private Path<?> getExistingJoinProperty(From<?, ?> element, String prop) { final Set<?> joins = element.getJoins(); for (Object object : joins) { Join<?, ?> join = (Join<?, ?>) object; if (join.getAttribute().getName().equals(prop)) { return join; } } return null; }
private Path<?> getExistingJoinProperty(From<?, ?> element, String prop) { final Set<?> joins = element.getJoins(); for (Object object : joins) { Join<?, ?> join = (Join<?, ?>) object; if (join.getAttribute().getName().equals(prop)) { return join; } } return null; }
private Path<?> getExistingJoinProperty(From<?, ?> element, String prop) { final Set<?> joins = element.getJoins(); for (Object object : joins) { Join<?, ?> join = (Join<?, ?>) object; if (join.getAttribute().getName().equals(prop)) { return join; } } return null; }
@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(); } } }
protected <T, S> Path<?> getPath(From<T, S> root, String name) { int index = name.indexOf("."); if (index > 0 ) { String attribute = name.substring(0, index); From<S, ?> join = getJoin(attribute, root.getJoins()); if (join == null) { join = root.join(attribute); } return getPath(join, name.substring(index + 1)); } else { return root.get(name); } }
/** * Retrieve an existing join within the ones within the given root and that match to given attribute. * * @param from * the from source element. * @param attribute * the attribute to join * @return The join/fetch path if it exists. * @param <U> * The source type of the {@link Join} * @param <T> * The resolved entity type of the path value. */ @SuppressWarnings("unchecked") protected <U, T> PathImplementor<T> getJoinPath(final From<?, U> from, final Attribute<?, ?> attribute) { // Search within current joins for (final Join<U, ?> join : from.getJoins()) { if (join.getAttribute().equals(attribute)) { return fixAlias((Join<U, T>) join, aliasCounter); } } return null; }
/** * Find an existing join for the property or create a new join. * * @param property property to be joined * @param from clause letting us keep track of all already existing joins * @return the join */ private static Join<?, ?> findOrCreateJoin(String property, From<?, ?> from) { for (Join<?, ?> rootJoin : from.getJoins()) { if (rootJoin.getAttribute().getName().equals(property)) { return rootJoin; } } return from.join(property); } }
private Join<?,?> reuseJoin(From<?, ?> path, String fieldName, boolean outer) { for (Join<?,?> join : path.getJoins()) { if (join.getAttribute().getName().equals(fieldName)) { if ((join.getJoinType() == JoinType.LEFT) == outer) { logger.debug("Reusing existing join for field " + fieldName); return join; } } } return outer ? path.join(fieldName, JoinType.LEFT) : path.join(fieldName); }
private static void collectJoins(Path<?> path, Map<String, Path<?>> joins) { if (path instanceof From) { ((From<?, ?>) path).getJoins().forEach(join -> collectJoins(join, joins)); } if (path instanceof FetchParent) { try { ((FetchParent<?, ?>) path).getFetches().stream().filter(fetch -> fetch instanceof Path).forEach(fetch -> collectJoins((Path<?>) fetch, joins)); } catch (NullPointerException openJPAWillThrowThisOnEmptyFetches) { // Ignore and continue. } } if (path instanceof Join) { joins.put(((Join<?, ?>) path).getAttribute().getName(), path); } else if (path instanceof Fetch) { joins.put(((Fetch<?, ?>) path).getAttribute().getName(), path); } }
private Join<?,?> reuseJoin(From<?, ?> path, String fieldName, boolean outer) { for (Join<?,?> join : path.getJoins()) { if (join.getAttribute().getName().equals(fieldName)) { if ((join.getJoinType() == JoinType.LEFT) == outer) { //logger.debug("Reusing existing join for field " + fieldName); return join; } } } return outer ? path.join(fieldName, JoinType.LEFT) : path.join(fieldName); }
/** * Returns an existing join for the given attribute if one already exists or creates a new one if not. * * @param from the {@link From} to get the current joins from. * @param attribute the {@link Attribute} to look for in the current joins. * @return will never be {@literal null}. */ private static Join<?, ?> getOrCreateJoin(From<?, ?> from, String attribute) { for (Join<?, ?> join : from.getJoins()) { boolean sameName = join.getAttribute().getName().equals(attribute); if (sameName && join.getJoinType().equals(JoinType.LEFT)) { return join; } } return from.join(attribute, JoinType.LEFT); }
if (currentJoinOfType.isPresent() && isOrLevel) { joinParent.getJoins().remove(join); fieldPath = currentJoinOfType.get(); } else {
private Path<?> determineDescriptionCriteraPath(final JPAPath selectItemPath, Path<?> p, final JPAElement jpaPathElement) { final Set<?> allJoins = root.getJoins(); final Iterator<?> iterator = allJoins.iterator(); while (iterator.hasNext()) { Join<?, ?> join = (Join<?, ?>) iterator.next(); if (join.getAlias() != null && join.getAlias().equals(selectItemPath.getAlias())) { final Set<?> subJoins = join.getJoins(); for (final Object sub : subJoins) { // e.g. "Organizations?$filter=Address/RegionName eq 'Kalifornien' // see createFromClause in JPAExecutableQuery if (((Join<?, ?>) sub).getAlias() != null && ((Join<?, ?>) sub).getAlias().equals(jpaPathElement.getExternalName())) { join = (Join<?, ?>) sub; } } p = join.get(((JPADescriptionAttribute) jpaPathElement).getDescriptionAttribute().getInternalName()); break; } } return p; } }
if (currentJoinOfType.isPresent() && isOrLevel) { joinParent.getJoins().remove(join); fieldPath = currentJoinOfType.get(); } else {
/** * 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); } }
this.renderFetchParents(from.getJoins()); if (!fetchParent.getFetches().isEmpty()) { this.appendLine(",");