List of usage examples for org.hibernate Session createQuery
@Override org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
From source file:baking.dao.BaseDao.java
License:Open Source License
/** * HQL?//from w w w.ja va 2 s . c o m * @param hql HQL? * @param offset ??? * @param value ? * @param pageSize ?? * @return ?list */ public List findList(final String hql, final Object value, final int offset, final int pageSize) { try { Session session = getSession(); return session.createQuery(hql).setParameter(0, value).setFirstResult(offset).setMaxResults(pageSize) .list(); } catch (RuntimeException re) { throw re; } }
From source file:baking.dao.BaseDao.java
License:Open Source License
/** * HQL?/*from w w w . j a v a 2s .c o m*/ * @param hql HQL? * @param offset ??? * @param values ? * @param pageSize ?? * @return ?list */ public List findList(final String hql, final Object[] values, final int offset, final int pageSize) { try { Session session = getSession(); Query query = session.createQuery(hql); for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); } return query.setFirstResult(offset).setMaxResults(pageSize).list(); } catch (RuntimeException re) { throw re; } }
From source file:baking.dao.BaseDao.java
License:Open Source License
/** * HQL?/*from w ww. j a v a 2 s. co m*/ * @param hql HQL? * @param offset ??? * @param name where in?? * @param vals where in? * @param pageSize ?? * @return ?list */ public List findList(final String hql, final String name, final List vals, final int offset, final int pageSize) { try { Session session = getSession(); return session.createQuery(hql).setParameterList(name, vals).list(); } catch (RuntimeException re) { throw re; } }
From source file:baking.dao.BaseDao.java
License:Open Source License
/** * ?hql//from w w w .j a v a2s. co m * @description * @author JiaCao * @param hql */ @SuppressWarnings("unchecked") public void executeHql(final String hql) { try { Session session = getSession(); session.createQuery(hql).executeUpdate(); } catch (RuntimeException re) { throw re; } }
From source file:baking.dao.BaseDao.java
License:Open Source License
/** * ?hql/*from www . jav a 2s. c om*/ * @description * @author JiaCao * @param hql * @param value */ @SuppressWarnings("unchecked") public void executeHql(final String hql, final Object value) { try { Session session = getSession(); session.createQuery(hql).setParameter(0, value).executeUpdate(); } catch (RuntimeException re) { throw re; } }
From source file:baking.dao.BaseDao.java
License:Open Source License
/** * ?hql/* ww w .j a v a 2 s.c o m*/ * @description * @author JiaCao * @param hql * @param values */ @SuppressWarnings("unchecked") public void executeHql(final String hql, final Object[] values) { try { Session session = getSession(); Query query = session.createQuery(hql); for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); } query.executeUpdate(); } catch (RuntimeException re) { throw re; } }
From source file:banco.UsuarioDAO.java
public boolean checkRegister(Usuario usuario) { List<Usuario> listUsuario = new ArrayList<Usuario>(); Transaction trns = null;/*from ww w . jav a 2 s .co m*/ Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); listUsuario = session.createQuery("from Usuario").list(); for (Usuario key : listUsuario) { if (key.getSenha().equals(usuario.getSenha()) || key.getLogin().equals(usuario.getLogin())) { return false; } } } catch (RuntimeException e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return true; }
From source file:banco.UsuarioDAO.java
public long getIdByUser(Usuario usuario) { List<Usuario> listUsuario = new ArrayList<Usuario>(); Transaction trns = null;//from w w w . ja v a 2 s . co m Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); listUsuario = session.createQuery("from Usuario").list(); for (Usuario key : listUsuario) { if (key.getSenha().equals(usuario.getSenha()) && key.getLogin().equals(usuario.getLogin())) { return key.getId(); } } } catch (RuntimeException e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return -1; }
From source file:banco.UsuarioDAO.java
public boolean checkLogin(Usuario usuario) { List<Usuario> listUsuario = new ArrayList<Usuario>(); Transaction trns = null;//from w ww . ja v a2 s . c om Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); listUsuario = session.createQuery("from Usuario").list(); for (Usuario key : listUsuario) { if (key.getSenha().equals(usuario.getSenha()) && key.getLogin().equals(usuario.getLogin())) { return true; } } } catch (RuntimeException e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return false; }
From source file:bank.DAO.BillDAO.java
public List<Bill> listBill() { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w. j a va 2 s . c o m List<Bill> result = session.createQuery("from Bill order by id").list(); session.getTransaction().commit(); return result; }