/** * 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); }
@SuppressWarnings({"unchecked"}) private void renderJoins( StringBuilder jpaqlQuery, RenderingContext renderingContext, Collection<Join<?, ?>> joins) { if (joins == null) { return; } for (Join join : joins) { ((FromImplementor) join).prepareAlias(renderingContext); jpaqlQuery .append(renderJoinType(join.getJoinType())) .append(((FromImplementor) join).renderTableExpression(renderingContext)); renderJoins(jpaqlQuery, renderingContext, join.getJoins()); renderFetches(jpaqlQuery, renderingContext, join.getFetches()); } }