List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:core.commonapp.server.dao.security.UserLoginDaoHibernateImpl.java
@Override public UserLogin findByUsernameAndPassword(String username, String password) { 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), builder.equal(root.get("password"), password)); return getEntityManager().createQuery(query).getSingleResult(); }
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:com.github.springtestdbunit.entity.EntityAssert.java
public void afterPropertiesSet() throws Exception { CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); this.criteriaQuery = cb.createQuery(SampleEntity.class); Root<SampleEntity> from = this.criteriaQuery.from(SampleEntity.class); this.criteriaQuery.orderBy(cb.asc(from.get("value").as(String.class))); }
From source file:core.commonapp.server.dao.security.UserLoginSecurityGroupDaoHibernateImpl.java
@Override public List<UserLoginSecurityGroup> findByUserLoginAndSecurityGroup(UserLogin userLogin, SecurityGroup securityGroup, boolean includeOld) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserLoginSecurityGroup> query = builder.createQuery(getPersistClass()); Root<UserLoginSecurityGroup> root = query.from(getPersistClass()); query.where(builder.equal(root.get("securityGroup"), securityGroup), builder.equal(root.get("userLogin"), userLogin), (includeOld ? builder.isNotNull(root.get("thruDate")) : builder.isNull(root.get("thruDate")))); return (List<UserLoginSecurityGroup>) getEntityManager().createQuery(query).getResultList(); }
From source file:core.commonapp.server.dao.security.UserLoginSecurityGroupDaoHibernateImpl.java
@Override public List<UserLoginSecurityGroup> findBySecurityGroup(SecurityGroup securityGroup, boolean includeOld) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserLoginSecurityGroup> query = builder.createQuery(getPersistClass()); Root<UserLoginSecurityGroup> root = query.from(getPersistClass()); query.where(builder.equal(root.get("securityGroup"), securityGroup)); if (!includeOld) { query.where(builder.isNull(root.get("thruDate"))); }/*w ww .j a v a 2 s. co m*/ return (List<UserLoginSecurityGroup>) getEntityManager().createQuery(query).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 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:com.github.springtestdbunit.entity.OtherEntityAssert.java
public void afterPropertiesSet() throws Exception { CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); this.criteriaQuery = cb.createQuery(OtherSampleEntity.class); Root<OtherSampleEntity> from = this.criteriaQuery.from(OtherSampleEntity.class); this.criteriaQuery.orderBy(cb.asc(from.get("value").as(String.class))); }
From source file:net.groupbuy.dao.impl.DepositDaoImpl.java
public Page<Deposit> findPage(Member member, Pageable pageable) { if (member == null) { return new Page<Deposit>(Collections.<Deposit>emptyList(), 0, pageable); }/*from w w w .j a v a 2 s . co m*/ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Deposit> criteriaQuery = criteriaBuilder.createQuery(Deposit.class); Root<Deposit> root = criteriaQuery.from(Deposit.class); criteriaQuery.select(root); criteriaQuery.where(criteriaBuilder.equal(root.get("member"), member)); return super.findPage(criteriaQuery, pageable); }
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 ww .j a va 2 s . co m*/ return getEntityManager().createQuery(query).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { return null; } }