Example usage for javax.persistence.criteria Root get

List of usage examples for javax.persistence.criteria Root get

Introduction

In this page you can find the example usage for javax.persistence.criteria Root get.

Prototype

<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);

Source Link

Document

Create a path corresponding to the referenced single-valued attribute.

Usage

From source file:com.fantasy.stataggregator.workers.StatCompilerTask.java

@Override
public void setYear(int year) throws Exception {
    this.year = year;

    GameDataRepository gdr = ctx.getBean(GameDataRepository.class);
    if (year == Integer.MAX_VALUE) {
        gamesData = gdr.findAll();//from  w ww  .  j  a  v a  2s .  c  o m
    } else {
        SimpleDateFormat sdf = ctx.getBean(SimpleDateFormat.class);
        sdf.applyLocalizedPattern("yyyyMMdd");

        Date min = sdf.parse(year + START_OF_YEAR);
        Date max = sdf.parse(year + END_OF_YEAR);

        CriteriaBuilder cb = gdr.getCriteriaBuilder();
        CriteriaQuery<GameData> cq = gdr.getCriteriaQuery();
        Root<GameData> gameData = gdr.getRoot();
        Path<GameDataPK> pk = gameData.get(GameData_.gameDataPK);
        cq.select(gameData).where(cb.equal(pk.get(GameDataPK_.year), year))
                .orderBy(cb.asc(pk.get(GameDataPK_.gameIdentifier)));

        gamesData = gdr.getCriteriaList(cq);
        System.out.println(gamesData.size());
    }
}

From source file:com.ttech.cordovabuild.domain.user.UserRepositoryImpl.java

@Override
public User findUserByEmail(String email) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> root = cq.from(User.class);
    return em.createQuery(cq.select(root).where(cb.equal(root.get(User_.email), email))).getSingleResult();
}

From source file:cz.muni.expense.data.UserRepository.java

public User findByUsername(String username) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> criteria = cb.createQuery(User.class);
    Root<User> user = criteria.from(User.class);
    criteria.select(user).where(cb.equal(user.get(User_.username), username));
    try {//from w ww  .  j a  v a 2 s  .  com
        return em.createQuery(criteria).getSingleResult();
    } catch (NoResultException ex) {
        return null;
    }
}

From source file:com.toptal.dao.UserDaoImpl.java

@Transactional
@Override// www  . ja  v a 2s .  c  o m
public final User saveIgnoringPassword(final User user) {
    final CriteriaBuilder builder = this.manager.getCriteriaBuilder();
    final CriteriaUpdate<User> update = builder.createCriteriaUpdate(User.class);
    final Root<User> root = update.from(User.class);
    update.set(root.get(NAME_FIELD), user.getName());
    update.set(root.get("role"), user.getRole());
    update.where(builder.equal(root.get("id"), user.getId()));
    this.manager.createQuery(update).executeUpdate();
    return this.manager.find(User.class, user.getId());
}

From source file:com.ttech.cordovabuild.domain.user.UserRepositoryImpl.java

@Override
public User findUserByUserName(String username) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> root = cq.from(User.class);
    return em.createQuery(cq.select(root).where(cb.equal(root.get(User_.username), username)))
            .getSingleResult();//from   ww  w . j a v a  2 s  .  c  om
}

From source file:cz.muni.expense.data.UserRepository.java

public User findByUsernameAndAuthToken(String authId, String authToken) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> criteria = cb.createQuery(User.class);
    Root<User> user = criteria.from(User.class);
    criteria.select(user).where(cb.equal(user.get(User_.username), authId));
    try {//from   w w  w  .  ja va  2 s  .  co m
        User userToReturn = em.createQuery(criteria).getSingleResult();
        return userToReturn.getAuthToken().equals(authToken) ? userToReturn : null;
    } catch (NoResultException ex) {
        return null;
    }
}

From source file:core.commonapp.server.dao.security.PermissionSecurityGroupDaoHibernateImpl.java

@Override
public List<PermissionSecurityGroup> findAllBySecurityGroup(SecurityGroup securityGroup, boolean includeOld) {
    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<PermissionSecurityGroup> query = builder.createQuery(getPersistClass());
    Root<PermissionSecurityGroup> root = query.from(getPersistClass());
    query.where(builder.equal(root.get("securityGroup"), securityGroup));

    if (!includeOld) {
        query.where(builder.isNull(root.get("thruDate")));
    }/*w  w  w .  j  a  va2  s  .co  m*/

    return (List<PermissionSecurityGroup>) getEntityManager().createQuery(query).getResultList();
}

From source file:example.springdata.jpa.showcase.snippets.AccountRepositoryImpl.java

@Override
public void removedExpiredAccounts(LocalDate reference) {

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Account> query = cb.createQuery(Account.class);
    Root<Account> account = query.from(Account.class);

    query.where(//www  . j a v  a  2s .  c  o m
            cb.lessThan(account.get("expiryDate").as(Date.class), reference.toDateTimeAtStartOfDay().toDate()));

    for (Account each : em.createQuery(query).getResultList()) {
        em.remove(each);
    }
}

From source file:com.luna.common.repository.SpecificationUserRepositoryIT.java

@Test
public void test() {

    userRepository.save(user);//  ww  w.ja v  a  2  s .  c o  m

    Specification<User> spec = new Specification<User>() {
        @Override
        public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            return cb.equal(root.get("id"), user.getId());
        }
    };

    clear();

    User dbUser = userRepository.findOne(spec);
    assertNotNull(dbUser);

}

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;
}