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:com.sfs.ucm.controller.SpecificationAction.java

/**
 * Load resources//from   www .ja v  a2 s .c om
 * 
 * @param project
 */
private void loadFeatures(final Project project) {

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Feature> c = cb.createQuery(Feature.class);
    Root<Feature> obj = c.from(Feature.class);
    c.select(obj);
    c.where(cb.equal(obj.get("project"), project));
    c.orderBy(cb.asc(obj.get("id")));
    this.features = em.createQuery(c).getResultList();
}

From source file:bq.jpa.demo.query.criteria.service.CriteriaService.java

/**
 * SELECT e FROM jpa_query_employee e WHERE e.name= :name
 *//*from w w w  .  j  av a  2 s.  co  m*/
@Transactional
public void doParameterQuery() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Employee> c = cb.createQuery(Employee.class);
    Root<Employee> e = c.from(Employee.class);

    // parameter, equal to ":name"
    ParameterExpression<String> paraName = cb.parameter(String.class, "name");

    // e.name = ":name"
    c.select(e).where(cb.equal(e.get("name"), paraName));

    // set param value
    TypedQuery<Employee> query = em.createQuery(c);
    query.setParameter("name", "employee_1");
    List<Employee> result = query.getResultList();
    ResultViewer.showResult(result, "criteria query : parameter query");
}

From source file:org.openmeetings.app.data.basic.Sessionmanagement.java

public Sessiondata getSessionByHash(String SID) {
    try {//from  w w w  .  j a v  a  2s.c o m
        log.debug("updateUser User SID: " + SID);

        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Sessiondata> cq = cb.createQuery(Sessiondata.class);
        Root<Sessiondata> c = cq.from(Sessiondata.class);
        Predicate condition = cb.equal(c.get("session_id"), SID);
        cq.where(condition);

        TypedQuery<Sessiondata> q = em.createQuery(cq);

        List<Sessiondata> fullList = q.getResultList();
        if (fullList.size() == 0) {
            log.error("Could not find session to update: " + SID);
            return null;
        }

        Sessiondata sd = fullList.get(0);

        return sd;
    } catch (Exception ex2) {
        log.error("[updateUser]: ", ex2);
    }
    return null;
}

From source file:eu.uqasar.service.dataadapter.CubesDataService.java

/**
 * Count the measurement results belonging to a specific adapter
 * @param adapter// w  w  w.j ava2 s. c o m
 * @return
 */
public int countAllByAdapter(AdapterSettings adapter) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class);
    Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.adapter), adapter);
    query.where(condition);
    return em.createQuery(query).getResultList().size();
}

From source file:eu.uqasar.service.dataadapter.CubesDataService.java

/**
 * //from  w ww .ja v a2s .co m
 * @param adapter
 * @return
 */
public List<CubesMetricMeasurement> getAllByAdapter(AdapterSettings adapter) {
    logger.info("Get measurements for adapter: " + adapter);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class);
    Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.adapter), adapter);
    query.where(condition);
    return em.createQuery(query).getResultList();
}

From source file:eu.uqasar.service.dataadapter.CubesDataService.java

/**
 * /*w ww .  ja v a 2s.  com*/
 * @param first
 * @param count
 * @param adapter
 * @return
 */
public List<CubesMetricMeasurement> getAllByAdapter(int first, int count, AdapterSettings adapter) {
    logger.info("Get measurements for adapter: " + adapter);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class);
    Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.adapter), adapter);
    query.orderBy(cb.asc(root.get(CubesMetricMeasurement_.self)));
    query.where(condition);
    return em.createQuery(query).setFirstResult(first).setMaxResults(count).getResultList();
}

From source file:eu.uqasar.service.dataadapter.CubesDataService.java

/**
 * //from w  w  w .  j  a va2  s .c  om
 * @param metric
 * @return
 * @throws uQasarException
 */
public List<CubesMetricMeasurement> getMeasurementsForMetric(String metric) throws uQasarException {
    logger.info("Get measurements for metric: " + metric);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class);
    Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.cubesMetric), metric);
    query.where(condition);
    query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp)));
    return em.createQuery(query).getResultList();
}

From source file:com.sfs.ucm.controller.SpecificationAction.java

/**
 * load specifications//from  w ww.j a  v a 2  s .com
 */
private void loadList() throws UCMException {

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Specification> c = cb.createQuery(Specification.class);
    Root<Specification> obj = c.from(Specification.class);
    c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id")));
    this.specifications = em.createQuery(c).getResultList();

}

From source file:eu.uqasar.service.dataadapter.CubesDataService.java

/**
 * @param project//from   w  w w . j a va2  s  .c o  m
 * @return List with all the measurements of a project
 */
public List<CubesMetricMeasurement> getMeasurementByProject(Project project) {
    logger.info("Obtaining measurements for the project: " + project);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CubesMetricMeasurement> query = cb.createQuery(CubesMetricMeasurement.class);
    Root<CubesMetricMeasurement> root = query.from(CubesMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(CubesMetricMeasurement_.project), project);
    query.where(condition);
    query.orderBy(cb.desc(root.get(CubesMetricMeasurement_.timeStamp)));
    return em.createQuery(query).getResultList();

}