/** * 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); }
private static ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl> [] getPeopleAssignmentsJoins( Join<TaskImpl,PeopleAssignmentsImpl> peopleAssignJoin) { ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl> [] joins = new ListJoin[3]; for( Join<PeopleAssignmentsImpl,?> join : peopleAssignJoin.getJoins() ) { String joinFieldName = join.getAttribute().getName(); if( PeopleAssignmentsImpl_.businessAdministrators.getName().equals(joinFieldName) ) { joins[0] = (ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl>) join; } else if( PeopleAssignmentsImpl_.potentialOwners.getName().equals(joinFieldName) ) { joins[1] = (ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl>) join; } else if( PeopleAssignmentsImpl_.taskStakeholders.getName().equals(joinFieldName) ) { joins[2] = (ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl>) join; } } if( joins[0] == null ) { joins[0] = peopleAssignJoin.join(PeopleAssignmentsImpl_.businessAdministrators, JoinType.LEFT); } if( joins[1] == null ) { joins[1] = peopleAssignJoin.join(PeopleAssignmentsImpl_.potentialOwners, JoinType.LEFT); } if( joins[2] == null ) { joins[2] = peopleAssignJoin.join(PeopleAssignmentsImpl_.taskStakeholders, JoinType.LEFT); } assert joins[0] != null : "Could not find business administrators join!"; assert joins[1] != null : "Could not find potential owners join!"; assert joins[2] != null : "Could not find task stakeholders join!"; return joins; }
for( Join<F, ?> join : grandparentJoin.getJoins() ) { if( join.getJavaType().equals(toAttrJoinType) ) { if( join.getAttribute().equals(parentJoinAttr) ) { fieldParentJoin = (Join<F, T>) join; if( ! JoinType.INNER.equals(fieldParentJoin.getJoinType()) ) {
@Override public Attribute<? super X, ?> getAttribute() { return join.getAttribute(); }
private <T> Join<T, ?> getJoin(String name, Set<Join<T, ?>> joins) { for (Join<T, ?> join : joins) { if (join.getAttribute().getName().equals(name)) { 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; }
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; }
/** * 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; }
private static boolean isLeftOrNonNullReferenceJoin(Join<?, ?> join, boolean dbSchemaStrict) { if (join.getAttribute().isCollection()) { return false; } if (join.getJoinType() == JoinType.LEFT) { return true; } if (!dbSchemaStrict) { return false; } SingularAttribute<?, ?> singularAttribute = (SingularAttribute<?, ?>)join.getAttribute(); return !singularAttribute.isOptional() && singularAttribute.getPersistentAttributeType() == PersistentAttributeType.MANY_TO_ONE; } }
/** * 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); }
protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) { Set<ClassMetaData> metas = new HashSet<ClassMetaData>(); MetamodelImpl metamodel = q.getMetamodel(); for (Root<?> root : q.getRoots()) { metas.add(((AbstractManagedType<?>)root.getModel()).meta); for (Join<?,?> join : root.getJoins()) { Class<?> cls = join.getAttribute().getJavaType(); if (join.getAttribute().isAssociation()) { ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true); PersistenceType type = MetamodelImpl.getPersistenceType(meta); if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) metas.add(meta); } } } // TODO -- need to handle subqueries exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]); }
protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) { Set<ClassMetaData> metas = new HashSet<ClassMetaData>(); MetamodelImpl metamodel = q.getMetamodel(); for (Root<?> root : q.getRoots()) { metas.add(((AbstractManagedType<?>)root.getModel()).meta); for (Join<?,?> join : root.getJoins()) { Class<?> cls = join.getAttribute().getJavaType(); if (join.getAttribute().isAssociation()) { ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true); PersistenceType type = MetamodelImpl.getPersistenceType(meta); if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) metas.add(meta); } } } // TODO -- need to handle subqueries exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]); }
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); }
protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) { Set<ClassMetaData> metas = new HashSet<ClassMetaData>(); MetamodelImpl metamodel = q.getMetamodel(); for (Root<?> root : q.getRoots()) { metas.add(((AbstractManagedType<?>)root.getModel()).meta); for (Join<?,?> join : root.getJoins()) { Class<?> cls = join.getAttribute().getJavaType(); if (join.getAttribute().isAssociation()) { ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true); PersistenceType type = MetamodelImpl.getPersistenceType(meta); if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) metas.add(meta); } } for (Fetch<?,?> fetch : root.getFetches()) { metas.add(metamodel.getRepository().getCachedMetaData(fetch.getAttribute().getJavaType())); } } exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]); }
protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) { Set<ClassMetaData> metas = new HashSet<ClassMetaData>(); MetamodelImpl metamodel = q.getMetamodel(); for (Root<?> root : q.getRoots()) { metas.add(((AbstractManagedType<?>)root.getModel()).meta); for (Join<?,?> join : root.getJoins()) { Class<?> cls = join.getAttribute().getJavaType(); if (join.getAttribute().isAssociation()) { ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true); PersistenceType type = MetamodelImpl.getPersistenceType(meta); if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) metas.add(meta); } } for (Fetch<?,?> fetch : root.getFetches()) { metas.add(metamodel.getRepository().getCachedMetaData(fetch.getAttribute().getJavaType())); } } exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]); }
/** * 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); } }