List of usage examples for javax.persistence.criteria CriteriaQuery from
<X> Root<X> from(Class<X> entityClass);
From source file:dao.jpa.JpaUtilsTest.java
@Test @Transactional/*from w w w . j a va 2s . c o m*/ public void testInitialize() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Category> c = cb.createQuery(Category.class); Root<Category> root = c.from(Category.class); c.where(cb.equal(JpaUtils.getPath(root, "name"), "Java")); List<Category> list = em.createQuery(c).getResultList(); Category cat = list.get(0); JpaUtils.initialize(em, cat, 2); cat.getBooks().contains(new Book()); }
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 {/* w w w.j a v a2 s.c om*/ return getEntityManager().createQuery(query).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:ro.alexdutescu.coduribare.service.AbstractFacade.java
public List<T> findAll() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return getEntityManager().createQuery(cq).getResultList(); }
From source file:eu.uqasar.service.company.CompanyService.java
public List<Company> getAllCompanys() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Company> query = cb.createQuery(Company.class); query.from(Company.class); return em.createQuery(query).getResultList(); }
From source file:net.groupbuy.dao.impl.CouponDaoImpl.java
public Page<Coupon> findPage(Boolean isEnabled, Boolean isExchange, Boolean hasExpired, Pageable pageable) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Coupon> criteriaQuery = criteriaBuilder.createQuery(Coupon.class); Root<Coupon> root = criteriaQuery.from(Coupon.class); criteriaQuery.select(root);// w ww . j av a 2 s . c om Predicate restrictions = criteriaBuilder.conjunction(); if (isEnabled != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isEnabled"), isEnabled)); } if (isExchange != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isExchange"), isExchange)); } if (hasExpired != null) { if (hasExpired) { 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.findPage(criteriaQuery, pageable); }
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 {/* w ww . j a v a2s . com*/ return getEntityManager().createQuery(query).getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:ro.alexdutescu.coduribare.service.AbstractFacade.java
public List<T> findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); javax.persistence.Query q = getEntityManager().createQuery(cq); q.setMaxResults(range[1] - range[0] + 1); q.setFirstResult(range[0]);/*www .j av a2 s. c om*/ return q.getResultList(); }
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:core.commonapp.server.dao.security.UserLoginDaoHibernateImpl.java
@Override public boolean existByUsername(String username) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserLogin> query = builder.createQuery(UserLogin.class); Root<UserLogin> root = query.from(UserLogin.class); query.where(builder.equal(root.get("username"), username)); return getEntityManager().createQuery(query).getResultList().size() > 0; }
From source file:core.commonapp.server.dao.security.UserLoginDaoHibernateImpl.java
@Override public List<UserLogin> findAllLikeUsername(String username) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserLogin> query = builder.createQuery(UserLogin.class); Root<UserLogin> root = query.from(UserLogin.class); query.where(builder.like(root.<String>get("username"), "%" + username + "%")); return getEntityManager().createQuery(query).getResultList(); }