Example usage for org.hibernate Session clear

List of usage examples for org.hibernate Session clear

Introduction

In this page you can find the example usage for org.hibernate Session clear.

Prototype

void clear();

Source Link

Document

Completely clear the session.

Usage

From source file:autoancillarieslimited.hiberate.dao.OrderDAO.java

public Long getTotalOrder() {
    Long set = null;/*from   w  w  w . java  2 s .c  om*/
    Session session = null;
    Transaction beginTransaction = null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        beginTransaction = session.beginTransaction();
        set = (Long) session.createQuery("select count(*) from PurchaseOrder").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.OrderDAO.java

public Long getTotalOrder(String dateFrom, String dateTo) {
    Long set = null;/* w ww . j  a v  a 2  s.c om*/
    Session session = null;
    Transaction beginTransaction = null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        beginTransaction = session.beginTransaction();
        set = (Long) session.createQuery("select count(*) from PurchaseOrder where Date_Order >='" + dateFrom
                + "' AND Date_Order <='" + dateTo + "'").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.OrderDAO.java

public Long getTotalOrderByStatus(int status) {
    Long set = null;/*from  ww w  . j av  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;//from  w  w w.j  a va2 s  .  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.  j ava  2  s .co  m
    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  ww. ja  va  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;//w w  w.  ja  v a2s  .  co 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.PurchaseOrderDAO.java

public List<PurchaseOrder> getListByIDCustomer(int id) {
    List<PurchaseOrder> set = null;
    Session session = null;
    Transaction beginTransaction = null;
    try {// w ww.  jav  a  2 s.  c  o  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  ww  .  ja  v a2 s  .c om
        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 w w  w.  j ava  2  s.  c  o 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;
}