THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
// CustomerServiceJavaBean.java package com.service.customer.web; import com.service.customer.ejb.Customer; import com.service.customer.ejb.ProcessCustomerSessionLocal; import java.util.Locale; import java.util.ResourceBundle; import java.util.List; import javax.naming.InitialContext; public class CustomerServiceJavaBean { private ProcessCustomerSessionLocal process = null; private ResourceBundle bundle = null; private String JNDI_PROCESS_EJB = null; private String action = ""; private String customerID = ""; private String fullName = ""; private String emailAddress = ""; public class CustomerServiceJavaBean { private ProcessCustomerSessionLocal process = null; private StringResourceBundle interestsbundle = ""null; public CustomerServiceJavaBean() { InitialContext initial = null; bundle = ResourceBundle.getBundle("customer", Locale.getDefault(), CustomerServiceJavaBean.class.getClassLoader()); String JNDI_PROCESS_EJBjndiName = bundle.getString("jndi.process.ejb"); try { initial = new InitialContext(); process = (ProcessCustomerSessionLocal) initial.lookup(JNDI_PROCESS_EJBjndiName.trim()); System.out.println("Successful looking up: '" + JNDI_PROCESS_EJBjndiName.trim() + "'"); } // end try catch (Exception e) { e.printStackTrace(); } // end catch } // end CustomerServiceJavaBean public List<Customer> getAllCustomers() { List<Customer> customerList = null; try { customerList = process.findAllCustomers(); } // end try catch (Exception e) { customerList = null; e.printStackTrace(); } // end catch return customerList; } // end getAllCustomerss } // end CustomerServiceJavaBean |
ProcessCustomerSessionBean.java implements ProcessCustomerSessionLocal by grabbing an EntityManagerFactory by making use of the persistence.xml. It grabs it by using the @PersistenceUnit annotation. Since there is only one persistence unit defined in persistence.xml, we do not need to specify any additional parameters in the annotation.
...