📄 orderbusinessimpl.java
字号:
package cn.com.tarena.ecport.biz.impl;
import java.util.List;
import org.hibernate.HibernateException;
import cn.com.tarena.ecport.biz.IOrderBusiness;
import cn.com.tarena.ecport.common.util.HibernateUtil;
import cn.com.tarena.ecport.dao.IOrdersDAO;
import cn.com.tarena.ecport.dao.IUserDAO;
import cn.com.tarena.ecport.dao.factory.DAOFactory;
import cn.com.tarena.ecport.exception.ECPortException;
import cn.com.tarena.ecport.pojo.Orders;
import cn.com.tarena.ecport.pojo.User;
public class OrderBusinessImpl implements IOrderBusiness {
public void checkOut(Orders order) throws ECPortException {
IOrdersDAO iod = (IOrdersDAO) DAOFactory.getDAO(IOrdersDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
iod.save(order);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
}
public void deleteOrder(Orders order) throws ECPortException {
IOrdersDAO iod = (IOrdersDAO) DAOFactory.getDAO(IOrdersDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
iod.delete(order);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
}
public void deleteOrderById(Long orderid) throws ECPortException {
IOrdersDAO iod = (IOrdersDAO) DAOFactory.getDAO(IOrdersDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
Orders order = iod.findById(orderid);
iod.delete(order);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
}
public List<Orders> findAllOrders() throws ECPortException {
IOrdersDAO iod = (IOrdersDAO) DAOFactory.getDAO(IOrdersDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction();
List<Orders> orders = iod.findAllOrders();
HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction().commit();
return orders;
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction().rollback();
}
return null;
}
public Orders getOrderById(Long orderid) throws ECPortException {
IOrdersDAO iod = (IOrdersDAO) DAOFactory.getDAO(IOrdersDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
Orders order = iod.findById(orderid);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
return order;
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
return null;
}
public List<Orders> getOrderListByUserId(String userid)
throws ECPortException {
IOrdersDAO iod = (IOrdersDAO) DAOFactory.getDAO(IOrdersDAO.class.getName());
IUserDAO iud = (IUserDAO)DAOFactory.getDAO(IUserDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
User user = iud.findUserById(userid);
List<Orders> orders = iod.findByProperty("users", user);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
return orders;
} catch (Exception e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -