List of usage examples for javax.persistence.criteria CriteriaQuery select
CriteriaQuery<T> select(Selection<? extends T> selection);
From source file:cz.muni.fi.pa165.bookingmanager.managers.UserManager.java
@Override public List<User> findAll() { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<User> query = criteriaBuilder.createQuery(User.class); Root<User> c = query.from(User.class); query.select(c); TypedQuery<User> typedQuery = entityManager.createQuery(query); return typedQuery.getResultList(); //return em.createQuery("SELECT u FROM User u WHERE u.user = :user", User.class).setParameter("user", user).getResultList(); }
From source file:org.businessmanager.dao.security.GroupDaoImpl.java
@Override public Group findGroupByName(String name) { CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Group> query = queryBuilder.createQuery(Group.class); Root<Group> groupQuery = query.from(Group.class); query.select(groupQuery).where(queryBuilder.equal(groupQuery.get(Group_.name), name)); try {//from w ww . j a v a 2 s.c om return getEntityManager().createQuery(query).getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:net.groupbuy.dao.impl.FriendLinkDaoImpl.java
public List<FriendLink> findList(Type type) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<FriendLink> criteriaQuery = criteriaBuilder.createQuery(FriendLink.class); Root<FriendLink> root = criteriaQuery.from(FriendLink.class); criteriaQuery.select(root); if (type != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type)); }/*from www. j av a 2 s . co m*/ criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:net.groupbuy.dao.impl.NavigationDaoImpl.java
public List<Navigation> findList(Position position) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Navigation> criteriaQuery = criteriaBuilder.createQuery(Navigation.class); Root<Navigation> root = criteriaQuery.from(Navigation.class); criteriaQuery.select(root); if (position != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("position"), position)); }// w ww . j a va 2 s. c o m criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:com.greendot.db.jpa.core.AbstractSearchDao.java
@Transactional(readOnly = true) public long count() { final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder(); final CriteriaQuery<Long> rootQuery = criteriaBuilder.createQuery(Long.class); rootQuery.select(criteriaBuilder.count(rootQuery.from(getEntityType()))); return getEntityManager().createQuery(rootQuery).getSingleResult(); }
From source file:org.businessmanager.dao.security.UserDaoImpl.java
@Override public User findUserByName(String username) { CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<User> query = queryBuilder.createQuery(User.class); Root<User> userQuery = query.from(User.class); query.select(userQuery).where(queryBuilder.equal(userQuery.get(User_.username), username)); try {/*from w ww . j ava 2s .c om*/ return getEntityManager().createQuery(query).getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:com.datapine.dao.impl.ItemDAOImpl.java
@Override @PostFilter("hasRole('ROLE_ADMIN') or hasPermission(filterObject, 'read')") public final List<Item> findAllOrderById() { final CriteriaBuilder builder = this.manager.getCriteriaBuilder(); final CriteriaQuery<Item> query = builder.createQuery(Item.class); final Root<Item> root = query.from(Item.class); query.select(root).orderBy(builder.asc(root.get("id"))); return this.manager.createQuery(query).getResultList(); }
From source file:net.groupbuy.dao.impl.ParameterDaoImpl.java
public List<Parameter> findList(ParameterGroup parameterGroup, Set<Parameter> excludes) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Parameter> criteriaQuery = criteriaBuilder.createQuery(Parameter.class); Root<Parameter> root = criteriaQuery.from(Parameter.class); criteriaQuery.select(root); Predicate restrictions = criteriaBuilder.conjunction(); if (parameterGroup != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("parameterGroup"), parameterGroup)); }//from w w w. ja va 2 s .com if (excludes != null && !excludes.isEmpty()) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.not(root.in(excludes))); } criteriaQuery.where(restrictions); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:com.nuevebit.persistence.repository.JPASearchableRepository.java
@Override public final List<T> search(S searchCriteria, Pageable pageable) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<T> query = cb.createQuery(getEntityClass()); Root<T> p = createQueryRoot(query, searchCriteria); query.select(p); Order sortOrder = getSortOrder(cb);/* w w w . ja v a 2s. c om*/ if (sortOrder != null) { query.orderBy(sortOrder); } TypedQuery<T> typedQuery = getEntityManager().createQuery(query); if (pageable != null) { typedQuery.setFirstResult(pageable.getOffset()).setMaxResults(pageable.getPageSize()); } return typedQuery.getResultList(); }
From source file:org.businessmanager.dao.security.PermissionDaoImpl.java
@Override public Permission findPermissionByName(String name) { CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Permission> query = queryBuilder.createQuery(Permission.class); Root<Permission> permissionQuery = query.from(Permission.class); query.select(permissionQuery).where(queryBuilder.equal(permissionQuery.get(Permission_.name), name)); try {/*from ww w . j av a2s . c om*/ return getEntityManager().createQuery(query).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { return null; } }