Example usage for org.hibernate.criterion DetachedCriteria add

List of usage examples for org.hibernate.criterion DetachedCriteria add

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria add.

Prototype

public DetachedCriteria add(Criterion criterion) 

Source Link

Document

Add a restriction

Usage

From source file:apm.common.core.DaoImpl.java

License:Open Source License

/**
 * ?/*from   w w w.  j a v  a2  s.  c o m*/
 * @param criterions Restrictions.eq("name", value);
 * @return 
 */
public DetachedCriteria createDetachedCriteria(Criterion... criterions) {
    DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
    for (Criterion c : criterions) {
        dc.add(c);
    }
    return dc;
}

From source file:apm.modules.sys.service.DictService.java

License:Open Source License

public Page<Dict> find(Page<Dict> page, Dict dict) {
    DetachedCriteria dc = dao.createDetachedCriteria();
    if (StringUtils.isNotEmpty(dict.getType())) {
        dc.add(Restrictions.eq("type", dict.getType()));
    }// w  w  w.  j  ava  2  s.  co  m
    if (StringUtils.isNotEmpty(dict.getDescription())) {
        dc.add(Restrictions.like("description", "%" + dict.getDescription() + "%"));
    }
    dc.add(Restrictions.eq(Dict.DEL_FLAG, Dict.DEL_FLAG_NORMAL));
    dc.addOrder(Order.asc("type")).addOrder(Order.asc("sort")).addOrder(Order.desc("id"));
    return dao.find(page, dc);
}

From source file:apm.modules.sys.service.LogService.java

License:Open Source License

public Page<Log> find(Page<Log> page, Map<String, Object> paramMap) {
    DetachedCriteria dc = dao.createDetachedCriteria();

    String createById = ObjectUtils.toString(paramMap.get("createById"));
    if (StringUtils.isNotEmpty(createById)) {
        dc.add(Restrictions.eq("createBy.id", createById));
    }/*from ww w  . ja  v  a2 s  .co  m*/

    String uri = ObjectUtils.toString(paramMap.get("uri"));
    if (StringUtils.isNotBlank(uri)) {
        dc.add(Restrictions.like("uri", "%" + uri + "%"));
    }

    String exception = ObjectUtils.toString(paramMap.get("exception"));
    if (StringUtils.isNotBlank(exception)) {
        dc.add(Restrictions.eq("type", Log.TYPE_EXCEPTION));
    }

    Date beginDate = DateUtils.parseDate(paramMap.get("beginDate"));
    if (beginDate == null) {
        beginDate = DateUtils.setDays(new Date(), 1);
        paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd"));
    }
    Date endDate = DateUtils.parseDate(paramMap.get("endDate"));
    if (endDate == null) {
        endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
        paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd"));
    }
    dc.add(Restrictions.between("createDate", beginDate, endDate));

    dc.addOrder(Order.desc("createDate"));
    return dao.find(page, dc);
}

From source file:apm.modules.sys.service.RoleService.java

License:Open Source License

public List<Role> findAllRole() {
    //1.??5?/*from  w w  w . ja  v a  2  s  . co m*/
    List<Role> rs = dao.findDefineRoles();

    //2.?
    User user = Users.currentUser();
    DetachedCriteria dc = dao.createDetachedCriteria();
    dc.createAlias("office", "office");
    dc.createAlias("userList", "userList", JoinType.LEFT_OUTER_JOIN);
    dc.add(dataScopeFilter(user, "office", "userList")); //??????
    dc.add(Restrictions.eq(Role.DEL_FLAG, Role.DEL_FLAG_NORMAL));
    dc.addOrder(Order.asc("office.code")).addOrder(Order.asc("name"));

    List<Role> rs2 = dao.find(dc);
    for (int i = 0; i < rs2.size(); i++) { //??
        Role r = rs2.get(i);
        if (!rs.contains(r)) {
            rs.add(r);
        }
    }
    return rs;
}

From source file:apm.modules.sys.service.UserService.java

License:Open Source License

public Page<User> findUser(Page<User> page, User user) {
    DetachedCriteria dc = dao.createDetachedCriteria();
    User currentUser = Users.currentUser();
    dc.createAlias("company", "company");

    if (user.getCompany() != null && StringUtils.isNotEmpty(user.getCompany().getId())) {
        dc.add(Restrictions.or(Restrictions.eq("company.id", user.getCompany().getId()), //?
                Restrictions.like("company.parentIds", "%," + user.getCompany().getId() + ",%") //??
        ));//from   ww w .j a  v a2 s .  com
    } else {
        dc.add(Restrictions.or(Restrictions.eq("company.id", currentUser.getCompany().getId()), //?
                Restrictions.like("company.parentIds", "%," + currentUser.getCompany().getId() + ",%") //??
        ));
    }
    /*dc.createAlias("office", "office");
    if (user.getOffice()!=null && StringUtils.isNotEmpty(user.getOffice().getId())){
       dc.add(Restrictions.or(                                                   
       Restrictions.eq("office.id", user.getOffice().getId()),                     //
       Restrictions.like("office.parentIds", "%,"+user.getOffice().getId()+",%")      //?
       ));
    }else{
       dc.add(Restrictions.or(                                                   
       Restrictions.eq("office.id", currentUser.getOffice().getId()),                     //
       Restrictions.like("office.parentIds", "%,"+currentUser.getOffice().getId()+",%")      //?
       ));
    }*/
    // ????
    if (!currentUser.isAdmin()) {
        dc.add(Restrictions.ne("id", "1"));
    }
    /*if(user.getOffice() != null && StringUtils.isNotBlank(user.getOffice().getId())){
    dc.add(dataScopeFilter(currentUser, "office", ""));
    }*/
    /*dc.add(dataScopeFilter(currentUser, "office", ""));*/

    //System.out.println(dataScopeFilterString(currentUser, "office", ""));
    if (StringUtils.isNotEmpty(user.getLoginName())) {
        dc.add(Restrictions.like("loginName", "%" + user.getLoginName() + "%"));
    }
    if (StringUtils.isNotEmpty(user.getName())) {
        dc.add(Restrictions.like("name", "%" + user.getName() + "%"));
    }
    dc.add(Restrictions.eq(User.DEL_FLAG, User.DEL_FLAG_NORMAL));
    if (!StringUtils.isNotEmpty(page.getOrderBy())) {
        /*dc.addOrder(Order.asc("company.code")).addOrder(Order.asc("office.code")).addOrder(Order.desc("id"));*/
        dc.addOrder(Order.asc("company.code")).addOrder(Order.desc("id"));
    }
    return dao.find(page, dc);
}

From source file:ar.com.zauber.commons.repository.SpringHibernateRepository.java

License:Apache License

/** @see Repository#find(Query) */
@SuppressWarnings("unchecked")
public final <T extends Persistible> List<T> find(final Query<T> query) {
    CriteriaSpecification criteria = getCriteriaSpecification(null, query, false);
    final SimpleQuery<T> simpleQuery = (SimpleQuery<T>) query;
    Criteria aCriteria;//from   w w  w. j  av  a2 s . c om
    // TODO Esto debera ir en el metodo que hace getCriteriaSpecification
    // pero como no tiene DetachedCriteria posibilidad de setearle valores
    // para paginacin hubo que hacerlo as.
    if (simpleQuery.getPaging() != null) {
        int firstResult = (simpleQuery.getPaging().getPageNumber() - 1)
                * simpleQuery.getPaging().getResultsPerPage();
        DetachedCriteria idsDetachedCriteria = (DetachedCriteria) criteria;
        idsDetachedCriteria.setProjection(Projections.id());
        Criteria idsCriteria = idsDetachedCriteria.getExecutableCriteria(this.getSession());
        idsCriteria.setCacheable(query.getCacheable());
        idsCriteria.setFirstResult(firstResult);
        idsCriteria.setMaxResults(simpleQuery.getPaging().getResultsPerPage());
        // Se hace primero el select de los IDs y luego el de los objetos en
        // si ya que de otra manera en aquellos casos que haya objetos
        // que tienen colecciones cuenta los mismos varias veces haciendo
        // que se devuelvan menos resultados.
        List<Long> ids = idsCriteria.list();
        DetachedCriteria theCriteria = (DetachedCriteria) getCriteriaSpecification(null, query, false);
        if (ids.isEmpty()) {
            return new ArrayList<T>();
        }
        theCriteria.add(Restrictions.in("id", ids));
        aCriteria = theCriteria.getExecutableCriteria(this.getSession());

    } else {
        aCriteria = ((DetachedCriteria) criteria).getExecutableCriteria(this.getSession());
    }
    aCriteria.setCacheable(query.getCacheable());
    return aCriteria.list();
}

From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.dao.impl.OttOmpOrderTrackScheduleDaoImpl.java

License:Open Source License

/**
 * This method retrieves the record using the batch name and return the
 * OttOmpOrderTrackSchedule object./*from w  w  w .j  av  a 2 s  .co m*/
 * @param batchName
 *        String
 * @return OttOmpOrderTrackSchedule
 */
public OttOmpOrderTrackSchedule retrieveOrderTrackingSchdule(String batchName) {
    LOG.info("retrieveOrderTrackingSchdule Method ----------- STARTS");
    OttOmpOrderTrackSchedule ottOmpOrderTrackSchedule = null;
    if (StringUtils.isNotEmpty(batchName)) {
        DetachedCriteria criteria = super.createDetachedCriteria();
        criteria.add(Restrictions.eq("batchName", batchName));
        List<OttOmpOrderTrackSchedule> ottOmpOrderTrackScheduleList = findByCriteria(criteria);
        if (!ottOmpOrderTrackScheduleList.isEmpty()) {
            LOG.debug("OttOmpOrderTrackScheduleDaoImpl : retrieveOrderTrackingSchdule : "
                    + "Record found for batch name " + batchName + " in OTT_OMP_ORDER_TRACK_SCHEDULE table");
            ottOmpOrderTrackSchedule = ottOmpOrderTrackScheduleList.get(0);
            return ottOmpOrderTrackSchedule;
        }
    }
    LOG.debug(
            "OttOmpOrderTrackScheduleDaoImpl : retrieveOrderTrackingSchdule : Record not found for batch name "
                    + batchName + " in OTT_OMP_ORDER_TRACK_SCHEDULE table");
    LOG.info("retrieveOrderTrackingSchdule Method ----------- ENDS");
    return ottOmpOrderTrackSchedule;
}

From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.dao.impl.OttOrderActivityDaoImpl.java

License:Open Source License

/**
 * This method is used to retrieve OrderTrackingActivityDetails using the last success run
 * and return the list of OttOrderActivity objects.
 * @param lastSuccessRun//from   ww  w  . j  a  v  a2 s. c o m
 *        Date
 * @return List
 */
public List<OttOrderActivity> retrieveOrderTrackingActivityDetails(Date lastSuccessRun) {
    LOG.info("retrieveOrderTrackingActivityDetails Method ----------- STARTS");
    List<OttOrderActivity> ottOrderActivityList = new ArrayList<OttOrderActivity>();
    if (lastSuccessRun != null) {
        DetachedCriteria criteria = super.createDetachedCriteria();
        Calendar c = Calendar.getInstance();
        c.setTime(lastSuccessRun);
        Date time = c.getTime();
        criteria.add(Restrictions.disjunction().add(Restrictions.eq("transitionTaskModifiedTime", time))
                .add(Restrictions.gt("transitionTaskModifiedTime", time)));

        ottOrderActivityList = findByCriteria(criteria);
        if (!ottOrderActivityList.isEmpty()) {
            LOG.debug("OttOrderActivityDaoImpl : retrieveOrderTrackingActivityDetails : "
                    + "Record found for lastSuccessRun " + lastSuccessRun
                    + " in OTT_ORDER_ACTIVITY_VIEW table");

        }

    }
    LOG.debug("OttOrderActivityDaoImpl : retrieveOrderTrackingActivityDetails : "
            + "Record not found for lastSuccessRun " + lastSuccessRun + " in OTT_ORDER_ACTIVITY_VIEW table");
    LOG.info("retrieveOrderTrackingActivityDetails Method ----------- ENDS");
    return ottOrderActivityList;

}

From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.dao.impl.OttOrderSummaryDaoImpl.java

License:Open Source License

/**
 * This method is used the retrieve OrderTrackingSummaryDetails using last success run
 * and returns the list of OttOrderSummary object.
 * @param lastSuccessRun//from  w  w w  . j  a va2s. co  m
 *         Date
 * @return List
 *
 */
public List<OttOrderSummary> retrieveOrderTrackingSummaryDetails(Date lastSuccessRun) {
    LOG.info("retrieveOrderTrackingSummaryDetails Method ----------- STARTS");
    List<OttOrderSummary> ottOrderSummaryList = new ArrayList<OttOrderSummary>();
    if (lastSuccessRun != null) {
        DetachedCriteria criteria = super.createDetachedCriteria();
        Calendar c = Calendar.getInstance();
        c.setTime(lastSuccessRun);
        criteria.add(Restrictions.disjunction().add(Restrictions.eq("orderModifiedDate", c.getTime()))
                .add(Restrictions.gt("orderModifiedDate", c.getTime()))
                .add(Restrictions.eq("orderCustomerModifiedDate", c.getTime()))
                .add(Restrictions.gt("orderCustomerModifiedDate", c.getTime())));

        ottOrderSummaryList = findByCriteria(criteria);
        if (!ottOrderSummaryList.isEmpty()) {
            LOG.debug("OttOrderSummaryDaoImpl : retrieveOrderTrackingSummaryDetails : "
                    + "Record found for lastSuccessRun " + lastSuccessRun + " in OTT_ORDER_SUMMARY_VIEW table");
            return ottOrderSummaryList;

        }
    }
    LOG.debug(
            "OttOrderSummaryDaoImpl : retrieveOrderTrackingSummaryDetails : Record not found for lastSuccessRun "
                    + lastSuccessRun + " in OTT_ORDER_SUMMARY_VIEW table");
    LOG.info("retrieveOrderTrackingSummaryDetails Method ----------- ENDS");
    return ottOrderSummaryList;

}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public Boolean hasBioCollections(LinkSubjectStudy linkSubjectStudy) {
    // Use WHERE EXIST to optimise query even further
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(LinkSubjectStudy.class, "lss");
    DetachedCriteria sizeCriteria = DetachedCriteria.forClass(BioCollection.class, "bc");
    criteria.add(Restrictions.eq("lss.id", linkSubjectStudy.getId()));
    sizeCriteria.add(Property.forName("lss.id").eqProperty("bc.linkSubjectStudy.id"));
    criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("bc.id"))));
    criteria.setProjection(Projections.rowCount());
    Boolean result = ((Long) criteria.uniqueResult()) > 0L;
    session.close();/*w w  w  . j  a  va  2  s .c o m*/

    return result;
}