Java 类javax.persistence.criteria.Fetch 实例源码

项目:jpasearch    文件:JpaUtil.java   
@SuppressWarnings("unchecked")
public <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) {
    Path<?> path = root;
    for (Attribute<?, ?> attribute : attributes) {
        boolean found = false;
        if (path instanceof FetchParent) {
            for (Fetch<E, ?> fetch : ((FetchParent<?, E>) path).getFetches()) {
                if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) {
                    path = (Join<E, ?>) fetch;
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            if ((attributes.indexOf(attribute) != (attributes.size() - 1)) && (attribute instanceof Bindable)
                    && Identifiable.class.isAssignableFrom(((Bindable<?>) attribute).getBindableJavaType()) && (path instanceof From)) {
                path = ((From<?, ?>) path).join(attribute.getName(), JoinType.LEFT);
            } else {
                path = path.get(attribute.getName());
            }
        }
    }
    return (Path<F>) path;
}
项目:jpasearch    文件:JpaUtil.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
public <E> void fetches(SearchParameters<E> sp, Root<E> root) {
    for (jpasearch.repository.query.Path<E, ?> path : sp.getFetches()) {
        FetchParent<?, ?> from = root;
        for (Attribute<?, ?> arg : metamodelUtil.toAttributes(root.getJavaType(), path.getPath())) {
            boolean found = false;
            for (Fetch<?, ?> fetch : from.getFetches()) {
                if (arg.equals(fetch.getAttribute())) {
                    from = fetch;
                    found = true;
                    break;
                }
            }
            if (!found) {
                if (arg instanceof PluralAttribute) {
                    from = from.fetch((PluralAttribute) arg, JoinType.LEFT);
                } else {
                    from = from.fetch((SingularAttribute) arg, JoinType.LEFT);
                }
            }
        }
    }
}
项目:bootstrap    文件:FetchHelper.java   
private Fetch<?, ?> getFetchedAssoc(final FetchParent<?, ?> parent, final JoinType joinType, final String propertyToFetch) {

        // Search within current fetches
        for (final Fetch<?, ?> fetch : parent.getFetches()) {
            if (fetch.getAttribute().getName().equals(propertyToFetch)) {
                return fetch;
            }
        }

        // Create a new one
        return parent.fetch(propertyToFetch, joinType);
    }
项目:my-paper    文件:BaseDaoImpl.java   
private void copyJoins(From<?, ?> from, From<?, ?> to) {
    for (Join<?, ?> join : from.getJoins()) {
        Join<?, ?> toJoin = to.join(join.getAttribute().getName(), join.getJoinType());
        toJoin.alias(getAlias(join));
        copyJoins(join, toJoin);
    }
    for (Fetch<?, ?> fetch : from.getFetches()) {
        Fetch<?, ?> toFetch = to.fetch(fetch.getAttribute().getName());
        copyFetches(fetch, toFetch);
    }
}
项目:rpb    文件:JpaUtil.java   
/**
 * Convert the passed propertyPath into a JPA path. <br>
 * Note: JPA will do joins if the property is in an associated entity.
 */
@SuppressWarnings("unchecked")
private static <E> Path<?> getPropertyOrderPath(Root<E> root, String propertyPath, SearchParameters sp) {
    String[] pathItems = StringUtils.split(propertyPath, ".");

    Path<?> path = null;

    String pathItem = pathItems[0];
    if (sp.getDistinct()) {
        // handle case when order on already fetched attribute
        for (Fetch<E, ?> fetch : root.getFetches()) {
            if (pathItem.equals(fetch.getAttribute().getName()) && fetch instanceof Join<?, ?>) {
                path = (Join<E, ?>) fetch;
            }
        }
        for (Join<E, ?> join : root.getJoins()) {
            if (pathItem.equals(join.getAttribute().getName()) && join instanceof Join<?, ?>) {
                path = (Join<E, ?>) join;
            }
        }
    }

    // if no fetch matches the required path item, load it from root
    if (path == null) {
        path = root.get(pathItem);
    }

    for (int i = 1; i < pathItems.length; i++) {
        path = path.get(pathItems[i]);
    }
    return path;
}
项目:katharsis-framework    文件:QueryUtil.java   
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;
}
项目:katharsis-framework    文件:QueryUtil.java   
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;
}
项目:Tank    文件:ProjectDao.java   
/**
 * 
 * @param name
 * @return
 */
public Project findByName(@Nonnull String name) {
    Project project = null;
    EntityManager em = getEntityManager();
    try {
        begin();
        CriteriaBuilder cb = em.getCriteriaBuilder();
     CriteriaQuery<Project> query = cb.createQuery(Project.class);
     Root<Project> root = query.from(Project.class);
     Fetch<Project, Workload>  wl = root.fetch(Project.PROPERTY_WORKLOADS);
     wl.fetch("jobConfiguration");
     query.select(root);
     query.where(cb.equal(root.<String>get(Project.PROPERTY_NAME), name));
     project = em.createQuery(query).getSingleResult();         
        if( project != null) {
            project.getWorkloads().get(0).getJobConfiguration().readConfig();
            project.getWorkloads().get(0).getJobConfiguration().getJobRegions();
            project.getWorkloads().get(0).getJobConfiguration().getVariables();
            project.getWorkloads().get(0).getJobConfiguration().getDataFileIds();
            project.getWorkloads().get(0).getJobConfiguration().getNotifications();
            for ( TestPlan tp : project.getWorkloads().get(0).getTestPlans() ) {
                for (ScriptGroup sg : tp.getScriptGroups() ) {
                    sg.getScriptGroupSteps();
                }
            }
        }
        commit();
    } catch (Exception e) {
        rollback();
        e.printStackTrace();
        throw new RuntimeException(e);
    } finally {
        cleanup();
    }
    return project;
}
项目:Tank    文件:ProjectDao.java   
/**
 * Finds all Objects of type T_ENTITY
 * 
 * @return the nonnull list of entities
 * @throws HibernateException
 *             if there is an error in persistence
 */
@Nonnull
public List<Project> findAll() throws HibernateException {
    List<Project> results = null;
    EntityManager em = getEntityManager();
    try {
        begin();
     CriteriaBuilder cb = em.getCriteriaBuilder();
     CriteriaQuery<Project> query = cb.createQuery(Project.class);
     Root<Project> root = query.from(Project.class);
     Fetch<Project, Workload>  wl = root.fetch(Project.PROPERTY_WORKLOADS);
     wl.fetch("jobConfiguration");
     query.select(root);
     results = em.createQuery(query).getResultList();
     for (Project project : results) {
        project.getWorkloads().get(0).getJobConfiguration().getVariables();
        project.getWorkloads().get(0).getJobConfiguration().getDataFileIds();               
     }
     commit();
    } catch (Exception e) {
        rollback();
        e.printStackTrace();
        throw new RuntimeException(e);
    } finally {
        cleanup();
    }
    return results;
}
项目:karaf4-eclipselink-jpa    文件:JpaUtil.java   
/**
 * 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;
}
项目:rpb    文件:JpaUtil.java   
/**
 * Convert the passed propertyPath into a JPA path. <br>
 * Note: JPA will do joins if the property is in an associated entity.
 */
@SuppressWarnings("unchecked")
private static <E> Path<?> getPropertyOrderPath(Root<E> root, String propertyPath, SearchParameters sp) {
    String[] pathItems = StringUtils.split(propertyPath, ".");

    Path<?> path = null;

    String pathItem = pathItems[0];
    if (sp.getDistinct()) {
        // handle case when order on already fetched attribute
        for (Fetch<E, ?> fetch : root.getFetches()) {
            if (pathItem.equals(fetch.getAttribute().getName()) && fetch instanceof Join<?, ?>) {
                path = (Join<E, ?>) fetch;
            }
        }
        for (Join<E, ?> join : root.getJoins()) {
            if (pathItem.equals(join.getAttribute().getName()) && join instanceof Join<?, ?>) {
                path = (Join<E, ?>) join;
            }
        }
    }

    // if no fetch matches the required path item, load it from root
    if (path == null) {
        path = root.get(pathItem);
    }

    for (int i = 1; i < pathItems.length; i++) {
        path = path.get(pathItems[i]);
    }
    return path;
}
项目:hibernate-semantic-query    文件:CriteriaInterpreter.java   
private void bindFetches(FetchParent<?, ?> lhs, SqmNavigableReference lhsBinding, SqmFromElementSpace space) {
    if ( !SqmNavigableSourceReference.class.isInstance( lhsBinding ) ) {
        if ( !lhs.getFetches().isEmpty() ) {
            throw new ParsingException( "Attempt to bind fetches against a NavigableBinding that is not also a NavigableSourceBinding " );
        }
        else {
            return;
        }
    }

    final SqmNavigableSourceReference sourceBinding = (SqmNavigableSourceReference) lhsBinding;

    for ( Fetch<?, ?> fetch : lhs.getFetches() ) {
        final JpaFetch<?,?> jpaFetch = (JpaFetch<?, ?>) fetch;

        final SqmAttributeReference attrBinding = (SqmAttributeReference) parsingContext.findOrCreateNavigableBinding(
                sourceBinding,
                fetch.getAttribute().getName()
        );

        // todo : handle treats

        final SqmAttributeJoin sqmFetch = querySpecProcessingStateStack.getCurrent().getFromElementBuilder().buildAttributeJoin(
                attrBinding,
                interpretAlias( jpaFetch.getAlias() ),
                // todo : this is where treat would be applied
                null,
                convert( fetch.getJoinType() ),
                true,
                false
        );
        space.addJoin( sqmFetch );
        bindFetches( fetch, sqmFetch.getBinding(), space );
        jpaPathResolutionMap.put( jpaFetch, sqmFetch.getBinding() );
    }
}
项目:hibernate-semantic-query    文件:AbstractFromImpl.java   
@Override
public void addFetch(Fetch<X, ?> fetch) {
    if ( fetches == null ) {
        fetches = new LinkedHashSet<Fetch<X, ?>>();
    }
    fetches.add( fetch );
}
项目:hibernate-semantic-query    文件:AbstractFromImpl.java   
@Override
@SuppressWarnings({"unchecked"})
public Set<Fetch<X, ?>> getFetches() {
    return fetches == null
            ? Collections.EMPTY_SET
            : fetches;
}
项目:stdlib    文件:JPAQueryBuilder.java   
private void addFetches(Collection<String> fetches)
{
    Map<String, Fetch> created = new HashMap<>();

    for (String fetch : fetches)
    {
        Fetch parent = null;

        final String[] parts = StringUtils.split(fetch, '.');

        for (int i = 0; i < parts.length; i++)
        {
            final String path = StringUtils.join(parts, '.', 0, i + 1);

            Fetch existing = created.get(path);

            if (existing == null)
            {
                if (parent == null)
                {
                    // attribute of root
                    existing = root.fetch(parts[i], JoinType.LEFT);
                }
                else
                {
                    // attribute of parent
                    existing = parent.fetch(parts[i], JoinType.LEFT);
                }

                created.put(path, existing);
            }

            parent = existing;
        }
    }
}
项目:gazpachoquest    文件:JpaUtil.java   
/**
 * 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;
}
项目:query-utils    文件:QueryUtils.java   
public static Iterable<Fetch<?,?>> getAllFetches(FetchParent<?, ?> parent) {
    return flatMap(new Transformer<Fetch<?,?>,Iterable<Fetch<?,?>>>() {
        @Override
        public Iterable<Fetch<?, ?>> transform(Fetch<?, ?> source) {
            return cons(source, getAllFetches(source));
        }
    }, parent.getFetches());
}
项目:query-utils    文件:JpaCriteriaCopy.java   
private static void copyFetches(FetchParent<?, ?> from, FetchParent<?, ?> to) {
    for (Fetch<?, ?> fetch : sort(fetchComparator, from.getFetches())) {
        Attribute<?, ?> attr = fetch.getAttribute();
        @SuppressWarnings({ "rawtypes", "unchecked" })
        Fetch<?, ?> f = attr instanceof SingularAttribute ? to.fetch((SingularAttribute) fetch.getAttribute(), fetch.getJoinType()) :
            attr instanceof CollectionAttribute ? to.fetch((CollectionAttribute) fetch.getAttribute(), fetch.getJoinType()) :
            attr instanceof SetAttribute ? to.fetch((SetAttribute) fetch.getAttribute(), fetch.getJoinType()) :
            attr instanceof ListAttribute ? to.fetch((ListAttribute) fetch.getAttribute(), fetch.getJoinType()) :
            attr instanceof MapAttribute ? to.fetch((MapAttribute) fetch.getAttribute(), fetch.getJoinType()) :
            to.fetch((CollectionAttribute) fetch.getAttribute(), fetch.getJoinType());
        copyFetches(fetch, f);
    }
}
项目:jdal    文件:JpaUtils.java   
/**
 * 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);
    }
}
项目:jdal    文件:JpaUtils.java   
/**
 * 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);
    }
}
项目:tap17-muggl-javaee    文件:MugglFrom.java   
@Override
public Set<Fetch<X, ?>> getFetches() {
    // TODO Auto-generated method stub
    return null;
}
项目:tap17-muggl-javaee    文件:MugglFrom.java   
@Override
public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> attribute) {
    // TODO Auto-generated method stub
    return null;
}
项目:tap17-muggl-javaee    文件:MugglFrom.java   
@Override
public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> attribute,
        JoinType jt) {
    // TODO Auto-generated method stub
    return null;
}
项目:tap17-muggl-javaee    文件:MugglFrom.java   
@Override
public <Y> Fetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> attribute) {
    // TODO Auto-generated method stub
    return null;
}
项目:tap17-muggl-javaee    文件:MugglFrom.java   
@Override
public <Y> Fetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> attribute,
        JoinType jt) {
    // TODO Auto-generated method stub
    return null;
}
项目:tap17-muggl-javaee    文件:MugglFrom.java   
@Override
public <X, Y> Fetch<X, Y> fetch(String attributeName) {
    // TODO Auto-generated method stub
    return null;
}
项目:tap17-muggl-javaee    文件:MugglFrom.java   
@Override
public <X, Y> Fetch<X, Y> fetch(String attributeName, JoinType jt) {
    // TODO Auto-generated method stub
    return null;
}
项目:my-paper    文件:BaseDaoImpl.java   
private void copyFetches(Fetch<?, ?> from, Fetch<?, ?> to) {
    for (Fetch<?, ?> fetch : from.getFetches()) {
        Fetch<?, ?> toFetch = to.fetch(fetch.getAttribute().getName());
        copyFetches(fetch, toFetch);
    }
}
项目:hibernate-semantic-query    文件:AbstractFromImpl.java   
@Override
public void addFetch(Fetch<X, ?> fetch) {
    throw new UnsupportedOperationException( "Cannot define fetch from a subquery correlation" );
}
项目:hexa.tools    文件:RootImpl.java   
@Override
public <Y> Fetch<T, Y> fetch( SingularAttribute<? super T, Y> arg0 )
{
    // TODO Auto-generated method stub
    return null;
}
项目:hexa.tools    文件:RootImpl.java   
@Override
public <Y> Fetch<T, Y> fetch( PluralAttribute<? super T, ?, Y> arg0 )
{
    // TODO Auto-generated method stub
    return null;
}
项目:hexa.tools    文件:RootImpl.java   
@Override
public <X, Y> Fetch<X, Y> fetch( String arg0 )
{
    // TODO Auto-generated method stub
    return null;
}
项目:hexa.tools    文件:RootImpl.java   
@Override
public <Y> Fetch<T, Y> fetch( SingularAttribute<? super T, Y> arg0, JoinType arg1 )
{
    // TODO Auto-generated method stub
    return null;
}
项目:hexa.tools    文件:RootImpl.java   
@Override
public <Y> Fetch<T, Y> fetch( PluralAttribute<? super T, ?, Y> arg0, JoinType arg1 )
{
    // TODO Auto-generated method stub
    return null;
}
项目:hexa.tools    文件:RootImpl.java   
@Override
public <X, Y> Fetch<X, Y> fetch( String arg0, JoinType arg1 )
{
    // TODO Auto-generated method stub
    return null;
}
项目:hexa.tools    文件:RootImpl.java   
@Override
public Set<Fetch<T, ?>> getFetches()
{
    // TODO Auto-generated method stub
    return null;
}
项目:raidenjpa    文件:RaidenRoot.java   
@Override
public Set<Fetch<X, ?>> getFetches() {
    // TODO Auto-generated method stub
    return null;
}
项目:raidenjpa    文件:RaidenRoot.java   
@Override
public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> attribute) {
    // TODO Auto-generated method stub
    return null;
}
项目:raidenjpa    文件:RaidenRoot.java   
@Override
public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> attribute,
        JoinType jt) {
    // TODO Auto-generated method stub
    return null;
}
项目:raidenjpa    文件:RaidenRoot.java   
@Override
public <Y> Fetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> attribute) {
    // TODO Auto-generated method stub
    return null;
}