Example usage for org.hibernate Criteria createCriteria

List of usage examples for org.hibernate Criteria createCriteria

Introduction

In this page you can find the example usage for org.hibernate Criteria createCriteria.

Prototype

public Criteria createCriteria(String associationPath) throws HibernateException;

Source Link

Document

Create a new Criteria, "rooted" at the associated entity.

Usage

From source file:com.scopix.periscope.corporatestructuremanagement.dao.CorporateStructureManagementHibernateDAOImpl.java

License:Open Source License

/**
 * Obtain a list of EvidenceProvider object using filters.
 *
 * @param evidenceProvider Filter object
 * @return List<EvidenceProvider> List of EvidenceProvider objects
 *//*from  w  ww  .  j  a  v  a2  s . c o m*/
@Override
public List<EvidenceProvider> getEvidenceProvidersList(EvidenceProvider evidenceProvider) {
    log.info("start");
    List<EvidenceProvider> list = null;
    Criteria criteria = this.getSession().createCriteria(EvidenceProvider.class);
    criteria.addOrder(Order.asc("id"));
    if (evidenceProvider != null) {
        if (evidenceProvider.getName() != null && evidenceProvider.getName().length() > 0) {
            criteria.add(Restrictions.ilike("name", evidenceProvider.getName(), MatchMode.ANYWHERE));
        }
        if (evidenceProvider.getDescription() != null && evidenceProvider.getDescription().length() > 0) {
            criteria.add(
                    Restrictions.ilike("description", evidenceProvider.getDescription(), MatchMode.ANYWHERE));
        }
        if (evidenceProvider.getEvidenceProviderType() != null
                && evidenceProvider.getEvidenceProviderType().getId() != null
                && evidenceProvider.getEvidenceProviderType().getId() > 0) {
            criteria.add(Restrictions.eq("evidenceProviderType.id",
                    evidenceProvider.getEvidenceProviderType().getId()));
        }
        if (evidenceProvider.getStore() != null && evidenceProvider.getStore().getId() != null
                && evidenceProvider.getStore().getId() > 0) {
            criteria.add(Restrictions.eq("store.id", evidenceProvider.getStore().getId()));
        }
        if (!evidenceProvider.getAreas().isEmpty()) {
            Set<Integer> ids = new HashSet<Integer>();
            for (Area a : evidenceProvider.getAreas()) {
                if (a.getId() != -1) {
                    ids.add(a.getId());
                }
            }
            if (ids.size() > 0) {
                criteria.createCriteria("areas").add(Restrictions.in("id", ids.toArray(new Integer[0])));
                // debemos cargar tambien las relaciones
                // criteria.createCriteria("relationEvidenceProviderLocationsFrom").add(Restrictions.in("area.id",
                // ids.toArray(new Integer[0])));
            }

        }
        // if (evidenceProvider.getArea() != null && evidenceProvider.getArea().getAreaType() != null
        // && evidenceProvider.getArea().getAreaType().getId() != null && evidenceProvider.getArea().
        // getAreaType().getId() > 0) {
        // criteria.createCriteria("area").add(Restrictions.eq("areaType.id",
        // evidenceProvider.getArea().getAreaType().getId()));
        // }
    }

    list = criteria.list();
    log.info("end " + list.size());
    return list;
}

From source file:com.scopix.periscope.corporatestructuremanagement.dao.CorporateStructureManagementHibernateDAOImpl.java

License:Open Source License

/**
 * Obtain a list of Sensor object using filters.
 *
 * @param sensor Filter object// ww w  .  ja v  a  2 s . c o  m
 * @return List<EvidenceProvider> List of EvidenceProvider objects
 */
@Override
public List<Sensor> getSensorList(Sensor sensor) {
    List<Sensor> list = null;
    Criteria criteria = this.getSession().createCriteria(Sensor.class);
    criteria.addOrder(Order.asc("id"));
    if (sensor != null) {
        if (sensor.getName() != null && sensor.getName().length() > 0) {
            criteria.add(Restrictions.ilike("name", sensor.getName(), MatchMode.ANYWHERE));
        }
        if (sensor.getDescription() != null && sensor.getDescription().length() > 0) {
            criteria.add(Restrictions.ilike("description", sensor.getDescription(), MatchMode.ANYWHERE));
        }
        if (sensor.getStore() != null && sensor.getStore().getId() != null && sensor.getStore().getId() > 0) {
            criteria.add(Restrictions.eq("store.id", sensor.getStore().getId()));
        }
        if (sensor.getArea() != null && sensor.getArea().getId() != null && sensor.getArea().getId() > 0) {
            criteria.add(Restrictions.eq("area.id", sensor.getArea().getId()));
        }
        if (sensor.getArea() != null && sensor.getArea().getAreaType() != null
                && sensor.getArea().getAreaType().getId() != null
                && sensor.getArea().getAreaType().getId() > 0) {
            criteria.createCriteria("area")
                    .add(Restrictions.eq("areaType.id", sensor.getArea().getAreaType().getId()));
        }
    }
    list = criteria.list();
    return list;
}

From source file:com.scopix.periscope.corporatestructuremanagement.dao.CorporateStructureManagementHibernateDAOImpl.java

License:Open Source License

/**
 * Obtain a list of Region object using filters.
 *
 * @param region Filter object//from   w w  w.  j a  v a 2 s . c om
 * @return List<Region> List of Region objects
 */
@Override
public List<Region> getRegionList(Region region) {
    List<Region> list = null;
    Criteria criteria = this.getSession().createCriteria(Region.class);
    criteria.addOrder(Order.asc("id"));
    if (region != null) {
        if (region.getName() != null && region.getName().length() > 0) {
            criteria.add(Restrictions.ilike("name", region.getName(), MatchMode.ANYWHERE));
        }
        if (region.getDescription() != null && region.getDescription().length() > 0) {
            criteria.add(Restrictions.ilike("description", region.getDescription(), MatchMode.ANYWHERE));
        }
        if (region.getCountry() != null && region.getCountry().getId() != null
                && region.getCountry().getId() > 0) {
            Criteria criteriaCountry = criteria.createCriteria("country");
            criteriaCountry.add(Restrictions.eq("id", region.getCountry().getId()));
        }
    }
    list = criteria.list();
    return list;
}

From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java

License:Open Source License

@Override
public Situation getSituationForAProcessId(Integer processId, Integer situationTemplateId) {
    log.debug("start");
    Situation situation = null;//from  w  w  w  . java 2  s.  co  m
    Session session = this.getSession();
    try {
        Criteria criteria = session.createCriteria(Situation.class);
        criteria.add(Restrictions.eq("processId", processId));
        criteria.createCriteria("situationTemplate").add(Restrictions.eq("id", situationTemplateId));
        List<Situation> situations = criteria.list();
        if (situations != null && !situations.isEmpty()) {
            situation = situations.get(0);
        }
    } catch (HibernateException e) {
    } finally {
        this.releaseSession(session);
    }
    log.debug("end");

    return situation;
}

From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java

License:Open Source License

@Override
public Metric getMetricForAProcessId(Integer processId, Integer situationTemplateId, Integer metricTemplateId,
        Integer evidenceProviderId) {
    log.debug("start");
    Metric metric = null;//from  ww  w  .  ja v  a2s.co  m
    Session session = this.getSession();
    try {
        Criteria criteria = session.createCriteria(Metric.class);
        criteria.createCriteria("metricTemplate").add(Restrictions.eq("id", metricTemplateId));

        Criteria situationCrit = criteria.createCriteria("situation");
        situationCrit.add(Restrictions.eq("processId", processId));
        situationCrit.createCriteria("situationTemplate").add(Restrictions.eq("id", situationTemplateId));

        // createCriteria("extractionPlanCustomizing")
        Criteria epmCriteria = criteria.createCriteria("extractionPlanMetric");
        epmCriteria.createCriteria("evidenceProviders").add(Restrictions.eq("id", evidenceProviderId));

        List<Metric> metrics = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
        if (metrics != null && !metrics.isEmpty()) {
            metric = metrics.get(0);
        }
    } catch (HibernateException e) {
        log.error(e, e);
    } finally {
        this.releaseSession(session);
    }
    log.debug("end");
    return metric;
}

From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java

License:Open Source License

@Override
public EvidenceRequest getEvidenceRequestForAMetric(EvidenceRequest evidenceRequest) {
    log.debug("start");
    EvidenceRequest er = null;//ww w .  j  av a2  s  . c  o m
    Session session = this.getSession();
    try {
        Criteria criteria = session.createCriteria(EvidenceRequest.class);
        if (evidenceRequest != null) {
            if (evidenceRequest.getMetric() != null && evidenceRequest.getMetric().getId() != null
                    && evidenceRequest.getMetric().getId() > 0) {
                log.debug("metricId:" + evidenceRequest.getMetric().getId());
                criteria.createCriteria("metric")
                        .add(Restrictions.eq("id", evidenceRequest.getMetric().getId()));
            }
            if (evidenceRequest.getDay() != null) {
                log.debug("day:" + evidenceRequest.getDay());
                criteria.add(Restrictions.eq("day", evidenceRequest.getDay()));
            }
            if (evidenceRequest.getType() != null) {
                log.debug("type:" + evidenceRequest.getType());
                criteria.add(Restrictions.eq("type", evidenceRequest.getType()));
            }
            if (evidenceRequest.getEvidenceProvider() != null
                    && evidenceRequest.getEvidenceProvider().getId() != null
                    && evidenceRequest.getEvidenceProvider().getId() > 0) {
                log.debug("providerId:" + evidenceRequest.getEvidenceProvider().getId());
                criteria.createCriteria("evidenceProvider")
                        .add(Restrictions.eq("id", evidenceRequest.getEvidenceProvider().getId()));
            }
        }
        List<EvidenceRequest> evidenceRequests = criteria.list();
        log.debug("evidenceRequests.size:" + evidenceRequests.size());
        if (evidenceRequests != null && !evidenceRequests.isEmpty()) {
            er = evidenceRequests.get(0);
        }
    } catch (HibernateException e) {
        log.error(e, e);
    } finally {
        this.releaseSession(session);
    }

    log.debug("end");
    return er;
}

From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java

License:Open Source License

@Override
public Evidence getEvidenceByPath(String evidencePath, Integer evidenceRequestId) {
    log.debug("start");
    Evidence evidence = null;// w w  w.j av  a  2s .  com
    Session session = this.getSession();
    try {
        Criteria criteria = session.createCriteria(Evidence.class);
        if (evidencePath != null && evidencePath.length() > 0) {
            criteria.add(Restrictions.eq("evidencePath", evidencePath));
            criteria.createCriteria("evidenceRequests").add(Restrictions.eq("id", evidenceRequestId));
            List<Evidence> evidences = criteria.list();
            if (evidences != null && !evidences.isEmpty()) {
                evidence = evidences.get(0);
            }
        }
    } catch (HibernateException e) {
        log.error(e, e);
    } finally {
        this.releaseSession(session);
    }
    log.debug("end");
    return evidence;
}

From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java

License:Open Source License

@Override
public Process getProcessFromAutomaticEvidenceAvailable(AutomaticEvidenceAvailableDTO evidenceAvailable) {
    Process p = null;/*from ww w  .  j ava 2  s.c o m*/
    Session session = this.getSession();
    try {
        Criteria criteria = session.createCriteria(Process.class);
        criteria.add(Restrictions.eq("processIdEs", evidenceAvailable.getProcessId()));
        criteria.createCriteria("eess")
                .add(Restrictions.eq("id", evidenceAvailable.getEvidenceExtractionServicesServerId()));
        List<Process> processes = criteria.list();
        if (processes != null && !processes.isEmpty()) {
            p = processes.get(0);
        }
    } catch (DataAccessResourceFailureException e) {
        log.warn(e);
    } catch (IllegalStateException e) {
        log.warn(e);
    } catch (HibernateException e) {
        log.warn(e);
    } finally {
        this.releaseSession(session);
    }
    return p;

}

From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java

License:Open Source License

@Override
public Area getAreaByreaTypeStore(Integer areaTypeId, Integer storeId) {
    Area a = null;//from  www .  ja va 2 s .  c  o  m
    Session session = this.getSession();
    try {
        Criteria criteria = session.createCriteria(Area.class);
        criteria.createCriteria("store").add(Restrictions.eq("id", storeId));
        criteria.createCriteria("areaType").add(Restrictions.eq("id", areaTypeId));
        List<Area> list = criteria.list();
        // se retorna la primera area de la lista si existen mas conbinaciones
        if (!list.isEmpty()) {
            a = list.get(0);
        }
        // a = (Area) criteria.uniqueResult();
    } catch (DataAccessResourceFailureException e) {
        log.error(e, e);
    } catch (IllegalStateException e) {
        log.error(e, e);
    } catch (HibernateException e) {
        log.error(e, e);
    } finally {
        this.releaseSession(session);
    }
    return a;
}

From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java

License:Open Source License

@Override
public AutomaticEvaluationResult getAutomaticEvaluationResultByEvidenceIdAndSituationTemplateId(
        Integer evidenceId, Integer situationTemplateId) {
    log.debug("start");
    AutomaticEvaluationResult aer = null;
    Session session = this.getSession();
    try {/* w  ww .  j a  v a2 s . c  o m*/
        Criteria criteria = session.createCriteria(AutomaticEvaluationResult.class);
        criteria.createCriteria("evidence").add(Restrictions.eq("id", evidenceId));
        criteria.createCriteria("situationTemplate").add(Restrictions.eq("id", situationTemplateId));
        List<AutomaticEvaluationResult> aers = criteria.list();
        if (aers != null && !aers.isEmpty()) {
            aer = aers.get(0);
        }
    } catch (HibernateException e) {
        log.error(e, e);
    } finally {
        this.releaseSession(session);
    }
    log.debug("end");

    return aer;
}