Example usage for org.hibernate.criterion DetachedCriteria addOrder

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

Introduction

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

Prototype

public DetachedCriteria addOrder(Order order) 

Source Link

Document

Adds an ordering

Usage

From source file:com.sccl.attech.modules.sys.service.SystemService.java

License:Open Source License

public Page<Menu> find(Page<Menu> page, Menu menu) {
    User user = UserUtils.getUser();//from ww  w.  java  2s  .com
    DetachedCriteria dc = menuDao.createDetachedCriteria();
    if (StringUtils.isNotEmpty(menu.getName())) {
        dc.add(Restrictions.like("name", "%" + menu.getName() + "%"));
    }
    //      dc.createAlias("createBy.office", "office");
    //      dc.add(dataScopeFilter(user, "office", "createBy"));
    dc.add(Restrictions.eq(Menu.FIELD_DEL_FLAG, Menu.DEL_FLAG_NORMAL));
    dc.addOrder(Order.asc("sort"));
    return menuDao.find(page, dc);
}

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

public List<TbFixShare> findByEntity(TbFixShare tbFixShare) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbFixShare.class);
    if (null != tbFixShare) {
        if (null != tbFixShare.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbFixShare.getId()));
        }/*from  ww w .  j ava2s . co m*/
        if (tbFixShare.getTmUser() != null) {
            detachedCriteria.createAlias("tmUser", "tmUser");
            if (StringUtils.isNotBlank(tbFixShare.getTmUser().getUserRealName())) {
                detachedCriteria.add(Restrictions.like("tmUser.userRealName",
                        "%" + tbFixShare.getTmUser().getUserRealName() + "%"));
            }

            if (tbFixShare.getTmUser().getId() != null) {
                detachedCriteria.add(Restrictions.eq("tmUser.id", tbFixShare.getTmUser().getId()));
            }
        }

        if (tbFixShare.getTbFixEntrustContent() != null) {

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

            if (tbFixShare.getTbFixEntrustContent().getTbWorkingInfo() != null) {

                detachedCriteria.createAlias("tbFixEntrustContent.tbWorkingInfo", "tbWorkingInfo");

                if (StringUtils
                        .isNotBlank(tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationCode())) {
                    detachedCriteria.add(Restrictions.like("tbWorkingInfo.stationCode", "%"
                            + tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationCode() + "%"));
                }

                if (StringUtils
                        .isNotBlank(tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationName())) {
                    detachedCriteria.add(Restrictions.like("tbWorkingInfo.stationName", "%"
                            + tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationName() + "%"));
                }

            }

            if (tbFixShare.getTbFixEntrustContent().getTbFixEntrust() != null) {
                detachedCriteria.createAlias("tbFixEntrustContent.tbFixEntrust", "tbFixEntrust");
                detachedCriteria.add(Restrictions.ne("tbFixEntrust.isvalid", 0L));
                if (StringUtils
                        .isNotBlank(tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getEntrustCode())) {
                    detachedCriteria.add(Restrictions.like("tbFixEntrust.entrustCode", "%"
                            + tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getEntrustCode() + "%"));
                }

                if (null != tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateStart()) {
                    detachedCriteria.add(Restrictions.ge("tbFixEntrust.fixDate",
                            tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateStart()));
                }
                if (null != tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateEnd()) {
                    detachedCriteria.add(Restrictions.le("tbFixEntrust.fixDate", CommonMethod.addDate(
                            tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateEnd(), 1)));
                }

                if (tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getTbCarInfo() != null) {
                    detachedCriteria.createAlias("tbFixEntrustContent.tbFixEntrust.tbCarInfo", "tbCarInfo");

                    if (StringUtils.isNotBlank(tbFixShare.getTbFixEntrustContent().getTbFixEntrust()
                            .getTbCarInfo().getLicenseCode())) {
                        detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode",
                                "%" + tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getTbCarInfo()
                                        .getLicenseCode() + "%"));
                    }
                }

                /*  */
                if (tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getBalanceDateBegin() != null
                        || tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getBalanceDateEnd() != null) {
                    List entrustIdList = tbBusinessBalanceDao
                            .getTbEntrustByBalanceDate(tbFixShare.getTbFixEntrustContent().getTbFixEntrust());
                    if (entrustIdList != null && entrustIdList.size() == 0) {
                        return null;
                    }
                    detachedCriteria.add(Restrictions.in("tbFixEntrust.id", entrustIdList));
                }
                /*  */
            }
        }
    } else {
        detachedCriteria.createAlias("tbFixEntrustContent", "tbFixEntrustContent");
        detachedCriteria.createAlias("tbFixEntrustContent.tbFixEntrust", "tbFixEntrust");
        detachedCriteria.add(Restrictions.ne("tbFixEntrust.isvalid", 0L));

    }
    detachedCriteria.addOrder(Order.asc("tmUser.id"));
    return tbFixShareDao.findByCriteria(detachedCriteria, tbFixShare);
}

From source file:com.thinkgem.jeesite.modules.issue.service.IssueProjectVersionService.java

License:Open Source License

public List<IssueProjectVersion> findAll(IssueProject project, IssueProjectVersion version) {
    DetachedCriteria dc = projectVersionDao.createDetachedCriteria();
    if (StringUtils.isNotEmpty(project.getId())) {
        dc.createAlias("project", "project");
        dc.add(Restrictions.eq("project.id", project.getId()));
    }/*  ww w . ja  v  a2 s .co  m*/

    if (StringUtils.isNotEmpty(version.getStatus())) {
        dc.add(Restrictions.eq("status", version.getStatus()));
    }

    if (StringUtils.isNotEmpty(version.getVersionNo())) {
        dc.add(Restrictions.ilike("versionNo", "%" + version.getVersionNo() + "%"));
    }

    dc.add(Restrictions.eq(IssueProjectVersion.FIELD_DEL_FLAG, IssueProjectVersion.DEL_FLAG_NORMAL));
    dc.addOrder(Order.desc("createDate"));
    return projectVersionDao.find(dc);
}

From source file:com.thinkgem.jeesite.modules.pms.service.CompanyService.java

License:Open Source License

public Page<Office> find(Page<Office> page, Office office) {
    User currentUser = UserUtils.getUser();

    //      System.out.println(">>>>>>>>>>>>>>>>>>>"+ office.getSort());

    DetachedCriteria dc = officeDao.createDetachedCriteria();

    //      if(StringUtils.isBlank(office.getSort())){
    //         dc.add(Restrictions.eq("id", "0"));
    //         return officeDao.find(page, dc);
    //      }else{
    //         if (!currentUser.isAdmin() && office.getSort().equals("1")){
    //            dc.add(Restrictions.eq("id", "0"));
    //         }//from w  w w  . j  av a  2  s. c  om
    //      }
    //      

    //      dc.createAlias("office", "office");

    if (StringUtils.isNotEmpty(office.getSort())) {
        dc.add(Restrictions.eq("sort", office.getSort()));
    }
    if (StringUtils.isNotEmpty(office.getName())) {
        //         dc.add(Restrictions.like("name", office.getName()));
        dc.add(Restrictions.like("name", "%" + office.getName() + "%"));
    }

    //      dc.add(dataScopeFilter2(currentUser, "", ""));

    //      System.out.println("dc.getAlias()>>>>>>>>>>>>>>>>>>>"+ dc.getAlias());

    dc.add(dataScopeFilter(UserUtils.getUser(), dc.getAlias(), ""));

    dc.add(Restrictions.eq(office.FIELD_DEL_FLAG, office.DEL_FLAG_NORMAL));
    dc.addOrder(Order.desc("id"));

    //      System.out.println(">>>>>>>>>>>>>>>>>>>"+ dc.);

    return officeDao.find(page, dc);
}

From source file:com.thinkgem.jeesite.modules.pms.service.UserService.java

License:Open Source License

public Page<User> findUser(Page<User> page, User user) {
    DetachedCriteria dc = userDao.createDetachedCriteria();
    User currentUser = UserUtils.getUser();
    dc.createAlias("company", "company");
    dc.createAlias("office", "office");

    List<House> houseList = HouseUtils.getHousesList(user.getHouseIds());
    List<String> userIdList = HouseUtils.getUsersByHouseIds(houseList);

    //      System.out.println("HouseUtils.getHousesList>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+houseList.size());

    //      user.setHouseList(houseList);

    if (userIdList.size() > 0) {
        dc.add(Restrictions.in("id", userIdList));
    }/*from   w w  w . ja  v  a 2 s.c  om*/

    if (user.getCompany() != null && StringUtils.isNotBlank(user.getCompany().getId())) {
        dc.add(Restrictions.or(Restrictions.eq("company.id", user.getCompany().getId()),
                Restrictions.like("company.parentIds", "%," + user.getCompany().getId() + ",%")));
    }

    if (user.getOffice() != null && StringUtils.isNotBlank(user.getOffice().getId())) {
        dc.add(Restrictions.or(Restrictions.eq("office.id", user.getOffice().getId()),
                Restrictions.like("office.parentIds", "%," + user.getOffice().getId() + ",%")));
    }

    //      dc.add(Restrictions.like("userType", "2")); 
    System.out.println("user.getUserType() >>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + user.getUserType());
    if (StringUtils.isNotEmpty(user.getUserType())) {
        dc.add(Restrictions.eq("userType", user.getUserType()));
    }

    // ????
    if (!currentUser.isAdmin()) {
        dc.add(Restrictions.ne("id", "1"));
    }

    dc.add(dataScopeFilter(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() + "%"));
    }

    if (StringUtils.isNotEmpty(user.getPhone())) {
        dc.add(Restrictions.like("phone", "%" + user.getPhone() + "%"));
    }

    if (StringUtils.isNotEmpty(user.getPhone())) {
        dc.add(Restrictions.like("mobile", "%" + user.getMobile() + "%"));
    }

    if (!StringUtils.isNotEmpty(page.getOrderBy())) {
        dc.addOrder(Order.asc("company.code")).addOrder(Order.asc("office.code")).addOrder(Order.desc("name"));
    }

    //      dc.addOrder(Order.asc("loginName"));

    dc.add(Restrictions.eq(User.FIELD_DEL_FLAG, User.DEL_FLAG_NORMAL));

    return userDao.find(page, dc);
}

From source file:com.thinkgem.jeesite.modules.sys.service.AreaService.java

License:Open Source License

public List<Area> findAllByPid(String pid) {
    @SuppressWarnings("unchecked")
    List<Area> areaList = (List<Area>) UserUtils.getCache(UserUtils.CACHE_AREA_LIST + pid);
    if (areaList == null) {
        DetachedCriteria dc = areaDao.createDetachedCriteria();
        dc.add(Restrictions.eq("parent.id", pid));
        dc.add(Restrictions.eq(Area.FIELD_DEL_FLAG, Area.DEL_FLAG_NORMAL));
        dc.addOrder(Order.asc("sort")).addOrder(Order.desc("id"));
        areaList = areaDao.find(dc);/*  w w w .j av  a  2  s  . co m*/
        UserUtils.putCache(UserUtils.CACHE_AREA_LIST + pid, areaList);
    }
    return areaList;
}

From source file:com.thinkgem.jeesite.modules.sys.service.CustomerService.java

License:Open Source License

public Page<Customer> findCustomer(Page<Customer> page, Customer customer) {
    DetachedCriteria dc = customerDao.createDetachedCriteria();
    if (StringUtils.isNotEmpty(customer.getName())) {
        dc.add(Restrictions.like("name", "%" + customer.getName() + "%"));
    }//from  ww w  .j  av a 2  s  .  c om

    //dc.add(Restrictions.eq(User.FIELD_DEL_FLAG, User.DEL_FLAG_NORMAL));
    if (!StringUtils.isNotEmpty(page.getOrderBy())) {
        dc.addOrder(Order.desc("name"));
    }
    return customerDao.find(page, dc);
}

From source file:com.us.bo.CatalogBo.java

License:Open Source License

public List<Catalog> findCataLog() {
    DetachedCriteria criteria = create(Catalog.class);
    // criteria.add(Restrictions.eq("creator.uuid", 1l));
    criteria.addOrder(Order.asc("order"));
    return find(criteria);
}

From source file:com.us.test.PageTest.java

License:Open Source License

public static void main(String[] args) {

    ApplicationContext app = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");

    IDao dao = app.getBean(IDao.class);

    DetachedCriteria criteria = dao.init(User.class);
    criteria.addOrder(Order.asc("uuid"));
    criteria.addOrder(Order.asc("name"));
    criteria.add(Restrictions.gt("uuid", 0l));

    dao.findPage(criteria, 1, 20);/* ww  w .  ja  v a 2s . c  om*/

}

From source file:com.ut.tekir.contact.ContactBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {
    DetachedCriteria crit = DetachedCriteria.forClass(Contact.class);

    crit.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("code"), "code").add(Projections.property("name"), "name")
            .add(Projections.property("fullname"), "fullname").add(Projections.property("ssn"), "ssn")
            .add(Projections.property("company"), "company").add(Projections.property("taxNumber"), "taxNumber")
            .add(Projections.property("taxOffice"), "taxOffice").add(Projections.property("title"), "title")
            .add(Projections.property("representative"), "representative")
            .add(Projections.property("info"), "info").add(Projections.property("exCode1"), "exCode1")
            .add(Projections.property("exCode2"), "exCode2").add(Projections.property("allType"), "allType")
            .add(Projections.property("customerType"), "customerType")
            .add(Projections.property("providerType"), "providerType")
            .add(Projections.property("agentType"), "agentType")
            .add(Projections.property("personnelType"), "personnelType")
            .add(Projections.property("branchType"), "branchType")
            .add(Projections.property("contactType"), "contactType")
            .add(Projections.property("bankType"), "bankType")
            .add(Projections.property("relatedType"), "relatedType")
            .add(Projections.property("foundationType"), "foundationType")));

    crit.setResultTransformer(Transformers.aliasToBean(ContactModel.class));

    if (filterModel.getCode() != null && filterModel.getCode().length() > 0) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }/*from ww w  . j av  a 2  s.  c  o  m*/

    if (filterModel.getFullname() != null && filterModel.getFullname().length() > 0) {
        crit.add(Restrictions.ilike("this.fullname", filterModel.getFullname(), MatchMode.ANYWHERE));
    }

    if (filterModel.getCompany() != null && filterModel.getCompany().length() > 0) {
        crit.add(Restrictions.ilike("this.company", filterModel.getCompany(), MatchMode.START));
    }

    if (filterModel.getSsn() != null && filterModel.getSsn().length() > 0) {
        crit.add(Restrictions.ilike("this.ssn", filterModel.getSsn(), MatchMode.START));
    }

    if (filterModel.getTaxNumber() != null && filterModel.getTaxNumber().length() > 0) {
        crit.add(Restrictions.ilike("this.taxNumber", filterModel.getTaxNumber(), MatchMode.START));
    }

    if (filterModel.getRepresentative() != null && filterModel.getRepresentative().length() > 0) {
        crit.add(Restrictions.ilike("this.representative", filterModel.getRepresentative(), MatchMode.START));
    }

    if (filterModel.getExCode1() != null && filterModel.getExCode1().length() > 0) {
        crit.add(Restrictions.ilike("this.exCode1", filterModel.getExCode1(), MatchMode.START));
    }

    if (filterModel.getExCode2() != null && filterModel.getExCode2().length() > 0) {
        crit.add(Restrictions.ilike("this.exCode2", filterModel.getExCode2(), MatchMode.START));
    }

    if (filterModel.getCategory() != null) {
        crit.add(Restrictions.eq("this.category", filterModel.getCategory()));
    }

    if (filterModel.getOrganization() != null) {
        crit.add(Restrictions.eq("this.organization", filterModel.getOrganization()));
    }

    if (filterModel.getCompanyType() != null && !filterModel.getCompanyType().equals("All")) {
        if (filterModel.getCompanyType().equals("Person")) {
            crit.add(Restrictions.eq("this.person", Boolean.TRUE));
        } else
            crit.add(Restrictions.eq("this.person", Boolean.FALSE));
    }

    if (filterModel.getType() != null && filterModel.getType() != ContactType.All) {
        crit.add(Restrictions.eq("this." + filterModel.getType().toString().toLowerCase() + "Type",
                Boolean.TRUE));
    }

    if (filterModel.getCountry() != null) {
        crit.createAlias("this.addressList", "addressList", CriteriaSpecification.INNER_JOIN);
        crit.add(Restrictions.eq("addressList.address.country", filterModel.getCountry()));

        if (filterModel.getCity1() != null) {
            crit.add(Restrictions.eq("addressList.city", filterModel.getCity1()));
        }
    }

    //FIXME: bu kontrol nasl olmal?
    if (hasRegionRestriction()) {
        if (activeUser.getContact() != null && activeUser.getContact().getOrganization() != null
                && activeUser.getContact().getOrganization() != null) {

            crit.add(Restrictions.or(
                    Restrictions.eq("this.organization.id", activeUser.getContact().getOrganization().getId()),
                    Restrictions.eq("this.isPublic", Boolean.TRUE)));
        }
    }
    crit.addOrder(Order.desc("this.code"));

    return crit;
}