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

📄 5.mht

📁 Enterprise Java Bean的PPT文档,很好的东西.
💻 MHT
📖 第 1 页 / 共 5 页
字号:
generated=20
that file by specifying the dao tag in the CustomerBean =
class.</I></FONT></P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Create Customer's =
DAO=20
Interface :</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P>Since we are going to use a DAO to access database for this bean, we =
have to=20
create a DAOImpl class to provide an implementation for the generated =
DAO=20
interface.</P>
<P><B>Go to src &gt; package <SPAN style=3D"TEXT-DECORATION: =
none">au.com.tusc.dao=20
&gt; Add a class </SPAN>CustomerDAOImpl in that package</B>.</P>
<P><IMG height=3D264=20
src=3D"http://www.tusc.com.au/tutorial/images/chap5/CustomerDAOImpl.png" =
width=3D577=20
align=3Dleft border=3D0 name=3DGraphic6><BR clear=3Dleft><BR><BR></P>
<P>Now go to your bean class and declare this tag at class level (ie. at =
the=20
top) as shown below to generate the DAO interface.</P><PRE><FONT =
color=3D#3f5fbf>   <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>@ejb.dao =
class=3D"au.com.tusc.bmp.CustomerDAO"</FONT></FONT></FONT>
<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>impl-class=3D"au.com.tusc.dao.CustomerDAOImpl"</FONT></FONT><=
/FONT></PRE>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D274=20
src=3D"http://www.tusc.com.au/tutorial/images/chap5/CustomerBeanDAOTag.pn=
g"=20
width=3D390 align=3Dleft border=3D0 name=3DGraphic7><BR =
clear=3Dleft><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<TABLE cellSpacing=3D2 cellPadding=3D3 width=3D"100%" border=3D0>
  <COLGROUP>
  <COL width=3D469>
  <COL width=3D473>
  <THEAD>
  <TR vAlign=3Dtop>
    <TD width=3D469>
      <P><B>Regenerate your classes and check that your DAO interface is =

      generated.</B></P>
      <P><FONT color=3D#800000><I>Note : For reference the steps are as=20
      follows:</I></FONT></P>
      <P><FONT color=3D#800000><I>Expand MyStoreMgr node under MyStore =
Project in=20
      Package Explorer. </I></FONT></P>
      <P><FONT color=3D#800000><I>Right click and a pop up menu will=20
      appear.</I></FONT></P>
      <P><FONT color=3D#800000><I>Go to Lomboz J2EE &gt; Generate EJB =
Classes as=20
      shown on the right.</I></FONT></P>
      <P><B>As shown below, our DAO interface is generated.</B></P>
      <P><IMG height=3D254=20
      =
src=3D"http://www.tusc.com.au/tutorial/images/chap5/CustomerSrcWithDAO.pn=
g"=20
      width=3D225 align=3Dleft border=3D0 name=3DGraphic10><BR =
clear=3Dleft><BR></P></TD>
    <TD width=3D473>
      <P><IMG height=3D432=20
      =
src=3D"http://www.tusc.com.au/tutorial/images/chap3/GenerateEJBClassesNow=
.png"=20
      width=3D474 align=3Dleft border=3D0 name=3DGraphic9><BR =
clear=3Dleft><BR><BR></P>
      <P><BR><BR></P>
      <P><BR></P></TD></TR></THEAD>
  <TBODY></TBODY></TABLE>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>If we look at the generated DAO class =
as shown=20
below, it has four more methods than StoreAccess (which was a Stateless =
Session=20
Bean) did when we first generated it (ie. prior to adding the method =
level=20
@dao:call tag).</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><FONT color=3D#800000><I>Note : It's =
worth=20
mentioning here that BMP Entity beans don't need the @dao:call tag for=20
generating DAO interface methods.</I></FONT></P>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D273=20
src=3D"http://www.tusc.com.au/tutorial/images/chap5/CustomerDAO.png" =
width=3D851=20
align=3Dleft border=3D0 name=3DGraphic11><BR clear=3Dleft><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>All these methods are generated by =
the tag=20
described earlier for DAO interface generation, also shown =
below</B>.</P>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D56=20
src=3D"http://www.tusc.com.au/tutorial/images/chap5/CustomerDAOTag.png" =
width=3D334=20
align=3Dleft border=3D0 name=3DGraphic12><BR clear=3Dleft><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Also, let's look at the descriptors =
generated=20
up until this step, in ejb-jar.xml under MyStoreMgr/META-INF.</B></P>
<TABLE cellSpacing=3D4 cellPadding=3D4 width=3D"100%" border=3D0>
  <COLGROUP>
  <COL width=3D145>
  <COL width=3D111>
  <THEAD>
  <TR vAlign=3Dtop>
    <TD width=3D"57%">
      <P>These descriptors are generated by the following tag in=20
      CustomerBean.</P><PRE><FONT face=3DSans><FONT style=3D"FONT-SIZE: =
11pt" size=3D2><FONT color=3D#3f5fbf>@ejb.bean</FONT> <FONT =
color=3D#3f5fbf>name=3D"Customer"</FONT></FONT></FONT>
<FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
color=3D#3f5fbf>jndi</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"CustomerBean"</FONT></FONT></FONT>
<FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
color=3D#3f5fbf>type=3D"BMP"</FONT> </FONT></FONT></PRE>
      <P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
      <P>This tag generates descriptors in jboss.xml as well, which will =
be=20
      covered later on. </P></TD>
    <TD width=3D"43%">
      <P><IMG height=3D284=20
      src=3D"http://www.tusc.com.au/tutorial/images/chap5/ejbJar.png" =
width=3D401=20
      align=3Dleft border=3D0 name=3DGraphic13><BR =
clear=3Dleft><BR></P></TD></TR></THEAD>
  <TBODY></TBODY></TABLE>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in">The next step is to add =
attributes/properties to=20
our Customer Bean, which will be accessible to clients through the =
remote=20
interface using getter and setter methods. These attributes are mapped =
to=20
corresponding columns in the relevant table in the database.</P>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>In order to add these =
properties/attributes ,=20
define all attributes (as private to encapsulate) and their =
corresponding=20
accessors/mutators (getter and setter methods). Each accessor (getter) =
method=20
will have two tags or three in the case of a primary key. The mutator =
(setter)=20
method will have only one tag declared on it.</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Add these tags for =
attributes/properties (in=20
Bean terms) as shown below.</B></P>
<TABLE cellSpacing=3D0 cellPadding=3D4 width=3D975 border=3D0>
  <COLGROUP>
  <COL width=3D503>
  <COL width=3D456>
  <THEAD>
  <TR vAlign=3Dtop>
    <TD width=3D503>
      <P style=3D"MARGIN-BOTTOM: 0in"><FONT face=3DSans><FONT=20
      style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
color=3D#3f5fbf>/**</FONT>=20
      </FONT></FONT></P><PRE><FONT color=3D#3f5fbf>    <FONT =
style=3D"FONT-SIZE: 11pt" size=3D2><FONT face=3DSans>* =
Returns</FONT></FONT></FONT><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans> <FONT color=3D#3f5fbf>the</FONT> <FONT =
color=3D#3f5fbf>customerID</FONT></FONT></FONT>
<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>*</FONT></FONT></FONT><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans> <B><FONT color=3D#7f9fbf>@return</FONT></B> =
<FONT color=3D#3f5fbf>the</FONT> <FONT =
color=3D#3f5fbf>customerID</FONT></FONT></FONT>
<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>*</FONT></FONT></FONT><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans> </FONT></FONT>
<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>*</FONT></FONT></FONT><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans> <FONT =
color=3D#3f5fbf>@ejb.persistence</FONT> </FONT></FONT>
<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>*</FONT></FONT></FONT><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans> <FONT color=3D#3f5fbf>@ejb.pk</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT color=3D#3f5fbf>field</FONT> =
</FONT></FONT>
<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>*</FONT></FONT></FONT><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans> <FONT =
color=3D#3f5fbf>@ejb.interface</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>method</FONT></FONT></FONT>
<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>*/</FONT></FONT></FONT>
<FONT color=3D#7f0055>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans><B>public</B></FONT></FONT></FONT><FONT style=3D"FONT-SIZE: =
11pt" size=3D2><FONT face=3DSans>  <FONT =
color=3D#000000>java.lang.String</FONT> <FONT =
color=3D#000000>getCustomerID() {</FONT></FONT></FONT>
<FONT color=3D#000000>         <FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans>return customerID ;</FONT></FONT></FONT>
<FONT color=3D#000000>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>}</FONT></FONT></FONT>

<FONT color=3D#3f5fbf>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>/**</FONT></FONT></FONT>
<FONT color=3D#3f5fbf>     <FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans>*</FONT></FONT></FONT><FONT =
style=3D"FONT-SIZE: 11pt" size=3D2><FONT face=3DSans> <FONT =
color=3D#3f5fbf>Sets</FONT> <FONT color=3D#3f5fbf>the</FONT> <FONT =
color=3D#3f5fbf>customerID</FONT></FONT></FONT>
<FONT color=3D#3f5fbf>     <FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans>*</FONT></FONT></FONT><FONT =
style=3D"FONT-SIZE: 11pt" size=3D2><FONT face=3DSans> <B><FONT =
color=3D#7f9fbf>@param</FONT></B> <FONT =
color=3D#3f5fbf>java.lang.String</FONT> <FONT color=3D#3f5fbf>the</FONT> =
<FONT color=3D#3f5fbf>new</FONT> <FONT color=3D#3f5fbf>customerID</FONT> =
<FONT color=3D#3f5fbf>value</FONT></FONT></FONT>
<FONT color=3D#3f5fbf>     <FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans>*</FONT></FONT></FONT><FONT =
style=3D"FONT-SIZE: 11pt" size=3D2><FONT face=3DSans>  </FONT></FONT>
<FONT color=3D#3f5fbf>     <FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans>*</FONT></FONT></FONT><FONT =
style=3D"FONT-SIZE: 11pt" size=3D2><FONT face=3DSans> <FONT =
color=3D#3f5fbf>@ejb.interface</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>method</FONT></FONT></FONT>
     <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT face=3DSans><FONT =
color=3D#3f5fbf>*/</FONT></FONT></FONT>
<FONT color=3D#7f0055>    <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans><B>public</B></FONT></FONT></FONT><FONT style=3D"FONT-SIZE: =
11pt" size=3D2><FONT face=3DSans> <B><FONT =
color=3D#7f0055>void</FONT></B> <FONT color=3D#000000>setCustomerID =
(java.lang.String</FONT> <FONT color=3D#000000>customerID)    =
</FONT></FONT></FONT>
<FONT color=3D#000000>         <FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT face=3DSans>this.customerID =3D =
customerID;</FONT></FONT></FONT></PRE>
      <P><FONT color=3D#000000><FONT face=3DSans><FONT =
style=3D"FONT-SIZE: 11pt"=20
      size=3D2>}</FONT></FONT></FONT></P>
      <P>Code snippet from CustomerBean is shown in figure at =
right.</P></TD>
    <TD width=3D456>
      <P><IMG height=3D484=20
      =
src=3D"http://www.tusc.com.au/tutorial/images/chap5/CustomerBeanPrimaryKe=
y.png"=20
      width=3D406 align=3Dleft border=3D0 name=3DGraphic5><BR=20
  clear=3Dleft><BR></P></TD></TR></THEAD>
  <TBODY></TBODY></TABLE>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Now, analyzing these tags</B>, </P>
<OL>
  <LI>
  <P style=3D"MARGIN-BOTTOM: 0in"><B>@ejb.persistence</B> specifies this =
as a=20
  persistent attribute. All accessor and mutator methods will be =
overridden in=20
  generated BMP class, in this case it is CustomerBMP, and all mutator =
methods=20
  will have a dirty flag in them, as persistence is controlled by =
ejbLoad() and=20
  ejbStore().</P>
  <LI>
  <P style=3D"MARGIN-BOTTOM: 0in"><B>@ejb.pk-field</B> specifies that =
this=20
  attribute is mapped to a primary key in database and and is assigned =
as a=20
  primary key in the PrimaryKey class, in this case the CustomerPK=20
  class<B>.</B></P>
  <LI>
  <P style=3D"MARGIN-BOTTOM: 0in"><B>@ejb.interface</B> generates these =
methods in=20
  the Remote interface.</P></LI></OL>
<P style=3D"MARGIN-BOTTOM: 0in">Now, in the case of mutator methods =
(that is=20
'setCustomerID') the only tag required is @ejb.interface-method for =
generating=20
this method in the remote interface.</P>
<P style=3D"MARGIN-BOTTOM: 0in">Similarly, add methods and their tags =
for rest of=20
the persistent fields. There will be no @ejb.pk-field tag as customerID =
is the=20
primary key. </P>
<P style=3D"MARGIN-BOTTOM: 0in"><FONT color=3D#800000><I>Note : In the =
case of a=20
composite primary key you have to specify @ejb.pk-field tags on the =
other=20
attributes/properties which make up the composite key.</I></FONT></P>
<P style=3D"MARGIN-BOTTOM: 0in">Similarly, Add tags and methods for rest =
of the=20
persistent fields, which in this case are, firstName, lastName, Address, =
phone=20
and shareholderStatus as shown in this code snippet from =

⌨️ 快捷键说明

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