List of usage examples for org.hibernate Query setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(String name, int val)
From source file:com.dz.module.driver.complain.ComplainDaoImpl.java
@Override public int selectAllByStateCount(Date beginDate, Date endDate, int state) throws HibernateException { Session session = null;/*from w w w .java2 s . c o m*/ try { session = HibernateSessionFactory.getSession(); String hql = "select count(*) from Complain c where c.state=:state"; if (beginDate != null) { hql += " and c.complainTime >= :beginDate"; } if (endDate != null) { hql += " and c.complainTime <= :endDate"; } Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } query.setInteger("state", state); //Query query = session.createQuery("select count(*) from Complain c where c.alreadyDeal is null or alreadyDeal = '?'"); return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.vehicle.electric.ElectricAnaylseService.java
public int createAnaylse(Date beginDate, Date endDate) { Session session = HibernateSessionFactory.getSession(); Transaction tx = null;//from w ww . j av a 2 s .co m int ea_id = 0; try { tx = session.beginTransaction(); ElectricAnaylse ea = new ElectricAnaylse(); Query query = session.createQuery("select count(*),sum(cast(money as integer)) " + "from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate"); Query query_dept = session.createQuery("select count(*),sum(cast(money as integer)) " + "from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "and carframeNum in (select carframeNum from Vehicle where dept=:dept)"); query.setDate("beginDate", beginDate); query.setDate("endDate", endDate); query_dept.setDate("beginDate", beginDate); query_dept.setDate("endDate", endDate); Object[] oarr = (Object[]) query.uniqueResult(); ea.setBeginDate(beginDate); ea.setEndDate(endDate); ea.setAllTimes((int) (long) oarr[0]); ea.setAllMoney((long) oarr[1]); query_dept.setString("dept", ""); oarr = (Object[]) query_dept.uniqueResult(); ea.setTime1((int) (long) oarr[0]); ea.setMoney1((long) oarr[1]); query_dept.setString("dept", ""); oarr = (Object[]) query_dept.uniqueResult(); ea.setTime2((int) (long) oarr[0]); ea.setMoney2((long) oarr[1]); query_dept.setString("dept", ""); oarr = (Object[]) query_dept.uniqueResult(); ea.setTime3((int) (long) oarr[0]); ea.setMoney3((long) oarr[1]); session.save(ea); // System.out.println("ElectricAnaylseService.createAnaylse(),line 76,ElectricAnaylse:\t"+ea); ea_id = ea.getId(); Query query_vehicle = session.createQuery( "insert into ElectricAnaylseVehicle(anaylseId,carframeNum,licenseNum,times,moneys) " + "select " + ea.getId() + ",carframeNum,licenseNum,cast(count(*) as integer),sum(cast(money as integer)) from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "group by carframeNum"); query_vehicle.setDate("beginDate", beginDate); query_vehicle.setDate("endDate", endDate); query_vehicle.executeUpdate(); Query query_act = session.createQuery( "insert into ElectricAnaylseAct(anaylseId,act,times,moneys) " + "select " + ea.getId() + ",act,cast(count(*) as integer),sum(cast(money as integer)) from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "group by act"); query_act.setDate("beginDate", beginDate); query_act.setDate("endDate", endDate); query_act.executeUpdate(); Query query_act_area = session .createQuery("insert into ElectricAnaylseActArea(anaylseActId,area,times) " + "select eaa.id,eh.area,cast(count(*) as integer) " + "from ElectricHistory eh,ElectricAnaylseAct eaa " + "where eaa.anaylseId=:aid " + "and eaa.act=eh.act " + "and STR_TO_DATE(eh.date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(eh.date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "group by eh.act,eh.area"); query_act_area.setInteger("aid", ea.getId()); query_act_area.setDate("beginDate", beginDate); query_act_area.setDate("endDate", endDate); query_act_area.executeUpdate(); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); } ex.printStackTrace(); return 0; } finally { HibernateSessionFactory.closeSession(); } return ea_id; }
From source file:com.dz.module.vehicle.VehicleAction.java
public String relookLicence() { Session s = null;//www . j a v a2 s . c o m Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); Query query = s.createQuery("from License where state=0"); List<License> is = query.list(); for (License i : is) { Vehicle v = (Vehicle) s.get(Vehicle.class, i.getCarframeNum()); BeanUtils.copyProperties(i, v, new String[] { "state" }); s.update(v); i.setState(1); s.update(i); Query q_c = s.createQuery( "select c from Contract c where c.state in (2,3) and c.idNum=:idNum and c.carframeNum=:carframeNum "); q_c.setString("idNum", v.getDriverId()); q_c.setString("carframeNum", v.getCarframeNum()); q_c.setMaxResults(1); Contract c = (Contract) q_c.uniqueResult(); if (c != null) { c.setCarNum(v.getLicenseNum()); s.saveOrUpdate(c); Query q_va = s.createQuery("from VehicleApproval c where c.contractId=:cid and c.checkType=0 "); q_va.setInteger("cid", c.getId()); q_va.setMaxResults(1); VehicleApproval approval = (VehicleApproval) q_va.uniqueResult(); approval.setLicenseRegisterDate(v.getLicenseNumRegDate()); approval.setOperateApplyDate(new Date()); s.saveOrUpdate(approval); } Message msg = new Message(); User u = (User) s.get(User.class, v.getLicenseRegister()); msg.setFromUser(v.getLicenseRegister()); msg.setTime(new Date()); msg.setCarframeNum(v.getCarframeNum()); msg.setType(""); msg.setMsg(String.format( "%tF %s?\n" + "%s(%s) ??", msg.getTime(), u.getUname(), v.getLicenseNum(), v.getCarframeNum())); s.saveOrUpdate(msg); Query q_us = s.createQuery( "from RelationUr where rid in (select rid from Role where rname = '')"); List<RelationUr> users = q_us.list(); for (RelationUr relationUr : users) { MessageToUser mu = new MessageToUser(); mu.setUid(relationUr.getUid()); mu.setMid(msg.getId()); mu.setAlreadyRead(false); s.saveOrUpdate(mu); } } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }
From source file:com.dz.module.vehicle.VehicleAction.java
public String relookService() { Session s = null;//from ww w .java 2 s. c om Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); Query query = s.createQuery("from ServiceInfo where state=0"); List<ServiceInfo> is = query.list(); for (ServiceInfo i : is) { Vehicle v = (Vehicle) s.get(Vehicle.class, i.getCarframeNum()); BeanUtils.copyProperties(i, v, new String[] { "state" }); s.update(v); i.setState(1); s.update(i); Query q_c = s.createQuery( "select c from Contract c where c.state in (2,3) and c.idNum=:idNum and c.carframeNum=:carframeNum "); q_c.setString("idNum", v.getDriverId()); q_c.setString("carframeNum", v.getCarframeNum()); q_c.setMaxResults(1); Contract c = (Contract) q_c.uniqueResult(); if (c != null) { Query q_va = s.createQuery("from VehicleApproval c where c.contractId=:cid and c.checkType=0 "); q_va.setInteger("cid", c.getId()); q_va.setMaxResults(1); VehicleApproval approval = (VehicleApproval) q_va.uniqueResult(); approval.setOperateCardDate(v.getOperateCardTime()); s.saveOrUpdate(approval); } } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }
From source file:com.dz.module.vehicle.VehicleAction.java
public String relookServiceRight() { Session s = null;/*from www . j a v a 2 s . com*/ Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); Query query = s.createQuery("from ServiceRightInfo where state=0"); List<ServiceRightInfo> is = query.list(); for (ServiceRightInfo i : is) { Vehicle v = (Vehicle) s.get(Vehicle.class, i.getCarframeNum()); BeanUtils.copyProperties(i, v, new String[] { "state" }); s.update(v); i.setState(1); s.update(i); Query q_c = s.createQuery( "select c from Contract c where c.state in (2,3) and c.idNum=:idNum and c.carframeNum=:carframeNum "); q_c.setString("idNum", v.getDriverId()); q_c.setString("carframeNum", v.getCarframeNum()); q_c.setMaxResults(1); Contract c = (Contract) q_c.uniqueResult(); if (c != null) { Query q_va = s.createQuery("from VehicleApproval c where c.contractId=:cid and c.checkType=0 "); q_va.setInteger("cid", c.getId()); q_va.setMaxResults(1); VehicleApproval approval = (VehicleApproval) q_va.uniqueResult(); approval.setOperateCardDate(v.getOperateCardTime()); s.saveOrUpdate(approval); } } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }
From source file:com.dz.module.vehicle.VehicleDaoImpl.java
@SuppressWarnings("unchecked") @Override/* www . j av a 2 s . c o m*/ public List<Vehicle> vehicleSearch(Page page, Vehicle vehicle, Triplet<String, String, Object>... conditions) throws HibernateException { // TODO Auto-generated method stub List<Vehicle> l = new ArrayList<Vehicle>(); Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Vehicle where state!=-1 "; if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { sql += "and carframeNum like :carframeNum "; } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { sql += "and engineNum like :engineNum "; } if (!StringUtils.isEmpty(vehicle.getCarMode())) { sql += "and carMode like :carMode "; } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { sql += "and certifyNum like :certifyNum "; } if (!StringUtils.isEmpty(vehicle.getDept())) { sql += "and dept like :dept "; } if (!StringUtils.isEmpty(vehicle.getDriverId())) { sql += "and driverId like :driverId "; } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { sql += "and licenseNum like :licenseNum "; } if (vehicle.getState() != null) { sql += "and state=:state "; } } for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(), condition.getValue0()); } } sql += " order by licenseNum "; Query query = session.createQuery(sql); query.setMaxResults(page.getEveryPage()); query.setFirstResult(page.getBeginIndex()); if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { query.setString("engineNum", "%" + vehicle.getEngineNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getCarMode())) { query.setString("carMode", "%" + vehicle.getCarMode() + "%"); } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { query.setString("certifyNum", "%" + vehicle.getCertifyNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getDept())) { query.setString("dept", "%" + vehicle.getDept() + "%"); } if (!StringUtils.isEmpty(vehicle.getDriverId())) { query.setString("driverId", "%" + vehicle.getDriverId() + "%"); } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%"); } if (vehicle.getState() != null) { query.setInteger("state", vehicle.getState()); } } for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { query.setParameter(condition.getValue0(), condition.getValue2()); } } l = query.list(); query = null; } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.vehicle.VehicleDaoImpl.java
@Override public int vehicleSearchCount(Vehicle vehicle, Triplet<String, String, Object>... conditions) throws HibernateException { // TODO Auto-generated method stub Session session = null;/*from ww w . j a va 2 s .com*/ try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) from Vehicle where state!=-1 "; if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { sql += "and carframeNum like :carframeNum "; } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { sql += "and engineNum like :engineNum "; } if (!StringUtils.isEmpty(vehicle.getCarMode())) { sql += "and carMode like :carMode "; } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { sql += "and certifyNum like :certifyNum "; } if (!StringUtils.isEmpty(vehicle.getDept())) { sql += "and dept like :dept "; } if (!StringUtils.isEmpty(vehicle.getDriverId())) { sql += "and driverId like :driverId "; } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { sql += "and licenseNum like :licenseNum "; } if (vehicle.getState() != null) { sql += "and state=:state "; } } 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 (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { query.setString("engineNum", "%" + vehicle.getEngineNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getCarMode())) { query.setString("carMode", "%" + vehicle.getCarMode() + "%"); } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { query.setString("certifyNum", "%" + vehicle.getCertifyNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getDept())) { query.setString("dept", "%" + vehicle.getDept() + "%"); } if (!StringUtils.isEmpty(vehicle.getDriverId())) { query.setString("driverId", "%" + vehicle.getDriverId() + "%"); } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%"); } if (vehicle.getState() != null) { query.setInteger("state", vehicle.getState()); } } for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { query.setParameter(condition.getValue0(), condition.getValue2()); } } return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.vehicle.VehicleDaoImpl.java
@SuppressWarnings("unchecked") @Override//from ww w.j a v a 2 s.co m public List<Vehicle> selectAll(Vehicle vehicle) { Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Vehicle where state!=-1 and carframeNum like '%" + (vehicle.getCarframeNum() == null ? "" : vehicle.getCarframeNum()) + "%' and engineNum like '%" + (vehicle.getEngineNum() == null ? "" : vehicle.getEngineNum()) + "%' and carMode like '%" + (vehicle.getCarMode() == null ? "" : vehicle.getCarMode()) + "%' and certifyNum like '%" + (vehicle.getCertifyNum() == null ? "" : vehicle.getCertifyNum()) + "%' " + "and dept like '%" + (vehicle.getDept() == null ? "" : vehicle.getDept()) + "%' " + (vehicle.getDriverId() == null ? "" : "%' and driverId like '%" + vehicle.getDriverId()) + "%' " + "and licenseNum like '%" + (vehicle.getLicenseNum() == null ? "" : vehicle.getLicenseNum()) + "%' "; if (vehicle.getState() != null) { sql += "and state=:state "; } Query query = session.createQuery(sql); if (vehicle.getState() != null) { query.setInteger("state", vehicle.getState()); } return query.list(); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.edgenius.core.dao.hibernate.CrFileNodeDAOHibernate.java
License:Open Source License
public boolean removeVersion(final String nodeUuid, final Integer version) { Query query = getCurrentSesssion().createQuery(REMOVE_BY_NODE_UUID_VER); query.setString("uuid", nodeUuid); query.setInteger("version", version); int size = query.executeUpdate(); return size > 0 ? true : false; }
From source file:com.edgenius.core.dao.hibernate.RoleDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Role> getRoles(final int roleType, final String filter) { String filterWith = ""; if (!StringUtils.isBlank(filter)) { filterWith = " and (r.displayName like :filter or r.description like :filter) "; }//from w w w . j av a 2 s . c om Query query = getCurrentSesssion().createQuery(GET_BY_TYPE + filterWith + GET_BY_TYPE_ORDERBY); query.setInteger("type", roleType); if (!StringUtils.isBlank(filter)) { query.setString("filter", "%" + filter.trim() + "%"); } return query.list(); }