List of usage examples for org.hibernate Session createSQLQuery
@Override NativeQuery createSQLQuery(String queryString);
From source file:com.bacic5i5j.framework.database.HibernateAccess.java
License:Open Source License
@Override public int count(String sql) { Session session = sessionFactory.currentSession(); int amount = ((Number) session.createSQLQuery(sql).uniqueResult()).intValue(); sessionFactory.closeSession();//from w ww. j a va2 s . c o m return amount; }
From source file:com.bahadirakin.dao.impl.BaseHibernateDAO.java
License:Apache License
public T getBySql(String query) { T entity = null;/*from w w w . ja va2 s . com*/ try { Session session = this.getCurrentSession(); Transaction transaction = session.beginTransaction(); entity = (T) session.createSQLQuery(query).addEntity(getPersistentClass()).uniqueResult(); transaction.commit(); } catch (Exception e) { LOG.error("Error while getWithSql Entity. M: " + e.getMessage() + " C: " + e.getCause() + " SQL: " + query, e); } return entity; }
From source file:com.bahadirakin.dao.impl.BaseHibernateDAO.java
License:Apache License
public List<T> getAllBySql(String query) { List<T> ts = null;/*from www .j a va 2 s .c o m*/ try { Session session = this.getCurrentSession(); Transaction transaction = session.beginTransaction(); ts = session.createSQLQuery(query).addEntity(getPersistentClass()).list(); transaction.commit(); } catch (Exception e) { LOG.error("Error while getAllWithSql Entities. M: " + e.getMessage() + " C: " + e.getCause() + " SQL: " + query, e); } return ts; }
From source file:com.bahadirakin.dao.impl.BaseHibernateDAO.java
License:Apache License
public void executeSQLQuery(String query) { try {/*from w ww .j ava 2s. c om*/ Session session = this.getCurrentSession(); Transaction transaction = session.beginTransaction(); session.createSQLQuery(query).addEntity(getPersistentClass()).executeUpdate(); transaction.commit(); } catch (Exception e) { LOG.error("Error while executeSQLQuery Entities. M: " + e.getMessage() + " C: " + e.getCause() + " SQL: " + query, e); } }
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(); }// ww w . ja v a 2 s. c o m 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; try {//from ww w.ja v a 2 s. c om 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; try {/*from ww w . j av a2 s .c o m*/ 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));/*from w ww.j a v a 2 s . c o 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.balero.models.TestDAO.java
License:Open Source License
/** * @deprecated makedb// ww w.j av a 2s . co m */ @Transactional public void makedb() { String query; Session session = sessionFactory.getCurrentSession(); query = "create database if not exists balero_cms"; session.createSQLQuery(query).executeUpdate(); }
From source file:com.balero.models.TestDAO.java
License:Open Source License
/** * @deprecated musedb/*w w w. jav a 2 s.c o m*/ */ @Transactional public void usedb() { String query; Session session = sessionFactory.getCurrentSession(); query = "use balero_cms"; session.createSQLQuery(query).executeUpdate(); }