List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:br.unisal.dao.PacienteDao.java
public Paciente getById(Paciente p) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Paciente paciente = new Paciente(); try {/*from w w w . ja va 2 s.c om*/ tx.begin(); Query query = session.createQuery("FROM Paciente WHERE idPaciente = :id"); query.setParameter("id", p.getIdPaciente()); paciente = (Paciente) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception PacienteDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return paciente; }
From source file:br.unisal.dao.ReuniaoDao.java
@Override public Reuniao getById(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Reuniao reuniao = new Reuniao(); try {/* w w w . j a v a 2 s . c o m*/ tx.begin(); Query query = session.createQuery("FROM Reuniao WHERE id_reuniao = :id"); query.setParameter("id", id); reuniao = (Reuniao) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception ReuniaoDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return reuniao; }
From source file:br.unisal.dao.SalaDao.java
@Override public Sala getById(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Sala sala = new Sala(); try {/*from w w w. jav a 2 s . c om*/ tx.begin(); Query query = session.createQuery("FROM Sala WHERE id_sala = :id"); query.setParameter("id", id); sala = (Sala) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception SalaDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return sala; }
From source file:br.unisal.dao.SensorDao.java
@Override public Sensor getById(Sensor s) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Sensor sensor = new Sensor(); try {/* w ww . j a va2 s. c om*/ tx.begin(); Query query = session.createQuery("FROM Sensor WHERE idSensor = :id"); query.setParameter("id", s.getIdSensor()); sensor = (Sensor) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception SensorDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return sensor; }
From source file:br.unisal.dao.UsuarioDao.java
@Override public Usuario getById(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Usuario usuario = new Usuario(); try {/*from w w w . j a v a 2 s . c o m*/ tx.begin(); Query query = session.createQuery("FROM Usuario WHERE id_usuario = :id"); query.setParameter("id", id); usuario = (Usuario) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception UsuarioDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return usuario; }
From source file:br.unisal.twitter.dao.TweetDao.java
public Tweet getById(Tweet s) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Tweet sensor = new Tweet(); try {/*from www . ja v a2 s . c o m*/ tx.begin(); Query query = session.createQuery("FROM Tweet WHERE id = :id"); query.setParameter("id", s.getId()); sensor = (Tweet) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception TweetDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return sensor; }
From source file:br.univates.paa.kickquiz.DAO.ConfiguracaoDAO.java
public Configuracao getByChave(String chave) { session = HibernateUtil.getSession(); session.beginTransaction();// w w w .j a v a 2 s . c om Query query = session.createQuery("from Configuracao where chave = :chave"); query.setParameter("chave", chave); List list = query.list(); session.getTransaction().commit(); return list.size() == 1 ? (Configuracao) list.get(0) : null; }
From source file:br.univates.paa.kickquiz.DAO.PermissoesDAO.java
public boolean temPermissao(Permissoes p) { session = HibernateUtil.getSession(); session.beginTransaction();/*from w w w. ja v a2s . c o m*/ Query query = session.createQuery( "from Permissoes where botao = :botao and objeto = :objeto and permissao = :permissao"); query.setParameter("botao", p.getBotao()); query.setParameter("objeto", p.getObjeto()); query.setParameter("permissao", p.getPermissao()); List list = query.list(); session.getTransaction().commit(); return list.size() >= 1; }
From source file:br.univates.paa.kickquiz.DAO.UsuarioDAO.java
public Usuario getUsuarioByNome(String nome) { session.beginTransaction();//w w w .j av a 2 s .c o m Query query = session.createQuery("from Usuario where nome = :nome"); query.setParameter("nome", nome); List list = query.list(); session.getTransaction().commit(); return list.size() >= 1 ? (Usuario) list.get(0) : null; }
From source file:br.univates.paa.kickquiz.DAO.UsuarioDAO.java
public Usuario checkLogin(Usuario u) { session.beginTransaction();// w w w. j a v a 2 s . com Query query = session.createQuery("from Usuario where login = :login and senha = :senha"); query.setParameter("login", u.getLogin()); query.setParameter("senha", encryptPassword(u.getSenha())); List list = query.list(); session.getTransaction().commit(); return list.size() == 1 ? (Usuario) list.get(0) : null; }