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:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of target name spaces available.
 *
 * @param modelVersion/*from   w  ww.  jav  a  2 s  .c o  m*/
 *            the model version.
 * @return the list of target name spaces available.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<String> getTargetNamespaces(final String modelVersion) {
    final List<String> value = new ArrayList<String>();
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<ClusterType> q = cb.createQuery(ClusterType.class);
    final Root<ClusterType> f = q.from(ClusterType.class);
    q.where(cb.equal(f.<String>get(ClusterType_.modelVersion), modelVersion));
    q.orderBy(cb.asc(f.<String>get(ClusterType_.name)), cb.asc(f.<String>get(ClusterType_.id)));
    final TypedQuery<ClusterType> typedQuery = this.em.createQuery(q);
    final List<ClusterType> cluster = typedQuery.getResultList();
    cluster.stream().filter(c -> Objects.nonNull(c.getName())).forEach(c -> value.add(c.getName()));
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Check if the {@link EnterpriseType} with given name and modelVersion
 * exists.//from ww w .ja  va 2 s . c om
 *
 * @param name
 *            the name of the {@link EnterpriseType}.
 * @param modelVersion
 *            the version of the model.
 * @return <code>true</code> if exists, else <code>false</code>.
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public boolean existsEnterprise(final String name, final String modelVersion) {
    boolean value = false;

    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<Long> q = cb.createQuery(Long.class);
    final Root<EnterpriseType> f = q.from(EnterpriseType.class);
    q.select(f.<Long>get(EnterpriseType_.hjid));
    q.where(cb.equal(f.<String>get(EnterpriseType_.name), name),
            cb.equal(f.<String>get(EnterpriseType_.modelVersion), modelVersion));
    final TypedQuery<Long> typedQuery = this.em.createQuery(q);
    try {
        final Long l = typedQuery.getSingleResult();
        if (l != null && l.longValue() != 0) {
            value = true;
        }
    } catch (final Exception e) {
        value = false;
    }
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link FlowType}s matching the name pattern.
 *
 * @param modelVersion/*from w w w . j a  v a 2 s  . c  o  m*/
 *            the model version.
 * @param namePattern
 *            the name pattern.
 * @return the list of {@link FlowType}s matching the name pattern.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<FlowType> getFlowByNamePattern(final String modelVersion, final Collection<String> namePattern) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<FlowType> q = cb.createQuery(FlowType.class);
    final Root<FlowType> f = q.from(FlowType.class);

    final Predicate or = cb.disjunction();
    namePattern.stream()
            .forEach(id -> or.getExpressions().add(cb.like(f.<String>get(FlowType_.name), "%" + id + "%")));
    final Predicate and = cb.conjunction();
    and.getExpressions().add(cb.equal(f.<String>get(FlowType_.modelVersion), modelVersion));
    and.getExpressions().add(or);
    q.where(and);
    final TypedQuery<FlowType> typedQuery = this.em.createQuery(q);
    final List<FlowType> value = typedQuery.getResultList();
    value.stream().forEach(ft -> EagerLoader.load(ft));
    return value;
}

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

/**
 * Get count of flowstep rules/*  w w  w  .ja va2s  .co  m*/
 * 
 * @return count
 */
private Long getFlowStepRuleCount() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> c = cb.createQuery(Long.class);
    c.select(cb.count(c.from(FlowStepRule.class)));
    return em.createQuery(c).getSingleResult();
}

From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java

public int itemsDateRangeCount(Date startDate, Date endDate) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery(TxInstance.class);
    Root<TxInstance> rt = cq.from(TxInstance.class);
    cq.select(cb.count(rt.get(TxInstance_.activityinstanceser)));
    cq.where(cb.and(rt.get(TxInstance_.completed).isNotNull(),
            cb.between(rt.get(TxInstance_.completed), startDate, endDate)));

    Query q = em.createQuery(cq);
    return ((Long) (q.getSingleResult())).intValue();
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the {@link ClusterType} with targetNamespace of the modelVersion.
 *
 * @param modelVersion//w w w .  jav a2s .c om
 *            the model version.
 * @param targetNamespace
 *            the target namespace.
 * @return the {@link ClusterType} with targetNamespace of the modelVersion.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public ClusterType getClusterByTargetNamespace(final String modelVersion, final String targetNamespace) {
    ClusterType value = null;
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<ClusterType> q = cb.createQuery(ClusterType.class);
    final Root<ClusterType> f = q.from(ClusterType.class);
    q.where(cb.equal(f.<String>get(ClusterType_.modelVersion), modelVersion),
            cb.equal(f.<String>get(ClusterType_.name), targetNamespace));
    final TypedQuery<ClusterType> typedQuery = this.em.createQuery(q);
    final List<ClusterType> list = typedQuery.getResultList();
    if (Objects.nonNull(list) && list.size() != 1) {
        value = list.get(0);
        EagerLoader.load(value);
    }
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the {@link ServiceType} with serviceId of the modelVersion.
 *
 * @param modelVersion/*from ww  w. j  a  va 2 s .c  o  m*/
 *            the model version.
 * @param serviceId
 *            the serviceId.
 * @return the {@link ServiceType} with serviceId of the modelVersion.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public ServiceType getServiceByServiceId(final String modelVersion, final String serviceId) {
    ServiceType value = null;
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<ServiceType> q = cb.createQuery(ServiceType.class);
    final Root<ServiceType> f = q.from(ServiceType.class);
    q.where(cb.equal(f.<String>get(ServiceType_.modelVersion), modelVersion),
            cb.equal(f.<String>get(ServiceType_.serviceId), serviceId));
    final TypedQuery<ServiceType> typedQuery = this.em.createQuery(q);
    final List<ServiceType> list = typedQuery.getResultList();
    if (Objects.nonNull(list) && list.size() == 1) {
        value = list.get(0);
        EagerLoader.load(value);
    }
    return value;
}

From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java

public List<TxInstance> itemsDateRange(Date startDate, Date endDate, int[] range) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery(TxInstance.class);
    Root<TxInstance> rt = cq.from(TxInstance.class);
    cq.where(cb.and(rt.get(TxInstance_.completed).isNotNull(),
            cb.between(rt.get(TxInstance_.completed), startDate, endDate)));
    cq.orderBy(cb.asc(rt.get(TxInstance_.completed)));
    Query q = em.createQuery(cq);
    q.setMaxResults(range[1] - range[0] + 1);
    q.setFirstResult(range[0]);/*from   w  w w. ja  va2s .co m*/
    return q.getResultList();
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link FieldMappingType} with the ids.
 *
 * @param modelVersion//from   www. j  a v a2  s.  com
 *            the model version.
 * @param ids
 *            the list of ids to return.
 * @return the list of {@link FieldMappingType}.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<FieldMappingType> getFieldMappingTypesById(final String modelVersion, final List<String> ids) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<FieldMappingType> q = cb.createQuery(FieldMappingType.class);
    final Root<FieldMappingType> f = q.from(FieldMappingType.class);
    final Predicate orIds = cb.disjunction();
    ids.stream().forEach(id -> orIds.getExpressions().add(cb.equal(f.<String>get(FieldMappingType_.id), id)));
    q.where(cb.equal(f.<String>get(FieldMappingType_.modelVersion), modelVersion), orIds);
    final TypedQuery<FieldMappingType> typedQuery = this.em.createQuery(q);
    final List<FieldMappingType> value = typedQuery.getResultList();
    value.stream().forEach(ct -> EagerLoader.load(ct));
    return value;
}

From source file:com.hiperium.dao.common.generic.GenericDAO.java

/**
 * //from   ww w . j  a v  a  2 s .c  o  m
 * @param entity
 * @param bypassCache
 * @return
 */
protected Long count(T entity, boolean bypassCache) {
    this.logger.debug("count - START");
    CriteriaBuilder criteriaBuilder = this.entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
    Root<T> root = criteriaQuery.from(this.entityClass);
    criteriaQuery.select(criteriaBuilder.count(root));
    // Create JPA Query
    Query query = this.entityManager.createQuery(criteriaQuery);
    if (bypassCache) {
        this.setBypassCahe(query);
    }
    // get the query results
    Long result = (Long) query.getSingleResult();
    this.logger.debug("count - END: " + result);
    return result;
}