List of usage examples for org.hibernate Query setBoolean
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBoolean(String name, boolean val)
From source file:com.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override//from w ww . ja va 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/* ww w . j a va 2s .co m*/ 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
@Override public int driverSearchConditionTotal(Date beginDate, Date endDate, Driver driver) throws HibernateException { Session session = null;/*from w ww .j a va 2s.c om*/ try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) from Driver where 1=1 "; if (!StringUtils.isEmpty(driver.getIdNum())) { sql += "and idNum like :idNum "; } 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 (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()); return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.driver.DriverDaoImpl.java
@Override public int selectDriverLeaveByConditionCount(Date beginDate, Date endDate, Vehicle vehicle, Driver driver, Boolean finished, String operation) { Session session = null;//from ww w. ja v a 2 s. co m try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) 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 + "%"); } return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override//from w ww . j a v a2s .co 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.enonic.cms.store.dao.ContentIndexEntityDao.java
License:Open Source License
public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters, final boolean cacheable) { return executeListResult(ContentKey.class, new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query compiled = session.createQuery(hqlQuery); compiled.setCacheable(cacheable); for (String key : parameters.keySet()) { Object value = parameters.get(key); if (value instanceof Date) { compiled.setTimestamp(key, (Date) value); } else if (value instanceof String) { compiled.setString(key, (String) value); } else if (value instanceof Boolean) { compiled.setBoolean(key, (Boolean) value); } else if (value instanceof Long) { compiled.setLong(key, (Long) value); } else if (value instanceof Integer) { compiled.setInteger(key, (Integer) value); } else if (value instanceof Byte) { compiled.setByte(key, (Byte) value); } else if (value instanceof byte[]) { compiled.setBinary(key, (byte[]) value); } else if (value instanceof Float) { compiled.setFloat(key, (Float) value); } else if (value instanceof Double) { compiled.setDouble(key, (Double) value); } else if (value instanceof BigDecimal) { compiled.setBigDecimal(key, (BigDecimal) value); } else if (value instanceof Short) { compiled.setShort(key, (Short) value); } else if (value instanceof BigInteger) { compiled.setBigInteger(key, (BigInteger) value); } else if (value instanceof Character) { compiled.setCharacter(key, (Character) value); } else { compiled.setParameter(key, value); }//from w w w . j a va 2s .c o m } final List result = compiled.list(); LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size()); for (Object value : result) { if (value instanceof ContentKey) { distinctContentKeySet.add((ContentKey) value); } else { Object[] valueList = (Object[]) value; distinctContentKeySet.add(((ContentKey) valueList[0])); } } List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size()); distinctContentKeyList.addAll(distinctContentKeySet); return distinctContentKeyList; } }); }
From source file:com.ikon.dao.AuthDAO.java
License:Open Source License
/** * Active user in database//from w w w .j a v a 2 s. co m */ public static void activeUser(String usrId, boolean active) throws DatabaseException { log.debug("activeUser({}, {})", usrId, active); String qs = "update User u set u.active=:active where u.id=:id"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setBoolean("active", active); q.setString("id", usrId); q.executeUpdate(); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("activeUser: void"); }
From source file:com.ikon.dao.AuthDAO.java
License:Open Source License
/** * Get all users in database//from ww w . jav a 2 s .co m * * @param filterByActive If only active user2 should be included. */ @SuppressWarnings("unchecked") public static List<User> findAllUsers(boolean filterByActive) throws DatabaseException { log.debug("findAllUsers({})", filterByActive); String qs = "from User u " + (filterByActive ? "where u.active=:active" : "") + " order by u.id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); if (filterByActive) { q.setBoolean("active", true); } List<User> ret = q.list(); log.debug("findAllUsers: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.AuthDAO.java
License:Open Source License
/** * Get all users within a role/* w w w .ja v a 2 s .c o m*/ */ @SuppressWarnings("unchecked") public static List<User> findUsersByRole(String rolId, boolean filterByActive) throws DatabaseException { log.debug("findUsersByRole({}, {})", rolId, filterByActive); String qs = "select u from User u, Role r where r.id=:rolId and r in elements(u.roles) " + (filterByActive ? "and u.active=:active" : "") + " order by u.id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("rolId", rolId); if (filterByActive) { q.setBoolean("active", true); } List<User> ret = q.list(); log.debug("findUsersByRole: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.AuthDAO.java
License:Open Source License
/** * Get all users within a role//from w w w . j a v a 2 s . co m */ @SuppressWarnings("unchecked") public static List<Role> findRolesByUser(String usrId, boolean filterByActive) throws DatabaseException { log.debug("findRolesByUser({}, {})", usrId, filterByActive); String qs = "select r from User u, Role r where u.id=:usrId and r in elements(u.roles) " + (filterByActive ? "and r.active=:active" : "") + " order by r.id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("usrId", usrId); if (filterByActive) { q.setBoolean("active", true); } List<Role> ret = q.list(); log.debug("findRolesByUser: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }