当前位置: 首页>>代码示例>>Java>>正文


Java Fetch类代码示例

本文整理汇总了Java中javax.persistence.criteria.Fetch的典型用法代码示例。如果您正苦于以下问题:Java Fetch类的具体用法?Java Fetch怎么用?Java Fetch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Fetch类属于javax.persistence.criteria包,在下文中一共展示了Fetch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPath

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
@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;
}
 
开发者ID:jpasearch,项目名称:jpasearch,代码行数:26,代码来源:JpaUtil.java

示例2: fetches

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
@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);
                }
            }
        }
    }
}
 
开发者ID:jpasearch,项目名称:jpasearch,代码行数:24,代码来源:JpaUtil.java

示例3: getFetchedAssoc

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
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);
	}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:13,代码来源:FetchHelper.java

示例4: copyJoins

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
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);
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:12,代码来源:BaseDaoImpl.java

示例5: getPropertyOrderPath

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ddRPB,项目名称:rpb,代码行数:36,代码来源:JpaUtil.java

示例6: containsMultiRelationFetch

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
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;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:14,代码来源:QueryUtil.java

示例7: containsMultiRelationJoin

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
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;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:13,代码来源:QueryUtil.java

示例8: findByName

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
/**
 * 
 * @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;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:41,代码来源:ProjectDao.java

示例9: findAll

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:35,代码来源:ProjectDao.java

示例10: getPath

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:antoniomaria,项目名称:karaf4-eclipselink-jpa,代码行数:32,代码来源:JpaUtil.java

示例11: bindFetches

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
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() );
	}
}
 
开发者ID:hibernate,项目名称:hibernate-semantic-query,代码行数:37,代码来源:CriteriaInterpreter.java

示例12: addFetch

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
@Override
public void addFetch(Fetch<X, ?> fetch) {
	if ( fetches == null ) {
		fetches = new LinkedHashSet<Fetch<X, ?>>();
	}
	fetches.add( fetch );
}
 
开发者ID:hibernate,项目名称:hibernate-semantic-query,代码行数:8,代码来源:AbstractFromImpl.java

示例13: getFetches

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
@Override
@SuppressWarnings({"unchecked"})
public Set<Fetch<X, ?>> getFetches() {
	return fetches == null
			? Collections.EMPTY_SET
			: fetches;
}
 
开发者ID:hibernate,项目名称:hibernate-semantic-query,代码行数:8,代码来源:AbstractFromImpl.java

示例14: addFetches

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
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;
		}
	}
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:37,代码来源:JPAQueryBuilder.java

示例15: getAllFetches

import javax.persistence.criteria.Fetch; //导入依赖的package包/类
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());
}
 
开发者ID:solita,项目名称:query-utils,代码行数:9,代码来源:QueryUtils.java


注:本文中的javax.persistence.criteria.Fetch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。