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.eucalyptus.objectstorage.metadata.DbMpuPartMetadataManagerImpl.java

License:Open Source License

/**
 * Provides the search criteria to handle the FK relation from PartEntity->Bucket
 * Returns a criteria for a search that matches the given bucket
 * @param baseCriteria/*from  w  w  w .j ava 2 s.  c  om*/
 * @param bucket
 * @return
 */
protected static Criteria getSearchByBucket(@Nonnull Criteria baseCriteria, @Nullable Bucket bucket) {
    if (bucket != null) {
        return baseCriteria.createCriteria("bucket").add(Restrictions.eq("naturalId", bucket.getNaturalId()));
    } else {
        return baseCriteria;
    }
}

From source file:com.googlecode.encomendaz.persistence.implementors.RastreioDAOImpl.java

License:Open Source License

@Override
public List<Rastreio> obterTodosRastreios() throws DAOException {
    Criteria criteria = HibernateUtil.getSessionFactory().openSession().createCriteria(Rastreio.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.createCriteria("situacoes").addOrder(Order.desc("data"));
    return criteria.list();

}

From source file:com.googlecode.ouvidoria.model.complaint.ComplaintDaoImpl.java

@Override
@SuppressWarnings("unchecked")
public List<?> searchByCriteria(final int transform, final String queryString, int pageNumber, int pageSize,
        final ComplaintVO vo) {
    Criteria criteria = this.getSession().createCriteria(Complaint.class);

    if (vo != null) {
        if (vo.getId() != null) {
            criteria.add(Restrictions.idEq(vo.getId()));
        } else {//from   w w  w. j ava 2s .c  o m
            if (vo.getStatus() != null) {
                System.out.println("DAO .... " + vo.getStatus());
                criteria.add(Restrictions.eq("status", vo.getStatus()));
            }
            //TODO demandant
            if (vo.getSubjectId() != null) {
                criteria.createCriteria("subject").add(Restrictions.idEq(vo.getSubjectId()));
            }
            if (vo.getText() != null) {
                criteria.add(Restrictions.ilike("text", "%" + vo.getText() + "%"));
            }
            if (vo.getTypeId() != null) {
                criteria.createCriteria("type").add(Restrictions.idEq(vo.getTypeId()));
            }
        }
    }
    criteria.addOrder(Order.desc("date"));

    if (pageNumber > 0 && pageSize > 0) {
        criteria.setFirstResult(super.calculateFirstResult(pageNumber, pageSize));
        criteria.setMaxResults(pageSize);
    }

    List results = criteria.list();
    transformEntities(transform, results);
    return results;
}

From source file:com.hmsinc.epicenter.model.health.impl.HealthRepositoryImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<? extends Interaction> getInteractions(String patientId, Facility facility, String visitNumber) {

    Validate.notNull(patientId, "Patient id must be specified");
    Validate.notNull(facility, "Facility must be specified");
    Validate.notNull(visitNumber, "Visit number must be specified");

    final Criteria c = criteriaQuery(entityManager, Interaction.class);
    c.createCriteria("patient").add(Restrictions.eq("patientId", patientId))
            .add(Restrictions.eq("facility", facility));
    c.add(Restrictions.eq("visitNumber", visitNumber));

    return c.list();
}

From source file:com.hmsinc.epicenter.model.surveillance.impl.SurveillanceRepositoryImpl.java

License:Open Source License

/**
 * @param c//w  ww . ja va 2  s. c o  m
 * @param startDate
 * @param endDate
 * @param includeAll
 * @param includeFacilityLocation
 * @param filter
 * @return
 */
private Criteria applyAnomalyCriteria(final Criteria c, final DateTime startDate, final DateTime endDate,
        final boolean includeAll, final Geometry filter, final Geometry excludeFacilityEventsFilter) {

    if (startDate == null && endDate != null) {
        c.add(Restrictions.lt("analysisTimestamp", endDate));
    } else if (startDate != null && endDate == null) {
        c.add(Restrictions.gt("analysisTimestamp", startDate));
    } else if (startDate != null && endDate != null) {
        c.add(Restrictions.between("analysisTimestamp", startDate, endDate));
    }

    if (!includeAll) {
        c.add(Restrictions.isEmpty("investigations")).createCriteria("disposition")
                .add(Restrictions.eq("type", WorkflowStateType.INITIAL));
    }

    if (filter != null && excludeFacilityEventsFilter == null) {

        c.createCriteria("geography").add(SpatialRestrictions.withinOrFilter("geometry", filter, 1000, true));

    } else if (filter == null && excludeFacilityEventsFilter != null) {

        final Conjunction conjunction = Restrictions.conjunction();
        c.createAlias("geography", "eventGeography");
        c.createAlias("task", "eventTask");

        conjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY));
        conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry",
                excludeFacilityEventsFilter, 1000, true));

        c.add(Restrictions.not(conjunction));

    } else if (filter != null && excludeFacilityEventsFilter != null) {

        final Conjunction conjunction = Restrictions.conjunction();
        c.createAlias("geography", "eventGeography");
        c.createAlias("task", "eventTask");

        // Find events where we have unlimited access
        conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry", filter, 1000, true));

        // Filter events in the limited region
        final Conjunction facilityEventsConjunction = Restrictions.conjunction();
        facilityEventsConjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY));
        facilityEventsConjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry",
                excludeFacilityEventsFilter, 1000, true));

        conjunction.add(Restrictions.not(facilityEventsConjunction));

        c.add(conjunction);
    }

    return c;
}

From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Subscription> getSubscriptions(Classification classification, Geography geography) {

    Validate.notNull(classification, "Classification must be specified.");
    Validate.notNull(geography, "Geography must be specified.");

    final Criteria c = criteriaQuery(entityManager, Subscription.class);
    c.createCriteria("classifications").add(Restrictions.idEq(classification.getId()));
    c.createCriteria("geographies").add(SpatialRestrictions.contains("geometry", geography.getGeometry()));
    c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return c.list();

}

From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java

License:Open Source License

/**
 * Basic filter for investigations.//from   w w w  .j  a v  a 2  s  .c  o m
 * 
 * @param c
 * @param startDate
 * @param endDate
 * @param geometry
 * @param organizations
 * @param showAll
 * @return
 */
private Criteria applyInvestigationCriteria(final Criteria c, DateTime startDate, DateTime endDate,
        Geometry geometry, Collection<Organization> organizations, boolean showAll) {

    if (startDate != null) {
        if (endDate == null) {
            c.add(Restrictions.gt("timestamp", startDate));
        } else {
            c.add(Restrictions.between("timestamp", startDate, endDate));
        }
    }

    if (organizations != null && organizations.size() > 0) {
        c.add(Restrictions.in("organization", organizations));
    }

    if (geometry != null) {
        c.add(Subqueries.exists(getInvestigationGeometryFilter(geometry)));
    }

    if (showAll == false) {
        c.createCriteria("state").add(Restrictions.ne("stateType", WorkflowStateType.TERMINAL));
    }

    return c;
}

From source file:com.hp.dao.CalendarDAOImpl.java

@Override
public List<Calendar> getCalendarList(String staff_id, String city, Date date) {
    Session session = HibernateSessionFactory.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    try {//from   ww w .ja  v a 2s.c o  m
        Criteria criteria = session.createCriteria(Calendar.class);
        //inner
        Criteria criteriaInner = criteria.createCriteria("staff");
        criteriaInner.add(Restrictions.eq("id", StringUtils.trimToEmpty(staff_id)));

        criteria.add(Restrictions.eq("calendarDate", date));
        criteria.add(Restrictions.eq("province", city));

        return criteria.list();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    finally {
        session.close();
    }

}

From source file:com.hp.dao.CalendarDAOImpl.java

@Override
public List<Calendar> getCalendarList(String pManagerID, String pStaff, Date pFromDate, Date pToDate) {
    Session session = HibernateSessionFactory.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    try {//from w w  w. j a  va 2  s .  c  o m
        Criteria criteria = session.createCriteria(Calendar.class);
        Criteria criteriaInner = criteria.createCriteria("staff");

        if (pStaff != null && !pStaff.equals("")) {
            criteriaInner.add(Restrictions.eq("id", pStaff));
        } else if (pManagerID != null && !pManagerID.equals("")) {
            criteriaInner.add(Restrictions.eq("manager", pManagerID));
        }

        if (pFromDate != null) {
            criteria.add(Restrictions.ge("calendarDate", pFromDate));
        }

        if (pToDate != null) {
            criteria.add(Restrictions.le("calendarDate", pToDate));
        }

        criteria.addOrder(Order.asc("calendarDate"));
        System.err.println(criteria.toString());

        return criteria.list();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    finally {
        session.close();
    }

}

From source file:com.hp.dao.ForLeaveDAOImpl.java

@Override
public List<ForLeave> getForLeaveList(String pManagerID, String pStaff, Date pFromDate, Date pToDate) {
    Session session = HibernateSessionFactory.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    try {/*from   ww  w.j a va  2  s. com*/
        Criteria criteria = session.createCriteria(ForLeave.class);
        Criteria criteriaInner = criteria.createCriteria("staff");

        if (pStaff != null && !pStaff.equals("")) {
            criteriaInner.add(Restrictions.eq("id", pStaff));
        } else if (pManagerID != null && !pManagerID.equals("")) {
            criteriaInner.add(Restrictions.eq("manager", pManagerID));
        }

        if (pFromDate != null) {
            criteria.add(Restrictions.ge("timeAt", pFromDate));
        }

        if (pToDate != null) {
            criteria.add(Restrictions.le("timeAt", pToDate));
        }

        criteria.addOrder(Order.asc("timeAt"));
        System.err.println(criteria.toString());

        return criteria.list();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    finally {
        session.close();
    }

}