Example usage for org.hibernate SessionFactory getCurrentSession

List of usage examples for org.hibernate SessionFactory getCurrentSession

Introduction

In this page you can find the example usage for org.hibernate SessionFactory getCurrentSession.

Prototype

Session getCurrentSession() throws HibernateException;

Source Link

Document

Obtains the current session.

Usage

From source file:automatedbillingsoftware_DA.Categories_DA.java

public List<Categories> searchCategories(String searchKeyWord) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createSQLQuery("Select * from categories_tbl  where catName like  '%" + searchKeyWord
            + "%' OR catDesc like  '%" + searchKeyWord + "%'AND status=1");
    Categories category = new Categories();
    List list = query.list();//w w  w  .j  a v  a2  s  . co  m
    List<Categories> catList = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        Object[] cat = (Object[]) list.get(i);
        int id = (Integer) cat[0];
        String name = (String) cat[3];
        String description = (String) cat[1];
        Date dt = (Date) cat[2];
        int status = (Integer) cat[5];
        double discount = (Double) cat[4];
        category = new Categories();
        category.setCatDesc(description);
        category.setCatName(name);
        category.setCatModifiedDate(dt);
        category.setDiscount(discount);
        category.setStatus(status);
        category.setCatid(id);
        catList.add(category);

    }

    beginTransaction.commit();
    return catList;
}

From source file:automatedbillingsoftware_DA.Categories_DA.java

public List<Categories> fetchCategorieses() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Categories c where c.status=:status");
    query.setParameter("status", 1);
    List<Categories> catList = (List<Categories>) query.list();
    beginTransaction.commit();/* w ww .jav  a 2 s .c om*/
    return catList;
}

From source file:automatedbillingsoftware_DA.Categories_DA.java

public void updateCategory(Categories cat) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    cat.setCatModifiedDate(new Date());
    //        System.out.println("update =>" + cat.getCatName());
    //        String name=cat.getCatName();
    // cat = (Categories) session.load(Categories.class, cat.getCatid());
    //cat.setCatName(name);
    session.update(cat);/* w w w.j ava2 s. c  om*/
    // session.flush();
    beginTransaction.commit();
}

From source file:automatedbillingsoftware_DA.Categories_DA.java

public void deleteCategory(Categories cat) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    cat.setCatModifiedDate(new Date());
    cat.setStatus(0);//from  w  ww  . j  ava2s.  co  m
    // cat = (Categories) session.load(Categories.class, cat.getCatid());
    //session.delete(cat);
    //session.flush();
    session.update(cat);
    beginTransaction.commit();
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public Challan addChallan(Challan challan) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.persist(challan);/*from  w  w  w . jav  a2  s . c  o  m*/
    beginTransaction.commit();

    return challan;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public ChallanGenerated saveChallanGen(ChallanGenerated challan) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    challan.setStatus(1);/*  w w  w  . j  a  v a2s .  c  o m*/
    session.saveOrUpdate(challan);
    beginTransaction.commit();

    return challan;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public ChallanGenerated fetchChallanGenById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from ChallanGenerated where status=:status and id=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<ChallanGenerated> challanList = (List<ChallanGenerated>) query.list();
    beginTransaction.commit();/*from w w  w  .  ja  v a 2s  .co  m*/

    return (challanList == null || challanList.size() == 0) ? null : challanList.get(0);
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public ChallanGenerated updateChallanGen(ChallanGenerated challan) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.update(challan);/*from  www  .  j  a  v a2s .c o m*/
    session.flush();
    beginTransaction.commit();

    return challan;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public List<Challan> fetchAllChallanList() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Challan where status=:status");
    query.setParameter("status", 1);
    List<Challan> challanList = (List<Challan>) query.list();
    beginTransaction.commit();//from w  w w.j  a v a 2 s .  co  m

    return challanList;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public void deleteChallan(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Challan where status=:status AND id=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<Challan> challanList = (List<Challan>) query.list();
    Challan challan = challanList.get(0);
    challan.setStatus(0);/*from   w  w w. j  a va  2  s  . com*/
    session.update(challan);
    beginTransaction.commit();
}