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:net.przemkovv.sphinx.dao.impl.DefaultSolutionDAO.java

@Override
public List<Solution> getSolutionsByTask(Task task) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Solution> cq = cb.createQuery(Solution.class);
    Root<Solution> solution = cq.from(Solution.class);
    cq.where(cb.equal(solution.get(Solution_.task), task));
    return em.createQuery(cq).getResultList();
}

From source file:de.widone.services.daos.UserDAO.java

public User findUserByUsername(String username) {
    CriteriaQuery<User> query = createCriteria();
    Root<User> userRoot = query.from(User.class);
    entityManager.getCriteriaBuilder().equal(userRoot.get("username"), username);
    List<User> users = entityManager.createQuery(query).getResultList();
    if (users.size() == 1)
        return users.get(0);
    return null;/*w  ww .ja  va  2 s  . com*/
}

From source file:com.github.lothar.security.acl.sample.SampleApplication.java

@Bean
public Specification<Customer> smithFamilySpec(JpaSpecFeature<Customer> jpaSpecFeature) {
    Specification<Customer> smithFamilySpec = new Specification<Customer>() {
        @Override/*from w  w w . j  ava2s  .  com*/
        public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            return cb.equal(root.get("lastName"), "Smith");
        }
    };
    customerStrategy.install(jpaSpecFeature, smithFamilySpec);
    return smithFamilySpec;
}

From source file:org.oncoblocks.centromere.jpa.test.EntrezGeneRepositoryImpl.java

public List<EntrezGene> guessGene(String keyword) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<EntrezGene> query = builder.createQuery(EntrezGene.class);
    Root<EntrezGene> root = query.from(EntrezGene.class);
    query.where(builder.equal(root.get("primaryGeneSymbol"), keyword));
    List<EntrezGene> genes = entityManager.createQuery(query).getResultList();
    if (genes != null && genes.size() > 0)
        return genes;

    query = builder.createQuery(EntrezGene.class);
    root = query.from(EntrezGene.class);
    Path join = root.join("aliases");
    query.where(builder.equal(join.get("name"), keyword));
    return entityManager.createQuery(query).getResultList();
}

From source file:com.excilys.ebi.sample.jpa.query.benchmark.repository.impl.JPACriteriaRepository.java

@Override
public List<Song> getSongsByArtistNameOrderBySongTitle(final String name) {

    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Song> query = builder.createQuery(Song.class);
    Root<Song> root = query.from(Song.class);

    query.where(builder.equal(root.get(Song_.artist).get(Artist_.name), name))
            .orderBy(builder.asc(root.get(Song_.title)));

    return em.createQuery(query).getResultList();
}

From source file:com.juliuskrah.multipart.repository.impl.HibernateAccountRepository.java

@Override
public Stream<Account> findByLastName(String lastName) {
    Session session = this.em.unwrap(Session.class);
    CriteriaBuilder qb = session.getCriteriaBuilder();
    CriteriaQuery<Account> cq = qb.createQuery(Account.class);
    Root<Account> root = cq.from(Account.class);
    Predicate predicate = qb.like(root.get(Account_.lastName), lastName);
    cq.where(predicate);/*  ww  w  .  ja va 2  s .  co  m*/

    return session.createQuery(cq).stream();
}

From source file:com.juliuskrah.multipart.repository.impl.HibernateAccountRepository.java

@Override
public Optional<Account> findByUsername(String username) {
    CriteriaBuilder qb = this.em.getCriteriaBuilder();
    CriteriaQuery<Account> query = qb.createQuery(Account.class);
    Root<Account> root = query.from(Account.class);
    Predicate predicate = qb.like(root.get(Account_.username), username);
    query.where(predicate);/*from w  w  w.j  av a  2  s. c o m*/
    Query q = this.em.createQuery(query);

    return Optional.of((Account) q.getSingleResult());
}

From source file:net.carinae.dev.async.dao.DummyEntityDaoJPA2.java

@Override
public List<DummyEntity> findByData(String data) {

    // select de from DummyEntity
    //  where de.data = data
    CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
    CriteriaQuery<DummyEntity> cq = cb.createQuery(DummyEntity.class);
    Root<DummyEntity> de = cq.from(DummyEntity.class);
    cq.select(de).where(cb.equal(de.get(DummyEntity_.data), data));

    return this.entityManager.createQuery(cq).getResultList();
}

From source file:core.commonapp.server.dao.contact.PartyContactMechDaoHibernateImpl.java

@Override
public Set<PartyContactMech> findByContactMechId(Integer contactMechId) {
    log.debug("PartyContactMechDaoHibernateImpl.findByContactMechId({0})", contactMechId);

    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<PartyContactMech> query = builder.createQuery(PartyContactMech.class);
    Root<PartyContactMech> root = query.from(PartyContactMech.class);
    builder.equal(root.get("contactMechId"), contactMechId);
    builder.isNull(root.get("thruDate"));

    return (Set<PartyContactMech>) new HashSet(getEntityManager().createQuery(query).getResultList());
}

From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.PersistentDocumentStoreController.java

/**
 * Gets all UUIDs for {@code T} type document stores owned by the given owner.
 * @param em the {@link EntityManager} to use.
 * @param ownerId the ID of the owner./*from w ww .ja  va 2 s . c o  m*/
 * @param entityClass the specific type of document stores to be retrieved; must be annotated with the {@link Entity} annotation.
 * @return a {@link List} containing {@link String} representations of the UUIDs.
 */
public <T extends PersistentDocumentStore> List<String> getAllUuids(EntityManager em, String ownerId,
        Class<T> entityClass) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");
    Validate.notNull(ownerId, CannedMessages.NULL_ARGUMENT, "ownerId");
    Validate.notNull(entityClass, CannedMessages.NULL_ARGUMENT, "entityClass");

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<byte[]> cq = cb.createQuery(byte[].class);
    Root<T> store = cq.from(entityClass);
    cq.multiselect(store.get("id"))
            .where(cb.equal(store.get("ownerId"), cb.parameter(String.class, "ownerId")));
    TypedQuery<byte[]> tq = em.createQuery(cq);
    tq.setParameter("ownerId", ownerId);
    return Lists.newArrayList(Iterables.transform(tq.getResultList(), UuidUtils.uuidBytesToStringFunction()));
}