當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。