List of usage examples for org.hibernate Query setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(String name, int val)
From source file:com.appeligo.search.entity.Message.java
License:Apache License
/** * /*w ww .j a v a 2s . c om*/ * @param max * @return */ @SuppressWarnings("unchecked") public static List<Message> getUnsentMessages(int maxResults, int maxAttempts) { Session session = getSession(); Query query = session.getNamedQuery("Message.getUnsent"); query.setTimestamp("now", new Timestamp(System.currentTimeMillis())); query.setInteger("maxAttempts", maxAttempts); query.setMaxResults(maxResults); return query.list(); }
From source file:com.appeligo.search.entity.Message.java
License:Apache License
public static void deleteOldMessages(int days, int maxAttempts) { Session session = getSession();/*from w w w . jav a 2s . c o m*/ Query query = session.getNamedQuery("Message.deleteOldMessages"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, (0 - (days * 24))); query.setTimestamp("oldestSent", new Timestamp(cal.getTimeInMillis())); query.setInteger("maxAttempts", maxAttempts); query.executeUpdate(); }
From source file:com.bakeryfactory.vendas.servidor.VendaCondicoesPagamentoDetalheAction.java
License:Open Source License
public void queryExcluir(List<VendaCondicoesParcelaVO> parcelas, VendaCondicoesPagamentoVO vendaCondicoesPagamento, Session session) throws HibernateException { String sqlExcluir = "delete from VENDA_CONDICOES_PARCELAS where ID not in (0"; for (int i = 0; i < parcelas.size(); i++) { parcelas.get(i).setVendaCondicoesPagamento(vendaCondicoesPagamento); session.saveOrUpdate(parcelas.get(i)); sqlExcluir += "," + parcelas.get(i).getId(); }//from w w w . java 2s .c om sqlExcluir += ") and ID_VENDA_CONDICOES_PAGAMENTO = :id"; Query query = session.createSQLQuery(sqlExcluir); query.setInteger("id", vendaCondicoesPagamento.getId()); query.executeUpdate(); }
From source file:com.bakeryfactory.vendas.servidor.VendaDetalheAction.java
License:Open Source License
private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request, HttpServletResponse response, HttpSession userSession, ServletContext context) { Session session = null;/*from w w w .java 2 s. c o m*/ try { Object[] pars = (Object[]) inputPar; VendaCabecalhoVO vendaCabecalho = (VendaCabecalhoVO) pars[2]; List<VendaDetalheVO> orcamentoDetalhe = (Vector) pars[3]; session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); if (vendaCabecalho.getVendaOrcamentoCabecalho().getId() == null) { vendaCabecalho.setVendaOrcamentoCabecalho(null); } if (vendaCabecalho.getTransportadora().getId() == null) { vendaCabecalho.setTransportadora(null); } session.update(vendaCabecalho); String sqlExcluir = "delete from VENDA_DETALHE where ID not in (0"; for (int i = 0; i < orcamentoDetalhe.size(); i++) { orcamentoDetalhe.get(i).setVendaCabecalho(vendaCabecalho); session.saveOrUpdate(orcamentoDetalhe.get(i)); sqlExcluir += "," + orcamentoDetalhe.get(i).getId(); } sqlExcluir += ") and ID_VENDA_CABECALHO = :id"; Query query = session.createSQLQuery(sqlExcluir); query.setInteger("id", vendaCabecalho.getId()); query.executeUpdate(); Criteria criteria = session.createCriteria(VendaComissaoVO.class); criteria.add(Restrictions.eq("vendaCabecalho", vendaCabecalho)); VendaComissaoVO comissao = (VendaComissaoVO) criteria.uniqueResult(); comissao.setVendedor(vendaCabecalho.getVendedor()); if (vendaCabecalho.getValorDesconto() != null) { comissao.setValorVenda( vendaCabecalho.getValorSubtotal().subtract(vendaCabecalho.getValorDesconto())); } else { comissao.setValorVenda(vendaCabecalho.getValorSubtotal()); } comissao.setTipoContabil("C"); comissao.setValorComissao(vendaCabecalho.getValorComissao()); comissao.setSituacao("A"); comissao.setDataLancamento(new Date()); session.update(comissao); session.getTransaction().commit(); return new VOResponse(vendaCabecalho); } catch (Exception ex) { ex.printStackTrace(); if (session != null) { session.getTransaction().rollback(); } return new ErrorResponse(ex.getMessage()); } finally { try { if (session != null) { session.close(); } } catch (Exception ex1) { ex1.printStackTrace(); } } }
From source file:com.bakeryfactory.vendas.servidor.VendaOrcamentoDetalheAction.java
License:Open Source License
private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request, HttpServletResponse response, HttpSession userSession, ServletContext context) { Session session = null;/*from w ww . jav a 2s . c om*/ try { Object[] pars = (Object[]) inputPar; VendaOrcamentoCabecalhoVO vendaOrcamentoCabecalho = (VendaOrcamentoCabecalhoVO) pars[2]; List<VendaOrcamentoDetalheVO> orcamentoDetalhe = (Vector) pars[3]; session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); if (vendaOrcamentoCabecalho.getTransportadora().getId() == null) { vendaOrcamentoCabecalho.setTransportadora(null); } session.update(vendaOrcamentoCabecalho); String sqlExcluir = "delete from VENDA_ORCAMENTO_DETALHE where ID not in (0"; for (int i = 0; i < orcamentoDetalhe.size(); i++) { orcamentoDetalhe.get(i).setVendaOrcamentoCabecalho(vendaOrcamentoCabecalho); session.saveOrUpdate(orcamentoDetalhe.get(i)); sqlExcluir += "," + orcamentoDetalhe.get(i).getId(); } sqlExcluir += ") and ID_VENDA_ORCAMENTO_CABECALHO = :id"; Query query = session.createSQLQuery(sqlExcluir); query.setInteger("id", vendaOrcamentoCabecalho.getId()); query.executeUpdate(); session.getTransaction().commit(); return new VOResponse(vendaOrcamentoCabecalho); } catch (Exception ex) { ex.printStackTrace(); if (session != null) { session.getTransaction().rollback(); } return new ErrorResponse(ex.getMessage()); } finally { try { if (session != null) { session.close(); } } catch (Exception ex1) { ex1.printStackTrace(); } } }
From source file:com.bakeryfactory.vendas.servidor.VendaRomaneioEntregaDetalheAction.java
License:Open Source License
public void queryExcluir(List<VendaCabecalhoVO> vendas, VendaRomaneioEntregaVO vendaRomaneioEntrega, Session session) throws HibernateException { String sqlExcluir = "update VENDA_CABECALHO set ID_VENDA_ROMANEIO_ENTREGA = null where ID not in (0"; for (int i = 0; i < vendas.size(); i++) { vendas.get(i).setVendaRomaneioEntrega(vendaRomaneioEntrega); session.update(vendas.get(i));/* ww w . ja va 2 s .co m*/ sqlExcluir += "," + vendas.get(i).getId(); } sqlExcluir += ") and ID_VENDA_ROMANEIO_ENTREGA = :id"; Query query = session.createSQLQuery(sqlExcluir); query.setInteger("id", vendaRomaneioEntrega.getId()); query.executeUpdate(); }
From source file:com.bancomat.springmvc.dao.MovimentiDao.java
public static ArrayList<Movimenti> getMovimenti(int id) { ArrayList<Movimenti> movimenti = new ArrayList<Movimenti>(); session = HibernateUtil.getSessionFactory().openSession(); Transaction tsc = session.beginTransaction(); String select = "from Movimenti m where idUtente = :id order by m.data desc "; Query qry = session.createQuery(select); qry.setInteger("id", id); qry.setMaxResults(10);/*from ww w . j a va 2 s . c om*/ movimenti = (ArrayList<Movimenti>) qry.list(); return movimenti; }
From source file:com.bancomat.springmvc.dao.UtenteDao.java
public static Utente getUtente(int id, int pin) { Utente utente = null;//from w w w .j av a 2 s.co m session = HibernateUtil.getSessionFactory().openSession(); Transaction tsc = session.beginTransaction(); Query qry = session.createQuery("from Utente where idUtente = :id and pin = :pin"); qry.setInteger("id", id); qry.setInteger("pin", pin); utente = (Utente) qry.uniqueResult(); return utente; }
From source file:com.bancomat.springmvc.dao.UtenteDao.java
public static double getSaldo(int id) { session = HibernateUtil.getSessionFactory().openSession(); Transaction tsc = session.beginTransaction(); Double saldo;//from w ww.j a v a 2s .c o m String selectAll = "select u.saldo from Utente u where idUtente = :id"; Query qry = session.createQuery(selectAll); qry.setInteger("id", id); saldo = (Double) qry.uniqueResult(); return saldo; }
From source file:com.bancomat.springmvc.dao.UtenteDao.java
public static int updateSaldo(int id, double saldo) { session = HibernateUtil.getSessionFactory().openSession(); Transaction tsc = session.beginTransaction(); String updateQuery = "update Utente u set u.saldo = :saldo where idUtente = :id"; Query qry = session.createQuery(updateQuery); qry.setDouble("saldo", saldo); qry.setInteger("id", id); int result = qry.executeUpdate(); session.getTransaction().commit();//w ww .j a v a 2 s . c om return result; }