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


Java CriteriaQuery.select方法代码示例

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


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

示例1: readPage

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Returns a page of objects.
 *
 * @param entityClass The entity class.
 * @param page The page index (zero indexed).
 * @param pageSize The page size.
 * @return A page of objects.
 */
@Override
public <T extends BaseEntity> List<T> readPage(
        final Class<T> entityClass,
        final int page,
        final int pageSize) {

    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<T> cq = cb.createQuery(entityClass);
    final Root<T> root = cq.from(entityClass);
    cq.select(root);
    cq.orderBy(cb.desc(root.get("id")));
    return em.createQuery(cq)
            .setFirstResult(page * pageSize)
            .setMaxResults(pageSize)
            .getResultList();
}
 
开发者ID:minijax,项目名称:minijax,代码行数:25,代码来源:DefaultBaseDao.java

示例2: getCountQuery

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> TypedQuery<Long> getCountQuery(CriteriaQuery<T> cq) {
	Class<T> domainClass = cq.getResultType();
	EntityManager em = getEntityManager(domainClass);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> countCq = cb.createQuery(Long.class);
	Root<T> root;
	if (cq.getRestriction() != null) {
		countCq.where(cq.getRestriction());
	}
	if (cq.getGroupRestriction() != null) {
		countCq.having(cq.getGroupRestriction());
	}
	if (cq.getRoots().isEmpty()) {
		root = countCq.from(domainClass);
	} else {
		countCq.getRoots().addAll(cq.getRoots());
		root = (Root<T>) countCq.getRoots().iterator().next();
	}
	countCq.groupBy(cq.getGroupList());
	if (cq.isDistinct()) {
		countCq.select(cb.countDistinct(root));
	} else {
		countCq.select(cb.count(root));
	}

	return em.createQuery(countCq);
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:29,代码来源:JpaUtil.java

示例3: findPersonaEntities

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
private List<Usuario> findPersonaEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Usuario.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:16,代码来源:UsuarioJpaController.java

示例4: getQuery

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
private CriteriaQuery<User> getQuery(User po) {
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	CriteriaQuery<User> query = cb.createQuery(User.class);
	Root<User> root = query.from(User.class);
	query.select(root);
	query.where(cb.and(getPredicates(cb, root, po)));
	return query;
}
 
开发者ID:lf23617358,项目名称:training-sample,代码行数:9,代码来源:JPAUserRepository.java

示例5: findRange

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public default List<E> findRange(Long from, Long to) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();

    CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
    criteriaQuery.select(criteriaQuery.from(getEntityClass()));
    TypedQuery<E> query = entityManager.createQuery(criteriaQuery);
    query.setMaxResults(Math.toIntExact(to - from + 1));
    query.setFirstResult(Math.toIntExact(from));

    return query.getResultList();
}
 
开发者ID:daniel-shuy,项目名称:JAX-RS-JPA-CRUD,代码行数:13,代码来源:RepositoryCRUD.java

示例6: findOne

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Find one with fetched associations.
 */
private T findOne(final K id, final Map<String, JoinType> fetchedAssociations) {
	final CriteriaBuilder builder = em.getCriteriaBuilder();
	final CriteriaQuery<T> query = builder.createQuery(getDomainClass());

	// Apply fetch
	final Root<T> root = query.from(getDomainClass());
	SpringUtils.getBean(FetchHelper.class).applyFetchedAssociations(fetchedAssociations, root);

	// Apply specification
	final Specification<T> specification = (r, q, cb) -> cb.equal(r.get("id"), id);
	query.where(specification.toPredicate(root, query, builder));
	query.select(root);
	return em.createQuery(query).getSingleResult();
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:18,代码来源:RestRepositoryImpl.java

示例7: getRowCount

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * @see FachadaIntegracion<T>{@link #getRowCount()}
 */
public Long getRowCount() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> cq = cb.createQuery(Long.class);
    cq.select(cb.count(cq.from(entityClass)));
    return em.createQuery(cq).getSingleResult();
}
 
开发者ID:EventSoftGroup,项目名称:EventSoft,代码行数:10,代码来源:ServicioIntegracionImp.java

示例8: findAll

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
protected  <T> List<T> findAll(Class clazz) throws DatabaseException {
    try {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<T> c = cb.createQuery(clazz);
        Root<T> root = c.from(clazz);
        CriteriaQuery<T> all = c.select(root);
        TypedQuery<T> allQuery = getEntityManager().createQuery(all);

        return allQuery.getResultList();
    } catch (EJBTransactionRolledbackException | PersistenceException e) {
        throw new DatabaseException("Could not find entity of class " + clazz.toString() + ", " + e.getMessage());
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:14,代码来源:AbstractRepository.java

示例9: getAllAddresses

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<Address> getAllAddresses() {
    CriteriaQuery<Address> cq = em.getCriteriaBuilder().createQuery(Address.class);
    Root<Address> address = cq.from(Address.class);
    cq.select(address);
    cq.where(cb.isTrue(address.get(Address_.active)));
    cq.distinct(true);
    TypedQuery<Address> q = em.createQuery(cq);
    return q.getResultList();
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:10,代码来源:AdminBean.java

示例10: getTelefonoCount

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public int getTelefonoCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<Telefono> rt = cq.from(Telefono.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:13,代码来源:TelefonoJpaController.java

示例11: findAll

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * 获取所有对象
 * @return
 */
public List<T> findAll() {
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<T> query = cb.createQuery(entityClass);
	Root<T> root = query.from(entityClass);
	query.select(root);
	TypedQuery<T> typedQuery = em.createQuery(query);
	return typedQuery.getResultList();
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:13,代码来源:BaseDao.java

示例12: txInspectionHookEntities

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<InspectionHookEntity> txInspectionHookEntities() {
    CriteriaBuilder criteriaBuilder = this.em.getCriteriaBuilder();

    CriteriaQuery<InspectionHookEntity> query = criteriaBuilder.createQuery(InspectionHookEntity.class);
    Root<InspectionHookEntity> r = query.from(InspectionHookEntity.class);
    query.select(r);

    return this.em.createQuery(query).getResultList();
}
 
开发者ID:opensecuritycontroller,项目名称:sdn-controller-nsc-plugin,代码行数:10,代码来源:RedirectionApiUtils.java

示例13: txInspectionPortEntities

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<InspectionPortEntity> txInspectionPortEntities() {
    CriteriaBuilder criteriaBuilder = this.em.getCriteriaBuilder();

    CriteriaQuery<InspectionPortEntity> query = criteriaBuilder.createQuery(InspectionPortEntity.class);
    Root<InspectionPortEntity> r = query.from(InspectionPortEntity.class);
    query.select(r);

    return this.em.createQuery(query).getResultList();
}
 
开发者ID:opensecuritycontroller,项目名称:sdn-controller-nsc-plugin,代码行数:10,代码来源:RedirectionApiUtils.java

示例14: getTotalJobCount

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Gets the total job count from the database
 * @param session2
 *
 * @return total job count
 */
public static Long getTotalJobCount(EntityManager em) {
    CriteriaBuilder cb = em.getCriteriaBuilder();

    CriteriaQuery<Long> query = cb.createQuery(Long.class);

    query = query.select(cb.count(query.from(JobRecord.class)));
    Long totalJobCount = em.createQuery(query).getSingleResult();

    return totalJobCount;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:JobEntityManager.java

示例15: getPlayersByPosition

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersByPosition(String position) {
    logger.info("getPlayersByPosition");
    List<Player> players = null;

    try {
        CriteriaQuery<Player> cq = cb.createQuery(Player.class);
        if (cq != null) {
            Root<Player> player = cq.from(Player.class);

            // Get MetaModel from Root
            //EntityType<Player> Player_ = player.getModel();

            // set the where clause
            cq.where(cb.equal(player.get(Player_.position), position));
            cq.select(player);
            TypedQuery<Player> q = em.createQuery(cq);
            players = q.getResultList();
        }
        return copyPlayersToDetails(players);
    } catch (Exception ex) {
        throw new EJBException(ex);
    }
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:24,代码来源:RequestBeanQueries.java


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