16.10.2015 Views

Getting Started with WebSphere Application Server

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

104 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> Community Edition<br />

}<br />

Listing 5.14 – Definition of StudentEJBInterface<br />

package com.ibm.start.wasce.studentejb;<br />

……<br />

@Stateless<br />

public class StudentEJB implements StudentEJBInterface {<br />

@PersistenceUnit(unitName = "Student")<br />

EntityManagerFactory emf;<br />

public List calculateCredit() {<br />

EntityManager em = emf.createEntityManager();<br />

List creditList = new ArrayList();<br />

Query query =<br />

em.createQuery("select s from Student AS s order by s.id");<br />

List sutdentList = query.getResultList();<br />

for (Student student : sutdentList) {<br />

int credit = (int) ((float) (student.getScore1()<br />

+ student.getScore2() + student.getScore3()) / 300 * 5);<br />

student.setCredit(credit);<br />

creditList.add(credit);<br />

}<br />

em.flush();<br />

em.close();<br />

return creditList;<br />

}<br />

}<br />

Listing 5.15 – Implementation of StudentEJB<br />

Step 2:<br />

Right click ejb-studentejb -> Build Path -> Configure Build Path -> Projects, add ejbstudentjpa<br />

project on build path<br />

Step 3:<br />

Right click ejb-studentejb -> Properties ->Project Reference, click ejb-studentjpa as a<br />

reference<br />

7. Create a Dynamic Web Project<br />

Step 1:<br />

In Eclipse click on File -> New -> Other…-> Dynamic Web Project to create a dynamic<br />

Web project ejb-studentweb.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!