Example usage for org.hibernate Query setFirstResult

List of usage examples for org.hibernate Query setFirstResult

Introduction

In this page you can find the example usage for org.hibernate Query setFirstResult.

Prototype

@Override
    Query<R> setFirstResult(int startPosition);

Source Link

Usage

From source file:com.dz.module.driver.complain.ComplainDaoImpl.java

@SuppressWarnings("unchecked")
@Override//from  w  w  w  . ja va  2 s  .c om
public List<Complain> selectByDriver(Driver driver, Page page) throws HibernateException {
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();
        Query query = session.createQuery("from Complain c where c.idNum = :idnum");
        query.setString("idnum", driver.getIdNum());
        query.setMaxResults(page.getEveryPage());
        query.setFirstResult(page.getBeginIndex());
        return query.list();
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
}

From source file:com.dz.module.driver.complain.ComplainDaoImpl.java

@SuppressWarnings("unchecked")
@Override//from  w ww  . j a  v  a 2 s . co m
public List<Complain> selectAllByStates(Complain complain, Page page, Date beginDate, Date endDate, String dept,
        Short[] states, String order) {
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();

        String hql = "select c from Complain c,Vehicle v where c.state in (:states)";

        if (beginDate != null) {
            hql += " and c.complainTime >= :beginDate";
        }

        if (endDate != null) {
            hql += " and c.complainTime <= :endDate";
        }

        if (!StringUtils.isEmpty(dept)) {
            hql += " and c.vehicleId in (select carframeNum from Vehicle where dept like :dept) ";
        }

        if (complain != null) {
            if (StringUtils.isNotEmpty(complain.getComplainClass())) {
                hql += " and c.complainClass like :complainClass";
            }

            if (StringUtils.isNotEmpty(complain.getComplainObject())) {
                hql += " and c.complainObject like :complainObject";
            }
        }

        hql += " and c.vehicleId=v.carframeNum ";

        if (StringUtils.equals(order, "complainTime")) {
            hql += " order by c.complainTime ";
        } else {
            hql += " order by v.licenseNum ";
        }

        Query query = session.createQuery(hql);

        if (beginDate != null) {
            query.setDate("beginDate", beginDate);
        }

        if (endDate != null) {
            query.setDate("endDate", endDate);
        }

        if (!StringUtils.isEmpty(dept)) {
            query.setString("dept", "%" + dept + "%");
        }

        query.setParameterList("states", states);

        if (complain != null) {
            if (StringUtils.isNotEmpty(complain.getComplainClass())) {
                query.setString("complainClass", "%" + complain.getComplainClass() + "%");
            }

            if (StringUtils.isNotEmpty(complain.getComplainObject())) {
                query.setString("complainObject", "%" + complain.getComplainObject() + "%");
            }
        }
        //Query query = session.createQuery("from Complain c where c.alreadyDeal is null or alreadyDeal = '?'");
        query.setMaxResults(page.getEveryPage());
        query.setFirstResult(page.getBeginIndex());
        return query.list();
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
}

From source file:com.dz.module.driver.DriverDaoImpl.java

@SuppressWarnings("unchecked")
@Override/* w  w w.  j  a  va  2s .c o  m*/
public List<Driver> search(Page page, Triplet<String, String, Object>... conditions) {
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();
        String sql = "from Driver where 1=1 ";

        if (conditions != null)
            for (Triplet<String, String, Object> condition : conditions) {
                if (condition != null) {
                    sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(),
                            condition.getValue0());
                }
            }

        Query query = session.createQuery(sql);

        if (conditions != null)
            for (Triplet<String, String, Object> condition : conditions) {
                if (condition != null) {
                    query.setParameter(condition.getValue0(), condition.getValue2());
                }
            }

        if (page != null) {
            query.setMaxResults(page.getEveryPage());
            query.setFirstResult(page.getBeginIndex());
        }

        return query.list();
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
}

From source file:com.dz.module.driver.DriverDaoImpl.java

@SuppressWarnings("unchecked")
@Override/*from  w w  w  .  j a v a  2 s.  c o m*/
public List<Driver> driverSearch(Page page) throws HibernateException {
    List<Driver> l = new ArrayList<Driver>();
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();
        Query query = session.createQuery("from Driver");
        query.setMaxResults(15);
        query.setFirstResult(page.getBeginIndex());
        l = query.list();

        //         for(Driver driver : l){
        //            System.out.println(driver.getApplyMatter());
        //         }

        query = null;
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
    return l;
}

From source file:com.dz.module.driver.DriverDaoImpl.java

@SuppressWarnings("unchecked")
public List<Driver> driverSearchCondition(Page page, String idNum, Date beginDate, Date endDate,
        Boolean isInCar, Triplet<String, String, Object>... conditions) throws HibernateException {
    List<Driver> l = new ArrayList<Driver>();
    Session session = null;/*from ww w .j a va2 s. c o m*/
    try {
        session = HibernateSessionFactory.getSession();
        String sql = "from Driver where 1=1 ";

        if (!StringUtils.isEmpty(idNum)) {
            sql += "and idNum like :idNum ";
        }

        if (beginDate != null) {
            sql += "and applyTime>:beginDate ";
        }
        if (endDate != null) {
            sql += "and applyTime<:endDate ";
        }

        if (isInCar != null)
            sql += "and isInCar=:isInCar";

        for (Triplet<String, String, Object> condition : conditions) {
            if (condition != null) {
                sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(),
                        condition.getValue0());
            }
        }

        System.out.println(sql);
        Query query = session.createQuery(sql);

        for (Triplet<String, String, Object> condition : conditions) {
            if (condition != null) {
                query.setParameter(condition.getValue0(), condition.getValue2());
            }
        }

        if (!StringUtils.isEmpty(idNum)) {
            query.setString("idNum", "%" + idNum + "%");
        }

        if (beginDate != null) {
            query.setDate("beginDate", beginDate);
        }

        if (endDate != null) {
            query.setDate("endDate", endDate);
        }

        if (isInCar != null)
            query.setBoolean("isInCar", isInCar);

        if (page != null) {
            query.setMaxResults(page.getEveryPage());
            query.setFirstResult(page.getBeginIndex());
        }

        l = query.list();
        query = null;
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
    return l;
}

From source file:com.dz.module.driver.DriverDaoImpl.java

@SuppressWarnings("unchecked")
@Override// w  w w . ja  v a2s  .  c om
public List<Vehicle> driverCarSearch(Page page, String idName, String idNum, String linence_num) {

    Session session = null;
    List<Vehicle> list = null;
    try {
        session = HibernateSessionFactory.getSession();
        String str = "from Vehicle v where v.licenseNum like '%" + linence_num + "%' &&"
                + " v.driverId in (select d.driverId from Driver d where d.idNum like '%" + idNum + "%' &&"
                + " d.name like '%" + idName + "%')";
        Query query = session.createQuery(str);
        query.setMaxResults(page.getEveryPage());
        query.setFirstResult(page.getBeginIndex());
        list = (List<Vehicle>) query.list();
    } catch (HibernateException he) {
        he.printStackTrace();
        list = new ArrayList<Vehicle>();
    }
    return list;
}

From source file:com.dz.module.driver.DriverDaoImpl.java

@SuppressWarnings("unchecked")
@Override/*from  w w  w. ja  v  a 2 s . c o m*/
public List<Driverincar> selectDriverInCarByCondition(Page page, Date beginDate, Date endDate, Vehicle vehicle,
        Driver driver, String operation, Boolean finished) {
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();
        String sql = "from Driverincar where 1=1 ";

        if (beginDate != null) {
            sql += "and opeTime>:beginDate ";
        }
        if (endDate != null) {
            sql += "and opeTime<:endDate ";
        }

        if (!StringUtils.isEmpty(vehicle.getCarframeNum())) {
            sql += "and carframeNum like :carframeNum ";
        }

        if (!StringUtils.isEmpty(vehicle.getLicenseNum())) {
            sql += "and carframeNum in (select carframeNum from Vehicle where licenseNum like :licenseNum ) ";
        }

        if (!StringUtils.isEmpty(driver.getIdNum())) {
            sql += "and idNumber like :idNum ";
        }

        if (!StringUtils.isEmpty(operation)) {
            sql += "and operation like :operation ";
        }

        if (finished != null) {
            sql += "and finished = :finished ";
        }

        Query query = session.createQuery(sql);

        if (!StringUtils.isEmpty(vehicle.getCarframeNum())) {
            query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%");
        }

        if (!StringUtils.isEmpty(vehicle.getLicenseNum())) {
            query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%");
        }

        if (!StringUtils.isEmpty(driver.getIdNum())) {
            query.setString("idNum", "%" + driver.getIdNum() + "%");
        }

        if (beginDate != null) {
            query.setDate("beginDate", beginDate);
        }
        if (endDate != null) {
            query.setDate("endDate", endDate);
        }

        if (!StringUtils.isEmpty(operation)) {
            query.setString("operation", "%" + operation + "%");
        }

        if (finished != null) {
            query.setBoolean("finished", finished);
            sql += "and finished = :finished ";
        }

        if (page != null) {
            query.setMaxResults(page.getEveryPage());
            query.setFirstResult(page.getBeginIndex());
        }
        return query.list();
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
}

From source file:com.dz.module.driver.DriverDaoImpl.java

@SuppressWarnings("unchecked")
@Override/*from w ww . jav a2s.com*/
public List<Driver> driverSearchCondition(Page page, Date beginDate, Date endDate, Driver driver)
        throws HibernateException {
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();
        String sql = "from Driver where 1=1 ";

        if (!StringUtils.isEmpty(driver.getIdNum())) {
            sql += "and idNum like :idNum ";
        }

        if (!StringUtils.isEmpty(driver.getName())) {
            sql += "and name like :name ";
        }

        if (!StringUtils.isEmpty(driver.getDept())) {
            sql += "and dept like :dept ";
        }

        if (!StringUtils.isEmpty(driver.getTeam())) {
            sql += "and team like :team ";
        }

        if (beginDate != null) {
            sql += "and applyTime>:beginDate ";
        }
        if (endDate != null) {
            sql += "and applyTime<:endDate ";
        }

        if (driver.getIsInCar() != null)
            sql += "and isInCar=:isInCar";

        Query query = session.createQuery(sql);

        if (!StringUtils.isEmpty(driver.getIdNum())) {
            query.setString("idNum", "%" + driver.getIdNum() + "%");
        }

        if (!StringUtils.isEmpty(driver.getName())) {
            query.setString("name", "%" + driver.getName() + "%");
        }

        if (beginDate != null) {
            query.setDate("beginDate", beginDate);
        }

        if (endDate != null) {
            query.setDate("endDate", endDate);
        }

        if (!StringUtils.isEmpty(driver.getDept())) {
            query.setString("dept", "%" + driver.getDept() + "%");
            sql += "and dept like :dept ";
        }

        if (!StringUtils.isEmpty(driver.getTeam())) {
            query.setString("team", "%" + driver.getTeam() + "%");
            sql += "and team like :team ";
        }

        if (driver.getIsInCar() != null)
            query.setBoolean("isInCar", driver.getIsInCar());

        if (page != null) {
            query.setMaxResults(page.getEveryPage());
            query.setFirstResult(page.getBeginIndex());
        }
        return query.list();
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
}

From source file:com.dz.module.driver.DriverDaoImpl.java

@SuppressWarnings("unchecked")
@Override/* w w  w  .j a  v a2  s  .  c o  m*/
public List<Driverleave> selectDriverLeaveByCondition(Page page, Date beginDate, Date endDate, Vehicle vehicle,
        Driver driver, Boolean finished, String operation) {
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();
        String sql = "from Driverleave where finished=:finished ";

        if (beginDate != null) {
            sql += "and opeTime>:beginDate ";
        }
        if (endDate != null) {
            sql += "and opeTime<:endDate ";
        }

        if (!StringUtils.isEmpty(vehicle.getCarframeNum())) {
            sql += "and carframeNum like :carframeNum ";
        }

        if (!StringUtils.isEmpty(driver.getIdNum())) {
            sql += "and idNumber like :idNum ";
        }

        if (!StringUtils.isEmpty(operation)) {
            sql += "and operation like :operation ";
        }

        Query query = session.createQuery(sql);

        query.setBoolean("finished", finished);

        if (!StringUtils.isEmpty(vehicle.getCarframeNum())) {
            query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%");
        }

        if (!StringUtils.isEmpty(driver.getIdNum())) {
            query.setString("idNum", "%" + driver.getIdNum() + "%");
        }

        if (beginDate != null) {
            query.setDate("beginDate", beginDate);
        }
        if (endDate != null) {
            query.setDate("endDate", endDate);
        }
        if (!StringUtils.isEmpty(operation)) {
            query.setString("operation", "%" + operation + "%");
        }
        if (page != null) {
            query.setMaxResults(page.getEveryPage());
            query.setFirstResult(page.getBeginIndex());
        }
        return query.list();
    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
}

From source file:com.dz.module.vehicle.InsuranceDaoImpl.java

@SuppressWarnings("unchecked")
@Override//from  www .j ava2  s . c  om
public List<Insurance> selectByCondition(Page page, Insurance insurance, Vehicle vehicle) {
    Session session = null;
    try {
        session = HibernateSessionFactory.getSession();
        String sql = "from Insurance where state>0 ";

        if (!StringUtils.isEmpty(insurance.getCarframeNum())) {
            sql += "and carframeNum like :carframeNum ";
        }

        if (!StringUtils.isEmpty(insurance.getInsuranceNum())) {
            sql += "and insuranceNum like :insuranceNum ";
        }

        if (!StringUtils.isEmpty(insurance.getInsuranceClass())) {
            sql += "and insuranceClass like :insuranceClass ";
        }

        if (vehicle != null) {
            if (!StringUtils.isEmpty(vehicle.getLicenseNum())) {
                sql += "and carframeNum in (select carframeNum from Vehicle where licenseNum  like :licenseNum ) ";
            }
        }

        Query query = session.createQuery(sql);

        if (!StringUtils.isEmpty(insurance.getCarframeNum())) {
            query.setString("carframeNum", "%" + insurance.getCarframeNum() + "%");
        }

        if (!StringUtils.isEmpty(insurance.getInsuranceNum())) {
            query.setString("insuranceNum", "%" + insurance.getInsuranceNum() + "%");
        }

        if (!StringUtils.isEmpty(insurance.getInsuranceClass())) {
            query.setString("insuranceClass", "%" + insurance.getInsuranceClass() + "%");
        }

        if (vehicle != null) {
            if (!StringUtils.isEmpty(vehicle.getLicenseNum())) {
                query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%");
            }
        }

        query.setFirstResult(page.getBeginIndex());
        query.setMaxResults(page.getEveryPage());
        return query.list();

    } catch (HibernateException e) {
        throw e;
    } finally {
        HibernateSessionFactory.closeSession();
    }
}