The business logic of the application is represented with a session bean named Project Facade. You need to create a separate Java package that stores the session bean and then manually add the implementation that is required.
From the context menu of the app_ejb, choose
.Enter the following package name com.sap.nwce.ra.sedm.ejb.service .
Enter ProjectFacade for the EJB class name and choose Finish.
Inject a persistence manager field to use the Entity Manager.
Syntax
@PersistenceContext(unitName = "ems/EJB3_simpl_EDM_DEMO_PU") protected EntityManager em;
With the Entity Manager you can effectively and easily manage your application entities.
Add the following implementation:
Syntax
public List< Project> findProjects(String nameDescrPtrn){ Query q = ("".equals(nameDescrPtrn)) ? em.createNamedQuery( "Project.getAll" ) : em.createNamedQuery( "Project.findByNameOrDescPart" ) ; if ( ! "".equals(nameDescrPtrn)){ q.setParameter("namepart", "%" + nameDescrPtrn + "%"); q.setParameter("namepart1", "%" + nameDescrPtrn + "%"); } return q.getResultList(); } public List< Employee> findEmployees(String nameDescrPtrn){ Query q = ("".equals(nameDescrPtrn)) ? em.createNamedQuery( "Employee.getAll" ) : em.createNamedQuery( "Employee.findByNamePart" ) ; if ( ! "".equals(nameDescrPtrn)){ q.setParameter("namepart", "%" + nameDescrPtrn + "%"); q.setParameter("namepart1", "%" + nameDescrPtrn + "%"); } return q.getResultList(); } public void saveProject(Project proj){ em.merge(proj); } public void saveEmployee(Employee empl){ em.merge(empl); } public Project getProjectById(int id){ Query q = em.createNamedQuery( "Project.getByProjectID" ); q.setParameter("prjId", id); return (Project) q.getSingleResult(); } public Employee getEmployeeById(int id){ Query q = em.createNamedQuery( "Employee.getById" ); q.setParameter("id", id); return (Employee) q.getSingleResult(); }
From the secondary mouse button, select
.Add all the methods to local interface by choosing the corresponding method from the Outline view, then from its context menu choose EJB methods—> Add to local Interfaces.