本文整理汇总了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();
}
示例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);
}
示例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();
}
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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());
}
}
示例8: 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();
}
示例9: 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();
}
}
示例10: 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();
}
示例11: 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();
}
示例12: 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();
}
示例13: 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;
}
示例14: 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);
}
}
示例15: 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;
}