customerserviceimpl.java

来自「网上售书电子商务网站」· Java 代码 · 共 71 行

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

import com.briup.bean.Customer;
import com.briup.common.BeanFactory;
import com.briup.dao.ICustomerDao;
import com.briup.service.ICustomerService;
import com.briup.common.exception.CustomerServiceException;
import com.briup.common.transaction.HibernateTransaction;

public class CustomerServiceImpl implements ICustomerService {
	private ICustomerDao customerDao = 
				(ICustomerDao)BeanFactory.getBean(BeanFactory.CUSTOMERDAO);
	
	public Customer login(String name, String password)
			throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			Customer customer = customerDao.findCustomerByName(name);
			if(customer == null){
				throw new Exception("用户名不正确");
			}else if(!customer.getPassword().equals(password)){
				throw new Exception("密码不正确");
			}
			ht.commit();
			return customer;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ht.rollback();
			throw new CustomerServiceException(e.getMessage(),e);
		}
		
	}

	public void register(Customer customer) throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			Customer c = customerDao.findCustomerByName(customer.getName());
			if(c != null)
				throw new Exception("该用户名已经存在");
			customerDao.saveOrupdateCustomer(customer);
			ht.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ht.rollback();
			throw new CustomerServiceException(e.getMessage(),e);
		}
	}

	public void update(Customer customer) throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			customerDao.saveOrupdateCustomer(customer);
			ht.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ht.rollback();
			throw new CustomerServiceException(e.getMessage(),e);
		}
	}

}

⌨️ 快捷键说明

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