List of usage examples for javax.persistence.criteria CriteriaBuilder createQuery
<T> CriteriaQuery<T> createQuery(Class<T> resultClass);
CriteriaQuery
object with the specified result type. From source file:net.groupbuy.dao.impl.PromotionDaoImpl.java
public List<Promotion> findList(Boolean hasBegun, Boolean hasEnded, Integer count, List<Filter> filters, List<Order> orders) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Promotion> criteriaQuery = criteriaBuilder.createQuery(Promotion.class); Root<Promotion> root = criteriaQuery.from(Promotion.class); criteriaQuery.select(root);//from ww w. j a v a 2 s.c om Predicate restrictions = criteriaBuilder.conjunction(); if (hasBegun != null) { if (hasBegun) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("beginDate").isNull(), criteriaBuilder.lessThanOrEqualTo(root.<Date>get("beginDate"), new Date()))); } else { restrictions = criteriaBuilder.and(restrictions, root.get("beginDate").isNotNull(), criteriaBuilder.greaterThan(root.<Date>get("beginDate"), new Date())); } } if (hasEnded != null) { if (hasEnded) { restrictions = criteriaBuilder.and(restrictions, root.get("endDate").isNotNull(), criteriaBuilder.lessThan(root.<Date>get("endDate"), new Date())); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("endDate").isNull(), criteriaBuilder.greaterThanOrEqualTo(root.<Date>get("endDate"), new Date()))); } } criteriaQuery.where(restrictions); return super.findList(criteriaQuery, null, count, filters, orders); }
From source file:com.toptal.dao.UserDaoImpl.java
@Override public final User findByName(final String name) { final CriteriaBuilder builder = this.manager.getCriteriaBuilder(); final CriteriaQuery<User> query = builder.createQuery(User.class); final Root<User> root = query.from(User.class); query.where(builder.equal(root.get(NAME_FIELD), name)); return this.getSingleResult(query); }
From source file:org.openmeetings.app.data.user.Salutationmanagement.java
/** * get a list of all availible Salutations * /*from w w w. ja va2 s .c o m*/ * @param user_level * @return */ public List<Salutations> getUserSalutations(long language_id) { try { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Salutations> cq = cb.createQuery(Salutations.class); Root<Salutations> from = cq.from(Salutations.class); CriteriaQuery<Salutations> select = cq.select(from); TypedQuery<Salutations> q = em.createQuery(select); List<Salutations> ll = q.getResultList(); for (Salutations ti : ll) { ti.setLabel(fieldmanagment.getFieldByIdAndLanguage(ti.getFieldvalues_id(), language_id)); } return ll; } catch (Exception ex2) { log.error("[addUserSalutation]", ex2); } return null; }
From source file:eu.uqasar.service.company.CompanyService.java
/** * //from w ww. j av a 2 s . c o m * @param companyId * @return */ public boolean companyExists(Long companyId) { logger.info(String.format("checking if Company with ID %d exists ...", companyId)); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = cb.createQuery(Long.class); Root<Company> from = criteria.from(Company.class); criteria.where(cb.equal(from.get(Company_.id), companyId)); criteria.select(cb.countDistinct(from)); return (em.createQuery(criteria).getSingleResult().longValue() == 1); }
From source file:com.zergiu.tvman.dao.impl.TVShowDaoImpl.java
@Override public Long getTVShowsCount() { CriteriaBuilder criteria = em.getCriteriaBuilder(); CriteriaQuery<Long> query = criteria.createQuery(Long.class); query.select(criteria.countDistinct(query.from(TVShow.class))); Long count = em.createQuery(query).getSingleResult(); log.debug("all count: " + count); return count; }
From source file:dtu.ds.warnme.dao.impl.AbstractGenericDao.java
@Override @Transactional(readOnly = true)//w w w . ja v a 2 s. com public List<T> getAll() { CriteriaBuilder builder = manager.getCriteriaBuilder(); CriteriaQuery<T> criteria = builder.createQuery(entityClazz); Root<T> root = criteria.from(entityClazz); criteria.select(root); return manager.createQuery(criteria).getResultList(); }
From source file:org.osiam.resource_server.storage.dao.ExtensionDao.java
/** * Get all stored extensions.// w w w. j ava 2 s.co m * * @return all extensions. */ public List<ExtensionEntity> getAllExtensions() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ExtensionEntity> cq = cb.createQuery(ExtensionEntity.class); Root<ExtensionEntity> extension = cq.from(ExtensionEntity.class); cq.select(extension); TypedQuery<ExtensionEntity> query = em.createQuery(cq); return query.getResultList(); }
From source file:eu.uqasar.service.company.CompanyService.java
public long countAllFiltered(final CompanyFilterStructure filter) { logger.infof("counting all Companies matching the filter %s ...", filter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = cb.createQuery(Long.class); Root<Company> from = criteria.from(Company.class); criteria.where(cb.or(cb.equal(from.get(Company_.name), filter.getName()), cb.equal(from.get(Company_.shortName), filter.getShortName()), cb.equal(from.get(Company_.country), filter.getCountry()))); criteria.select(cb.countDistinct(from)); return em.createQuery(criteria).getSingleResult(); }
From source file:eu.uqasar.service.company.CompanyService.java
/** * // ww w. j a v a2 s . c om * @param innovationObjective * @return */ public List<Company> getAllByAscendingName() { logger.infof("loading all Company ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Company> criteria = cb.createQuery(Company.class); Root<Company> root = criteria.from(Company.class); criteria.orderBy(cb.asc(root.get(Company_.name))); return em.createQuery(criteria).getResultList(); }
From source file:com.zergiu.tvman.dao.impl.TVShowDaoImpl.java
@Override public Long getActiveTVShowsCount() { CriteriaBuilder criteria = em.getCriteriaBuilder(); CriteriaQuery<Long> query = criteria.createQuery(Long.class); Root<TVShow> show = query.from(TVShow.class); query.select(criteria.countDistinct(show)); query.where(criteria.equal(show.<TVShowStatus>get("status"), TVShowStatus.Continuing)); Long count = em.createQuery(query).getSingleResult(); log.debug("active count: " + count); return count; }