Example usage for org.hibernate.criterion DetachedCriteria forClass

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

Introduction

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

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldGroupDAS.java

License:Open Source License

@SuppressWarnings("unchecked")
public MetaFieldGroup getGroupByName(Integer entityId, EntityType entityType, String name) {
    if (name == null || name.trim().length() == 0) {
        return null;
    }/*from   w  ww  .  j  a  v  a2 s  .co  m*/
    DetachedCriteria query = DetachedCriteria.forClass(MetaFieldGroup.class);
    query.add(Restrictions.eq("entityId", entityId));
    query.add(Restrictions.eq("entityType", entityType));
    query.add(Restrictions.eq("description", name));
    query.add(Restrictions.eq("class", MetaFieldGroup.class));
    List<MetaFieldGroup> fields = (List<MetaFieldGroup>) getHibernateTemplate().findByCriteria(query);
    return !fields.isEmpty() ? fields.get(0) : null;
}

From source file:com.scit.spring.dao.GenericDAOImpl.java

@Override
public Pagina selPagina2(int pag, String colQuery, String query, String colOrder, Estructuras.Orden orden) {
    DetachedCriteria dc = DetachedCriteria.forClass(clazz)
            .add(Restrictions.like(colQuery, query, MatchMode.ANYWHERE));
    Criteria c = dc.getExecutableCriteria(getCurrentSession());
    if (!colOrder.equals("") && orden != null) {
        switch (orden) {
        case asc:
            c.addOrder(Order.asc(colOrder));
            break;
        case desc:
            c.addOrder(Order.desc(colOrder));
            break;
        }/* www .jav  a 2 s .  c  o  m*/
    }
    return calcular(c, pag);
}

From source file:com.scopix.periscope.periscopefoundation.persistence.DAOHibernate.java

License:Open Source License

/**
 *
 * @return DetachedCriteria
 */
public DetachedCriteria newCriteriaInstance() {
    return DetachedCriteria.forClass(this.getType());
}

From source file:com.selfsoft.baseinformation.service.impl.TbCardHisServiceImpl.java

public List<TbCardHis> findByTbCardHis(TbCardHis tbCardHis) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCardHis.class);

    if (null != tbCardHis) {

        if (null != tbCardHis.getCardNo() && !"".equals(tbCardHis.getCardNo())) {

            detachedCriteria.add(Restrictions.like("cardNo", "%" + tbCardHis.getCardNo() + "%"));

        }//from   w  w  w  .j av a2 s .  com

        if (null != tbCardHis.getOperationDateFrom()) {

            detachedCriteria.add(Restrictions.ge("operationDate", tbCardHis.getOperationDateFrom()));

        }

        if (null != tbCardHis.getOperationDateTo()) {

            detachedCriteria.add(
                    Restrictions.le("operationDate", CommonMethod.addDate(tbCardHis.getOperationDateTo(), 1)));

        }

        if (null != tbCardHis.getLicenseCode() && !"".equals(tbCardHis.getLicenseCode())) {

            detachedCriteria.add(Restrictions.like("licenseCode", "%" + tbCardHis.getLicenseCode() + "%"));

        }

        if (null != tbCardHis.getOperationType() && !"".equals(tbCardHis.getOperationType())) {

            detachedCriteria.add(Restrictions.eq("operationType", tbCardHis.getOperationType()));

        }

        if (null != tbCardHis.getBalanceCode() && !"".equals(tbCardHis.getBalanceCode())) {
            detachedCriteria.add(Restrictions.like("balanceCode", "%" + tbCardHis.getBalanceCode() + "%"));
        }

        if (null != tbCardHis.getCustomerCode() && !"".equals(tbCardHis.getCustomerCode())) {

            detachedCriteria.add(Restrictions.eq("customerCode", tbCardHis.getCustomerCode()));

        }

        if (null != tbCardHis.getCustomerName() && !"".equals(tbCardHis.getCustomerName())) {

            detachedCriteria.add(Restrictions.eq("customerName", tbCardHis.getCustomerName()));

        }

    }

    else {

        return null;

    }

    /*List<TbCardHis> list = tbCardHisDao.findByCriteria(detachedCriteria, tbCardHis);
            
    List<TbCardHis> tbCardHisList = null;
            
    if(null != list && list.size() > 0){
               
       tbCardHisList = new ArrayList<TbCardHis>();
               
       for(TbCardHis _tbCardHis : list){
            
    TmUser tmUser = tmUserService.findById(_tbCardHis.getUserId());
            
    _tbCardHis.setTmUser(tmUser);
            
    tbCardHisList.add(_tbCardHis);
            
       }
               
    }*/

    return tbCardHisDao.findByCriteria(detachedCriteria, tbCardHis);
}

From source file:com.selfsoft.baseinformation.service.impl.TbCarInfoServiceImpl.java

public List<TbCarInfo> findByTbCarInfo(TbCarInfo tbCarInfo) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCarInfo.class);

    if (null != tbCarInfo) {
        if (null != tbCarInfo.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbCarInfo.getId()));
        }//  w w  w . j  a va 2  s .  c  o  m
        if (null != tbCarInfo.getLicenseCode() && !"".equals(tbCarInfo.getLicenseCode())) {
            //?
            detachedCriteria.add(Restrictions.like("licenseCode", "%" + tbCarInfo.getLicenseCode() + "%"));
        }
        if (null != tbCarInfo.getInsureCardCode() && !"".equals(tbCarInfo.getInsureCardCode())) {
            detachedCriteria
                    .add(Restrictions.like("insureCardCode", "%" + tbCarInfo.getInsureCardCode() + "%"));
        }
        if (null != tbCarInfo.getTmCarModelType()) {

            detachedCriteria.createAlias("tmCarModelType", "tmCarModelType");

            if (null != tbCarInfo.getTmCarModelType().getId()) {
                detachedCriteria
                        .add(Restrictions.eq("tmCarModelType.id", tbCarInfo.getTmCarModelType().getId()));
            }
        }
        if (null != tbCarInfo.getTbCustomer()) {

            detachedCriteria.createAlias("tbCustomer", "tbCustomer");

            if (null != tbCarInfo.getTbCustomer().getId()) {
                detachedCriteria.add(Restrictions.eq("tbCustomer.id", tbCarInfo.getTbCustomer().getId()));
            }
            if (null != tbCarInfo.getTbCustomer().getCustomerCode()) {
                detachedCriteria.add(Restrictions.like("tbCustomer.customerCode",
                        "%" + tbCarInfo.getTbCustomer().getCustomerCode() + "%"));
            }
            if (null != tbCarInfo.getTbCustomer().getCustomerName()) {
                detachedCriteria.add(Restrictions.like("tbCustomer.customerName",
                        "%" + tbCarInfo.getTbCustomer().getCustomerName() + "%"));
            }
            if (null != tbCarInfo.getTbCustomer().getTelephone()) {
                detachedCriteria.add(Restrictions.like("tbCustomer.telephone",
                        "%" + tbCarInfo.getTbCustomer().getTelephone() + "%"));
            }
        }

        if (StringUtils.isNotBlank(tbCarInfo.getBeginLicenseDate())) {
            detachedCriteria.add(Restrictions.ge("licenseDate", Date.valueOf(tbCarInfo.getBeginLicenseDate())));
        }

        if (StringUtils.isNotBlank(tbCarInfo.getEndLicenseDate())) {
            detachedCriteria.add(Restrictions.le("licenseDate", Date.valueOf(tbCarInfo.getEndLicenseDate())));
        }

        if (StringUtils.isNotBlank(tbCarInfo.getBeginPurchaseDate())) {
            detachedCriteria
                    .add(Restrictions.ge("purchaseDate", Date.valueOf(tbCarInfo.getBeginPurchaseDate())));
        }

        if (StringUtils.isNotBlank(tbCarInfo.getEndPurchaseDate())) {
            detachedCriteria.add(Restrictions.le("purchaseDate", Date.valueOf(tbCarInfo.getEndPurchaseDate())));
        }
        if (StringUtils.isNotBlank(tbCarInfo.getChassisCode())) {
            detachedCriteria.add(Restrictions.like("chassisCode", "%" + tbCarInfo.getChassisCode() + "%"));
        }

        if (tbCarInfo.getCarProperty() != null) {
            detachedCriteria.add(Restrictions.eq("carProperty", tbCarInfo.getCarProperty()));
        }

        if (StringUtils.isNotBlank(tbCarInfo.getLicenseMonth())) {
            detachedCriteria
                    .add(Restrictions.sqlRestriction("month(LICENSE_DATE)=" + tbCarInfo.getLicenseMonth()));
        }
        if (tbCarInfo.getMaxKilo() != null && tbCarInfo.getMinKilo() != null) {
            detachedCriteria.add(Restrictions.between("kilo", tbCarInfo.getMinKilo(), tbCarInfo.getMaxKilo()));
        }
    }

    return tbCarInfoDao.findByCriteria(detachedCriteria, tbCarInfo);
}

From source file:com.selfsoft.baseinformation.service.impl.TbCustomerServiceImpl.java

public List<TbCustomer> findByTbCustomer(TbCustomer tbCustomer, String types) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCustomer.class);

    if (null != tbCustomer) {
        if (null != tbCustomer.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbCustomer.getId()));
        }//from w w  w .  ja  v a 2  s .c  om
        if (null != tbCustomer.getCustomerCode() && !"".equals(tbCustomer.getCustomerCode())) {
            detachedCriteria.add(Restrictions.like("customerCode", "%" + tbCustomer.getCustomerCode() + "%"));
        }
        if (null != tbCustomer.getCustomerName() && !"".equals(tbCustomer.getCustomerName())) {
            detachedCriteria.add(Restrictions.like("customerName", "%" + tbCustomer.getCustomerName() + "%"));
        }
        if (null != tbCustomer.getPinyinCode() && !"".equals(tbCustomer.getPinyinCode())) {
            detachedCriteria.add(Restrictions.like("pinyinCode", "%" + tbCustomer.getPinyinCode() + "%"));
        }
        if (null != tbCustomer.getTelephone() && !"".equals(tbCustomer.getTelephone())) {
            detachedCriteria.add(Restrictions.like("telephone", "%" + tbCustomer.getTelephone() + "%"));
        }
        if (null != tbCustomer.getCustomerProperty()) {
            detachedCriteria.add(Restrictions.eq("customerProperty", tbCustomer.getCustomerProperty()));
        }
        if (null != tbCustomer.getTmCustomerType()) {
            detachedCriteria.setFetchMode("tmCustomerType", FetchMode.JOIN);
            if (null != tbCustomer.getTmCustomerType().getId()) {
                detachedCriteria
                        .add(Restrictions.eq("tmCustomerType.id", tbCustomer.getTmCustomerType().getId()));
            }
        }

    }
    if (StringUtils.isNotBlank(types)) {
        List<Long> list = new ArrayList<Long>();
        for (String type : types.split(",")) {
            list.add(new Long(type));
        }

        detachedCriteria.add(Restrictions.in("customerProperty", list));
    }
    return tbCustomerDao.findByCriteria(detachedCriteria, tbCustomer);
}

From source file:com.selfsoft.baseinformation.service.impl.TbCustomerServiceImpl.java

public List<TbCustomer> findByTbCustomer(TbCustomer tbCustomer) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCustomer.class);

    if (null != tbCustomer) {
        if (null != tbCustomer.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbCustomer.getId()));
        }//  ww w  .j  a  v a2s.  c  om
        if (null != tbCustomer.getCustomerCode() && !"".equals(tbCustomer.getCustomerCode())) {
            detachedCriteria.add(Restrictions.like("customerCode", "%" + tbCustomer.getCustomerCode() + "%"));
        }
        if (null != tbCustomer.getCustomerName() && !"".equals(tbCustomer.getCustomerName())) {
            detachedCriteria.add(Restrictions.like("customerName", "%" + tbCustomer.getCustomerName() + "%"));
        }
        if (null != tbCustomer.getPinyinCode() && !"".equals(tbCustomer.getPinyinCode())) {
            detachedCriteria.add(Restrictions.like("pinyinCode", "%" + tbCustomer.getPinyinCode() + "%"));
        }
        if (null != tbCustomer.getTelephone() && !"".equals(tbCustomer.getTelephone())) {
            detachedCriteria.add(Restrictions.like("telephone", "%" + tbCustomer.getTelephone() + "%"));
        }
        if (null != tbCustomer.getCustomerProperty()) {
            detachedCriteria.add(Restrictions.eq("customerProperty", tbCustomer.getCustomerProperty()));
        }
        if (null != tbCustomer.getTmCustomerType()) {
            detachedCriteria.setFetchMode("tmCustomerType", FetchMode.JOIN);
            if (null != tbCustomer.getTmCustomerType().getId()) {
                detachedCriteria
                        .add(Restrictions.eq("tmCustomerType.id", tbCustomer.getTmCustomerType().getId()));
            }
        }
    }

    return tbCustomerDao.findByCriteria(detachedCriteria, tbCustomer);
}

From source file:com.selfsoft.baseinformation.service.impl.TbMembershipCardServiceImpl.java

public List<TbMembershipCard> findByTbMembershipCard(TbMembershipCard tbMembershipCard) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbMembershipCard.class);

    if (null != tbMembershipCard) {

        if (null != tbMembershipCard.getCardNo() && !"".equals(tbMembershipCard.getCardNo())) {

            detachedCriteria.add(Restrictions.like("cardNo", "%" + tbMembershipCard.getCardNo() + "%"));

        }/* w  w  w. j  av  a  2  s  . com*/

        if (null != tbMembershipCard.getCardStatus()) {

            detachedCriteria.add(Restrictions.eq("cardStatus", tbMembershipCard.getCardStatus()));

        }

        if (null != tbMembershipCard.getTmCardType() && null != tbMembershipCard.getTmCardType().getId()) {

            detachedCriteria.createAlias("tmCardType", "tmCardType");

            detachedCriteria.add(Restrictions.eq("tmCardType.id", tbMembershipCard.getTmCardType().getId()));

        }

        //boolean flag = false;

        //if(null!=tbMembershipCard.getLicenseCode()&&!"".equals(tbMembershipCard.getLicenseCode())){

        //   flag = true;
        //   
        //   detachedCriteria.createAlias("tbCarInfo", "tbCarInfo");

        //   detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode","%"+tbMembershipCard.getLicenseCode()+"%"));
        //}
        //if(null!=tbMembershipCard.getTbCustomer()){

        if ((null != tbMembershipCard.getCustomerName() && !"".equals(tbMembershipCard.getCustomerName()))
                || (null != tbMembershipCard.getTelephone() && !"".equals(tbMembershipCard.getTelephone())
                        || (null != tbMembershipCard.getCustomerId()))) {

            //detachedCriteria.setFetchMode("tbMembershipCard.tbCustomer", FetchMode.JOIN);

            //if(!flag)
            detachedCriteria.createAlias("tbCustomer", "tbCustomer");

        }

        if (null != tbMembershipCard.getCustomerId()) {

            detachedCriteria.add(Restrictions.eq("tbCustomer.id", tbMembershipCard.getCustomerId()));

        }

        if (null != tbMembershipCard.getCustomerName() && !"".equals(tbMembershipCard.getCustomerName())) {

            detachedCriteria.add(Restrictions.like("tbCustomer.customerName",
                    "%" + tbMembershipCard.getCustomerName() + "%"));

        }

        if (null != tbMembershipCard.getTelephone() && !"".equals(tbMembershipCard.getTelephone())) {

            detachedCriteria.add(
                    Restrictions.like("tbCustomer.telephone", "%" + tbMembershipCard.getTelephone() + "%"));

        }

        //}

    }

    return tbMembershipCardDao.findByCriteria(detachedCriteria, tbMembershipCard);
}

From source file:com.selfsoft.business.service.impl.TbAnvancePayServiceImpl.java

public List<TbAnvancePay> findByTbAnvancePay(TbAnvancePay tbAnvancePay) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbAnvancePay.class);

    if (null != tbAnvancePay) {
        if (null != tbAnvancePay.getAnvanceCode()) {
            detachedCriteria.add(Restrictions.like("anvanceCode", "%" + tbAnvancePay.getAnvanceCode() + "%"));
        }//from  ww w . ja  v  a  2 s.c  o m
        if (null != tbAnvancePay.getTbCarInfo()) {
            detachedCriteria.createAlias("tbCarInfo", "tbCarInfo");

            if (null != tbAnvancePay.getTbCarInfo().getLicenseCode()
                    && !"".equals(tbAnvancePay.getTbCarInfo().getLicenseCode())) {
                detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode",
                        "%" + tbAnvancePay.getTbCarInfo().getLicenseCode() + "%"));
            }
        }
    }
    return tbAnvancePayDao.findByCriteria(detachedCriteria, tbAnvancePay);
}

From source file:com.selfsoft.business.service.impl.TbBookServiceImpl.java

public List<TbBook> findByTbBook(TbBook tbBook) {
    // TODO Auto-generated method stub
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbBook.class);

    if (null != tbBook) {
        if (null != tbBook.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbBook.getId()));
        }/*from   w  w w  . j  a  va2 s  . c o m*/
        if (null != tbBook.getBookCode()) {
            detachedCriteria.add(Restrictions.like("bookCode", "%" + tbBook.getBookCode() + "%"));
        }
        if (null != tbBook.getRegisterDateStart()) {
            detachedCriteria.add(Restrictions.ge("registerDate", tbBook.getRegisterDateStart()));
        }
        if (null != tbBook.getRegisterDateEnd()) {
            detachedCriteria.add(Restrictions.le("registerDate", tbBook.getRegisterDateEnd()));
        }
        if (null != tbBook.getLicenseCode() && !"".equals(tbBook.getLicenseCode())) {
            detachedCriteria.add(Restrictions.like("licenseCode", "%" + tbBook.getLicenseCode() + "%"));
        }
        if (null != tbBook.getIsCome()) {
            detachedCriteria.add(Restrictions.eq("isCome", tbBook.getIsCome()));
        }
        if (null != tbBook.getPlanFixTimeStart()) {
            detachedCriteria.add(Restrictions.ge("planFixTime", tbBook.getPlanFixTimeStart()));
        }
        if (null != tbBook.getPlanFixTimeEnd()) {
            detachedCriteria.add(Restrictions.le("planFixTime", tbBook.getPlanFixTimeEnd()));
        }
        if (null != tbBook.getTmUser()) {

            if (null != tbBook.getTmUser().getId()) {

                detachedCriteria.createAlias("tmUser", "tmUser");

                detachedCriteria.add(Restrictions.eq("tmUser.id", tbBook.getTmUser().getId()));

            }
        }
    }

    return tbBookDao.findByCriteria(detachedCriteria, tbBook);
}