package com.bergcomputers.ejb;

import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.bergcomputers.domain.Customer;

/**
 * Session Bean implementation class AccountController
 */
@Stateless
public class CustomerController implements ICustomerController{
	
	@PersistenceContext
	EntityManager  em;
	
	public CustomerController(){
		
	}
	
	public List<Customer> getCustomers()
	{
		return this.em.createNamedQuery(Customer.findAll).getResultList();
	}
	/*
	@PostConstruct
	public void init(){
	}
	*/

	@Override
	public Customer create(Customer customer) {
		if (null != customer && null == customer.getCreationDate()){
			customer.setCreationDate(new Date());
		}
		customer = em.merge(customer);
		em.persist(customer);
		em.flush();
		return customer;
	}

	/* (non-Javadoc)
	 * @see com.bergcomputers.ejb.ICustomerController#save(com.bergcomputers.domain.Customer)
	 

	@Override
	
	public void save(Customer customer)
	{
			this.em.merge(customer);
	}

	/* (non-Javadoc)
	 * @see com.bergcomputers.ejb.ICustomerController#findCustomer(long)
	 */
	
	@Override
	public Customer findCustomer(long id)
	{
		return this.em.find(Customer.class, id);
	}

	


	/* (non-Javadoc)
	 * @see com.bergcomputers.ejb.ICustomerController#delete(long)
	 */
	@Override
	public void delete(long customerid)
	{
		Customer item = findCustomer(customerid);
		if (item != null)
		{
			em.remove(item);
		}
	}
	
	

}



@@ -711,116 +711,8 @@
 ) %7B%0A
-%09%09if (null != customer && null == customer.getCreationDate())%7B%0A%09%09%09customer.setCreationDate(new Date());%0A%09%09%7D%0A
 %09%09cu
@@ -1432,16 +1432,266 @@
 %09%09%7D%0A%09%7D%0A%09
+@Override%0A%09public Customer update(long customerid, Customer customer)%7B%0A%09%09Customer  cust = (Customer)em.find(Customer.class ,customerid);%0A%09%09   cust.setFirstName(customer.getFirstName());%0A%09%09   cust.setLastName(customer.getLastName());%0A%09%09return cust;%0A%09%7D
 %0A%09%0A%0A%7D%0A%0A%0A

Test update v1