tddd05 ejb lab (part of slides reused from mikhail’s)

22
TDDD05 EJB Lab (Part of slides reused from Mikhail’s) Lu Li [email protected]

Upload: aliza

Post on 09-Jan-2016

33 views

Category:

Documents


1 download

DESCRIPTION

TDDD05 EJB Lab (Part of slides reused from Mikhail’s). Lu Li [email protected]. Agenda. EJB brief introduction Practical hints. Why EJB. EJBs is a powerful component model for building distributed, server-side, and Java-based enterprise application components. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

TDDD05 EJB Lab(Part of slides reused from Mikhail’s)

Lu [email protected]

Page 2: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Agenda

• EJB brief introduction• Practical hints

Page 3: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Why EJB

• EJBs is a powerful component model for building distributed, server-side, and Java-based enterprise application components.

• Code reuse by middleware service, such as object life-cycle management, resource (beans, database connection) mapping etc.

Page 4: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

EJB architecture

Page 5: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

EJB architecture

Page 6: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

EJB architecture

Page 7: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Connect Glassfish to Database

• Configure MySQL database• Copy driver to Glassfish directory• Configure a connection pool (For example

“TDDD05_MySQL”), and do a ping test• Configure JDBC resource (For example

“TDDD05_JDBC”) to use the connection pool (“TDDD05_MySQL”)

Page 8: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Create an JPA to use database

• JPA is a kind of EJB for interaction with database.

• Configure persistence.xml under META-INF folder, if no such xml file found, create one.

Page 9: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Create an Stateless Bean

• Create a EJB project• Add library appserv-rt.jar, j2ee.jar

Page 10: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Create an Stateless Bean

• Create an interface

Page 11: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Create an Stateless Bean

• Create an implementation

Page 12: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Deploy EJB

• Export jar• Start Glassfish• Copy jar file into the autodeploy directory• Check the file generated• There is another way to deploy. (Covered

later)

Page 13: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

JNDI lookup

Page 14: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

JNDI Application

Page 15: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Dependency injection

Page 16: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

DI Application

Page 17: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

DI Application

• Deployment(Glassfish_Home)/bin/asadmin deploy –

retrieve . Ex1-ee.ear• Execution

(Glassfish_Home)/bin/Appclient –client ./ex1-eeClient.jar –mainclass client.AppClient

Page 18: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Facade

Page 19: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Summary

• You needs a MySQL with a designed table.• You needs to make a Glassfish to know the

connection to your MySQL• You needs a JPA to use the connection and

interact with MySQL• You needs a Stateless session bean to use the

JPA.

Page 20: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Summary

• You needs to declare an interface to expose functionality to external clients.

• You needs a JNDI lookup client which can run independently

• You needs a DI client in connection with EJB (Two components are package in EAR project), to be deployed in Glassfish and invoke them by Appclient.

Page 21: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Some suggestions

• Try to understand how different components interact with each other at implementation level.

• Do a thorough unit testing before integrating all components together

• Today’s lesson covers most but not all steps needed for lab 2. Feel free to change some steps if you think it is necessary.

Page 22: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

Questions?