Example usage for javax.persistence.criteria CriteriaBuilder equal

List of usage examples for javax.persistence.criteria CriteriaBuilder equal

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder equal.

Prototype

Predicate equal(Expression<?> x, Object y);

Source Link

Document

Create a predicate for testing the arguments for equality.

Usage

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: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: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: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: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 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:eu.uqasar.service.company.CompanyService.java

/**
 * //www. ja  v a 2  s . c  o m
 * @param companyId
 * @return
 */
public boolean companyExists(Long companyId) {
    logger.info(String.format("checking if Company with ID %d exists ...", companyId));
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = cb.createQuery(Long.class);
    Root<Company> from = criteria.from(Company.class);
    criteria.where(cb.equal(from.get(Company_.id), companyId));
    criteria.select(cb.countDistinct(from));
    return (em.createQuery(criteria).getSingleResult().longValue() == 1);
}

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 {//w  ww  . jav  a 2s.  c  o m
        return getEntityManager().createQuery(query).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

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.//w w w  . ja  v a  2 s .co 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()));
}

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

public long countAllFiltered(final CompanyFilterStructure filter) {
    logger.infof("counting all Companies matching the filter %s ...", filter);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = cb.createQuery(Long.class);
    Root<Company> from = criteria.from(Company.class);
    criteria.where(cb.or(cb.equal(from.get(Company_.name), filter.getName()),
            cb.equal(from.get(Company_.shortName), filter.getShortName()),
            cb.equal(from.get(Company_.country), filter.getCountry())));
    criteria.select(cb.countDistinct(from));
    return em.createQuery(criteria).getSingleResult();
}