Example usage for org.hibernate Session flush

List of usage examples for org.hibernate Session flush

Introduction

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

Prototype

void flush() throws HibernateException;

Source Link

Document

Force this session to flush.

Usage

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

public Long getTotalOrder(String dateFrom, String dateTo) {
    Long set = null;//from  ww w .  j a  va  2s .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 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 www  . ja v a 2s  .  co 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;//  www  . j a v  a  2  s.  co  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  a va  2 s . com*/
    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;//from  ww w .  jav  a  2 s .com
    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 ww. ja v a 2s.  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 {//from  w  w w.  java2 s.c  om
        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  ww  w.j  a  v  a  2s .co  m*/
        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  ww  w.  j  av a 2s  .c om*/
        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 {/*from w  w w .ja v a  2  s. c om*/
        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;
}