⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netstoreserviceimpl.java

📁 网上商城
💻 JAVA
字号:
package com.witbridge.netstore.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import com.witbridge.netstore.dao.CustomerDao;
import com.witbridge.netstore.dao.ItemDao;
import com.witbridge.netstore.dao.LineItemDao;
import com.witbridge.netstore.dao.OderDao;
import com.witbridge.netstore.factory.MyDaoImpl;
import com.witbridge.netstore.model.Customers;
import com.witbridge.netstore.model.Items;
import com.witbridge.netstore.model.LineItem;
import com.witbridge.netstore.model.Oder;
import com.witbridge.netstore.util.DBUtil;

public class NetStoreServiceImpl implements NetStoreService {
	ItemDao itemDao=MyDaoImpl.getItemDaoImpl();
	CustomerDao customerDao=MyDaoImpl.getCustomerDaoImpl();
	OderDao orderDao=MyDaoImpl.getOderDaoImpl();
	LineItemDao lineItemDao=MyDaoImpl.getLineItemDaoImpl();
	
	Connection conn=null;
	PreparedStatement pt=null;

	public void deleteItemById(Long id) {
		
		itemDao.deleteItem(id);
	}

	public Customers getCustomerById(Long id) {
		
		return customerDao.getCustomer(id);
	}

	public Items getItemById(Long id) {
		return itemDao.getItem(id);
	}

	public List<Items> getItems() {
		
		return itemDao.getAllItems();
	}

	public Customers login(String name, String password) {
		
		return customerDao.getCustomer(name, password);
	}

	public void newItem(Items item) {
		
		itemDao.addItem(item);
		
	}

	public int saveOrUpdateCustomer(Customers customer) {
		int i= customerDao.addCustomer(customer);
		return i;
	}

	public void saveOrder(Oder order) {
		
		List<LineItem> lineItems=order.getLineItems();
		try {
			conn=DBUtil.getIstance().getConn(false);
			int i = orderDao.addOder(conn, order);
			for(LineItem lineItem:lineItems){
				int j = lineItemDao.addLineItem(conn, lineItem);
			}
			conn.commit();
			DBUtil.rollback(conn);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}

⌨️ 快捷键说明

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