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:de.logicline.splash.dao.UserDaoImpl.java

public UserEntity getUser(String token) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserEntity> cq = cb.createQuery(UserEntity.class);
    Root<UserEntity> user = cq.from(UserEntity.class);
    cq.select(user);//w w w. ja va2 s .  co m
    cq.where(cb.equal(user.get("token"), token));
    List<UserEntity> resultList = getEntityManager().createQuery(cq).getResultList();

    UserEntity result = null;
    if (resultList != null && resultList.size() > 0) {
        result = resultList.get(0);
        return result;
    }

    return null;
}

From source file:de.logicline.splash.dao.UserDaoImpl.java

public UserEntity getUserByName(String username) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserEntity> cq = cb.createQuery(UserEntity.class);
    Root<UserEntity> user = cq.from(UserEntity.class);
    cq.select(user);// w  ww . ja  v a2s .  c  o m
    cq.where(cb.equal(user.get("username"), username));
    List<UserEntity> resultList = getEntityManager().createQuery(cq).getResultList();

    if (resultList == null || resultList.size() == 0) {
        log.debug("UserEntity not found");
        return null;
    } else if (resultList.size() > 1) {
        log.warn("Multiple Users found for User with Username: " + username);
        return null;
    }

    return resultList.get(0);
}

From source file:net.groupbuy.dao.impl.TagDaoImpl.java

public List<Tag> findList(Type type) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tag> criteriaQuery = criteriaBuilder.createQuery(Tag.class);
    Root<Tag> root = criteriaQuery.from(Tag.class);
    criteriaQuery.select(root);//from w ww .  j av a  2 s  .  c  om
    if (type != null) {
        criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type));
    }
    criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order")));
    return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList();
}

From source file:net.osgiliath.jpa.repository.impl.HelloJpaRepository.java

@Override
public Collection<? extends HelloEntity> findByHelloObjectMessage(String message_p) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<HelloEntity> cq = cb.createQuery(HelloEntity.class);
    Root<HelloEntity> helloObject = cq.from(HelloEntity.class);
    cq.select(helloObject);/*from  www.  j  a va 2 s .com*/
    Predicate where = cb.equal(helloObject.get("helloMessage"), message_p);
    cq.where(where);
    TypedQuery<HelloEntity> q = entityManager.createQuery(cq);
    List<HelloEntity> result = q.getResultList();
    return result;
}

From source file:org.wallride.repository.PostRepositoryImpl.java

@Override
public void lock(long id) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> query = cb.createQuery(Long.class);
    Root<Post> root = query.from(Post.class);
    query.select(root.get(Post_.id));
    query.where(cb.equal(root.get(Post_.id), id));
    entityManager.createQuery(query).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult();
}

From source file:eu.uqasar.service.company.CompanyService.java

/**
 * //from   ww w . j  a va 2s .c o m
 * @param innovationObjective
 * @return
 */
public List<Company> getAllByAscendingNameFiltered(CompanyFilterStructure filter, int first, int count) {
    logger.infof("loading all Companies ordered by ascending name matching the given filter %s...", filter);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Company> criteria = cb.createQuery(Company.class);
    Root<Company> root = criteria.from(Company.class);

    criteria.where(cb.or(cb.equal(root.get(Company_.name), filter.getName()),
            cb.equal(root.get(Company_.shortName), filter.getShortName()),
            cb.equal(root.get(Company_.country), filter.getCountry()))

    );
    return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList();
}

From source file:org.wallride.repository.CustomFieldRepositoryImpl.java

@Override
public void lock(long id) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> query = cb.createQuery(Long.class);
    Root<CustomField> root = query.from(CustomField.class);
    query.select(root.get(CustomField_.id));
    query.where(cb.equal(root.get(CustomField_.id), id));
    entityManager.createQuery(query).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult();
}

From source file:net.dontdrinkandroot.persistence.dao.ExampleGeneratedIdEntityDaoImpl.java

@Override
@Transactional(readOnly = true)/*from   w  ww  .ja va2s.  c o  m*/
public ExampleEnum findMaxEnum() {
    final CriteriaBuilder builder = this.getCriteriaBuilder();
    final CriteriaQuery<ExampleEnum> criteriaQuery = builder.createQuery(ExampleEnum.class);
    final Root<ExampleGeneratedIdEntity> root = criteriaQuery.from(this.entityClass);

    criteriaQuery.select(root.get(ExampleGeneratedIdEntity_.exampleEnum));

    final List<ExampleEnum> enums = this.getEntityManager().createQuery(criteriaQuery).getResultList();
    ExampleEnum max = null;
    for (final ExampleEnum exampleEnum : enums) {
        if (max == null || exampleEnum.ordinal() > max.ordinal()) {
            max = exampleEnum;
        }
    }

    return max;
}

From source file:com.datapine.dao.impl.UserDAOImpl.java

/**
 * Gets an iterator for the collection of all users sorted by id.
 * @return An iterator.//from w  w  w  . ja  v  a  2  s  . c  o m
 */
@Override
public final Iterator<User> findAllOrderById() {
    final CriteriaBuilder builder = this.manager.getCriteriaBuilder();
    final CriteriaQuery<User> query = builder.createQuery(User.class);
    final Root<User> root = query.from(User.class);
    query.select(root).orderBy(builder.asc(root.get("id")));
    return this.manager.createQuery(query).getResultList().iterator();
}

From source file:net.kaczmarzyk.spring.data.jpa.domain.PathSpecification.java

@SuppressWarnings("unchecked")
protected <F> Path<F> path(Root<T> root) {
    Path<?> expr = null;// ww w  .j  av  a 2 s .  c  om
    for (String field : path.split("\\.")) {
        if (expr == null) {
            expr = root.get(field);
        } else {
            expr = expr.get(field);
        }
    }
    return (Path<F>) expr;
}