tddd05 ejb lab (part of slides reused from mikhail’s)
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 PresentationTRANSCRIPT
![Page 2: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/2.jpg)
Agenda
• EJB brief introduction• Practical hints
![Page 3: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/3.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/4.jpg)
EJB architecture
![Page 5: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/5.jpg)
EJB architecture
![Page 6: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/6.jpg)
EJB architecture
![Page 7: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/7.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/8.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/9.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/10.jpg)
Create an Stateless Bean
• Create an interface
![Page 11: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/11.jpg)
Create an Stateless Bean
• Create an implementation
![Page 12: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/12.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/13.jpg)
JNDI lookup
![Page 14: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/14.jpg)
JNDI Application
![Page 15: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/15.jpg)
Dependency injection
![Page 16: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/16.jpg)
DI Application
![Page 17: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/17.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/18.jpg)
Facade
![Page 19: TDDD05 EJB Lab (Part of slides reused from Mikhail’s)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/19.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/20.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/21.jpg)
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)](https://reader035.vdocuments.us/reader035/viewer/2022062422/56814038550346895daba4a3/html5/thumbnails/22.jpg)
Questions?