📄 code3.html
字号:
<CODE>AUCTIONITEMS</CODE> table shown just below.
<P>
<CODE>AuctionItemHome</CODE> is the home interface. It describes how
the Bean is created in, found in, and removed from its container. The
Enterprise Bean server deployment tools will provide the implementation
for this interface.
<P>
<CODE>AuctionItemBean</CODE> is the Enterprise Bean. It implements
<CODE>EntityBean</CODE>, provides the business logic for
the developer-defined methods, and implements <CODE>EntityBean</CODE>
methods for creating the Bean and setting the session context. This
is a class that the Bean developer needs to implement. Its
field variables map to fields in the <CODE>AUCTIONITEMS</CODE> table
shown just below.
<P>
<CODE>AuctionItemPK</CODE> is the primary key class. The Enterprise
JavaBeans server requires a container-managed entity Bean to have
a primary key class with a public primary key field (or fields, if
using composite primary keys). The Bean developer implements this class.
The <CODE>ID</CODE> field is the
primary key in the <CODE>AUCTIONITEMS</CODE> table shown just
below, so the
<CODE>id</CODE> field is a public field in this class. The
<CODE>id</CODE> field is assigned a value when the primary key
class is constructed.
<P>
You can request the container manage database persistence for an Enterprise Bean
or write the code to manage the persistence yourself. In this chapter,
all beans (entity and session) are container-managed. With
container-managed Beans, all you do is specify which fields are
container managed and let the Enterprise JavaBeans server do the
rest. This is great for simple applications, but if you are coding
something that is fairly complex, you might need more control.
<P>
How to override the underlying Enterprise JavaBeans services to gain
more control or provide similar services for non-Enterprise JavaBean
applications is covered in Chapter 3.
<H4>Auction Items Table</H4>
Here is the <CODE>AUCTIONITEMS</CODE> table.
</FONT>
<PRE>
create table AUCTIONITEMS (SUMMARY VARCHAR(80) ,
ID INT ,
COUNTER INT ,
DESCRIPTION VARCHAR(1000) ,
STARTDATE DATE ,
ENDDATE DATE ,
STARTPRICE DOUBLE PRECISION ,
INCREMENT DOUBLE PRECISION ,
SELLER VARCHAR(30) ,
MAXBID DOUBLE PRECISION,
BIDCOUNT INT,
HIGHBIDDER VARCHAR(30) )
</PRE>
<FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<H4>Registration Entity Bean</H4>
<CODE>RegistrationBean</CODE> consists of the same kinds
of classes and database table as the <CODE>AuctionItem</CODE>
Bean, except the actual business logic, database table fields, and
primary key are somewhat different. Rather than describe the classes,
you can browse them and refer back to the <CODE>AuctionItem</CODE>
Bean discussion if you have questions.
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/registration/Registration.java">Registration.java</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/registration/RegistrationHome.java">RegistrationHome.java</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/registration/RegistrationBean.java">RegistrationBean.java</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/registration/RegistrationPK.java">RegistrationPK.java</A></FONT>
</UL>
<H4>Registration Table</H4>
Here is the <CODE>REGISTRATION</CODE> table.
</FONT>
<PRE>
create table REGISTRATION (THEUSER VARCHAR(40) ,
PASSWORD VARCHAR(40) ,
EMAILADDRESS VARCHAR(80) ,
CREDITCARD VARCHAR(40) ,
BALANCE DOUBLE PRECISION )
</PRE>
<FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A NAME="session"></A>
<H3>Session Beans</H3>
<CODE>BidderBean</CODE> and <CODE>SellerBean</CODE> are the session
Beans. <CODE>BidderBean</CODE> retrieves lists of auction items,
searches for an item, checks the user ID and password when
someone places a bid, and stores new bids in the database.
<CODE>SellerBean</CODE>
checks the user ID and password when someone posts an auction
item, and adds new auction items to the database.
<P>
Both session Beans are initially deployed as stateless Beans. A stateless
Bean does not keep a record of what the client did in a previous call;
whereas, a stateful Bean does. Stateful Beans are very useful if the operation
is more than a simple lookup and the client operation depends on something that
happened in a previous call.
<H4>Bidder Session Bean</H4>
Here are the <CODE>BidderBean</CODE> classes.
Enterprise
Beans use the Remote Method Invocation (RMI) API, so when
an error occurs, an RMI remote exception is thrown.
<P>
There is no
primary key class because these Beans are transient and no database access is involved.
To retrieve auction items from the database,
<CODE>BidderBean</CODE> creates an instance of
<CODE>AuctionItemBean</CODE>, and to process bids,
it creates an instance of <CODE>RegistrationBean</CODE>.
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/bidder/Bidder.java">Bidder.java</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/bidder/BidderHome.java">BidderHome.java</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/bidder/BidderBean.java">BidderBean.java</A></FONT>
</UL>
<CODE>Bidder</CODE> is the remote interface. It describes what
the Bean does by declaring the developer-defined methods that
provide the business logic for this Bean. These methods are the ones that
the client calls remotely.
<P>
<CODE>BidderHome</CODE> is the home interface. It describes
how the Bean is created in, found in, and removed from its
container.
<CODE>BidderBean</CODE> is the Enterprise Bean. It implements
<CODE>SessionBean</CODE>, provides the business logic for the
developer-defined methods, and implements <CODE>SessionBean</CODE>
methods for creating the Bean and setting the session context.
<H4>Seller Session Bean</H4>
<CODE>SellerBean</CODE> consists of the same kinds of classes
as <CODE>BidderBean</CODE>, except the business logic is
different. Rather than describe the classes, you can browse them
and refer back to the <CODE>BidderBean</CODE> discussion if you
have questions.
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/seller/Seller.java">Seller.java</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/seller/SellerHome.java">SellerHome.java</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="./Code/seller/SellerBean.java">SellerBean.java</A></FONT>
</UL>
<A NAME="container"></A>
<H3>Container Classes</H3>
The classes needed by the container to deploy an Enterprise Bean onto
a particular Enterprise JavaBeans server are generated with
a deployment tool. The classes include <CODE>_Stub.class</CODE> and
<CODE>_Skel.class</CODE> classes that provide the RMI hooks on the client
and server respectively.
<P>
These classes are used
for marshaling (moving) data between the client program and the
Enterprise JavaBeans server. In addition, implementation classes are created
for the interfaces and deployment rules defined for our Bean.
<P>
The <CODE>Stub</CODE> object is installed on or
downloaded to the client system and provides a local proxy
object for the client. It implements the remote interfaces
and transparently delegates all method calls
across the network to the remote object.
<P>
The <CODE>Skel</CODE> object is installed on or downloaded
to the server system and provides a local proxy object for the
server. It unwraps data received over the network from the
<CODE>Stub</CODE> object for processing by the server.
<P ALIGN="RIGHT">
<FONT SIZE="-1">[<A HREF="#top">TOP</A>]</FONT>
</FONT>
</TD>
</TR>
</TABLE>
<!-- ================ -->
<!-- End Main Content -->
<!-- ================ -->
</TD>
</TR>
</TABLE>
<!-- Copyright Insert -->
<BR CLEAR="ALL">
<FORM ACTION="/cgi-bin/search.cgi" METHOD="POST">
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="5">
<TR>
<TD VALIGN="TOP">
<P ALIGN=CENTER>
<FONT SIZE="-1" COLOR="#999999" FACE="Verdana, Arial, Helvetica, sans-serif">
[ This page was updated: <!-- new date --> 13-Oct-99 ]</font></P>
</TD>
</TR>
<TR>
<TD BGCOLOR="#CCCCCC">
<IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD>
<CENTER>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="http://java.sun.com/products/">Products & APIs</A> |
<A HREF="/developer/index.html">Developer Connection</A> |
<A HREF="/developer/infodocs/index.shtml">Docs & Training</A> |
<A HREF="/developer/support/index.html">Online Support</A><BR>
<A HREF="/developer/community/index.html">Community Discussion</A> |
<A HREF="http://java.sun.com/industry/">Industry News</A> |
<A HREF="http://java.sun.com/solutions">Solutions Marketplace</A> |
<A HREF="http://java.sun.com/casestudies">Case Studies</A>
</FONT>
</CENTER>
</TD>
</TR>
<TR>
<TD BGCOLOR="#CCCCCC">
<IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD ALIGN="CENTER">
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="http://java.sun.com/docs/glossary.html">Glossary</A> -
<A HREF="http://java.sun.com/applets/">Applets</A> -
<A HREF="http://java.sun.com/docs/books/tutorial/">Tutorial</A> -
<A HREF="http://java.sun.com/jobs/">Employment</A> -
<A HREF="http://java.sun.com/nav/business/">Business & Licensing</A> -
<A HREF="http://java.sun.com/javastore/">Java Store</A> -
<A HREF="http://java.sun.com/casestudies/">Java in the Real World</A>
</FONT>
</TD>
</TR>
<TR>
<TD>
<CENTER>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
<a href="/siteinfo/faq.html">FAQ</a> |
<a href="/feedback/index.html">Feedback</a> |
<a href="http://www.dynamicdiagrams.net/mapa/cgi-bin/help.tcl?db=javasoft&dest=http://java.sun.com/">Map</a> |
<A HREF="http://java.sun.com/a-z/index.html">A-Z Index</A>
</FONT>
</CENTER>
</TD>
</TR>
<TR>
<TD>
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="0">
<TR>
<TD WIDTH="50%">
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
For more information on Java technology<BR>
and other software from Sun Microsystems, call:<BR>
</FONT>
<FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif">
(800) 786-7638<BR></FONT>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
Outside the U.S. and Canada, dial your country's
<A HREF="http://www.att.com/business_traveler/attdirecttollfree/">AT&T Direct Access Number</A> first.<BR>
</FONT>
</TD>
<TD ALIGN="RIGHT" WIDTH="50%">
<A HREF="http://www.sun.com"><IMG SRC="/images/lgsun.gif" width="64" height="30" border="0" ALT="Sun Microsystems, Inc."></A><BR>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
Copyright © 1995-99
<A HREF="http://www.sun.com">Sun Microsystems, Inc.</A><BR>
All Rights Reserved.
<a href="http://www.sun.com/share/text/SMICopyright.html">Legal Terms</a>.
<A HREF="http://www.sun.com/privacy/">Privacy Policy</A>.
</FONT>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
<!-- End Copyright Insert -->
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -