📄 ch05s06.html
字号:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Container Managed Persistence - CMP</title><link rel="stylesheet" href="styles.css" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets Vimages/callouts/"><link rel="home" href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html" title="JBoss 3.0 Documentation"><link rel="up" href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html" title="Chapter 5. Using container-managed persistence"><link rel="previous" href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html" title="Chapter 5. Using container-managed persistence"><link rel="next" href="ch05s08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s08.html" title="Creating the Beans"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="jboss.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss.gif" border="0"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch05s08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s08.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table><div class="section"><a name="d0e1823"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="d0e1823"></a>Container Managed Persistence - CMP</h2></div></div><div class="section"><a name="d0e1826"></a><div class="titlepage"><div><h3 class="title"><a name="d0e1826"></a>Determine the persistent classes</h3></div></div><p>In this simple example we will use two Enterprise JavaBeans. The first, called
"CD" models a music CD.
It contains attributes (instance variables) that store the title ID code and
various other
properties of a music CD. The second is called "CDCollection", and models a
collection of such CDs.
This bean acts as a simple interface between the client and the CD Bean;
technically we could
manage without it but it does make certain operations easy to follow. The
CDCollection Bean
will have the following methods deleteAll(), addCd(), findInAnyField() and
findAll(). </p><p>
<div class="itemizedlist"><ul><li><p><a name="d0e1834"></a>addCd() - Adds a single CD specified by values of its attributes</p></li><li><p><a name="d0e1837"></a>deleteAll() - Delete all CDs </p></li><li><p><a name="d0e1840"></a>findInAnyField() - Returns an array of CD instances which have
the specified text string in any of their attributes</p></li><li><p><a name="d0e1843"></a> findAll() - Returns an array of all CD instances in the system </p></li></ul></div>
</p><p>All these methods could be implemented by direct manipulation of the home
interface of the CD Bean,
but it is slightly more elegant to do it this way. </p><p>
Because the CDCollection Bean only interacts with the CD Beans during requests
from clients, it
appears to have no persistent information. So it is a session Bean. Moreover,
since each method
is completely self-contained, it is a stateless session bean. </p><p>The CD Bean, however, will be an entity EJB because some of its information is
persistent.
For example, the ID, artist, title, type and notes about the recording will
all be persistent.
Of course the CD Bean may have other instance variables, but they won't
necessarily be persistent.
For example, some will hold temporary data, and others will be derived from
the persistent attributes. </p><p>
In this example, I will assume that the persistent fields are all Java
Primitive type values representing
the ID, title, artist, type and notes. </p></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch05s08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s08.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -