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.CompanyDetailsDA.java

public void updateCurrentCompany(Company comp) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();//w  ww.j av  a 2 s .com
    Query query = session.createQuery("from Company c where c.companyId=:id");
    query.setParameter("id", UserSession.getCompany().getCompanyId());
    Company com = (Company) query.list().get(0);
    com.setAddress(comp.getAddress());
    com.setCompanyName(comp.getCompanyName());
    com.setCountry(comp.getCountry());
    com.setDateOfInsertion(comp.getDateOfInsertion());
    com.setEmail(comp.getEmail());
    com.setLogo(comp.getLogo());
    com.setName(comp.getName());
    com.setPanNo(comp.getPanNo());
    com.setPassword(comp.getPassword());
    com.setPhone(comp.getPhone());
    com.setStatus(1);
    com.setTax(comp.getTax());
    com.setVatNo(comp.getVatNo());
    com.setWebsite(comp.getWebsite());

    session.update(com);
    UserSession.setCompany(com);
    session.getTransaction().commit();

}

From source file:automatedbillingsoftware_DA.InvoiceReport_DA.java

public InvoiceReport saveInvoiceReport(InvoiceReport invReport) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.saveOrUpdate(invReport);//from  w  w w. j  ava2 s  .  c  o m
    beginTransaction.commit();

    return invReport;
}

From source file:automatedbillingsoftware_DA.InvoiceReport_DA.java

public List<InvoiceReport> fetchAllInvoiceReport() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from InvoiceReport where status =:status");
    query.setParameter("status", 1);
    List<InvoiceReport> invoiceReportList = query.list();
    beginTransaction.commit();//from   w ww .ja  v  a2  s .  c o m
    return invoiceReportList;
}

From source file:automatedbillingsoftware_DA.InvoiceReport_DA.java

public InvoiceReport updateInvoiceReport(InvoiceReport invReport) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.update(invReport);//from   w  w w . j  av  a  2 s  . c  o  m
    beginTransaction.commit();
    return invReport;
}

From source file:automatedbillingsoftware_DA.InvoiceReport_DA.java

public List<InvoiceReport> searchInvoiceReport(Date frmDate, Date toDate, int orderNo, String docName,
        int docNo) {
    List<InvoiceReport> invoiceList = new LinkedList<>();
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from InvoiceReport where status =:status");
    query.setParameter("status", 1);
    List<InvoiceReport> invoiceReportList = query.list();

    List<InvoiceReport> searchList = new LinkedList<>();

    for (int i = 0; i < invoiceReportList.size(); i++) {
        if (invoiceReportList.get(i).getOrderNo() == (double) orderNo
                || (invoiceReportList.get(i).getBillDate().compareTo(toDate) <= 0
                        && invoiceReportList.get(i).getBillDate().compareTo(frmDate) >= 0)
                || new ChallanBL().fetchChallanByDocName(docName) != null) {
            searchList.add(invoiceReportList.get(i));
        }// w w w  .  j a v  a2 s. c  o  m
    }

    beginTransaction.commit();
    System.out.println("searchList=>" + searchList);
    return searchList;

}

From source file:automatedbillingsoftware_DA.Products_DA.java

public Products addProducts(Products prod) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.saveOrUpdate(prod);//from   w w  w. j a v  a2  s .  c  o  m
    beginTransaction.commit();
    return prod;
}

From source file:automatedbillingsoftware_DA.Products_DA.java

public void deleteProducts(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Products p where p.status=:status AND p.prodid=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<Products> list = (List<Products>) query.list();
    Products get = list.get(0);//from   w  ww  .  j a  v  a2 s.  c om
    get.setStatus(0);
    session.update(get);
    beginTransaction.commit();

}

From source file:automatedbillingsoftware_DA.Products_DA.java

public void updateProduct(Products prod) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.update(prod);//from   w  ww  .j  a v  a 2  s . co  m

    beginTransaction.commit();

}

From source file:automatedbillingsoftware_DA.Products_DA.java

public Products fetchProductById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Products p where p.status=:status AND p.prodid=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<Products> list = (List<Products>) query.list();
    Products get = list.get(0);/*from   w  w  w  .  j  av a 2 s  .  c  o m*/

    beginTransaction.commit();
    return get;
}

From source file:automatedbillingsoftware_DA.Products_DA.java

public List<Products> fetchAllProducts() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Products p where status=:status");
    query.setParameter("status", 1);
    List<Products> list = (List<Products>) query.list();
    beginTransaction.commit();/* w ww  . j av a 2 s  . co  m*/
    return list;
}