orderserviceimpl.java

来自「网上书城源代码~~在学习JAVA的时候做的」· Java 代码 · 共 90 行

JAVA
90
字号
package com.briup.service.impl;

import java.util.Map;

import com.briup.bean.Book;
import com.briup.bean.Orderform;
import com.briup.common.BeanFactory;
import com.briup.common.exception.OrderServiceException;
import com.briup.common.transaction.HibernateTransaction;
import com.briup.dao.IOrderDao;
import com.briup.service.IOrderService;

public class OrderServiceImpl implements IOrderService {
	private IOrderDao orderDao;
	public OrderServiceImpl(){
		orderDao=(IOrderDao) BeanFactory.getBean(BeanFactory.ORDERDAO);
	}
	public void delOrder(Long orderid) throws OrderServiceException {
		HibernateTransaction tran=new HibernateTransaction();
		tran.beginTransaction();
		try {
			orderDao.deleteOrder(orderid);
			tran.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tran.rollback();
			throw new OrderServiceException("订单删除失败!");
		}
	}

	public Orderform findOrderById(Long orderid) throws OrderServiceException {
		HibernateTransaction tran=new HibernateTransaction();
		tran.beginTransaction();
		Orderform orderform=null;
		try {
			orderform=orderDao.findOrderById(orderid);
			tran.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tran.rollback();
			throw new OrderServiceException("查询失败!");
		}
		return orderform;
	}

	public Map<Long,Orderform> listAllOrder(Long customerid) throws OrderServiceException {
		HibernateTransaction tran=new HibernateTransaction();
		tran.beginTransaction();
		Map<Long,Orderform> orderform=null;
		try {
			orderform=orderDao.findAllOrder(customerid);
			tran.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tran.rollback();
			throw new OrderServiceException("查询失败!");
		}
		return orderform;
	}

	public void saveOrder(Orderform order) throws OrderServiceException {
		HibernateTransaction tran=new HibernateTransaction();
		tran.beginTransaction();
		try {
			orderDao.saveOrder(order);
			tran.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tran.rollback();
			throw new OrderServiceException("提交订单不成功!");
		}
	}

	public Map<Long,Book> listAllBook() throws OrderServiceException {
		Map<Long,Book> books=null;
		HibernateTransaction tran=new HibernateTransaction();
		tran.beginTransaction();
		try {
			books=orderDao.findAllBook();
			tran.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tran.rollback();
			throw new OrderServiceException("查询书籍出错!");
		}
		return books;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?