List of usage examples for org.hibernate SQLQuery setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(int position, int val)
From source file:com.neu.web.phmis.dao.ResourceDao.java
public void createRequest(DeviceRequestBean deviceRequestBean) { try {//from w w w . j av a2s . c o m session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery("CALL createDeviceRequest(:1, :2, :3, :4, :5, :6)"); query.setInteger("1", deviceRequestBean.getCreatedBy().getId()); query.setString("2", deviceRequestBean.getNumber()); query.setInteger("3", deviceRequestBean.getTypeId()); query.setInteger("4", deviceRequestBean.getStatusId()); query.setInteger("5", deviceRequestBean.getWarehouse().getId()); query.setString("6", deviceRequestBean.getSpecialInstruction()); List<Integer> list = query.list(); deviceRequestBean.setId(list.get(0)); for (ProductBean p : deviceRequestBean.getRequestedProducts()) { query = session.createSQLQuery("INSERT INTO productrequested VALUES (:requestId, :productId)"); query.setInteger("requestId", deviceRequestBean.getId()); query.setInteger("productId", p.getId()); query.executeUpdate(); } session.getTransaction().commit(); } catch (HibernateException e) { session.getTransaction().rollback(); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } }
From source file:com.neu.web.phmis.dao.ResourceDao.java
public SurgeryRequestBean processRequest(SurgeryRequestBean surgeryRequestBean) { try {/*from w w w . java 2s . c o m*/ session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery( "UPDATE request SET statusId = :status, processedDate = NOW(), processComment = :comment WHERE id = :id"); query.setInteger("status", surgeryRequestBean.getStatusId()); query.setString("comment", surgeryRequestBean.getProcessComment()); query.setInteger("id", surgeryRequestBean.getId()); query.executeUpdate(); surgeryRequestBean = (SurgeryRequestBean) session.get(SurgeryRequestBean.class, surgeryRequestBean.getId()); session.getTransaction().commit(); } catch (HibernateException e) { session.getTransaction().rollback(); surgeryRequestBean = null; e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); return surgeryRequestBean; } }
From source file:com.neu.web.phmis.dao.ResourceDao.java
public int isDateAvailable(Date date, SurgeryRequestBean surgeryRequestBean) { int flag = 0; try {/*from www.ja v a 2 s . c om*/ session = HibernateUtil.getSessionFactory().openSession(); SQLQuery query = session.createSQLQuery("CALL isDateAvailable (:1, :2, :3);"); query.setInteger("1", surgeryRequestBean.getCreatedBy().getEnterpriseBean().getId()); query.setDate("2", date); query.setInteger("3", surgeryRequestBean.getStaffCount()); List<Integer> list = query.list(); flag = list.get(0).intValue(); } catch (HibernateException e) { session.getTransaction().rollback(); surgeryRequestBean = null; e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); return flag; } }
From source file:com.neu.web.phmis.dao.ResourceDao.java
public void scheduleSurgery(SurgeryBean surgeryBean) { try {/*from ww w . java2 s.c om*/ session = HibernateUtil.getSessionFactory().openSession(); SQLQuery query = session.createSQLQuery("CALL addSurgery (:1, :2, :3)"); session.beginTransaction(); query.setInteger("1", surgeryBean.getId()); query.setDate("2", surgeryBean.getScheduleDate()); query.setInteger("3", surgeryBean.getOperatingRoomBean().getId()); query.executeUpdate(); session.getTransaction().commit(); } catch (HibernateException e) { e.printStackTrace(); session.getTransaction().rollback(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } }
From source file:com.ori.outlierserver.dao.ReadingsDao.java
public List<Reading> getLastNReadingsByClientId(String clientId, int N) { List<Reading> theReadingList = null; Session theSession = null;//w w w . j a v a 2 s. com if (N <= 0) { return Collections.<Reading>emptyList(); } try { theSession = sessionFactory.openSession(); theSession.beginTransaction(); String sql = "SELECT * FROM readings WHERE client_id = :id limit :lim"; SQLQuery query = theSession.createSQLQuery(sql); query.addEntity(Reading.class); query.setString("id", clientId); query.setInteger("lim", N); theReadingList = query.list(); theSession.getTransaction().commit(); } catch (Exception e) { if (theSession != null) { theSession.getTransaction().rollback(); } } finally { if (theSession != null) { theSession.close(); } } return theReadingList; }
From source file:com.sip.pe.dao.ClienteDAO.java
public List<Object> ObtenerHistorialCliente(int idCliente) { List<Object> listaHistorial = null; SessionFactory sesFact = HibernateUtil.getSessionFactory(); Session ses = sesFact.openSession(); try {//from w w w .j av a 2 s . c o m SQLQuery q = ses.createSQLQuery("exec sp_ObtenerHistorialCliente :IdCliente"); q.addScalar("ID_TRANSACCION", INTEGER); q.addScalar("FE_TRANSACCION"); q.addScalar("TIPO_CUENTA"); q.addScalar("SERVICIO"); q.addScalar("ENTIDAD"); q.addScalar("BANCO"); q.addScalar("NU_CUENTA"); q.addScalar("IMPORTE_PAGO", FLOAT); q.setInteger("IdCliente", idCliente); listaHistorial = q.list(); } catch (HibernateException e) { System.out.println("Error en la aplicacion: " + e.toString()); System.out.println("causa: " + e.getClass()); e.printStackTrace(); } finally { ses.close(); } return listaHistorial; }
From source file:com.syntelinc.BOK.ATM.menupkg.Hibernate.java
public BigDecimal getBalance(int accountID, String accountType) { SQLQuery q; com.syntelinc.BOK.ATM.transactionpkg.Transaction transac; if (accountType.equals("checking")) { transac = new CheckingTransaction(); q = session.createSQLQuery("select balance from checkingtrans where acctid=?"); } else {/*from w ww . j av a 2s.co m*/ transac = new SavingsTransaction(); q = session.createSQLQuery("select balance from savingtrans where acctid=?"); } transac.setAcctid(accountID); q.setInteger(0, transac.getAcctid()); List ld = q.list(); BigDecimal bal; if (ld.isEmpty()) bal = new BigDecimal(0); else bal = (BigDecimal) ld.get(ld.size() - 1); return bal; }
From source file:com.syntelinc.BOK.ATM.transactionpkg.HibernateTransaction.java
private void AccountTrans(Transaction tran) throws IllegalArgumentException { Configuration cfg = new Configuration().configure(); SessionFactory sf = cfg.buildSessionFactory(); Session s = sf.openSession();/*www.j av a2 s . c o m*/ org.hibernate.Transaction t = s.beginTransaction(); SQLQuery q; if (sessionMap.get("accounttype").equals("checking")) { tran = new CheckingTransaction(); q = s.createSQLQuery("select balance from checkingtrans where acctid=?"); } else { tran = new SavingsTransaction(); q = s.createSQLQuery("select balance from savingtrans where acctid=?"); } tran.setAcctid(Integer.parseInt((String) sessionMap.get("accountid"))); q.setInteger(0, tran.getAcctid()); List ld = q.list(); BigDecimal bal; if (ld.isEmpty()) bal = new BigDecimal(0); else bal = (BigDecimal) ld.get(ld.size() - 1); tran.setTime(new Date()); tran.setLocation("1234 North Vegas Street"); DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.CEILING); tran.setDebitamt(Double.parseDouble((String) sessionMap.get("depositamt"))); tran.setDebitamt(Double.parseDouble(df.format(tran.getDebitamt()))); tran.setCreditamt(Double.parseDouble((String) sessionMap.get("withdrawamt"))); tran.setCreditamt(Double.parseDouble(df.format(tran.getCreditamt()))); switch ((String) sessionMap.get("type")) { case "cash": tran.setType(1); tran.setBalance(bal.doubleValue() + tran.getDebitamt() - tran.getCreditamt()); tran.setBalance(Double.parseDouble(df.format(tran.getBalance()))); break; case "check": tran.setType(2); tran.setBalance(bal.doubleValue()); tran.setBalance(Double.parseDouble(df.format(tran.getBalance()))); break; case "default": throw new IllegalArgumentException(); } sessionMap.put("balance", tran.getBalance()); s.save(tran); t.commit(); s.close(); sf.close(); }
From source file:com.syntelinc.BOK.ATM.withdrawpkg.CheckDailyLimit.java
public double getCurrentTotal(int accountid) { Configuration cfg = new Configuration().configure(); SessionFactory sf = cfg.buildSessionFactory(); Session s = sf.openSession();/*from w ww. j a va 2 s.co m*/ org.hibernate.Transaction t = s.beginTransaction(); SQLQuery q; q = s.createSQLQuery("select creditamt from checkingtrans where acctid=? AND TIME < ? AND TIME > ?"); q.setInteger(0, accountid); q.setTimestamp(1, getDayEnd()); q.setTimestamp(2, getDayStart()); List<BigDecimal> li = q.list(); double totalCredit = 0; if (li.isEmpty()) totalCredit = 0; else if (li.get(0) == null) totalCredit = 0; else { for (BigDecimal cred : li) { totalCredit += cred.doubleValue(); } } System.out.println(totalCredit); if (!li.isEmpty()) return totalCredit; else return 0; }
From source file:com.upcera.ddx.dao.user.impl.UserDaoImpl.java
@Override public List<Map<String, Object>> getSessionUserGroupUnit(Integer mainUserId) throws Exception { List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); String sql = "select a.email,a.last_name,b.lab_name as name,'lab_login' as logType,a.password from ddx_user a,ddx_lab b where a.lab_id = b.lab_id and a.parent_id =:mainId union all select a.email,a.last_name,b.name,'practice_login' as logType,a.password from ddx_user a,ddx_practice b where a.practice_id = b.practice_id and a.parent_id =:mainId"; SQLQuery query = getSession().createSQLQuery(sql); query.setInteger("mainId", mainUserId); List<Object> objList = query.list(); for (int i = 0; i < objList.size(); i++) { Object[] obj = (Object[]) objList.get(i); Map<String, Object> map = new HashMap<String, Object>(); map.put("userEmal", obj[0]); map.put("userLastName", obj[1]); map.put("unitName", obj[2]); map.put("logType", obj[3]); map.put("password", obj[4]); result.add(map);//from ww w .jav a2 s. co m } return result; }