Tải bản đầy đủ - 0 (trang)
Chapter 23. Exercises for Chapter 5

Chapter 23. Exercises for Chapter 5

Tải bản đầy đủ - 0trang

23.1Exercise5.1:TheRemoteComponent

Interfaces

TheexampleprogramsinExercise5.1diveintosomeofthe

featuresofthehomeinterfaceofanEJB,includingtheuseof

theremove()method.Theyalsoshowyouhowtoobtainand

usevariousmetadataavailablethroughanEJB'sAPI.



23.1.1StartUpJBoss

IfyoualreadyhaveJBossrunning,thereisnoreasontorestart

it.Otherwise,startitupasinstructedintheJBossInstallation

andConfigurationchapteratthebeginningofthisworkbook.



23.1.2InitializetheDatabase

Thedatabaseshouldcontainthe100rowscreatedbya

successfulexecutionofthetestprogramsfromExercise4.1.



23.1.3BuildandDeploytheExamplePrograms

Performthefollowingsteps:

1. Openacommandpromptorshellterminaland

changetotheex05_1directorycreatedbythe

extractionprocess.

SettheJAVA_HOMEandJBOSS_HOMEenvironmentvariablesto

pointtowhereyourJDKandJBoss4.0areinstalled.Examples:



Windows:

C:\workbook\ex05_1>setJAVA_HOME=C:\jdk1.4.2

C:\workbook\ex05_1>setJBOSS_HOME=C:\jboss-4.0



Unix:

$exportJAVA_HOME=/usr/local/jdk1.4.2

$exportJBOSS_HOME=/usr/local/jboss-4.0



Addanttoyourexecutionpath.

Windows:

C:\workbook\ex05_1>setPATH=..\ant\bin;%PATH%

Unix:

$exportPATH=../ant/bin:$PATH



Performthebuildbytypingant.

Asinthelastexercise,youwillseetitan.jarrebuilt,copiedto

theJBossdeploydirectory,andredeployedbytheapplication

server.



23.1.4ExaminetheJBoss-SpecificFiles



TherearenonewJBossconfigurationfilesorcomponentsin

thisexercise.



23.1.5ExamineandRuntheClientApplications

Twoexampleprogramsillustratetheconceptsexplainedinthe

EJBbook:



Client_51a.java

Illustratestheuseoftheremove()methodontheCabin

EJBhomeinterface.



Client_51b.java

Illustratestheuseofbeanmetadatamethods.

TheexamplecodeforClient_51aandClient_51bispulled

directlyfromtheEJBbook.Thereisnoneedtogointothiscode

herebecausetheEJBbookalreadydoesaverygoodjobof

that.

RunClient_51abyinvokingantrun.client_51aatthe

commandprompt.RemembertosetyourJBOSS_HOMEandPATH

environmentvariables.RunClient_51bthesameway:ant

run.client_51b.TheoutputofClient_51ashouldbeexactlyas

describedintheEJBbook.TheoutputofClient_51bisas

follows:

C:\workbook\ex05_1>antrun.client_51b

Buildfile:build.xml



prepare:



compile:



run.client_51b:

[java]com.titan.cabin.CabinHomeRemote

[java]com.titan.cabin.CabinRemote

[java]java.lang.Integer

[java]false

[java]MasterSuite



NotethatifyoutrytorunClient_51amorethanonce,an

exceptionwilltellyouthattheentityyou'reattemptingto

removedoesnotexist.



[java]java.rmi.NoSuchObjectException:Entitynotfound:primar



23.2Exercise5.2:TheEJBObject,Handle,and

PrimaryKey

TheexampleprogramsinExercise5.2exploretheAPIs

availablethroughtheEJBObjectandEJBMetaDatainterfaces.

TheyalsorevealhowtouseHandleandHomeHandleas

persistentreferencestoEJBobjectsandhomes.



23.2.1StartUpJBoss

IfyoualreadyhaveJBossrunning,thereisnoreasontorestart

it.Otherwise,startitupasinstructedintheJBossInstallation

andConfigurationchapteratthebeginningofthisworkbook.



23.2.2InitializetheDatabase

Thedatabaseshouldcontainthe100rowscreatedbya

successfulexecutionofthetestprogramsfromExercise4.1;

otherwise,thisexamplewillnotworkproperly.



23.2.3BuildandDeploytheExamplePrograms

Intheex05_2directory,buildanddeploytheexamplesasyou

didforExercise5.1.



23.2.4ExaminetheJBoss-SpecificFiles

TherearenonewJBossconfigurationfilesorcomponentsin

thisexercise.



23.2.5ExamineandRuntheClientApplications

Threeexampleprogramsillustratetheconceptsexplainedinthe

EJBbook:



Client_52a.java

ShowstheuseofEJBObjecttoretrieveanEJB'shome

interface.



Client_52b.java

ShowshowtouseisIdentical()todeterminewhether

twoEJBreferencesaretothesameobject.



Client_52c.java

ShowshowtouseEJBhandlesaspersistentbean

references.

TheexamplecodeispulleddirectlyfromtheEJBbookand

embellishedsomewhattoexpandonintroducedconcepts.The

EJBbookdoesaprettygoodjobofexplainingtheconcepts

illustratedintheexampleprograms,sofurtherexplanationof

thecodeisnotneededinthisworkbook.

RunClient_52a,Client_52b,andClient_52cbyinvokingthe

appropriateAnttaskasyoudidinpreviousexamples:

run.client_52a,run.client_52b,andrun.client_52c.

RemembertosetyourJBOSS_HOMEandPATHenvironment

variables.



23.3Exercise5.3:TheLocalComponent

Interfaces

TheexampleprograminExercise5.3explorestheuseoflocal

interfaces.TheCabinentitybeanyoucreatedinExercise4.1

willbeexpandedtoprovidealocalinterfaceforuseinthe

TravelAgentstatelesssessionbean.Thisexercisealsodescribes

howtomodifyyourEJBdeploymentdescriptorstoenablelocal

interfaces.



23.3.1StartUpJBoss

IfyoualreadyhaveJBossrunning,thereisnoreasontorestart

it.Otherwise,startitupasinstructedintheJBossInstallation

andConfigurationchapter.



23.3.2InitializetheDatabase

Thedatabaseshouldcontainthe100rowscreatedbya

successfulexecutionofthetestprogramsfromExercise4.1.



23.3.3BuildandDeploytheExamplePrograms

Intheex05_3directory,buildanddeploytheexamplesasyou

didforExercise5.1.



23.3.4ExaminetheJBoss-SpecificFiles

JBosshasaminorrestriction.Itrequiresthatyouuse


link>whenyouwantyourbeantoreferencealocalbean

throughantag.



23.3.4.1ejb-jar.xml





...



TravelAgentEJB

com.titan.travelagent.TravelAgentHomeRemote

com.titan.travelagent.TravelAgentRemote



com.titan.travelagent.TravelAgentBean
Stateless

Container





ejb/CabinHomeLocal

Entity

com.titan.cabin.CabinHomeLocal

com.titan.cabin.CabinLocal





CabinEJB



...





Ifyouexaminethejboss.xmlfileforExercise5.3,you'llsee

thatyoumustalsodeclaretheJNDIbindingfortheremote

homeinterface.TheCabinEJB'slocalhomeinterfacedoesn't

needabindinginjboss.xml,though,becausethebinding

informationiscontainedinthetaginstead.JBoss

willregisterbothCabinHomeRemoteandCabinHomeLocalinto

theJNDItree.



23.3.4.2jboss.xml







CabinEJB

CabinHomeRemote

CabinHomeLocal





TravelAgentEJBonlytellsJBossunderwhichJNDInameit

shouldbebound:



TravelAgentEJB

TravelAgentHomeRemote









23.3.5ExamineandRuntheClientApplications

TheexamplecodeforClient_53isexactlythesameasClient_3

fromExercise4.2.

RunClient_53byinvokingtheappropriateAnttask,asyoudid

inpreviousexamples:run.client_53.Remembertosetyour

JBOSS_HOMEandPATHenvironmentvariables.

Theoutputshouldlooksomethinglikethis:

C:\workbook\ex05_3>antrun.client_53

Buildfile:build.xml



prepare:



compile:



ejbjar:



run.client_53:

[java]1,MasterSuite,1

[java]3,Suite101,1

[java]5,Suite103,1

[java]7,Suite105,1

[java]9,Suite107,1

[java]12,Suite201,2

[java]14,Suite203,2

[java]16,Suite205,2

[java]18,Suite207,2

[java]20,Suite209,2

[java]22,Suite301,3

[java]24,Suite303,3



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 23. Exercises for Chapter 5

Tải bản đầy đủ ngay(0 tr)

×