TDDD05 EJB Lab (Part of slides reused from Mikhails) Lu - - PowerPoint PPT Presentation

tddd05 ejb lab part of slides reused from mikhail s
SMART_READER_LITE
LIVE PREVIEW

TDDD05 EJB Lab (Part of slides reused from Mikhails) Lu - - PowerPoint PPT Presentation

TDDD05 EJB Lab (Part of slides reused from Mikhails) Lu Li lu.li@liu.se Agenda EJB brief introducDon PracDcal hints Why EJB EJBs is a


slide-1
SLIDE 1

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

Lu ¡Li ¡ lu.li@liu.se ¡

slide-2
SLIDE 2

Agenda ¡

  • EJB ¡brief ¡introducDon ¡
  • PracDcal ¡hints ¡
slide-3
SLIDE 3

Why ¡EJB ¡

  • EJBs ¡is ¡a ¡powerful ¡component ¡model ¡for ¡

building ¡distributed, ¡server-­‑side, ¡and ¡Java-­‑ based ¡enterprise ¡applicaDon ¡components. ¡

  • Code ¡reuse ¡by ¡middleware ¡service, ¡such ¡as ¡
  • bject ¡life-­‑cycle ¡management, ¡resource ¡

(beans, ¡database ¡connecDon) ¡mapping ¡etc. ¡

slide-4
SLIDE 4

EJB ¡architecture ¡

slide-5
SLIDE 5

EJB ¡architecture ¡

slide-6
SLIDE 6

EJB ¡architecture ¡

slide-7
SLIDE 7

Connect ¡Glassfish ¡to ¡Database ¡

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

“TDDD05_MySQL”), ¡and ¡do ¡a ¡ping ¡test ¡

  • Configure ¡JDBC ¡resource ¡(For ¡example ¡

“TDDD05_JDBC”) ¡to ¡use ¡the ¡connecDon ¡pool ¡ (“TDDD05_MySQL”) ¡

slide-8
SLIDE 8

Create ¡an ¡JPA ¡to ¡use ¡database ¡

  • JPA ¡is ¡a ¡kind ¡of ¡EJB ¡for ¡interacDon ¡with ¡
  • database. ¡
  • Configure ¡persistence.xml ¡under ¡META-­‑INF ¡

folder, ¡if ¡no ¡such ¡xml ¡file ¡found, ¡create ¡one. ¡

slide-9
SLIDE 9

Create ¡an ¡Stateless ¡Bean ¡

  • Create ¡a ¡EJB ¡project ¡
  • Add ¡library ¡appserv-­‑rt.jar, ¡j2ee.jar ¡
slide-10
SLIDE 10

Create ¡an ¡Stateless ¡Bean ¡

  • Create ¡an ¡interface ¡
slide-11
SLIDE 11

Create ¡an ¡Stateless ¡Bean ¡

  • Create ¡an ¡implementaDon ¡

¡

slide-12
SLIDE 12

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) ¡

slide-13
SLIDE 13

JNDI ¡lookup ¡

slide-14
SLIDE 14

JNDI ¡ApplicaDon ¡

slide-15
SLIDE 15

Dependency ¡injecDon ¡

slide-16
SLIDE 16

DI ¡ApplicaDon ¡

slide-17
SLIDE 17

DI ¡ApplicaDon ¡

  • Deployment ¡

¡(Glassfish_Home)/bin/asadmin ¡deploy ¡– retrieve ¡. ¡Ex1-­‑ee.ear ¡

  • ExecuDon ¡

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

slide-18
SLIDE 18

Facade ¡

slide-19
SLIDE 19

Summary ¡

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

connecDon ¡to ¡your ¡MySQL ¡

  • You ¡needs ¡a ¡JPA ¡to ¡use ¡the ¡connecDon ¡and ¡

interact ¡with ¡MySQL ¡

  • You ¡needs ¡a ¡Stateless ¡session ¡bean ¡to ¡use ¡the ¡
  • JPA. ¡ ¡
slide-20
SLIDE 20

Summary ¡

  • You ¡needs ¡to ¡declare ¡an ¡interface ¡to ¡expose ¡

funcDonality ¡to ¡external ¡clients. ¡

  • You ¡needs ¡a ¡JNDI ¡lookup ¡client ¡which ¡can ¡run ¡

independently ¡

  • You ¡needs ¡a ¡DI ¡client ¡in ¡connecDon ¡with ¡EJB ¡

(Two ¡components ¡are ¡package ¡in ¡EAR ¡project), ¡ to ¡be ¡deployed ¡in ¡Glassfish ¡and ¡invoke ¡them ¡ by ¡Appclient. ¡

slide-21
SLIDE 21

Some ¡suggesDons ¡

  • Try ¡to ¡understand ¡how ¡different ¡components ¡

interact ¡with ¡each ¡other ¡at ¡implementaDon ¡

  • level. ¡
  • Do ¡a ¡thorough ¡unit ¡tesDng ¡before ¡integraDng ¡

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. ¡

slide-22
SLIDE 22

QuesDons? ¡ ¡