📄 code2.html
字号:
data stored in a database table. In the auction house example,
<CODE>RegistrationBean</CODE> is an entity Bean that represents
data for one registered user, and <CODE>AuctionItemBean</CODE> is
an entity Bean that represents the data for one auction item.
Entity Beans are transactional and long-lived. As long as the data
remains, the entity Bean can access and update that data.
This does not mean you need a Bean running for every table row. Instead,
Enterprise Beans are loaded and saved as needed.
<P>
A session Bean
might execute database reads and writes, but it is not required.
A session Bean might invoke the JDBC calls itself or it might use an
entity Bean to make the call, in which case the session Bean is a client
to the entity Bean. A session Bean's fields contain the state of the
conversation and are transient. If the server or client crashes, the
session Bean is gone. A session Bean is often used with one or more entity
Beans and for complex operations on the data.
<P>
<TABLE BORDER=2>
<TR><TH BGCOLOR="#FAF0E6"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Session Beans</FONT></TH>
<TH BGCOLOR="#FAF0E6"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Entity Beans</FONT></TH></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Fields contain conversation state.</FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Represents data in a database.</FONT></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Handles database access for client.</FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Shares access for multiple users.</FONT></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Life of client is life of Bean.</FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Persists as long as data exists.</FONT></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Can be transaction aware.</FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Transactional.</FONT></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Does not survive server crashes.</FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Survives server crashes.</FONT></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Not fine-grained data handling</FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Fine-grained data handling</FONT></TD></TR>
</TABLE>
<P>
<BLOCKQUOTE>
<STRONG>Note:</STRONG> In the Enterprise Java
Beans specification, Enterprise JavaBeans Server support for
session Beans is mandatory. Enterprise JavaBeans server support
for entity Beans was optional, but is mandatory for
version 2.0 of the specification.
</BLOCKQUOTE>
<A NAME="house"></A>
<H3>Auction House Workings</H3>
The diagram shows the Enterprise Beans for the auction house
application and their relationship to the Enterprise JavaBeans server.
The thin-client server invokes business logic in the four Enterprise
Beans through their home and remote interfaces. The Enterprise
JavaBeans server in this example handles the low-level details including
database read and write operations.
<P>
The four Enterprise Beans in the example are:
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>AuctionItemBean</CODE> is an entity Bean that maintains
information for an auction item.</FONT>
<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>RegistrationBean</CODE> is an entity Bean that stores user
registration information. </FONT>
<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>BidderBean</CODE> is a session Bean that uses
<CODE>AuctionItemBean</CODE> to retrieve a
list of all auction items, only new items, items due to close,
and items whose summary matches a search string from the
database. It also checks the user ID
and password when someone places a bid, and stores new bids in the database. </FONT>
<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>SellerBean</CODE> is a session Bean that uses
<CODE>RegistrationBean</CODE> to check the user ID and password when
someone posts an auction item, and <CODE>AuctionItemBean</CODE> to add
new auction items to the database.</FONT>
</UL>
<P>
<IMG SRC="./Art/workings.gif">
<P>
As depicted in the figure above, an entity or session Bean is really
a collection of interfaces and classes. All entity and session Beans
consist of a remote interface, home interface, and the Bean class.
The servlet looks up the Beans's home interface running in the
Enterprise JavaBeans server, uses the home interface to create
the remote interface, and invokes Bean methods through the remote
interface.
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">An Enterprise Bean's remote interface describes the Bean's
methods, or what the Bean does. A client program or another
Enterprise Bean calls the methods defined in the remote interface
to invoke the business logic implemented by the Bean.</FONT>
<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">An Enterprise Bean's home interface describes how a client program
or another Enterprise Bean creates, finds (entity Beans only), and removes
that Enterprise Bean from its container.</FONT>
<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">The container, shown in light blue (cyan), provides the interface
between the Enterprise Bean and the low-level platform-specific
functionality that supports the Enterprise Bean.</FONT>
</UL>
<A NAME="dev"></A>
<H3>Developing and Running Applications</H3>
Deployment tools and an Enterprise JavaBeans server are
essential to running Enterprise JavaBeans applications.
Deployment tools generate containers, which are classes that
provide an interface to the low-level implementations in a
given Enterprise JavaBeans server. The server provider can include
containers and deployment tools for their server and will typically
publish their low-level interfaces so other vendors can develop
containers and deployment tools for their server.
<P>
The auction house example uses the Enterprise JavaBeans server
and deployment tools created by
<A HREF="http://weblogic.beasys.com/index.htm">BEA Weblogic</A>.
Visit this site for a free
<A HREF="http://weblogic.beasys.com/downloads/index.htm">30-day trial</A>.
<P>
Because everything is written to specification, all Enterprise Beans
are interchangeable with containers, deployment tools, and servers
created by other vendors. In fact, you might or might not write your
own Enterprise Beans because it is possible, and sometimes desirable,
to use Enterprise Beans written by one or more providers that you
assemble into an Enterprise JavaBeans application.
<A NAME="how"></A>
<H3>How Multitiered Applications Work</H3>
The goal in a multitiered application is that the client be able to work on
application data without knowing at build time where the data is stored. To
make this level of transparency possible, the underlying services in a
multitiered architecture use lookup services to locate remote server objects
(the Bean's remote interface object), and data communication services to move
data from the client, through the remote server object, to its final destination
in a storage medium.
<H4>Lookup Service</H4>
To find remote server objects at runtime, the client program needs a way
to look them up. One way to look remote server objects up at runtime is to use
the Java Naming and Directory Interface<FONT SIZE="-2"><SUP>TM</SUP></FONT> (JNDI) API. JNDI is a common interface
to existing naming and directory interfaces. The Enterprise JavaBeans containers
use JNDI as an interface to the Remote Method Invocation (RMI) naming service.
<P>
At deployment time, the JNDI service registers (binds) the remote interface with a name.
As long as the client program uses the same naming service and asks for the
remote interface by its registered name, it will be able to find it.
The client program calls the <CODE>lookup</CODE> method on a
<CODE>javax.naming.Context</CODE> object to ask for the remote interface
by its registered name. The <CODE>javax.naming.Context</CODE> object
is where the bindings are stored and is a different object from the
Enterprise JavaBeans context, which is covered later.
<H4>Data Communication</H4>
Once the client program gets a reference to a remote server object, it
makes calls on the remote server object's methods. Because the client
program has a reference to the remote server object, a technique called
data marshalling is used to make it appear as if the remote server object
is local to the client program.
<P>
Data marshalling is where methods called on the remote server object are wrapped
with their data and sent to the remote server object. The remote server
object unwraps (unmarshalls) the methods and data, and calls the Enterprise Bean.
The results of the call to the Enterprise Bean are wrapped again, passed back
to the client through the remote server object, and unmarshalled.
<P>
The Enterprise JavaBeans containers use RMI services to marshal data. When
the Bean is compiled, <CODE>stub</CODE> and <CODE>skeleton</CODE> files are
created. The <CODE>stub</CODE> file provides the data wrapping and unwrapping
configuration on the client, and the <CODE>skeleton</CODE> provides the same
information for the server.
<P>
The data is passed between the client program and
the server using serialization. Serialization is a way to representat Java<FONT SIZE="-2"><SUP>TM</SUP></FONT>
objects as bytes that can be sent over the network as a stream and reconstructed
on the other side in the same state they were in went originally sent.
<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 + -