List of usage examples for org.hibernate Session createSQLQuery
@Override NativeQuery createSQLQuery(String queryString);
From source file:br.com.alberteije.balcao.DavController.java
License:Open Source License
@Override public Response insertRecord(ValueObject newPersistentObject) throws Exception { davCabecalho = (EcfDavCabecalhoVO) newPersistentObject; Calendar dataAtual = Calendar.getInstance(); SimpleDateFormat formatoHora = new SimpleDateFormat("HH:mm:ss"); String horaAtual = formatoHora.format(dataAtual.getTime()); BigDecimal valorTotal = BigDecimal.ZERO; List<EcfDavDetalheVO> listaDavDetalhe = grid.getGrid1().getVOListTableModel().getDataVector(); if (listaDavDetalhe.isEmpty()) { return new ErrorResponse("Nenhum item na lista!"); }/*from w w w .j a v a2 s . c o m*/ for (int i = 0; i < listaDavDetalhe.size(); i++) { if (listaDavDetalhe.get(i).getCancelado() == null) { listaDavDetalhe.get(i).setCancelado("N"); valorTotal = valorTotal.add(listaDavDetalhe.get(i).getValorTotal()); valorTotal.setScale(2, RoundingMode.DOWN); } } davCabecalho.setValor(valorTotal); davCabecalho.setDataEmissao(dataAtual.getTime()); davCabecalho.setHoraEmissao(horaAtual); davCabecalho.setSituacao("P"); davCabecalho.setIdPessoa(0); davCabecalho.setTaxaAcrescimo(BigDecimal.ZERO); davCabecalho.setAcrescimo(BigDecimal.ZERO); davCabecalho.setTaxaDesconto(BigDecimal.ZERO); davCabecalho.setDesconto(BigDecimal.ZERO); davCabecalho.setSubtotal(BigDecimal.ZERO); davCabecalho.setHashIncremento(-1); Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); String sql = "select NUMERO_DAV from DAV_CABECALHO where ID = (select max(ID) from DAV_CABECALHO)"; String numeroUltimoDav = (String) session.createSQLQuery(sql).uniqueResult(); if (numeroUltimoDav != null) { if (numeroUltimoDav.equals("9999999999")) { davCabecalho.setNumeroDav("0000000001"); } else { int numeroNovoDav = Integer.valueOf(numeroUltimoDav) + 1; DecimalFormat formatoDav = new DecimalFormat("0000000000"); davCabecalho.setNumeroDav(formatoDav.format(numeroNovoDav)); } } else { davCabecalho.setNumeroDav("0000000001"); } session.save(davCabecalho); EcfDavDetalheVO davDetalhe; for (int i = 0; i < listaDavDetalhe.size(); i++) { davDetalhe = listaDavDetalhe.get(i); davDetalhe.setEcfDavCabecalhoVO(davCabecalho); davDetalhe.setValorUnitario(davDetalhe.getProduto().getValorVenda()); davDetalhe.setNumeroDav(davCabecalho.getNumeroDav()); davDetalhe.setDataEmissao(davCabecalho.getDataEmissao()); davDetalhe.setTotalizadorParcial(davDetalhe.getProduto().getTotalizadorParcial()); davDetalhe.setMesclaProduto("N"); session.save(davDetalhe); } session.getTransaction().commit(); return new VOResponse(newPersistentObject); } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); return new ErrorResponse("Erro ao gerar o DAV"); } finally { session.close(); } }
From source file:br.com.dasa.hepic.SqlDaoHepic.java
public List<ExameEnvioHepic> buscaExameHepic(LabSistema sistema, String strDbName) { Session session = null; Transaction tx = null;/*www . j av a 2 s .c o m*/ List<ExameEnvioHepic> listExameEnvioHepic = new ArrayList<ExameEnvioHepic>(); try { session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName); tx = session.beginTransaction(); Query query = session.createSQLQuery(StaticsQuery.SQLHEPICEXAME); query.setString("uniStCodigo", sistema.getUniStCodigo().getUniStCodigo()); query.setString("sisStCodigo", sistema.getSisStCodigo()); List list = query.list(); tx.commit(); if (list != null && !list.isEmpty()) { for (int i = 0; i < list.size(); i++) { ExameEnvioHepic exameEnvioHepic = new ExameEnvioHepic(); Object[] tupla = (Object[]) list.get(i); exameEnvioHepic.setReqStCodigo((String) tupla[0]); exameEnvioHepic.setExaStCodigo((String) tupla[1]); exameEnvioHepic.setSeqStCodigo((String) tupla[2]); exameEnvioHepic.setExaStDescricao((String) tupla[3]); exameEnvioHepic.setDerDtEntradaMat((Date) tupla[4]); exameEnvioHepic.setReqStCodigoAlt((String) tupla[5]); exameEnvioHepic.setPacStNome((String) tupla[6]); exameEnvioHepic.setDerDtAssinatura((Date) tupla[7]); exameEnvioHepic.setMatStCodigo((String) tupla[8]); exameEnvioHepic.setMatStDescricao((String) tupla[9]); exameEnvioHepic.setPacStProntuario((String) tupla[10]); exameEnvioHepic.setReq_bl_infoauxiliar((String) tupla[11]); exameEnvioHepic.setDepStCodigo((String) tupla[12]); // exameEnvioHepic.setExaChGrupo((String) tupla[13]); exameEnvioHepic.setDerInCodigo((BigDecimal) tupla[14]); listExameEnvioHepic.add(exameEnvioHepic); } } } finally { if (session != null && session.isOpen()) { session.close(); } } return listExameEnvioHepic; }
From source file:br.com.dasa.hepic.SqlDaoHepic.java
public List<AntibiogramaResultado> buscaResultadoTsa(String reqStCodigo, String strDbName) { List<AntibiogramaResultado> listResulTsa = null; Session session = null; Transaction tx = null;// w ww . jav a 2 s . c o m try { session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName); tx = session.beginTransaction(); Query query = session.createSQLQuery(StaticsQuery.RESULTADOTSAHEPIC); query.setString("reqStCodigo", reqStCodigo); List list = query.list(); tx.commit(); if (list != null && !list.isEmpty()) { listResulTsa = new ArrayList<AntibiogramaResultado>(); for (int i = 0; i < list.size(); i++) { AntibiogramaResultado antibiogramaResultado = new AntibiogramaResultado(); Object[] tupla = (Object[]) list.get(i); antibiogramaResultado.setReqStCodigo((String) tupla[0]); antibiogramaResultado.setSeqStCodigo((String) tupla[1]); antibiogramaResultado.setResStIngresso((String) tupla[2]); antibiogramaResultado.setResStResultado((String) tupla[3]); listResulTsa.add(antibiogramaResultado); } } } finally { if (session != null && session.isOpen()) { session.close(); } } return listResulTsa; }
From source file:br.com.dasa.siscan.SqlDaoSiscan.java
public List<ExameColoUtero> buscaCitopatologico(String uniStCodigo, String strDbName) { List<ExameColoUtero> listExame = new ArrayList<ExameColoUtero>(); Session session = null; Transaction tx = null;/*from w w w .ja v a 2 s .co m*/ try { session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName); tx = session.beginTransaction(); Query query = session.createSQLQuery(StaticsQuery.SQLSISCOLO); query.setString("uniStCodigo", uniStCodigo); List lst = query.list(); tx.commit(); if (lst != null && !lst.isEmpty()) { for (int i = 0; i < lst.size(); i++) { ExameColoUtero exameColoUtero = new ExameColoUtero(); Object[] tupla = (Object[]) lst.get(i); exameColoUtero.setPacInCodsus((BigDecimal) tupla[0]); exameColoUtero.setOriStCnes((String) tupla[1]); exameColoUtero.setUniStCnes((String) tupla[2]); exameColoUtero.setPacStNome((String) tupla[3]); exameColoUtero.setPacDtNascimento((Date) tupla[4]); exameColoUtero.setPacStSexo((Character) tupla[5]); exameColoUtero.setPacStResp((String) tupla[6]); // exameColoUtero.setPacStRaca("99");tupla[7] // exameColoUtero.setPacStRaca("99");tupla[8] exameColoUtero.setPacStProntuario((String) tupla[9]); exameColoUtero.setCinStCodigo((String) tupla[10]); exameColoUtero.setResStIngresso((String) tupla[11]); exameColoUtero.setReqDtCadastro((Date) tupla[12]); exameColoUtero.setDerDtAssinatura((Date) tupla[13]); exameColoUtero.setUsuStCodigoass((String) tupla[14]); exameColoUtero.setUsuStCpf((String) tupla[15]); exameColoUtero.setReqStDum((String) tupla[16]); exameColoUtero.setReqStCodigo((String) tupla[17]); listExame.add(exameColoUtero); } } } finally { if (session != null && session.isOpen()) { session.close(); } } return listExame; }
From source file:br.com.dasa.sqdasa.alvaro.SqDasaDaoLabor.java
public Date dbDataMySql(String strDbName) { Date dtMySql = null;/*from w w w . j av a2s . com*/ Session session = null; Transaction tx = null; try { System.out.println("buscando session"); session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName); System.out.println("session "); tx = session.beginTransaction(); Query q = session.createSQLQuery("select CURDATE()"); List lDate = q.list(); tx.commit(); if (lDate != null && !lDate.isEmpty()) { dtMySql = (Date) lDate.get(0); } } finally { if (session != null && session.isOpen()) { session.close(); } } return dtMySql; }
From source file:br.com.jn.dao.CandidatoDAO.java
public List<Candidato> listar() { Authentication a = SecurityContextHolder.getContext().getAuthentication(); //Authentication authentication = context.getAuthentication(); Object principal = a.getPrincipal(); String username = ""; username = (((User) a.getPrincipal()).getUsername()); //username = ((UserDetails) principal).getUsername(); System.out.println("login selecionado:" + username); Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w .j av a 2 s . c om String sql = "select * from users where username = :username"; SQLQuery query = session.createSQLQuery(sql); query.addEntity(Users.class); query.setParameter("username", username); //Users usuario = (Users) query.uniqueResult(); List logado = query.list(); //List<Users> results = query.getResultList(); String UserId = logado.get(0).toString(); String usuario = "4"; //System.out.println("Id do usuario selecionado:" + usuario.getUserId()); //System.out.println("Id do usuario selecionado:" + usuario.getNome()); //Integer UserId = usuario.getUserId(); System.out.println("Id do usuario selecionado:" + UserId); Criteria crit = session.createCriteria(Candidato.class); crit.add(Restrictions.ge("notaEliminatoria", (5.0))); crit.add(Restrictions.eq("orientador1", username)); crit.addOrder(Order.asc("nome")); List<Candidato> lista = crit.list(); session.close(); return lista; }
From source file:br.com.ln.dao.GenericDao.java
public static Date grabDateFromDB() { Session session = null; Transaction tx = null;// www. j ava2 s . co m Date rightNow = null; try { session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); tx = session.beginTransaction(); Query query = session.createSQLQuery("select now()"); List listQuery = query.list(); if (listQuery != null && !listQuery.isEmpty()) { for (int i = 0; i < listQuery.size(); i++) { java.sql.Timestamp rightNowTimeStamp = (java.sql.Timestamp) listQuery.get(i); rightNow = new Date(rightNowTimeStamp.getTime()); break; } } } catch (HibernateException ex) { logger.error("Problemas no acesso a data do banco de dados: " + ex.getMessage()); } finally { if (session != null && session.isOpen()) { session.close(); } } return rightNow; }
From source file:br.com.ln.dao.GenericDao.java
public static String grabIdByNextValueStringSQL(String strSql) { Session session = null; String strResult = null;/*from w w w. j a v a 2 s . com*/ List result; try { session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); Transaction tx = session.beginTransaction(); org.hibernate.Query query = session.createSQLQuery(strSql); result = query.list(); tx.commit(); if (result != null) { strResult = result.get(0).toString(); } } finally { if (session != null && session.isOpen()) { session.close(); } } return strResult; }
From source file:br.com.ln.dao.PlanoContaDao.java
private static Date grabBuscaUltimoSaldo(Integer ctaInCodigo) { Session session = null; Transaction tx;//from www.ja v a 2 s. co m Date dataSaldo = null; try { session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); tx = session.beginTransaction(); Query query = session.createSQLQuery("select max(sac_dt_data) sac_dt_data from ln_saldoconta\n" + "where cta_in_codigo = :ctaInCodigo\n"); query.setInteger("ctaInCodigo", ctaInCodigo); List list = query.list(); tx.commit(); if (list != null && list.size() > 0) { dataSaldo = (Date) list.get(0); } } finally { if (session != null && session.isOpen()) { session.close(); } } return dataSaldo; }
From source file:br.com.ln.hibernate.Postgress.java
public static Date grabDateFromDB() { Session session = null; Transaction tx = null;/*from w ww .ja va 2 s . c o m*/ Date rightNow = null; try { session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); tx = session.beginTransaction(); Query query = session.createSQLQuery("select now()"); List listQuery = query.list(); if (listQuery != null && !listQuery.isEmpty()) { for (int i = 0; i < listQuery.size(); i++) { java.sql.Timestamp rightNowTimeStamp = (java.sql.Timestamp) listQuery.get(i); rightNow = new Date(rightNowTimeStamp.getTime()); break; } } } catch (HibernateException xcp) { System.out.println(xcp.getMessage()); } finally { if (session != null && session.isOpen()) { session.close(); } } return rightNow; }