List of usage examples for org.hibernate Query setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(String name, int val)
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!/* ww w. j a v a 2 s . com*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param idint DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public void deleteFilter(Session hsession, String repositoryName, Integer idint) throws Exception { try { Query query = hsession.getNamedQuery("delete-filter-by-idint"); query.setInteger("idint", idint); query.setString("username", repositoryName); query.executeUpdate(); hsession.flush(); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!/*from w ww . j ava 2 s . c om*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public Vector getFilters(Session hsession, String repositoryName) throws MailException { Vector filters = new Vector(); try { Query query = hsession.getNamedQuery("filters"); query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); ScrollableResults scroll = query.scroll(); while (scroll.next()) { Filter filter = (Filter) scroll.get(0); FilterObj obj = new FilterObj(); Label label = filter.getLabel(); obj.setArchive(filter.isFilArchive()); obj.setDoesntHaveWords(filter.getFilDoesntHaveWords()); obj.setForward(filter.getFilForwardTo()); obj.setFrom(filter.getFilFrom()); obj.setHasAttachment(filter.isFilHasAttacment()); obj.setHasWords(filter.getFilHasWords()); obj.setIdint(filter.getFilIdint()); obj.setImportant(filter.isFilImportant()); obj.setLabel(new LabelObj(label.getLabIdint(), label.getLabName())); obj.setOperator(!filter.isFilOrOperator()); obj.setSubject(filter.getFilSubject()); obj.setTo(filter.getFilTo()); obj.setTrash(filter.isFilTrash()); filters.addElement(obj); } return filters; } catch (Exception e) { throw new MailException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!//from w ww . j a v a2 s. c o m * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param idint DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public FilterObj getFilter(Session hsession, String repositoryName, Integer idint) throws MailException { try { Query query = hsession.getNamedQuery("filter"); query.setInteger("idint", idint); query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); Filter filter = (Filter) query.uniqueResult(); FilterObj obj = new FilterObj(); Label label = filter.getLabel(); obj.setArchive(filter.isFilArchive()); obj.setDoesntHaveWords(filter.getFilDoesntHaveWords()); obj.setForward(filter.getFilForwardTo()); obj.setFrom(filter.getFilFrom()); obj.setHasAttachment(filter.isFilHasAttacment()); obj.setHasWords(filter.getFilHasWords()); obj.setIdint(filter.getFilIdint()); obj.setImportant(filter.isFilImportant()); obj.setLabel(new LabelObj(label.getLabIdint(), label.getLabName())); obj.setOperator(!filter.isFilOrOperator()); obj.setSubject(filter.getFilSubject()); obj.setTo(filter.getFilTo()); obj.setTrash(filter.isFilTrash()); return obj; } catch (Exception e) { throw new MailException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.duroty.service.analyzer.LuceneFiltersAnalysis.java
License:Open Source License
/** * DOCUMENT ME!/* w ww. j a va 2s . c o m*/ * * @param hsession DOCUMENT ME! * @param username DOCUMENT ME! * * @return DOCUMENT ME! */ private Vector getFilters(Session hsession, String username) { try { Vector filters = new Vector(); Criteria crit = hsession.createCriteria(Users.class); crit.add(Restrictions.eq("useUsername", username)); crit.add(Restrictions.eq("useActive", new Boolean(true))); Users user = (Users) crit.uniqueResult(); Query query = hsession.getNamedQuery("filter-by-user"); query.setInteger("user", user.getUseIdint()); ScrollableResults scroll = query.scroll(); while (scroll.next()) { filters.addElement(scroll.get(0)); } return filters; } catch (Exception ex) { DLog.log(DLog.ERROR, this.getClass(), ex); } finally { GeneralOperations.closeHibernateSession(hsession); } return null; }
From source file:com.dz.module.charge.ChargeAction.java
public void rollbackImport() throws IOException { ServletActionContext.getResponse().setContentType("text/plain"); ServletActionContext.getResponse().setCharacterEncoding("utf-8"); PrintWriter out = ServletActionContext.getResponse().getWriter(); JSONArray jarray = JSONArray.fromObject(jsonStr); Session session = HibernateSessionFactory.getSession(); Transaction tx = null;/* w ww .j av a2 s . c o m*/ String msg = "???"; int fid = 0; try { tx = session.beginTransaction(); for (int i = 0; i < jarray.size(); i++) { int id = Integer.parseInt(jarray.get(i).toString()); BankRecordTmp bt = (BankRecordTmp) session.get(BankRecordTmp.class, id); String licenseNum = bt.getLicenseNum(); fid = bt.getFid(); Query q_v = session.createQuery("select carframeNum from Vehicle where licenseNum=:carnum"); q_v.setString("carnum", licenseNum); q_v.setMaxResults(1); String carframeNum = q_v.uniqueResult().toString(); Query q_dept = session.createQuery("select branchFirm from Contract where carframeNum=:id "); q_dept.setString("id", carframeNum); q_dept.setMaxResults(1); String dept = q_dept.uniqueResult().toString(); Query query = session.createQuery("from ClearTime where department = :dept"); query.setString("dept", dept); Object obj = query.uniqueResult(); ClearTime ct = (ClearTime) obj; Date current = ct.getCurrent(); if (isYearAndMonth(current, bt.getInTime())) { Query q_c = session .createQuery("delete from ChargePlan where feeType='add_bank' and comment=:id"); q_c.setString("id", "" + id); q_c.executeUpdate(); session.delete(bt); } else { msg = "???"; } } Query q_f = session.createQuery("select count(*) from BankRecordTmp where fid=:id "); q_f.setInteger("id", fid); long ct = (long) q_f.uniqueResult(); if (ct == 0) { BankFile bf = (BankFile) session.get(BankFile.class, fid); session.delete(bf); } tx.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (tx != null) { tx.rollback(); } msg = "?" + ex.getMessage(); } finally { HibernateSessionFactory.closeSession(); } out.print(msg); out.flush(); out.close(); }
From source file:com.dz.module.charge.ChargeService.java
/** * ??/*from www. j av a2s .com*/ * @param contractId none * @param clearTime none * @return none */ private boolean clear(int contractId, Date clearTime) throws HibernateException { Session session = HibernateSessionFactory.getSession(); Contract c = (Contract) session.get(Contract.class, contractId); BigDecimal account = c.getAccount(); //? ChargePlan lastMonthRecord = new ChargePlan(); lastMonthRecord.setFee(account); lastMonthRecord.setIsClear(true); lastMonthRecord.setContractId(contractId); lastMonthRecord.setTime(clearTime); lastMonthRecord.setFeeType("last_month_left"); session.saveOrUpdate(lastMonthRecord); Query query = session.createQuery( "from ChargePlan where contractId = :contractId and isClear=false and year(time)=year(:date) and month(time)=month(:date)"); query.setInteger("contractId", contractId); query.setDate("date", clearTime); // List<ChargePlan> plans = chargeDao.getUnclears(contractId,clearTime); List<ChargePlan> plans = query.list(); for (ChargePlan plan : plans) { // System.out.println(plan.getFeeType() + " test "+plan.getFee()); String feeType = plan.getFeeType(); if (feeType.startsWith("add") || feeType.startsWith("plan_sub")) { account = account.add(plan.getFee()); } else if (feeType.startsWith("sub") || feeType.startsWith("plan_add") || feeType.startsWith("plan_base")) { account = account.subtract(plan.getFee()); } // chargeDao.cleared(plan); plan.setIsClear(true); session.saveOrUpdate(plan); } // contractDao.updateAccount(contractId,account); c.setAccount(account); session.saveOrUpdate(c); return true; }
From source file:com.dz.module.charge.ChargeService.java
public List<CheckChargeTable> getAllCheckChargeTable(Date date, String dept, String licenseNum, int status/**0,1,2,3,4 -- ,,,,*/ ) {/*from w ww.j av a 2s.c o m*/ if (date == null) date = new Date(); Calendar clear_time = Calendar.getInstance(); clear_time.setTime(getCurrentTime("".equals(dept) ? "total" : dept)); clear_time.add(Calendar.DATE, -1); Session session = HibernateSessionFactory.getSession(); try { if (date.before(clear_time.getTime())) { String ql = "from CheckChargeTable where YEAR(time)=:year and MONTH(time)=:month "; if (dept != null && !"".equals(dept)) { ql += "and dept = :dept "; } if (!StringUtils.isEmpty(licenseNum)) { ql += "and carNumber like :carNum "; } String ql2; switch (status) { case 1:// ThisMonthTotalOwe>0 ql2 = "and thisMonthTotalOwe >0.0 "; break; case 0:// ql2 = "and thisMonthTotalOwe<=0.0 "; break; case 2:// ql2 = "and bank <= 0.0 "; break; case 3:// ql2 = "and bank >0.0 "; break; default: ql2 = ""; } Query qy = session.createQuery(ql + ql2); if (dept != null && !"".equals(dept)) { qy.setString("dept", dept); } if (!StringUtils.isEmpty(licenseNum)) { qy.setString("carNum", "%" + licenseNum + "%"); } qy.setInteger("year", date.getYear() + 1900); qy.setInteger("month", date.getMonth() + 1); List<CheckChargeTable> lst = qy.list(); return lst; } String hql = // "select c.id " //+ "from Contract c " //+ "where c.state in (0,-1,1,4) " "and c.state in (0,-1,1,4) " + "and (c.abandonedFinalTime is null or (YEAR(c.abandonedFinalTime)*12+MONTH(c.abandonedFinalTime)+(case when DAY(c.abandonedFinalTime)>26 then 1 else 0 end) " + ">= (YEAR(:currentClearTime)*12+MONTH(:currentClearTime)))) "; if (dept != null && !"".equals(dept)) { hql += "and c.branchFirm = :dept "; } if (!StringUtils.isEmpty(licenseNum)) { hql += "and c.carNum like :carNum "; } String hql2; switch (status) { case 1:// ThisMonthTotalOwe>0 hql2 = "having avg(case when year(cl.current)<year(:currentClearTime) then c.account" + " when year(cl.current)=year(:currentClearTime) and month(cl.current)<=month(:currentClearTime) then c.account " + " when p.feeType='last_month_left' then p.fee" + " else 0.0 " + "end)- " + "sum(case " + "when p.feeType like '%bank%' then 0.0 " + "when p.feeType like '%cash%' then 0.0 " + "when p.feeType like '%oilAdd%' then 0.0 " + "when p.feeType like '%insurance%' then 0.0 " + "when p.feeType like '%other%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end)>0.0 "; break; case 0:// hql2 = "having avg(case when year(cl.current)<year(:currentClearTime) then c.account" + " when year(cl.current)=year(:currentClearTime) and month(cl.current)<=month(:currentClearTime) then c.account " + " when p.feeType='last_month_left' then p.fee" + " else 0.0 " + "end)- " + "sum(case " + "when p.feeType like '%bank%' then 0.0 " + "when p.feeType like '%cash%' then 0.0 " + "when p.feeType like '%oilAdd%' then 0.0 " + "when p.feeType like '%insurance%' then 0.0 " + "when p.feeType like '%other%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end)<=0.0 "; break; case 2:// hql2 = "having " + "sum(case " + "when p.feeType not like '%bank%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end) <=0.0 "; break; case 3:// hql2 = "having " + "sum(case " + "when p.feeType not like '%bank%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end) >0.0 "; break; default: hql2 = ""; } String hql_out = "select new com.dz.module.charge.CheckChargeTable(" + "p.contractId as contractId,p.time as time," + "sum(case " + "when p.feeType not like '%bank%' then 0.0 " + "when p.feeType like '%plan%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end) as bank" + "," + "sum(case " + "when p.feeType not like '%cash%' then 0.0 " + "when p.feeType like '%plan%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end) as cash" + "," + "sum(case " + "when p.feeType not like '%insurance%' then 0.0 " + "when p.feeType like '%plan%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end) as insurance" + "," + "sum(case " + "when p.feeType not like '%oil%' then 0.0 " + "when p.feeType like '%plan%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end) as oilAdd" + "," + "sum(case " + "when p.feeType not like '%other%' then 0.0 " + "when p.feeType like '%plan%' then 0.0 " + "when p.feeType like '%add%' then p.fee " + "else (-p.fee) end) as other" + "," + "sum(case " + "when p.feeType not like '%plan%' then 0.0 " + "when p.feeType like '%sub%' then -p.fee " + "else (p.fee) end) as planAll " + "," + "c.carNum as carNumber," + "c.branchFirm as dept," + "d.name as driverName, " + "avg(case when year(cl.current)<year(:currentClearTime) then c.account" + " when year(cl.current)=year(:currentClearTime) and month(cl.current)<=month(:currentClearTime) then c.account " + " when p.feeType='last_month_left' then p.fee" + " else 0.0 " + "end) as lastMonthOwe " + ") from ChargePlan " //+ "where contractId in (" + hql+ " ) " + "p ,Contract c,Driver d,ClearTime cl " + "where p.contractId=c.id and d.idNum=c.idNum and cl.department=c.branchFirm " + "and p.isClear != true " + hql + "and p.time is not null and year(p.time)=year(:currentClearTime) and month(p.time)=month(:currentClearTime) " + "group by c.id " + hql2 + "order by c.branchFirm,c.carNum"; // Query query = session.createQuery(hql_out).setResultTransformer(Transformers.aliasToBean(CheckChargeTable.class)); Query query = session.createQuery(hql_out); if (dept != null && !"".equals(dept)) { query.setString("dept", dept); } if (!StringUtils.isEmpty(licenseNum)) { query.setString("carNum", "%" + licenseNum + "%"); } query.setDate("currentClearTime", date); return query.list(); } catch (HibernateException ex) { ex.printStackTrace(); return new ArrayList<>(); } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.contract.ContractDaoImpl.java
@SuppressWarnings("unchecked") @Override/*from w ww . ja v a 2 s .c o m*/ public List<Contract> contractSearchByState(Short state) throws HibernateException { List<Contract> l = new ArrayList<Contract>(); Session session = null; try { session = HibernateSessionFactory.getSession(); Query query = session.createQuery("from Contract where state = :state"); query.setInteger("state", state); l = query.list(); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.contract.ContractDaoImpl.java
@Override public Contract selectById(int id) { Contract c = null;/*www . j av a2s. c o m*/ Session session = HibernateSessionFactory.getSession(); Query query = session.createQuery("from Contract where id = :id"); query.setInteger("id", id); c = (Contract) query.uniqueResult(); HibernateSessionFactory.closeSession(); return c; }
From source file:com.dz.module.driver.complain.ComplainDaoImpl.java
/** * ?//www. j ava 2 s . c o m * @return * @throws HibernateException */ @SuppressWarnings("unchecked") @Override public List<Complain> selectAllByState(Page page, Date beginDate, Date endDate, int state) throws HibernateException { Session session = null; try { session = HibernateSessionFactory.getSession(); String hql = "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("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(); } }