Académique Documents
Professionnel Documents
Culture Documents
中国Java开发
网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计
您没有登录
As I’m progressing on SCBCD I abstract 200 Bullet Points from the book” Head first EJB”.
Hopeful it will benefit to your guys.
1 of 5 5/15/2006 3:34 AM
中国Java开发网 - 200 Bullet Points from the book” Head first EJB” http://www.cjsdn.net/post/view?bid=4&id=92484&sty=1&tpg=1...
implements it. This class is used to make the EJBOjbect for the bean.(The Bean’s bodyguard).
28. The container also creates a stub to the EJBObject.
29. you create the Remote Component Interface by writing an interface that extends
javax.ejb.EJBObject (an interface that extends java.rmi.Remote)
30. You also create the bean class where the actual business methods are implemented (despite
the fact that the bean class technically doesn’t implement the Remote Component interface)
31. The Home is the factory for the bean. Its main job is to hand the client a reference to the
bean. But remember, the client can never truly get a reference to the bean – the best the client
can do is to get a reference to the bean’s EJBObject.
32. You create the Home interface by writing an interface that extends javax.ejb.EJBHome( and
interface that extends java.rmi.Remote)
33. The container is responsible for implementing the Home interface by building a class that
implements it, and the container also generates the stub for the Home.
34. There is only one Home per deployed bean. For example, a ShoppingCart bean would have a
single ShoppingCart Home, regardless of how many ShoppingCart beans have been created.
35. The methods of the bean are exposed to the client through the component interface.
36. The client can’t directly get a reference to the bean; the client must go through the bean’s
EJBObject, which implement the component interface.
37. The client gets a reference to the bean’s EJBOjbect from the bean’s home.
38. To get the bean’s home, the client does a lookup on JNDI, using the logical name under
which the bean was deployed.
39. To do a JNDI lookup, the client must first get an initialContext, which is the entry point into
the server’s JNDI “ virtual directory tree”
40. For a Remote home interface, the stub returned from JNDI must be both cast and narrow.
41. Narrow is “exotic casting” needed for the stub objects that come from a method that does
not return the stub’s client interface. Since the JNDI lookup return type object, the object
returned from the lookup must be narrowed to the bean’s Home interface, and then cast to the
bean’s home interface.
42. Narrow is required for IIOP stub(IIOP is wire protocol for CORBA), because what’s return
from the lookup might not be capable of implementing multiple interface, and thus would know
only about the methods in type Objects. Narrowing returns an object that implements the home
interface.
43. The home interface extends EJBHome, which have four additional methods the client can
see: getEJBMetadata, getHomeHandle, remove(Handle h), remove(Object primarykey), The
remove(Object primarykey) must not be called on Session bean.
44. You expose your bean’s business methods in the component interface.
45. Remote component interface must extend javax.ejb.EJBObject.
46. The client get a reference to the bean’s EJBOjbect by calling a method on the bean’s home
interface.
47. Reference to both stateless bean and stateful bean are retrieved from the home’s create()
methods
48. From the EJBObject interface, the client sees five additional methods: getEJBHome,
getHandle, remove, isIdentical and getPrimaryKey
49. Only entity bean clients are allowed to call getPrimaryKey() on the bean’s component
interface. SessionBean clients will get a RemoteException.
50. The getEJBHome() method returns a reference to the bean’s home interface, so that client
doesn’t have to go through a JNDI lookup, if they want to make more beans of that type.
51. The getHandle() method returns a Serializable object that can be used later to reestablish
contact with the server, and get back the stub to the component interface that the client used to
get the handle.
52. The handle has one method, getEjbOjbect(), that returns the Remote stub as type
EJBObject. That means the stub must be cast and narrowed, just as you must do with the home
stub that you get from a JNDI lookup.
53. The isIdentical() method is kind of like doing an equals() method on the server. It returns
true for two different stateless beans from the same home, false for two different stateful beans
from the same home, and true for references to entities bean with the same primary key.
54. You can expose your bean to local client using a local client view.
55. Local component interfaces must extend javax.ejb.EJBLocalObject. Local home interfaces
must extend javax.ejb.EJBLocalHome.
56. Methods in local client interfaces do not declare RemoteException.
57. Some of interface methods exposed to Remote clients are not exposed to local clients.
58. Local client cannot get handles, since handles are used to re-establish a connection to the
Remote object.
59. EJBMetadata is not used with local clients, since a local client can use reflection to
interrogate the EJB object and Home object.
60. Local home interface have only one remove() method – the one that takes a primarykey .
the remove() that takes a Handle doesn’t exist in the local home interface, since Handle aren’t
used with a local client view.
61. Because of the only remove() in the local home interface requires a primary key argument,
local session bean client can’t remove a bean using the bean’s home; they can call remove() only
2 of 5 5/15/2006 3:34 AM
中国Java开发网 - 200 Bullet Points from the book” Head first EJB” http://www.cjsdn.net/post/view?bid=4&id=92484&sty=1&tpg=1...
3 of 5 5/15/2006 3:34 AM
中国Java开发网 - 200 Bullet Points from the book” Head first EJB” http://www.cjsdn.net/post/view?bid=4&id=92484&sty=1&tpg=1...
88. Entitle home interface can also have home business methods, for operations that apply to
more than one entity, as opposed to one specific entity. Batch updates would be good use for a
home business method.
89. the real benefit of home business methods is that – unlike create and finder methods –
home business methods can return something other than an EJB object reference. If the client
want only data,say, a Collection of Strings representing the name and phone number of each
customer, a home business method can do that while a finder can not.
90. An entity bean create() is very different from a session bean create(), because an entity
bean create() inserts a new entity into the underlying persistent store(i.e. new row in the
database)
91. An entity bean remove() is dramatically different from a session bean remove(). When a
client calls remove on an entity bean, it’s to delete the entity from the database! That means
everyone is done with the bean.
92. Entity bean can have persistent relationship with other entity beans.
93. A container-managed relationship(CMR) field is defined in the bean class just as a CMP field
is -- with a pair of abstract getters and setters that return either the local component interface of
the bean, or a Collection.
94. If the virtual field is a Collection, it must be declared as either java.util.Collection or
java.util.Set. No other Collection type is allowed as the declared return type of a CMR field.
95. Relationship have multiplicities – they can be one-to-one, one-to-many, many-to-many.
96. Multiplicity affects the return type of the virtual field. Movie has only one Director, so the
CMR field in the bean is getDirector(), that return a reference to a Director’s local component
interface. But a Director has many Movie, so a Director’s virtual field is getMovie(), with return a
Collection.
97. A CMP bean must define an “abstract – persistence –schema” in the DD, that lists each of
the bean’s CMP fields, and also identifies which of the fields is the primary key ( unless it’s a
compound primary key), The DD must always define the type of the primary key, even if the
primary key is not a field of the bean. (remember, if the primary key is not a field of the bean, it
must be a primary key class composed of CMP fields from the bean)
98. Relationship fields are not defined in the <enterprise-bean> portion of the DD( where you
define your CMP fields), but are instead defined in the <relationship> session of the DD.
99. Each relationship must have two partners, with each partner described in an
<ejb-relationship-role> element that include the CMR field name, the source for the partner, the
multiplicity and an optional(<cascade-delete/> which means “delete me if my partner is
deleted”).
100. Cascade-delete tell the Container to delete the bean with the <cascade-delete/> tag when
the bean’s partner is deleted. This work only if the bean has a multiplicity of one. ( You wouldn’t
want to delete a Director just because one of this Movies was deleted; but you might want to
delete a Movie if its sole Director was deleted).
101. More coming at Part 2.
---------------------------------------
SCJP. SCWCD.
----------------------------------------
• 寻求java高手!
作者 Re:200 Bullet Points from the book” Head first EJB” [Re:jamesfeng2]
Ricol 于 2004-05-17 11:31
Thanks a lot.
发贴: 77 • javaweb开发的通用功能
积分: 0
作者 Re:200 Bullet Points from the book” Head first EJB” [Re:jamesfeng2]
specialdrink 于 2004-05-19 07:23
发贴: 0
积分: 0
• 向服务器传输文件小程序
4 of 5 5/15/2006 3:34 AM
中国Java开发网 - 200 Bullet Points from the book” Head first EJB” http://www.cjsdn.net/post/view?bid=4&id=92484&sty=1&tpg=1...
已读帖子
新的帖子
被删除的帖子
返回中国Java开发网论坛
5 of 5 5/15/2006 3:34 AM