List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:br.com.aula.dao.LoginDAO.java
public boolean existe(Usuario usuario) { Session session = factory.openSession(); Query query = session.createQuery("from Usuario u where u.login = " + " :plogin and u.senha = :pSenha"); query.setParameter("plogin", usuario.getUsuario()); query.setParameter("pSenha", usuario.getSenha()); boolean encontrado = !query.list().isEmpty(); session.flush();//from www . jav a 2 s . co m session.close(); return encontrado; }
From source file:br.com.aula.dao.LoginDAO.java
public boolean buscar(String login, String senha) { Session session = HibernateUtil.getSessionFactory().openSession(); //session.beginTransaction(); String sql = " from Usuario u where u.usuario=:login and u.senha=:senha"; Query query = session.createQuery(sql); query.setParameter("login", login); query.setParameter("senha", senha); List<Usuario> list = query.list(); if (list.size() > 0) { session.close();//from w w w . j a va 2s . com return true; } session.close(); return false; }
From source file:br.com.barterserver.dao.ChatDAO.java
public List<Chat> getChatMessages(Long tradeId) { Query q = session.createQuery("from Chat c where c.trade.id = :tradeId"); q.setParameter("tradeId", tradeId); return q.list(); }
From source file:br.com.barterserver.dao.TradeDAO.java
public List<Trade> listMyTrades(User user) { Query q = session.createQuery( "from Trade t where t.userOffering = :user_offering or t.userRequiring = :user_requiring"); q.setParameter("user_offering", user); q.setParameter("user_requiring", user); return q.list(); }
From source file:br.com.barterserver.dao.UserDAO.java
public User getUserByCredentials(String email, String password) { Query q = session.createQuery("from User u where u.email = :email and u.password = :password "); q.setParameter("email", email); q.setParameter("password", password); return (User) q.uniqueResult(); }
From source file:br.com.barterserver.dao.UserDAO.java
public List<Picture> searchPictures(String title) { Query q = session.createQuery("from Picture p where p.title = :title "); q.setParameter("title", title); List<Picture> pictures = q.list(); return pictures; }
From source file:br.com.barterserver.dao.UserDAO.java
public User getUserByEmail(String email) { Query q = session.createQuery("from User where u.email = :email"); q.setParameter("email", email); return (User) q.uniqueResult(); }
From source file:br.com.bluesoft.pronto.dao.TicketDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<TicketComentario> listarPorDataComentario(Date dataComentario) { log.info("Entrou TicketDao.listarPorDataComentario"); final long data = dataComentario.getTime(); final Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(data);/*from ww w.j a v a 2 s .c o m*/ log.info("Data pesquisada ==>> " + cal.toString()); final StringBuilder builder = new StringBuilder(); builder.append(" select distinct tc from TicketComentario tc"); //colocar hora, min, seg e milis com valor 0 para incio do dia. cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 1); cal.set(Calendar.MILLISECOND, 0); Date dataInicial = cal.getTime(); log.info("Data inicial ==>> " + dataInicial); //coloca hora, min, seg e milis para fim do dia. cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); Date dataFinal = cal.getTime(); log.info("Data final ==>> " + dataFinal); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); builder.append(" where tc.data between :dataInicial and :dataFinal order by tc.data desc"); // builder.append(" where tc.data between " + sdf.format(dataInicial) + " and " + sdf.format(dataFinal)); final Query query = getSession().createQuery(builder.toString()); query.setParameter("dataInicial", dataInicial); query.setParameter("dataFinal", dataFinal); List result = query.list(); log.info("Executou TicketDao.listarPorDataComentario qtde comentario do dia ==>> " + result.size()); return result; }
From source file:br.com.construtora.dao.financeiro.DespesasGeralDAO.java
public DespesasGeral findByTipoDespesas(String tipoDespesa) { session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w . j a va 2 s. c o m Query q = session.getNamedQuery("DespesasGeral.findByTpDesp"); q.setParameter("tpDesp", tipoDespesa); DespesasGeral despesasGeral = (DespesasGeral) q.uniqueResult(); session.getTransaction().commit(); return despesasGeral; }
From source file:br.com.digilabs.persistence.AbstractHibernateDaoImpl.java
License:Apache License
public List<T> find(String query, Object... values) { Query queryObject = getSession().createQuery(query); if (values != null) { for (int i = 0; i < values.length; i++) { queryObject.setParameter(i, values[i]); }/*from w w w. ja v a2s . c o m*/ } return queryObject.list(); }