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

Chapter 24. Exercises for Chapter 6

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

24.1Exercise6.1:BasicPersistenceinCMP2.0

ThisexercisebeginswalkingyouthroughtheintricaciesofCMP

2.0.Inthischapter,youwilllearnmoredetailedJBossCMP2.0

configurationmechanismsbycreatingtheCustomerEJB

describedintheEJBbook.



24.1.1StartUpJBoss

IfyoualreadyhaveJBossrunning,thereisnoreasontorestart

it.Otherwise,startitupasinstructedintheJBossInstallation

andConfigurationchapter.



24.1.2InitializetheDatabase

Thedatabasetableforthisexercisewillautomaticallybe

createdinJBoss'sdefaultdatabase,HypersonicSQL,whenthe

EJBJARisdeployed.



24.1.3BuildandDeploytheExamplePrograms

Performthefollowingsteps:

1. Openacommandpromptorshellterminaland

changetotheex06_1directorycreatedbythe

extractionprocess

SettheJAVA_HOMEandJBOSS_HOMEenvironmentvariablesto

pointtowhereyourJDKandJBoss4.0areinstalled.Examples:

Windows:



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

C:\workbook\ex06_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\ex06_1>setPATH=..\ant\bin;%PATH%

Unix:

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



Performthebuildbytypingant.

Asinthelastexercise,youwillseetitan.jarrebuilt,copiedto

theJBossdeploydirectory,andredeployedbytheapplication

server.



24.1.4ExaminetheJBoss-SpecificFiles

Inthissection,weintroduceanewJBossCMP2.0deployment

descriptor,jbosscmp-jdbc.xml.Thisfileprovidesmoredetailed



controlofyourbean'sdatabasemappingaswellasmore

advancedperformance-tuningoptions.



24.1.4.1jbosscmp-jdbc.xml







java:/DefaultDS

HypersonicSQL

true

true









CustomerEJB

Customer



id

ID







lastName

LAST_NAME





firstName

FIRST_NAME





hasGoodCredit

HAS_GOOD_CREDIT











24.1.4.2Thesection



TheconfigurationvariabletellsJBoss'sCMP

enginewhatdatabaseconnectionpooltousefortheentity

beansdefinedinthisJAR.

java:/DefaultDS



Itiscurrentlyconfiguredtousethedefaultdatasourcedefined

in$JBOSS_HOME/server/default/deploy/hsqldb-service.xml,but

youcanchangeittoyourowndefineddatasources.The

workbook'sAppendixgoesintomoredetailonhowtoconfigure

yourowndatasources.

ThisvariabledescribesthedatabasemappingthatCMPshould

use:

HypersonicSQL



Herearesomeothermappingsyoucoulduse(thislistisnot

exhaustive):

Oracle8

Oracle7

MSSQLSERVER

MSSQLSERVER2000



Forotheravailablesupporteddatabasemappings,pleasereview

JBoss'sadvanceddocumentationonitswebsiteat

http://www.jboss.org.



Whentheconfigurationvariableissettotrue,

JBosscreatesthedatabasetablesforeachentitybeandefined

inthedeploymentdescriptorunlessthesetablesalreadyexist.

ThiscreateactionistriggeredwhentheEJBJARisdeployed:

true



Whentheconfigurationvariableissettotrue,

JBossdropsthedatabasetablesforeachentitybeandefinedin

thedeploymentdescriptor.Thisremoveactionistriggeredwhen

theEJBJARisredeployedorundeployed:

true



24.1.4.3Thesection

There'sanXMLfragmentforeachentity

beandefinedinthisEJBJAR.Thevariabledefines

theentitybeanthatisdescribedinthatsection:

CustomerEJB

Thevariabledefineswhatdatabasetablethis

entitybeanshouldmapto:

Customer



Eachsectiondescribesthemappingbetweenan

entitybean'sfieldsandthecorrespondingcolumnsofthe

databasetable.Thetagistheentitybeanfield's



name,whilethedefinesthetablecolumn's

name:



id

ID





24.1.5ExamineandRuntheClientApplications

Thereisonlyoneclientapplicationforthisexercise,Client_61.

ItismodeledaftertheexampleintheEJBbook.Itcreates

CustomerEJBsinthedatabasebasedonthecommand-line

parameters.

Toruntheclient,firstsetyourJBOSS_HOMEandPATH

environmentvariablesappropriately.Theninvoketheprovided

wrapperscripttoexecutetheprogram.Foreachcustomer,you

mustsupplyonthecommandlineasetofvaluesforprimary

key,firstname,andlastname,asshownhere:

Client_61777BillBurke888SachaLabourey



Theoutputofthisexecutionshouldbe:

C:\workbook\ex06_1>client_61777BillBurke888SachaLabourey

Buildfile:build.xml



prepare:



compile:



ejbjar:



run.client_61:

[java]777=BillBurke

[java]888=SachaLabourey



Whenitfinishes,theexampleprogramremovesthecreated

beans,sonodataremainsinthedatabase.



24.2Exercise6.2:DependentValueClassesin

CMP2.0

TheexampleprogramsinExercise6.2exploreusinga

dependentvalueclasstocombinemultipleCMPfieldsintoa

singleserializableobjectthatcanbepassedinandoutof

entity-beanmethods.



24.2.1StartUpJBoss

IfyoualreadyhaveJBossrunning,thereisnoreasontorestart

it.



24.2.2InitializetheDatabase

Nodatabaseinitializationisneeded.



24.2.3BuildandDeploytheExamplePrograms

Performthefollowingsteps:

1. Openacommandpromptorshellterminaland

changetotheex06_2directorycreatedbythe

extractionprocess

SettheJAVA_HOMEandJBOSS_HOMEenvironmentvariablesto

pointtowhereyourJDKandJBoss4.0areinstalled.Examples:

Windows:

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



C:\workbook\ex06_2>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\ex06_2>setPATH=..\ant\bin;%PATH%



Unix:

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



Performthebuildbytypingant.

Asinthelastexercise,youwillseetitan.jarrebuilt,copiedto

theJBossdeploydirectory,andredeployedbytheapplication

server.



24.2.4ExaminetheJBoss-SpecificFiles

TherearenonewJBossconfigurationfilesorcomponentsin

thisexercise.



24.2.5ExamineandRuntheClientApplications

Theexampleprogram,Client_62,showshowtheName

dependentvalueclassisusedwiththeCustomerEJB.The

examplecodeispulleddirectlyfromtheEJBbookand

embellishedsomewhattoexpandonintroducedconcepts.The

EJBbookdoesaprettygoodjobofexplainingtheconcepts

illustratedinClient_62,sofurtherexplanationofthecodeisnot

neededinthisworkbook.

TheclientapplicationusesthenewgetName()andsetName(

)methodsoftheCustomerEJBtoinitialize,modify,anddisplay

anewlycreatedCustomerbeanusingtheNamedependentvalue

class.Thistestbeanisthenremovedfromthedatabasebefore

theapplicationfinishes.

TorunClient_62,invoketheAnttaskrun.client_62.

RemembertosetyourJBOSS_HOMEandPATHenvironment

variables.Theoutputshouldlooksomethinglikethis:

C:\workbook\ex06_2>antrun.client_62

Buildfile:build.xml



prepare:



compile:



ejbjar:



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

Chapter 24. Exercises for Chapter 6

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

×