/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dao_impl;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import dao.BillDAO;
import dao.DeliverstatusDAO;
import dao.PriceDAO;
import pojo.Bill;
import pojo.Billdetail;
import pojo.Deliverstatus;
import pojo.Price;
import util.HibernateUtil;
/**
*
* @author phuc
*/
public class DeliverstatusDAOImpl implements DeliverstatusDAO {
private static final Logger logger = Logger.getLogger(DeliverstatusDAOImpl.class);
//get all List Deliverstatus
public List<Deliverstatus> getListDeliverstatus(){
logger.debug("getListDeliverstatus start");
List<Deliverstatus> ds = null;
Session session = HibernateUtil.getSessionFactory().openSession();
try {
String hql = "from Deliverstatus";
Query query = session.createQuery(hql);
ds = query.list();
logger.debug("getListDeliverstatus success");
} catch (HibernateException ex) {
System.err.println(ex);
logger.error("getListDeliverstatus error : " + ex);
} finally {
session.close();
}
logger.debug("getListDeliverstatus end");
return ds;
}
//get Info Deliverstatus by id
public Deliverstatus getInfoDeliverstatus(Integer id) {
logger.debug("getInfoDeliverstatus by id start");
Deliverstatus sp = null;
Session session = HibernateUtil.getSessionFactory().openSession();
try {
sp = (Deliverstatus) session.get(Deliverstatus.class, id);
logger.debug("getInfoDeliverstatus by id success");
} catch (HibernateException ex) {
System.err.println(ex);
logger.error("getInfoDeliverstatus by id error : " + ex);
} finally {
session.close();
}
logger.debug("getInfoDeliverstatus by id end");
return sp;
}
//add Deliverstatus
public boolean addDeliverstatus(Deliverstatus sp) {
logger.debug("addDeliverstatus start");
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
session.save(sp);
transaction.commit();
logger.debug("addDeliverstatus success");
} catch (HibernateException ex) {
transaction.rollback();
logger.error("addDeliverstatus error : " + ex);
} finally {
session.close();
}
logger.debug("addDeliverstatus end");
return true;
}
//delete Deliverstatus
public boolean delDeliverstatus(int id) {
logger.debug("delDeliverstatus start");
Session session = HibernateUtil.getSessionFactory().openSession();
Deliverstatus u = (Deliverstatus) session.get(Deliverstatus.class, id);
Transaction transaction = null;
try {
transaction = session.beginTransaction();
session.delete(u);
transaction.commit();
logger.debug("delDeliverstatus success");
} catch (HibernateException ex) {
transaction.rollback();
System.err.println(ex);
logger.error("delDeliverstatus error : " + ex);
} finally {
session.close();
}
logger.debug("delDeliverstatus end");
return true;
}
public Deliverstatus getDefaultDeliverstatus() {
return getInfoDeliverstatus(1);
}
}