Example usage for javax.persistence.criteria CriteriaQuery from

List of usage examples for javax.persistence.criteria CriteriaQuery from

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaQuery from.

Prototype

<X> Root<X> from(Class<X> entityClass);

Source Link

Document

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.

Usage

From source file:ch.sdi.plugins.oxwall.job.OxSqlJob.java

/**
 * Checks if the given hash is present in the ow_base_avatar table
 *
 * @param aHash//from  ww w.  j ava 2 s .  c om
 * @return
 */
public boolean isAvatarHashPresent(Long aHash) {
    if (myDryRun) {
        myLog.debug("DryRun is active. Not checking for duplicate avatar hash");
        return false;
    } // if myDryRun

    CriteriaBuilder cb = myEntityManager.getCriteriaBuilder();

    CriteriaQuery<OxAvatar> criteria = cb.createQuery(OxAvatar.class);
    Root<OxAvatar> root = criteria.from(OxAvatar.class);
    ParameterExpression<Long> avatarParam = cb.parameter(Long.class);
    avatarParam = cb.parameter(Long.class);
    criteria.select(root).where(cb.equal(root.get("hash"), avatarParam));
    TypedQuery<OxAvatar> query = myEntityManager.createQuery(criteria);
    query.setParameter(avatarParam, aHash);
    List<OxAvatar> results = query.getResultList();

    if (results.size() > 0) {
        myLog.debug("given avatar hash is already present: " + aHash);
        return true;
    } // if results.size() > 0

    return false;
}

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

/**
 * load requirements/*w  w w . j av  a 2  s. c o  m*/
 */
private void loadList() throws UCMException {

    Set<String> versions = this.projectService.findActiveProductReleaseVersions(this.authUser, this.project);

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Requirement> c = cb.createQuery(Requirement.class);
    Root<Requirement> obj = c.from(Requirement.class);
    c.select(obj).where(cb.equal(obj.get("project"), this.project),
            obj.get("productRelease").get("version").in(versions)).orderBy(cb.asc(obj.get("id")));
    this.requirements = em.createQuery(c).getResultList();

}

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

/**
 * find tests associated with this artifact
 *//*from  w w  w.j a v  a  2s  . 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

/**
 * //from  ww  w  .j  av  a  2  s .  c o m
 * @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:in.bookmylab.jpa.JpaDAO.java

public List<ResourceBooking> searchResourceBooking(BookingSearchInput si) {
    EntityManager em = emf.createEntityManager();
    try {/*from  www .  jav  a 2  s.  c o m*/
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<ResourceBooking> cq = cb.createQuery(ResourceBooking.class);
        Root<ResourceBooking> s = cq.from(ResourceBooking.class);
        List<Predicate> pred = new ArrayList<Predicate>();
        if (si.userId != null) {
            pred.add(cb.equal(s.<User>get("user").<Integer>get("userId"), si.userId));
        }
        if (si.bookingDateFrom != null) {
            pred.add(cb.greaterThanOrEqualTo(s.<Date>get("bookingDate"), si.bookingDateFrom));
        }
        if (si.bookingDateTo != null) {
            pred.add(cb.lessThanOrEqualTo(s.<Date>get("bookingDate"), si.bookingDateTo));
        }
        if (!StringUtils.isEmpty(si.lab)) {
            pred.add(cb.equal(s.<String>get("lab"), si.lab));
        }
        if (!StringUtils.isEmpty(si.status)) {
            pred.add(cb.equal(s.<String>get("status"), si.status));
        }
        cq.select(s).where(pred.toArray(new Predicate[] {}));
        return em.createQuery(cq).getResultList();
    } finally {
        em.close();
    }
}

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

/**
 * //ww w  .ja va  2s .  c o m
 * @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  w w  .ja v  a 2s  . 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   w  ww .  j a v  a2 s  .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  ww .j  a  v  a 2 s .  c  om*/
 * @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  va 2 s  .  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();
}