⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 6.mht

📁 Enterprise Java Bean的PPT文档,很好的东西.
💻 MHT
📖 第 1 页 / 共 5 页
字号:
src=3D"http://www.tusc.com.au/tutorial/images/chap6/ItemsBeanEnityContext=
.png"=20
width=3D394 align=3Dleft border=3D0 name=3DGraphic11><BR =
clear=3Dleft><FONT=20
color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Now all business =
and finder=20
methods are complete, so it's time to generate EJB=20
classes.</B></FONT></FONT></P>
<P><B><FONT face=3D"Nimbus Roman No9 L"><FONT color=3D#000000>Let's =
examine the=20
generated</FONT></FONT></B> <B>ItemCMP class, which is of most =
interest</B>=20
.</P>
<P>Unlike our BMP bean all persistent attribute behavior is being =
overridden by=20
abstract methods. This is because the EJB container is responsible for=20
maintaining their persistence. </P>
<P><IMG height=3D586=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/ItemCMPAbstractMethod=
s.png"=20
width=3D444 align=3Dleft border=3D0 name=3DGraphic22><BR =
clear=3Dleft><BR><BR></P>
<P>All the callback methods we have implemented are being overridden as =
shown=20
below. </P>
<P><IMG height=3D166=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/ItemCMPCallBackMethod=
s.png"=20
width=3D378 align=3Dleft border=3D0 name=3DGraphic23><BR =
clear=3Dleft><FONT=20
color=3D#800000><I>Note : There are no ejbFinder methods in this class =
as with BMP=20
beans, as all this is controlled by the container. Also as pointed out =
before,=20
there is no PrimaryKey class generated and there is no need for a DAO =
class, as=20
this too is controlled by the container.</I></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Now, =
before we deploy=20
our bean, we will just have a look at ejb-jar.xml and jboss.xml to see =
what=20
descriptors are generated.</B></FONT></FONT></P>
<P><FONT color=3D#800000><FONT face=3D"Nimbus Roman No9 L"><I>Note : We =
don't have=20
to write any descriptors for the data sources as we did with Session and =
BMP=20
beans, as the EJB container is responsible for =
that.</I></FONT></FONT></P>
<P><IMG height=3D578=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/ejbJarFirst.png" =
width=3D460=20
align=3Dleft border=3D0 name=3DGraphic12><BR clear=3Dleft><B><FONT=20
face=3D"Nimbus Roman No9 L"><FONT color=3D#000000>As shown in the code =
snippet above=20
from the ejb-jar.xml file, all abstract methods are generated as =
persistent=20
fields under the tag &lt;cmp-field&gt; because of the tag =
@persistence-field=20
declared at each accessor method. Also the primary key class descriptor =
is=20
generated</FONT></FONT></B> <B>under the &lt;primary-key-class&gt; tag =
and the=20
primary key field is generated under the &lt;primarykey-field&gt; =
because of the=20
tag @field-pk declared for the relevant attribute(s)</B>. </P>
<P><B>Descriptors for finder methods are generated along with the query =
defined=20
to fetch the data as shown below</B>. <B>These finder tags are generated =
by the=20
@ejb.finder tag declared at class level. </B></P>
<P><IMG height=3D484=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/ejbJarSecond.png" =
width=3D630=20
align=3Dleft border=3D0 name=3DGraphic13><BR clear=3Dleft><B>And in the =
jboss.xml file,=20
the following descriptors are generated due to the tag @ejb.bean =
declared at=20
class level, as shown below.</B></P>
<P><IMG height=3D88 =
src=3D"http://www.tusc.com.au/tutorial/images/chap6/jboss.png"=20
width=3D322 align=3Dleft border=3D0 name=3DGraphic15><BR =
clear=3Dleft><FONT=20
color=3D#800000><FONT face=3D"Nimbus Roman No9 L"><I>Note : @ejb.bean =
tag has been=20
covered in previous chapters.</I></FONT></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Item Bean=20
functionality is complete in and ready for =
deployment.</B></FONT></FONT></P>
<H3><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Deploy =
Item Bean=20
:</B></FONT></FONT></H3>
<P><B>Go to Lomboz J2EE View &gt; expand node MyStore &gt; expand =
MyStoreMgr=20
&gt; select Jboss 3.2.1 ALL.</B></P>
<P><B>Right click &gt; select Debug Sever on the pop up menu.</B></P>
<P><FONT color=3D#800000><I>Note : This is to start your server, if you =
are=20
already running your server then skip these steps and go to the next=20
one.</I></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Go to =
MyStoreMgr node=20
in LombozJ2EE view &gt; right click &gt; select Deploy on the pop up =
menu as=20
shown below.</B></FONT></FONT></P>
<P><IMG height=3D230=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/LombozJ2EEViewDeployB=
ean.png"=20
width=3D444 align=3Dleft border=3D0 name=3DGraphic19><BR =
clear=3Dleft><BR><BR></P>
<P><FONT color=3D#800000><I>Note : All these steps have been detailed in =
previous=20
chapters (1 and 3), so, please refer to them.</I></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Messages =
in the=20
console will indicate whether deployment of your bean has been =
successful or=20
not.</B></FONT></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Now, lets =
modify=20
StoreAccessBean to invoke methods on ItemBean.</B></FONT></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Add a =
field to store=20
our Item reference (obtained from JNDI =
lookup).</B></FONT></FONT></P><PRE style=3D"MARGIN-BOTTOM: 0.2in"><FONT =
face=3DSans><FONT size=3D3><SPAN style=3D"BACKGROUND: none transparent =
scroll repeat 0% 0%"><FONT color=3D#000000>private</FONT></SPAN><FONT =
color=3D#7f0055> </FONT><FONT color=3D#000000>ItemLocalHome</FONT> =
item<FONT color=3D#000000>LocalHome</FONT>;</FONT></FONT></PRE>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>In the =
ejbCreate=20
method store this reference in the itemLocalHome variable by invoking =
the=20
getLocalHome static method in the ItemUtil class as shown in this code =
snippet=20
below from StoreAccess Bean.</B></FONT></FONT></P>
<P><IMG height=3D282=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/StoreAccessEjbCreate.=
png"=20
width=3D448 align=3Dleft border=3D0 name=3DGraphic20><BR =
clear=3Dleft><BR><BR></P>
<H3><B>Add a Business Method to StoreAccess :</B></H3>
<P><B>Add another business method to the StoreAccess Bean which will =
invoke this=20
business method on our Item Bean.</B></P>
<P><FONT face=3D"Nimbus Roman No9 L"><B>Now, add a business method with =
this=20
signature:</B></FONT></P>
<P><FONT face=3D"Nimbus Roman No9 L"><B><FONT color=3D#000000>public =
ItemData</FONT>=20
<FONT color=3D#000000>getItemData(String itemID)</FONT></B></FONT></P>
<P><FONT face=3D"Nimbus Roman No9 L"><B><FONT color=3D#000000>.. with =
Interface type=20
as Remote. As managers will log on to MyStore with username, once=20
authe</FONT>nticated they will be identified by their userid. They can =
then=20
retrieve their account details from MyStore using that userid. A Manager =
can=20
invoke methods on the Item Bean to examine the inventory of=20
MyStore.</B></FONT></P>
<P><FONT color=3D#800000><FONT face=3D"Nimbus Roman No9 L"><I>Note : =
Steps to create=20
business methods are covered in previous chapters.</I></FONT></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><FONT =
size=3D3><B>Now=20
invoke one of Item's finder methods via the reference variable we have =
created=20
in the ejbCreate method.</B></FONT></FONT></FONT></P><PRE =
style=3D"MARGIN-BOTTOM: 0.2in"><FONT size=3D3><FONT =
face=3DSans>ItemLocal item  =3D   =
itemLocalHome.findByPrimaryKey(itemID)</FONT> </FONT>        </PRE>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><FONT =
size=3D3><B>Now=20
invoke the business method of Customer on this=20
reference.</B></FONT></FONT></FONT></P><PRE style=3D"MARGIN-BOTTOM: =
0.2in"><FONT face=3DSans><FONT size=3D3>ItemData myItem =3D =
item.getItemData() </FONT></FONT></PRE>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Code =
snippet for this=20
business method is shown below.</B></FONT></FONT></P>
<P><IMG height=3D356=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/StoreAccessGetItemDat=
a.png"=20
width=3D500 align=3Dleft border=3D0 name=3DGraphic31><BR =
clear=3Dleft><BR><BR></P>
<P><B>Add another business method to StoreAccess Bean.</B></P>
<P><B>Add a business method with this signature:</B></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>public=20
java.util.ArrayList getOutOfStockItems()</B></FONT></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>.. with =
Interface type=20
as Remote. This will return the items which are out of stock in=20
MyStore.</B></FONT></FONT></P>
<P style=3D"FONT-STYLE: normal"><FONT color=3D#000000><FONT=20
face=3D"Nimbus Roman No9 L"><FONT size=3D3><B>Create two variables of =
type=20
Collection and ArrayList respectively, as the finder method for Items =
returns a=20
Collection and this method will return an ArrayList, after populating =
items=20
which are out of stock from the returned=20
Collection.</B></FONT></FONT></FONT></P><PRE style=3D"MARGIN-BOTTOM: =
0.2in"><FONT face=3DSans><FONT size=3D3>Collection items =3D =
null;</FONT></FONT>
<FONT size=3D3><FONT face=3DSans>ArrayListItemsOutOfStock =3D =
null;</FONT>  </FONT>      </PRE>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Now invoke =
one of the=20
finder methods of Item on the reference variable we have created in the=20
ejbCreate method.</B></FONT></FONT></P><PRE style=3D"MARGIN-BOTTOM: =
0.2in"><FONT face=3DSans><FONT size=3D3>items =3D =
itemLocalHome.findByOutOfStock()</FONT></FONT></PRE>
<P><B>Now iterate through the collection of out of stock items and add =
to the=20
ArrayList.</B></P><PRE style=3D"MARGIN-BOTTOM: 0.2in"><FONT =
color=3D#000000><FONT face=3DSans><FONT size=3D3><B>I</B>temLocal =
myItemLocal  =3D (ItemLocal) iterate.next();</FONT></FONT></FONT>
<FONT color=3D#000000><FONT face=3DSans><FONT =
size=3D3>itemsOutOfStock.add(myItemLocal.getItemData()); =
</FONT></FONT></FONT></PRE>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Code =
snippet for this=20
business method is shown below.</B></FONT></FONT></P>
<P><IMG height=3D392=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/StoreAccessGetItemOut=
OfStock.png"=20
width=3D558 align=3Dleft border=3D0 name=3DGraphic36><BR =
clear=3Dleft><BR><BR></P>
<P><B>Add another business method to StoreAccess Bean.</B></P>
<P><B>Add a business method with this signature:</B></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>public=20
java.util.ArrayList getItemBySupplier(String =
supplierID)</B></FONT></FONT></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>.. with =
Interface type=20
as Remote. This will return the items which are provided to MyStore by a =
given=20
supplier.</B></FONT></FONT></P>
<P style=3D"FONT-STYLE: normal"><FONT color=3D#000000><FONT=20
face=3D"Nimbus Roman No9 L"><FONT size=3D3><B>Create two variables of =
type=20
Collection and ArrayList respectively as the finder method for Items =
returns a=20
Collection and this method will return ArrayList, after populating items =
which=20
are supplied by a particular supplier from the returned=20
Collection.</B></FONT></FONT></FONT></P><PRE style=3D"MARGIN-BOTTOM: =
0.2in"><FONT face=3DSans><FONT size=3D3>Collection suppliedItems =3D =
null;</FONT></FONT>
<FONT size=3D3><FONT face=3DSans>ArrayList itemsBySupplier =3D =
null;</FONT>  </FONT>      </PRE>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Now invoke =
one of the=20
finder methods of Item on the reference variable we have created in the=20
ejbCreate method.</B></FONT></FONT></P><PRE style=3D"MARGIN-BOTTOM: =
0.2in"><FONT face=3DSans><FONT size=3D3>suppliedItems =3D =
itemLocalHome.findBySupplierID(supplierID)</FONT></FONT></PRE>
<P><B>Now iterate through the collection of items for this supplier and =
add to=20
the ArrayList.</B></P><PRE style=3D"MARGIN-BOTTOM: 0.2in"><FONT =
color=3D#000000><FONT face=3DSans><FONT size=3D3><B>I</B>temLocal =
myItemsLocal  =3D (ItemLocal) iterate.next();</FONT></FONT></FONT>
<FONT color=3D#000000><FONT face=3DSans><FONT =
size=3D3>itemsBySupplier.add(myItemsLocal.getItemData()); =
</FONT></FONT></FONT>
<FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><FONT =
size=3D3><B>Code snippet for this business method is shown =
below.</B></FONT></FONT></FONT></PRE>
<P><IMG height=3D396=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/StoreAccessGetItemByS=
upplier.png"=20
width=3D538 align=3Dleft border=3D0 name=3DGraphic37><BR =
clear=3Dleft><BR><BR></P>
<P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>Now all =
the methods in=20
StoreAccess Bean for accessing Item's business methods have been added. =
The only=20
remaining bit is the deployment descriptors required for =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -