Package com.finiac.dao

Source Code of com.finiac.dao.BillDAOImpl

package com.finiac.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.finiac.model.Bill;

public class BillDAOImpl implements BillDAO {

private HibernateTemplate hibernateTemplate;
 
  public void setSessionFactory(SessionFactory sessionFactory){
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
  }
 
 
  @SuppressWarnings("unchecked")
  @Override
  public long createBill(Bill bill)
  {
    hibernateTemplate.save(bill);
    Bill lastBill = new Bill();
    List<Bill> billList = hibernateTemplate.find("from Bill where id = (select max(id) from Bill)");
    for(int i=0;i<billList.size();i++)
    {
      lastBill = billList.get(i);
    }
    return lastBill.getId();
   
  }


  @SuppressWarnings("unchecked")
  @Override
  public long lastBillId()
  {
    Bill lastBill = new Bill();
    List<Bill> billList = hibernateTemplate.find("from Bill where id = (select max(id) from Bill)");
    for(int i=0;i<billList.size();i++)
    {
      lastBill = billList.get(i);
    }
    return lastBill.getId();
   
  }


  @SuppressWarnings("unchecked")
  @Override
  public Bill selectBill(long id) {
    Bill bill = new Bill();
    List<Bill> billList = hibernateTemplate.find("from Bill where id ="+id);
    for(int i=0;i<billList.size();i++)
    {
      bill = billList.get(i);
    }
    return bill;
  }


  @Override
  public void updateBill(Bill bill) {
    hibernateTemplate.update(bill);
   
  }
 
 

}
TOP

Related Classes of com.finiac.dao.BillDAOImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.