Example usage for javax.persistence.criteria CriteriaBuilder createQuery

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

Introduction

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

Prototype

<T> CriteriaQuery<T> createQuery(Class<T> resultClass);

Source Link

Document

Create a CriteriaQuery object with the specified result type.

Usage

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

/**
 * //w  w  w .jav  a2 s  .c  o  m
 * @return
 */
public List<JiraMetricMeasurement> getAllJiraMetricObjects() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<JiraMetricMeasurement> query = cb.createQuery(JiraMetricMeasurement.class);
    query.from(JiraMetricMeasurement.class);
    return em.createQuery(query).getResultList();
}

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

/**
 * // ww  w . j a  va  2s  . c  om
 * @param adapter
 * @return
 */
public int countAllByAdapter(AdapterSettings adapter) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<JiraMetricMeasurement> query = cb.createQuery(JiraMetricMeasurement.class);
    Root<JiraMetricMeasurement> root = query.from(JiraMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(JiraMetricMeasurement_.adapter), adapter);
    query.where(condition);
    return em.createQuery(query).getResultList().size();
}

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

/**
 * /*from   w  w w .  ja  v a2  s.  com*/
 * @param adapter
 * @return
 */
public List<JiraMetricMeasurement> getAllByAdapter(AdapterSettings adapter) {
    logger.info("Get measurements for adapter: " + adapter);

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

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

/**
 * //from   w ww . j  a  v a 2  s .  c  o m
 * @param first
 * @param count
 * @param adapter
 * @return
 */
public List<JiraMetricMeasurement> getAllByAdapter(int first, int count, AdapterSettings adapter) {
    logger.info("Get measurements for adapter: " + adapter);

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

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

/**
 * //from  www  . j a  va  2s  . c  o  m
 * @param first
 * @param count
 * @return
 */
public List<JiraMetricMeasurement> getAllByAscendingName(int first, int count) {
    logger.infof("loading all JiraMetricMeasurement ordered by ascending name ...");
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<JiraMetricMeasurement> criteria = cb.createQuery(JiraMetricMeasurement.class);
    Root<JiraMetricMeasurement> root = criteria.from(JiraMetricMeasurement.class);
    criteria.orderBy(cb.asc(root.get(JiraMetricMeasurement_.self)));
    return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList();
}

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

/**
 * //from w  w  w  .  ja v a  2s . co  m
 * @param metric
 * @return
 * @throws uQasarException
 */
public List<JiraMetricMeasurement> getMeasurementsForMetric(String metric) throws uQasarException {
    logger.info("Get measurements for metric: " + metric);

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

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

/**
 * /*from   ww w.j a v  a  2s.  c  o  m*/
 * @param metric
 * @return
 * @throws uQasarException
 */
private List<JiraMetricMeasurement> getMeasurementsByMetricAndDate(String metric, Date date)
        throws uQasarException {
    logger.info("Get measurements for metric: " + metric);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<JiraMetricMeasurement> query = cb.createQuery(JiraMetricMeasurement.class);
    Root<JiraMetricMeasurement> root = query.from(JiraMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(JiraMetricMeasurement_.jiraMetric), metric);
    Predicate condition2 = cb.equal(root.get(JiraMetricMeasurement_.timeStamp), date);
    Predicate condition3 = cb.and(condition, condition2);
    query.where(condition3);
    query.orderBy(cb.desc(root.get(JiraMetricMeasurement_.timeStamp)));
    return em.createQuery(query).getResultList();
}

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

/**
 * /*from  ww w. j  a  v  a 2 s .c om*/
 * @param metric
 * @param date
 * @return
 * @throws uQasarException
 */
public int countMeasurementsByMetricAndDate(String metric, Date date) throws uQasarException {
    logger.info("Count measurements for metric: " + metric + " and date: " + date);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<JiraMetricMeasurement> query = cb.createQuery(JiraMetricMeasurement.class);
    Root<JiraMetricMeasurement> root = query.from(JiraMetricMeasurement.class);
    Predicate condition = cb.equal(root.get(JiraMetricMeasurement_.jiraMetric), metric);
    Predicate condition2 = cb.equal(root.get(JiraMetricMeasurement_.timeStamp), date);
    Predicate condition3 = cb.and(condition, condition2);
    query.where(condition3);
    query.orderBy(cb.desc(root.get(JiraMetricMeasurement_.timeStamp)));
    Integer res = em.createQuery(query).getResultList().size();
    logger.info("Results' count: " + res);
    return res;
}

From source file:com.sfs.captor.controller.RequirementAction.java

/**
 * find tests associated with this artifact
 *//*from  w  w  w  .ja va  2  s. c o  m*/
private List<RequirementTest> findRequirementTests(Requirement requirement) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<RequirementTest> c = cb.createQuery(RequirementTest.class);
    Root<RequirementTest> obj = c.from(RequirementTest.class);
    c.select(obj).where(cb.equal(obj.get("requirement"), requirement));
    return em.createQuery(c).getResultList();
}

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

/**
 * Get the latest date of measurement snapshots
 * @return/*from   w  w  w. ja  v  a  2 s. c o m*/
 */
public Date getLatestDate() {
    logger.info("Get the latest date from JIRA measurements...");
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<JiraMetricMeasurement> query = cb.createQuery(JiraMetricMeasurement.class);
    Root<JiraMetricMeasurement> root = query.from(JiraMetricMeasurement.class);
    query.select(root);
    query.orderBy(cb.desc(root.get(JiraMetricMeasurement_.timeStamp)));
    Date latest;
    try {
        JiraMetricMeasurement m = em.createQuery(query).setMaxResults(1).getSingleResult();
        latest = m.getTimeStamp();
    } catch (NoResultException nre) {
        latest = null;
    }
    return latest;
}