javax.persistence.criteria.Fetch Java Examples

The following examples show how to use javax.persistence.criteria.Fetch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryStructure.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked" })
private void renderFetches(
		StringBuilder jpaqlQuery,
		RenderingContext renderingContext,
		Collection<Fetch> fetches) {
	if ( fetches == null ) {
		return;
	}

	for ( Fetch fetch : fetches ) {
		( (FromImplementor) fetch ).prepareAlias( renderingContext );
		jpaqlQuery.append( renderJoinType( fetch.getJoinType() ) )
				.append( "fetch " )
				.append( ( (FromImplementor) fetch ).renderTableExpression( renderingContext ) );

		renderFetches( jpaqlQuery, renderingContext, fetch.getFetches() );
	}
}
 
Example #2
Source File: QueryUtil.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
private static boolean containsMultiRelationFetch(Set<?> fetches) {
	for (Object fetchObj : fetches) {
		Fetch<?, ?> fetch = (Fetch<?, ?>) fetchObj;

		Attribute<?, ?> attr = fetch.getAttribute();
		if (attr.isAssociation() && attr.isCollection())
			return true;

		if (containsMultiRelationFetch(fetch.getFetches()))
			return true;
	}
	return false;
}
 
Example #3
Source File: QueryUtil.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
private static boolean containsMultiRelationJoin(Set<?> fetches) {
	for (Object fetchObj : fetches) {
		Fetch<?, ?> fetch = (Fetch<?, ?>) fetchObj;
		Attribute<?, ?> attr = fetch.getAttribute();
		if (attr.isAssociation() && attr.isCollection())
			return true;

		if (containsMultiRelationFetch(fetch.getFetches()))
			return true;
	}
	return false;
}
 
Example #4
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addFetch(Fetch<X, ?> fetch) {
	if ( fetches == null ) {
		fetches = new LinkedHashSet<Fetch<X, ?>>();
	}
	fetches.add( fetch );
}
 
Example #5
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public Set<Fetch<X, ?>> getFetches() {
	return fetches == null
			? Collections.EMPTY_SET
			: fetches;
}
 
Example #6
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public <X, Y> Fetch<X, Y> fetch(String attributeName, JoinType jt) {
	if ( !canBeFetchSource() ) {
		throw illegalFetch();
	}

	Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName );
	if ( attribute.isCollection() ) {
		return (Fetch<X, Y>) fetch( (PluralAttribute) attribute, jt );
	}
	else {
		return (Fetch<X, Y>) fetch( (SingularAttribute) attribute, jt );
	}
}
 
Example #7
Source File: QueryUtil.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
private static boolean containsMultiRelationFetch(Set<?> fetches) {
  for (Object fetchObj : fetches) {
    Fetch<?, ?> fetch = (Fetch<?, ?>) fetchObj;

    Attribute<?, ?> attr = fetch.getAttribute();
    if (attr.isAssociation() && attr.isCollection())
      return true;

    if (containsMultiRelationFetch(fetch.getFetches()))
      return true;
  }
  return false;
}
 
Example #8
Source File: QueryUtil.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
private static boolean containsMultiRelationJoin(Set<?> fetches) {
  for (Object fetchObj : fetches) {
    Fetch<?, ?> fetch = (Fetch<?, ?>) fetchObj;
    Attribute<?, ?> attr = fetch.getAttribute();
    if (attr.isAssociation() && attr.isCollection())
      return true;

    if (containsMultiRelationFetch(fetch.getFetches()))
      return true;
  }
  return false;
}
 
Example #9
Source File: JpaUtil.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert the passed propertyPath into a JPA path.
 * <p>
 * Note: JPA will do joins if the property is in an associated entity.
 */
@SuppressWarnings("unchecked")
public static <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) {
    Path<?> path = root;
    for (Attribute<?, ?> attribute : attributes) {
        boolean found = false;
        // handle case when order on already fetched attribute
        for (Fetch<E, ?> fetch : root.getFetches()) {
            if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) {
                path = (Join<E, ?>) fetch;
                found = true;
                break;
            }
        }
        for (Join<E, ?> join : root.getJoins()) {
            if (attribute.getName().equals(join.getAttribute().getName())) {
                path = join;
                found = true;
                break;
            }
        }
        if (!found) {
            path = path.get(attribute.getName());
        }
    }
    return (Path<F>) path;
}
 
Example #10
Source File: JpaUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Copy Fetches
 * @param from source From
 * @param to destination From
 */
public static void copyFetches(From<?, ?> from, From<?, ?> to) {
	for (Fetch<?, ?> f : from.getFetches()) {
		Fetch<?, ?> toFetch = to.fetch(f.getAttribute().getName());
		copyFetches(f, toFetch);
	}
}
 
Example #11
Source File: JpaUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Copy Fetches
 * @param from source Fetch
 * @param to dest Fetch
 */
public static void copyFetches(Fetch<?, ?> from, Fetch<?, ?> to) {
	for (Fetch<?, ?> f : from.getFetches()) {
		Fetch<?, ?> toFetch = to.fetch(f.getAttribute().getName());
		// recursively copy fetches
		copyFetches(f, toFetch);
	}
}
 
Example #12
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addFetch(Fetch<X, ?> fetch) {
	throw new UnsupportedOperationException( "Cannot define fetch from a subquery correlation" );
}
 
Example #13
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> singularAttribute) {
	return fetch( singularAttribute, DEFAULT_JOIN_TYPE );
}
 
Example #14
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <Y> Fetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> pluralAttribute) {
	return fetch( pluralAttribute, DEFAULT_JOIN_TYPE );
}
 
Example #15
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <X, Y> Fetch<X, Y> fetch(String attributeName) {
	return fetch( attributeName, DEFAULT_JOIN_TYPE );
}
 
Example #16
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 votes vote down vote up
public void addFetch(Fetch<X, ?> fetch);