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.perceptive.epm.perkolcentral.dataaccessor.EmployeeDataAccessor.java

public LinkedHashMap<Long, EmployeeBO> getAllEmployeesByTemplate() throws ExceptionWrapper {
    LinkedHashMap<Long, EmployeeBO> employeeLinkedHashMap = new LinkedHashMap<Long, EmployeeBO>();

    try {//from  w ww  . j  av  a 2 s.c  om
        DetachedCriteria criteria = DetachedCriteria.forClass(Employee.class);
        criteria.add(Restrictions.eq("isActive", true));
        criteria.addOrder(Order.asc("employeeName"));

        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            Employee employee = (Employee) item;
            EmployeeBO employeeBO = new EmployeeBO(employee);

            //Get the group information for the employee
            for (Object obj : employee.getEmployeegroupmaps()) {
                Employeegroupmap employeegroupmap = (Employeegroupmap) obj;
                employeegroupmap = hibernateTemplate.get(Employeegroupmap.class,
                        employeegroupmap.getEmployeeGroupMappingId());
                GroupBO groupBO = new GroupBO(employeegroupmap.getGroups());
                employeeBO.getGroups().add(groupBO);
            }
            //==================================================================================================================
            //Get the license info for the employee
            for (Object obj : employee.getEmployeelicensemappings()) {
                Employeelicensemapping employeelicensemapping = (Employeelicensemapping) obj;
                LicenseBO licenseBO = new LicenseBO(employeelicensemapping.getLicensemaster());
                employeeBO.getLicenses().add(licenseBO);
            }
            //==================================================================================================================
            employeeLinkedHashMap.put(Long.valueOf(employee.getEmployeeId()), employeeBO);
        }

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return employeeLinkedHashMap;
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public LinkedHashMap<String, Imagenowlicenses> getAllImageNowLicenses() throws ExceptionWrapper {
    LinkedHashMap<String, Imagenowlicenses> imagenowlicensesLinkedHashMap = new LinkedHashMap<String, Imagenowlicenses>();
    try {//  w ww . ja  v a  2  s.c o  m
        DetachedCriteria criteria = DetachedCriteria.forClass(Imagenowlicenses.class);
        criteria.createAlias("employeeByRequestedByEmployeeId", "emp");
        criteria.createAlias("groups", "group");
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("group", FetchMode.JOIN);
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            Imagenowlicenses imagenowlicenses = (Imagenowlicenses) item;
            imagenowlicensesLinkedHashMap.put(imagenowlicenses.getImageNowLicenseRequestId(), imagenowlicenses);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return imagenowlicensesLinkedHashMap;
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public LinkedHashMap<String, Imagenowlicenses> getAllImageNowLicensesByRequestor(String employeeUID)
        throws ExceptionWrapper {
    LinkedHashMap<String, Imagenowlicenses> imagenowlicensesLinkedHashMap = new LinkedHashMap<String, Imagenowlicenses>();
    try {/*  ww  w. ja v a  2s . co m*/
        DetachedCriteria criteria = DetachedCriteria.forClass(Imagenowlicenses.class);
        criteria.createAlias("employeeByRequestedByEmployeeId", "emp");
        criteria.createAlias("groups", "group");
        criteria.add(Restrictions.eq("emp.employeeUid", employeeUID));
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("group", FetchMode.JOIN);
        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            Imagenowlicenses imagenowlicenses = (Imagenowlicenses) item;
            imagenowlicensesLinkedHashMap.put(imagenowlicenses.getImageNowLicenseRequestId(), imagenowlicenses);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return imagenowlicensesLinkedHashMap;
}

From source file:com.rockagen.gnext.service.spring.AccountBillServImpl.java

License:Apache License

@Override
public List<AccountBill> loadListByAccount(long accountId) {
    QueryObject qo = new QueryObject();
    DetachedCriteria dc = qo.generateDetachedCriteria(AccountBill.class);
    dc.createAlias("account", "a");
    dc.add(Restrictions.eq("a.id", accountId));
    dc.addOrder(Order.desc("createdAt"));
    return find(qo);
}

From source file:com.rockagen.gnext.service.spring.AccountServImpl.java

License:Apache License

@Override
public List<Account> loadListByUid(long uid) {
    QueryObject qo = new QueryObject();
    DetachedCriteria dc = qo.generateDetachedCriteria(Account.class);
    dc.createAlias("user", "u");
    dc.add(Restrictions.eq("u.id", uid));
    dc.addOrder(Order.desc("updatedAt"));
    return find(qo);
}

From source file:com.saituo.talk.modules.sys.utils.UserUtils.java

License:Open Source License

public static List<Office> getOfficeList() {
    @SuppressWarnings("unchecked")
    List<Office> officeList = (List<Office>) getCache(CACHE_OFFICE_LIST);
    if (officeList == null) {
        User user = getUser();/*from   w  w  w  . ja  va 2 s.  co m*/
        // if (user.isAdmin()){
        // officeList = officeDao.findAllList();
        // }else{
        // officeList = officeDao.findAllChild(user.getOffice().getId(),
        // "%,"+user.getOffice().getId()+",%");
        // }
        DetachedCriteria dc = officeDao.createDetachedCriteria();
        dc.add(dataScopeFilter(user, dc.getAlias(), ""));
        dc.add(Restrictions.eq(Office.FIELD_DEL_FLAG, Office.DEL_FLAG_NORMAL));
        dc.addOrder(Order.asc("code"));
        officeList = officeDao.find(dc);
        putCache(CACHE_OFFICE_LIST, officeList);
    }
    return officeList;
}

From source file:com.salesmanager.core.service.reference.impl.dao.CoreModuleServiceDao.java

License:Open Source License

public Collection<CoreModuleService> findByServiceTypeAndSubTypeByRegion(int type, int subType, String region) {

    try {/* w  ww  .  j a v a 2  s . com*/

        List countryList = new ArrayList();
        countryList.add(region);
        countryList.add(Constants.ALLCOUNTRY_ISOCODE);

        DetachedCriteria crit = DetachedCriteria.forClass(CoreModuleService.class);
        crit.add(Expression.in("countryIsoCode2", countryList));
        crit.add(Expression.eq("coreModuleServiceCode", type));
        crit.add(Expression.eq("coreModuleServiceSubtype", subType));
        crit.addOrder(org.hibernate.criterion.Order.desc("coreModuleServicePosition"));
        Collection result = this.getHibernateTemplate().findByCriteria(crit);

        List countrySpecificList = new ArrayList();
        Iterator i = result.iterator();
        while (i.hasNext()) {
            CoreModuleService cms = (CoreModuleService) i.next();
            if (cms.getCountryIsoCode2().equals(region)) {

                countrySpecificList.add(cms);
            }
        }

        if (countrySpecificList.size() > 0) {
            return countrySpecificList;
        } else {
            return result;
        }

    } catch (RuntimeException re) {
        // log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.reference.impl.dao.CoreModuleServiceDao.java

License:Open Source License

public Collection<CoreModuleService> findByServiceTypeAndByRegion(int type, String region) {

    try {/*ww  w  .  j a va  2  s.  c om*/

        List countryList = new ArrayList();
        countryList.add(region);
        countryList.add(Constants.ALLCOUNTRY_ISOCODE);

        DetachedCriteria crit = DetachedCriteria.forClass(CoreModuleService.class);
        crit.add(Expression.in("countryIsoCode2", countryList));
        crit.add(Expression.eq("coreModuleServiceCode", type));
        crit.addOrder(org.hibernate.criterion.Order.desc("coreModuleServicePosition"));
        Collection result = this.getHibernateTemplate().findByCriteria(crit);

        List countrySpecificList = new ArrayList();
        Iterator i = result.iterator();
        while (i.hasNext()) {
            CoreModuleService cms = (CoreModuleService) i.next();
            if (cms.getCountryIsoCode2().equals(region)) {

                countrySpecificList.add(cms);
            }
        }

        if (countrySpecificList.size() > 0) {
            return countrySpecificList;
        } else {
            return result;
        }

    } catch (RuntimeException re) {
        throw re;
    }
}

From source file:com.salesmanager.core.service.reference.impl.dao.CoreModuleServiceDao.java

License:Open Source License

public CoreModuleService findByModuleAndRegion(String module, String region) {

    try {/*from  www  .j  ava  2  s . co  m*/

        List countryList = new ArrayList();
        countryList.add(region);
        countryList.add(Constants.ALLCOUNTRY_ISOCODE);

        DetachedCriteria crit = DetachedCriteria.forClass(CoreModuleService.class);
        crit.add(Expression.in("countryIsoCode2", countryList));
        crit.add(Expression.eq("coreModuleName", module));
        crit.addOrder(org.hibernate.criterion.Order.desc("coreModuleServicePosition"));
        Collection result = this.getHibernateTemplate().findByCriteria(crit);

        List countrySpecificList = new ArrayList();
        Iterator i = result.iterator();
        CoreModuleService tempCms = null;
        while (i.hasNext()) {
            CoreModuleService cms = (CoreModuleService) i.next();
            if (cms.getCountryIsoCode2().equals(region)) {
                return cms;
            }
            if (cms.getCountryIsoCode2().equals(Constants.ALLCOUNTRY_ISOCODE)) {
                tempCms = cms;
            }
        }

        return tempCms;

    } catch (RuntimeException re) {
        throw re;
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<MetaField> getAvailableFields(Integer entityId, EntityType[] entityType, Boolean primary) {
    DetachedCriteria query = DetachedCriteria.forClass(MetaField.class);
    query.add(Restrictions.eq("entityId", entityId));
    query.add(Restrictions.in("entityType", entityType));
    if (null != primary) {
        query.add(Restrictions.eq("primary", primary.booleanValue()));
    }// ww  w .j a  v a2s. c o m
    query.addOrder(Order.asc("displayOrder"));
    List<MetaField> result = null;
    try {

        result = (List<MetaField>) getHibernateTemplate().findByCriteria(query);
    } catch (Exception e) {
        LOG.error(e.getMessage());
        e.printStackTrace();
        LOG.error(e);
    }
    return result;
}