List of usage examples for org.hibernate Session createQuery
@Override org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
From source file:autoancillarieslimited.hiberate.dao.OrderDAO.java
public Long getTotalOrderByStatus(int status) { Long set = null;/*ww w .jav a 2 s . c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = (Long) session .createQuery("select count(*) from PurchaseOrder where Status like '" + status + "'") .uniqueResult(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.ProductDAO.java
public TypeItem getTypeItemByID(int id_Item) { TypeItem set = null;/* w w w.j a v a 2s . c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = (TypeItem) session.createQuery("from TypeItem where ID = ?").setInteger(0, id_Item) .uniqueResult(); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.ProductDAO.java
public List<Item> getItems(int pageNumber) { List<Item> set = null;//from w w w .ja v a 2 s . c om Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from Item ORDER BY Date_Created DESC") .setFirstResult((pageNumber - 1) * pageSize).setMaxResults(pageSize).list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.ProductDAO.java
public List<Item> getItems(Item filter, int page) { List<Item> set = null;/* w w w . java 2 s.c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); if (filter.getType_ID() != 0) { set = session.createQuery("from Item where Name like '%" + filter.getName() + "%' AND Type_ID ='" + filter.getType_ID() + "' ORDER BY Date_Created DESC").list(); } else { set = session .createQuery( "from Item where Name like '%" + filter.getName() + "%' ORDER BY Date_Created DESC") .list(); } session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.ProductDAO.java
public Long getCountItems(String category, String name) { Long set = null;/*from w w w . j a v a 2 s .c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); if (category != null && !category.equals("") && (name == null || name.equals(""))) { set = (Long) session.createQuery("select count(*) from Item where Type_ID ='" + category + "'") .uniqueResult(); } else if (name != null && !name.equals("")) { if (category != null && !category.equals("")) { set = (Long) session.createQuery("select count(*) from Item where Name like '%" + name + "%' AND Type_ID ='" + category + "' ").uniqueResult(); } else { set = (Long) session.createQuery("select count(*) from Item where Name like '%" + name + "%'") .uniqueResult(); } } else { set = (Long) session.createQuery("select count(*) from Item").uniqueResult(); } session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } long countPage = set / pageSize; if (set % pageSize > 0) { countPage++; } return countPage; }
From source file:autoancillarieslimited.hiberate.dao.ProductDAO.java
public List<TypeItem> getTypeItem() { List<TypeItem> set = null; Session session = null; Transaction beginTransaction = null; try {// w w w . jav a 2 s .com session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from TypeItem").list(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.PurchaseOrderDAO.java
public List<PurchaseOrder> getListByIDCustomer(int id) { List<PurchaseOrder> set = null; Session session = null; Transaction beginTransaction = null; try {/*from www . java2 s. co m*/ session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session .createQuery("from PurchaseOrder where ID_Customer like '" + id + "' ORDER BY dateOrder DESC") .list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.PurchaseOrderDAO.java
public List<PurchaseOrder> getListByIDCustomer(int id, String dateFrom, String dateTo) { List<PurchaseOrder> set = null; Session session = null; Transaction beginTransaction = null; try {//from w w w .j a va 2 s . com session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from PurchaseOrder where ID_Customer like '" + id + "' AND Date_Order >='" + dateFrom + "' AND Date_Order <='" + dateTo + "' ORDER BY dateOrder DESC").list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.PurchaseOrderDAO.java
public List<PurchaseOrder> getListByIDCustomer(int id, String dateFrom, String dateTo, String status) { List<PurchaseOrder> set = null; Session session = null; Transaction beginTransaction = null; try {/*from www . j a v a2 s .co m*/ session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from PurchaseOrder where ID_Customer like '" + id + "' AND Status like '" + status + "' AND Date_Order >='" + dateFrom + "' AND Date_Order <='" + dateTo + "' ORDER BY dateOrder DESC").list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.PurchaseOrderDAO.java
public List<PurchaseOrder> getListByIDCustomer(int id, String status) { List<PurchaseOrder> set = null; Session session = null; Transaction beginTransaction = null; try {// w w w . ja v a 2s . c o m session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery( "from PurchaseOrder where ID_Customer like '" + id + "' AND Status like '" + status + "'") .list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }