Finally, don’t forget to do a lot of mock exams. Head First EJB contains a lot of example questions, and on JavaRanch you can find links to other sites. This gives you an idea about the kind of questions you can expect, and identify the sections that require some more studying to be fully prepared. For example, I know from my teaching experience that the questions about role-responsibilities can be harder than expected when reading the theory.
JavaBlackBelt’s SCBCD Study Guide 1 1.1
2
Introduction
Author Liesbeth Jaco is a Java instructor at Loop Factory, Belgium. She moderates the EJB and WebSphere sections at JavaBlackBelt.com.
Why this document? Together with the “Head First EJB” book and the Sun EJB version 2.0 Specification, this study guide should help you to become fully prepared for the SCBCD certification exam.
+
+
She will be happy to get your feedback about this document by email: Liesbeth
+
3
Reviewers This study guide has been kindly reviewed by …
The basis of this document was written when I studied for the SCBCD certification myself. I felt that next to the clear explanations of “Head First EJB”, the summarizing bullet points, recap exercises and mock questions, I needed a more concise, structured document to allow me to have an overview and have a quick, last-minute check of some difficult sections. Kind of like Valentin Crettaz’s cheat sheets I found on JavaRanch. Other “summaries” were sometimes too wordy and elaborate, and not structured enough to serve as a real study guide. Recently, I taught a class of students with the purpose of obtaining the EJB certification. As I used “Head First EJB” in my course material, I got the same remarks from the students about it as I made myself, which encouraged me to transform my personal notes into this complete studyguide.
1.2
How to use it? As introduced, this document should not be used as a standalone study guide. First of all, I assume that you already have an understanding of EJB - by reading “Head First EJB” or a similar book. Secondly, I often refer to the HF book, e.g. for a concrete example, for additional theory that was not easy to summarize, or when the book contains a nice structured summary anyway. So the purpose of these notes is not to replace this book, but to be a guide-book.
Valentin Crettaz has a Masters degree in Information and Computer Science from the Swiss Federal Institute of Technology in Lausanne (EPFL). He has worked as a software engineer with SRI International (Menlo Park, CA) and as a principal engineer in the Software Engineering Laboratory of EPFL. Valentin is the co-founder and CTO of Condris Technologies, a company specializing in the development of next generation software architecture solutions. His research and development interests include aspect-oriented technologies, design and architectural patterns, web services, and software architecture. During his spare-time, Valentin moderates the SCBCD and SCDJWS forums at Javaranch.com and acts as a technical reviewer for O'Reilly's Head First series. He holds various Sun and IBM certifications, such as SCJP, SCJD, SCBCD, SCWCD, SCDJWS and IBM XML. He has also had the great opportunity to serve as a co-author for Whizlabs' SCBCD and SCDJWS Exam Simulators. John Rizzo is cofounder and managing director of Loop Factory, a Java focused education company. He has spent the last decade teaching IT; from OO to Java, going through AS/400 systems, methodologies and Delphi; to professionals, unemployed and children. John has co-founded JavaBlackBelt.com, a web site dedicated to technical quizzes about Java related technologies.
JavaBlackBelt’s SCBCD Study Guide
page 1
4
Bibliography • • • • •
Head First EJB (Brain-Friendly Study Guide) by Kathy Sierra and Bert Bates (referred to as [HFEjb]) Sun Microsystems Enterprise JavaBeans Specification, Version 2.0 (referred to as [EjbSpec]) http://www.valoxo.ch/jr/cheatsheets.html: Cheat sheets and spec-toobjectives mapping (See e.g. appendix DD Schema) http://www.valoxo.ch/jr/SCBCD_Links.html: JavaRanch links to objectives, mock exams, … http://www.javaworld.com/jw-10-1998/jw-10-beans-p3.html: introductory article
JavaBlackBelt’s SCBCD Study Guide
page 2
• • • •
EJB Overview and Architecture 1
Do not create or get classloader Do not access security policy info Do not load native library Do not pass this (bean instance) as argument or method result, only component interface • Some others and reason: page 494 [EjbSpec] So, you’re allowed to use: java.net.Socket, inheritance for bean classes, final static fields.
Use, Benefits, and Characteristics of EJBs • Have an overall understanding of how EJBs work, what they are good for, what they provide and what they don’t provide. Know the architecture and how it supports EJB features. • Described in [HFEjb], especially chapters one to three.
2 2.1
Container Requirements
4
• Roles: Bean Provider, Application Assembler, Deployer, Container and Server Provider, System Administrator • Responsibilities: - Description: page 26 [HFEjb] - Must be able to match a role with a responsibility description, or deployment descriptor (DD) tags o Pages 617-619 [HFEjb] o see DD Schema
Guaranteed APIs EJB 2.0, J2SE 1.3, JNDI, JTA, JDBC 2.0, JMS, JavaMail, JAXP
2.2
Guaranteed Services and Behavior Example list (not exhaustive): • Distributed transaction • Thread-safety • A security domain and one principal realm • Enforcement of client access security policies • Implementation of java:comp/env for bean • Generation of implementation classes of home and component interface, and stubs for remote object • Implementation of resource manager connection factory classes for resources configured with the server • Others: described throughout the [EjbSpec] under “Responsibilities of Container Provider” sections (7.11, 10.7, 15.8). So the following are NOT guaranteed: clustering, load-balancing, fault-tolerance, lazy-loading of entity data, in-memory data caching, …
3
EJB Programming Restrictions Restrictions for business methods to ensure portability and avoid deployment errors: • Do not read/write static fields • Do not use synchronization and threads • Do not use AWT to output or get keyboard input • Do not use java.io • Do not use ServerSocket
EJB Roles with Responsibilities
5
Requirements for an EJB-jar File • [NameToChoose].jar - META-INF - ejb-jar.xml -
- home interfaces (session + entity) - component interfaces (session + entity) - bean classes (session + entity + message driven) - primary key class (entity bean) - non J2SE/J2EE classes/interfaces that any of the above depend on • Forbidden: Container generated classes (implementation classes home and component interface, stubs for remote objects) • Optional: Manifest file (usage: page 487 [EjbSpec], point 23.3)
JavaBlackBelt’s SCBCD Study Guide
page 3
• IsIdentical() • find out whether two stubs refer to the same bean: - stateless SB: true if stubs came from same home - stateful SB: always false - EB: true if stubs refer to two entities with the same PK • page 142 [HFEjb]
Client View 1
Client View of Beans • Description in [EjbSpec] ….
Session
Home interface
Component interface
Remote EJBHome Local EJBLocalHome Remote EJBObject Local EJBLocalObject
Entity
page 58, 6.3
page 111, 9.5
page 60, 6.4
page 114 , 9.6
Message Driven
page 121, 9.9 page 61, 6.5 page 122, 9.10
• Memorize methods: see Interfaces Schema
2
4
Interfaces to Memorize See Interfaces Schema for the methods of following interfaces You must know when certain methods cannot be called! • EJBHome - remove(Object PK) for SB: RemoveException • EJBLocalHome - remove(Object PK) for SB: RemoveException • EJBObject - getPrimaryKey() for SB: RemoteException • EJBLocalObject - getPrimaryKey() for SB: EJBException
Client Lookup You have to know the syntax of a lookup and must recognize whether a client is local or remote.
2.1
Remote Home Interface Context initialContext = new InitialContext(); Object o = initialContext.lookup("java:comp/env/ejb/cart"); CartHome cartHome = (CartHome)javax.rmi.PortableRemoteObject.narrow(o, CartHome.class);
2.2
Local Home Interface Context initialContext = new InitialContext(); Object o = initialContext.lookup("java:comp/env/ejb/cart"); CartHome cartHome = (CartHome) o;
3
Handles • Serializable representation of component or home interface, that knows how to get back to the original Remote object (getEJBObject(), getEJBHome()) • Page 139 [HFEjb]
JavaBlackBelt’s SCBCD Study Guide
page 4
• Only for stateful SB; stateless SB goes back to pool between each method call, since not tied to a particular client. • Bean provider responsibility: when ejbPassivate method completes, all nontransient instance variables must be passivatable: - Serializable object - null - component or home interface (remote or local) - SessionContext object - Bean’s JNDI context (java:comp/env), or subcontext of it - UserTransaction object - Resource manager connection factory (e.g. javax.sql.DataSource) • Gets re-activated (container deserializes and calls ejbActivate) when client calls business method - Container must restore the passivatable instance variables with functionally equivalent variables. Transient variables must not be restored.
Session Beans 1
Stateless vs Stateful • Stateful: conversational state (instance fields and referenced objects) • Stateless: no conversational state (state that belongs to a specific client) - page 87 [EjbSpec], intro point 7.8
2
Implementation Requirements (Bean Provider) • Read in [HFEjb] …. Home interface Home methods
Component interface
page 232
Business methods
Bean class page 233
page 234
page 235
6
• Bean class (other rules) - page 236 [HFEjb] - summary bean class: see Bean Classes Schema
3
Creation • stateless: ejbCreate not tied to client called create() (same for removal) • stateful: create() calls constructors of EJBObject, SessionContext and bean class, and methods setSessionContext and ejbCreate Object interaction diagram and implementation: pages 194, 195 [HFEjb]
4
SessionContext • EJBContext, and additional SessionContext methods: see Interfaces Schema • Know what you can call under which circumstances: see WhatYouCanCall Schema
5
Lifecycles • See Lifecycles Schema • Missed ejbRemove Calls - When? Crash of EJB Container System Exception from bean instance Timeout of client inactivity while bean in passive state - Consequences for automatic resource releasing: page 82 [EjbSpec], point 7.6.3
Passivation of Conversational State • Stateful session beans are saved in temporary storage to save resources by calling ejbPassivate - Who calls method? Container - When? Client hasn’t called any method for a while and bean is not in transaction. - How? Using Serialization or something equivalent
7
Use of SessionSynchronization Interface • See Transactions-section
8
Interfaces to Memorize See Interfaces Schema: Methods of following interfaces • SessionBean • SessionContext • SessionSynchronization
JavaBlackBelt’s SCBCD Study Guide
page 5
Entity Bean 1
Primary keys • Unique identity: may be visible as one or more CMP fields - Must be set by the end of ejbCreate - Once set, cannot be changed (else IllegalStateException) - page 133 [EjbSpec], point 10.3.5 • Specified by Bean Provider - Single field in EB class: <primkey-field> - Multiple fields in EB class: define PK Class Class must be public and serializable public constructor without parameter public fields, subset of the names of the CMP fields suitable implementation of hashCode() and equals(Object)
2
4
Component interface
Local
10.6.12
10.6.11
Remote
10.6.10
10.6.9
• Bean class - Overview: Bean Classes-Schema - General: page 190 [EjbSpec], point 10.6.2 - Implementation rules (sections from [EjbSpec]): ejbCreate 10.6.4 ejbPostCreate 10.6.5 ejbHome 10.6.6 ejbSelect 10.6.7 business methods 10.6.8
Creation Create new entity in underlying persistent store Comparison with Session Bean: page 281 [HFEjb]
}
In bean class
Removal
5
EntityContext • EJBContext, and additional EntityContext methods: see Interfaces Schema • Know what you can call under which circumstances: see WhatYouCanCall Schema
6
Home interface
In home interface
Entity deleted from underlying persistent store, entity bean goes back to pool Comparison with Session Bean: page 282 [HFEjb]
Implementation Requirements (Bean Provider) For certif.: only those for CMP must be known! • Description in [EjbSpec]….
3
public CompIntfType create(params) throws CreateException, RemoteException; public PKType ejbCreate(params) {…} - PK must be set - return null when CMP - only declare exceptions when thrown public void ejbPostCreate(params) {…} - only declare exceptions when thrown
Passivation/Activation • ejbPassivate: Entity bean has finished a business method (other than remove()) and is about to go back to the pool, where it has no identity • ejbActivate: bean is needed to service a business method from a client • Comparison with Session Bean: page 309 [HFEjb]
7
Finders • • • • • •
8
Declared in home interface, nothing about them in bean class. Can return (collection of) EJB(Local)Object of the same type as entity bean. Implemented by container, using home interface and DD information (EJB-QL). Mandatory: findByPrimaryKey (but this one is not declared in DD) Object interaction diagram page 340 [HFEjb] [EjbSpec] point 10.5.6
Selectors • Abstract method defined in the bean class, not exposed in home or component interface • Can return CMP or CMR fields • Typically used in home business method to do the real data access. • If it returns (collection of) EJBObject, use
JavaBlackBelt’s SCBCD Study Guide
page 6
Remote (default is Local) • Implemented by container, using DD information (EJB-QL). • [EjbSpec] point 10.5.7
9
CMP fields • Abstract Persistent Schema: - Virtual Fields: abstract getters/setters, implemented by container - info in DD: ... <entity> ... SchemaName field1 field2 <primkey-field>field1 ... ...
• Example in entire Deployment Descriptor: see DD Schema
10 CMR Fields (Relationships) • Abstract Persistent Schema: - Virtual Fields: abstract getters/setters, implemented by container Local component interface type or Collection type (java.util.Collection/Set) - info in DD: ... <ejb-relation> <ejb-relationship-role> <ejb-relationship-role-name>role1 <multiplicity>Many
<ejb-name>bean1 field3 java.util.Collection <method> <ejb-name>MyBean <method-name> * Required <method> <ejb-name>MyOtherBean <method-name>myOverloadedMethod <method-params> <method-param>int Required <method> <ejb-name>MyOtherBean <method-name>myOverloadedMethod <method-params> <method-param>int <method-param>java.lang.String Required
4
5
5.1
5.2
BMT
• Use UserTransaction (so lookup JTA) - Setting: setRollbackOnly() (must be called from within a transaction, so between ut.begin() and ut.commit()/rollback()) - checking: call getStatus()
CMT
6
Session Synchronization • Only for CMT stateful session beans • javax.ejb.SessionSynchronization interface
• Reading message and performing business logic in one transaction • If transaction rolls back, the message goes back to the original destination - Vendor dependent: setting a maximum on the number of times the message is resent.
4.2
CMT
• Use EJBContext - Setting: Call setRollbackOnly() - Checking: Call getRollbackOnly() • Both methods must be called from within a transaction, so within a method marked Required, RequiresNew or Mandatory
Remarks for MDB (Message Acknowledgement)
4.1
setRollbackOnly • Mark the transaction so that it will never commit. • No rollback immediately, but when the transaction ends naturally: - When method that started transaction completes (CMT) - When the bean’s code calls commit() or rollback() (BMT) • Other participants of transaction can check whether transaction is already doomed.
Before transaction
BMT:
• transaction begins after bean receives message • If the method throws a runtime exception, message goes back to the original destination • use DD to specify how the Container sends acknowledgement to messaging service: Auto-acknowledge|Dups-ok-acknowledge
What can you call?
-
JavaBlackBelt’s SCBCD Study Guide
In transaction afterBegin Business beforeCompletion method SessionContext: everything like CMT SB Access java:comp/env, resource managers, other beans
After transaction (commit or rollback called)
afterCompletion (boolean hasCommitted) From SessionContext: no transaction related things. Access only java:comp/env
Use? See page 512 [HFEjb] Memorize methods: see Interfaces Schema
page 11
Exceptions 1
Application vs. System Exceptions
1.1
See Exceptions-Summary appendix
1.2
Standard EJB Application Exceptions
• API: see Exceptions-Summary • Stateless SB: never RemoveException • When thrown and client’s point of view: pages 548-549 [HFEjb]
1.3
Common System Exceptions
• API: see Exceptions-Summary • When thrown? page 552 [HFEjb]
2
Responsibilities
2.1
Bean provider responsibilities
• If you catch or create an application exception, throw it to container as application exception - If you find you can’t continue transaction, call setRollbackOnly() first • If business logic throws an exception the client does not expect, catch it and rethrow it as EJBException • Don’t catch runtime exception in business logic, just propagate it • Application exception must be declared in client interface and bean class • When creating own application exceptions: extend Exception - NOT RuntimeException or RemoteException
2.2
Container responsibilities
[HFEjb] p546 • Send application exception as is, and don’t rollback • If system exception - RemoteException or EJBException - Log exception - Rollback transaction - Kill bean
3
Scenarios Read example scenarios: pages 558-560 [HFEjb]
JavaBlackBelt’s SCBCD Study Guide
page 12
Director <method> <ejb-name>MyBean <method-name>methodTwo <method-params> <method-param>String
Security 1
Declarative Security: Class-Level
1.1
Bean Provider: do nothing
1.2
Application Assembler
• Define roles in DD: <security-role> <description>this role is for employees who .... Admin <security-role> <description>this role is for employees who .... Director ...
<method> <ejb-name>MyBean <method-intf>Remote <method-name>methodOne <method-permission> <method> <ejb-name>MyOtherBean <method-name>methodTwo
• Assign method permissions in DD: - Method permissions interact as a union - : method free for everyone to call <method-permission> Admin <method> <ejb-name>MyBean <method-name>* <ejb-name>MyOtherBean <method-name>methodOne <method-permission>
1.3
Deployer
• Assign security domain and principal realm to the application • Map users and/or groups to abstract security roles See page 583 [HFEjb]
2
Programmatic Security: Instance-Level
2.1
Bean Provider: Use EJBContext
• java.security.Principal p = context.getCallerPrincipal() - p.getName(): not guaranteed to match user’s login name • isCallerInRole(String): Declare abstract role names in Deployment Descriptor with <security-role-ref>, elements
JavaBlackBelt’s SCBCD Study Guide
page 13
2.2
Application Assembler: Mapping
4
• Define roles and assign method permissions (see Declarative Security) • Mapping: Add element <enterprise-beans> <session> <ejb-name>MyBean ... <security-role-ref> <description>this role should be assigned to .... Admin Administrator
3
Security Propagation with • Change the role the bean propagates as its outgoing identity, when calling other beans • Not for Message Driven Beans!
Principals and Roles, Users and Groups: Mapping • In Operational Environment - User (individuals, mapped to login name and password) - Groups: organization of users • In EJB - User or Group authenticates Æ represented by a java.security.Principal - Principal associated with abstract security role(s) (defined by Application Assembler) - Bean Provider optionally hard-codes security role references • Deployer maps between abstract security roles and User/Group • See page 590 [HFEjb]
<enterprise-beans> <session> <ejb-name>MyBean ... <security-identity> OtherRole
• Pages 591-592 [HFEjb]
JavaBlackBelt’s SCBCD Study Guide
page 14
Enterprise Bean Environment 1
java:comp/env
• One bean environment per home • Look things up in bean’s business method: InitialContext ic = new InitialContext(); Type var = (Type) ic.lookup(“java:comp/env/[subcontext/]madeUpName“); • Always cast. Narrow when it’s a remote home interface reference • Bean Provider uses made-up name in the code, and declares it in the Deployment Descriptor - anything followed by a slash, automatically becomes a subcontext • Deployer maps the made-up name to the real JNDI name of the resource • A single bean must not be deployed with more than one resource with the same name (different subcontext = different name!).
Following sections explain the 4 possible resources to lookup, and how to declare them.
2
• Complete resource mapping: page 612 [HFEjb]
• deployment-time values: cannot be changed dynamically, only by redeploying
<env-entry-type> <env-entry-value>
4
Enterprise Bean Reference •
without java:comp/env Legal: String and wrapper classes Optionally set by Bean Provider, Deployer must ensure validity
When a bean wants to do a lookup of another bean’s home interface
Remote reference Local reference <ejb-ref> <ejb-local-ref> <ejb-ref-name> <ejb-ref-type>
<ejb-link>
• Scope: private and unique to each home, so can reuse the same name for another bean’s environment entry.
3
Container or Bean Bean: programmer uses getConnection(username, password) Container: deployer must configure sign-on information (vendor and resource specific) Shareable (default) or Unshareable Whether for other beans in same application, using same resource, in the SAME transaction, can use the same connection.
Environment Entries
<env-entry> <description> <env-entry-name>
without java:comp/env Legal: - javax.sql.DataSource - javax.jms.QueueConnectionFactory - javax.jms.TopicConnectionFactory - javax.mail.Session - javax.net.URL
Resource Manager Connection Factories • Used for creating connections to a resource, e.g. DataSource for connecting to a database.
JavaBlackBelt’s SCBCD Study Guide
without java:comp/env Session or Entity Fully qualified home interface Fully qualified component interface Only if the referenced bean is in the same application. Must match <ejb-name> of the same DD See page 615 [HFEjb]
page 15
5
Resource Environment References
• Directly gives the thing you want, the (JMS) destination without java:comp/env
javax.jms.Queue javax.jms.Topic Others (not yet standardized)
JavaBlackBelt’s SCBCD Study Guide
page 16
Appendix The next sections contain the appendices: • • • • • • •
Exception Summary Transaction Summary Bean Class Schema Interfaces Schema Lifecycles What You Can Call DD Schema
JavaBlackBelt’s SCBCD Study Guide
page 17
Exception Summary
2
System Exceptions
Æ to Memorize
System Exceptions What?
Runtime exceptions and RemoteException
Applications Exceptions
Local Clients (Unchecked!)
Checked, but don’t extend RemoteException!
javax.ejb. EJBException
(checked, but not expected !)
Client recovery? Effect Send to client as … Tx status?
No RemoteException (to remote client) or EJBException (to local client) Automatic rollback
Bean instance Logging?
Dies Yes
Possible Exactly as thrown
java.lang. IllegalStateException
javax.ejb. NoSuchEntityException
No rollback, unless setRollbackOnly was called Lives No
javax.ejb. NoSuchObjectLocalException
javax.ejb. TransactionRequiredLocalException
Remote Clients (Checked!)
1
java.lang. RuntimeException
javax.ejb. TransactionRolledbackLocalException
java.rmi. RemoteException
Application Exceptions java.rmi. NoSuchObjectException
Checked!
javax.ejb. CreateException
javax.ejb. DuplicateKeyException
javax.ejb. TransactionRequiredException
javax.ejb. TransactionRolledbackException
java.lang. Exception
javax.ejb. FinderException
javax.ejb. RemoveException
javax.ejb. ObjectNotFoundException
JavaBlackBelt’s SCBCD Study Guide
page 18
Transaction Summary Æ to Memorize
Situation: methodA() calls methodB()… Attribute for methodB() Required RequiresNew Mandatory Supports NotSupported Never
CMT Bean Type Session beans
methodA() within transaction TxA, methodB() within… TxA TxB TxA TxA Unspecified tx Context Exception
methodA() without transaction, methodB() within… TxA TxA Exception Unspecified tx Context Unspecified tx Context Unspecified tx Context
Tx attribute required for … business methods in the component interface Component interface
business methods remove() methods
Home interface
methods written by the Bean Provider Remove() methods
Entity beans
Message-driven beans
onMessage()
Run in “Unspecified Tx contect”… 1. 2.
3.
All CMT methods marked NotSupported, Never or Supports CMT Session Bean methods: Reason? not part of client’s tx ejbCreate() (any of them) not part of client’s tx ejbRemove() never called when SB in tx ejbPassivate() never called when SB in tx ejbActivate() not part of client’s tx CMT Message-Driven Bean methods ejbCreate() and ejbRemove()
JavaBlackBelt’s SCBCD Study Guide
page 19
Bean Class Schema Message-driven beans
Session beans
Creation
Container Callbacks
Stateless ejbRemove() setXxxContext(XxxContext) ejbActivate() ejbPassivate() ejbLoad() ejbStore() unsetEntityContext()
; ;
ejbCreate() ejbCreate<METHOD>(…) ejbPostCreate<METHOD>(…)
Required Forbidden
Business Logic?
Stateful
Entity beans CMP CMR
BMP BMR
; ; ; ;
Required Forbidden
; ; ; ; ; ; ; At least one
Optional One matching for each ejbCreate<METHOD>
onMessage(Message)
busMethXxx(…)
busMethXxx(…) ejbHome<METHOD>(…)
afterBegin() beforeCompletion() afterCompletion(boolean)
SessionSynchronization
abstract getter/setter
Persistent state?
Not implemented, nor declared. (generated from EJB-QL in DD)
finders
Not in Certification Objectives
abstract ejbSelectXxx
selectors
Remark: Gray areas mean that the option is not applicable in the given context.
JavaBlackBelt’s SCBCD Study Guide
page 20
Interfaces Schema java.r mi .Rem o te
javax.e jb.EJBH o me getEJ BMetaD ata() getH omeH andle() rem ove(H andle) rem ove(O bject P K)
ja vax. ejb.H om eH an dle g etE JBH om e()
javax.ejb .EJBObje ct
javax .ejb.E JB Lo calHo m e
javax.ej b.EJBL oca lObject
get EJBH ome() get Handle() get Prim aryKey() isIdentical(E JBO bject) remove()
remove(Objec t PK)
getEJ BLocalH ome() getPrimaryK ey() isIdentic al(EJ BLocalOb ject)
j avax .ejb.H an dle g etE JBO bject()
java.io.S erializ able
j avax .ejb.E nterpri seB ean
javax.e jb.En tityBean
javax.ejb .Session Bean
javax.ejb .MessageD riven Bean
ejbR em ove() setEntityContext(E ntityC ontext) ejbAc tivate() ejbPass ivate() ejbLoad() ejbStore() uns etE ntityC ont ext()
ejbRemove() setSessionC ontext(Sess ionC ontext) ejbActivate() ejbPassivate()
ejb Remove() s et Mess ag eD rivenC ontext(MessageDrivenC ont ext)
javax.jm s.MessageL isten er
javax.e jb.EJBC on te xt
onMes sage(M essage)
getEJ BH om e() getEJ BLocalH ome() isC allerInR ole(String) getC allerP rinc ipal() getU serTransaction() s etR ollbac kOnly() getR ollback Only()
javax.ejb .EntityC o ntext getEJB Loc alObjec t() getEJB Object () getPrimaryKey()
j avax .ejb. Session Co ntext
javax.ejb. M e ssag eDr iven C on text
getEJB LocalObjec t() getEJB Objec t()
javax.transaction . U serT ransaction begin() comm it() getStatus() rollback() setR ollback Only()
javax.ejb. Session Syn chro niz atio n afterBegin() beforeC om pletion() afterC ompletion(b oolean)
JavaBlackBelt’s SCBCD Study Guide - appendix
page 21
SessionBean stateless Constructor setXxxContext for EB: unsetEntityContext
ejbCreate ejbRemove
ejbPostCreate
nothing context. ; access ; context. ; ; access ; -
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
EntityBean
stateful nothing context. ; access ; context. ; ; ; ; access ; ; ;
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
nothing context. ; access ; context. ; ; ; ; access ; ; ; context. ; ; ; ; ; ; access ; ; ;
MessageDrivenBean nothing
getEJB(Local)Home getEJB(Local)Object getPrimaryKey() isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT)
context. -
setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT)
access ; -
java:comp/env other bean’s methods resource manager
context. ;
setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT)
access ; -
java:comp/env other bean’s methods resource manager
java:comp/env other bean’s methods resource manager getEJB(Local)Home getEJB(Local)Object getPrimaryKey() isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
getEJB(Local)Home getEJB(Local)Object getPrimaryKey() isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
Business method - for SB, EB: from comp interface - for MDB: onMessage
context. ; ; ; ; ; ; access ; ; ;
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
context. ; ; ; ; ; ; access ; ; ;
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
Home business method
ejbActivate ejbPassivate
ejbLoad ejbStore
context. ; ; ; ; access ; ; ;
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
context. ; ; ; ; ; access ; ; ; context. ; ; ; ; access ; ; ; context. ; ; ; access ; context. ; ; ; ; ; ; access ; ; ;
getEJB(Local)Home getEJB(Local)Object isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager getEJB(Local)Home getEJB(Local)Object getPrimaryKey() isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager getEJB(Local)Home getEJB(Local)Object getPrimaryKey() isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction java:comp/env other bean’s methods resource manager getEJB(Local)Home getEJB(Local)Object getPrimaryKey() isCallerInRole(s)/getCallerPrincipal() setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT) java:comp/env other bean’s methods resource manager
context. ; ; ;
setRollbackOnly (CMT) getRollbackOnly(CMT) getUserTransaction (BMT)
access ; ; ;
java:comp/env other bean’s methods resource manager
Lifecycles session/message beans does not exist
bean throws system exception new instance setXxxContext
entity beans bean throws system exception
timeout
ejbRemove or timeout
ate ctiv A b j e
ejbCreate
ready
does not exist new instance setXxxContext
passive
e ivat
unsetEntityContext
pooled
ass ejbP
ejbCreate ejbPostCreate ejbActivate
or or
ejbFindXxx ejbSelectXxx ejbHomeXxx
ejbRemove ejbPassivate
or
business methods ejbLoad ejbStore
ready
business methods (comp intf) black: stateless session bean + message driven bean black + green italic: stateful session bean black + red times: entity bean
ejbSelect
<ejb-jar> <enterprise-beans> <entity> <description>Entity bean description Display name for tools <small-icon>File name of a JPEG/GIF image File name of a JPEG/GIF image <ejb-name>SomeEntityBean com.company.EntityBeanRemoteHome com.company.EntityBeanRemote com.company.EntityBeanLocalHome com.company.EntityBeanLocal <ejb-class>com.company.EntityBeanEJB Container / Bean <prim-key-class>com.company.EntityBeanPK False / True 2.x /1.x EntityBean field1 field2 <primkey-field>field1 <env-entry> <description>Environment entry description <env-entry-name>envEntry1 <env-entry-type>java.lang.Integer <env-entry-value>2000 <ejb-ref> <description>EJB reference description <ejb-ref-name>ejb/OtherEntityBeanHomeRemote <ejb-ref-type>Entity /Session com.company.OtherEntityBeanRemoteHome com.company.OtherEntityBeanRemote <ejb-link>SomeEntityOrSessionBeanName <ejb-local-ref> <description>Local EJB reference description <ejb-ref-name>ejb/OtherLocalEntityBeanHomeRemote <ejb-ref-type>Entity / Session com.company.OtherLocalEntityBeanRemoteHome com.company.OtherLocalEntityBeanRemote <ejb-link>SomeEntityOrSessionBeanName
Bean Provider Application Assembler Deployer Bold: Mandatory elements Red: Default values
<description>Some DataSource description jdbc/SomeDB javax.sql.DataSource Container / Application Shareable / Unshareable <description>Some DataSource description jms/SomeQueue javax.jms.Queue <security-role-ref> <description>Security role reference description Manager Administrator <security-identity> <description>Security identity description <description>Run as description Manager OR <use-caller-identity /> <description>Query description <method-name>findSomething <method-params> <method-param>java.lang.String Local / Remote <ejb-ql>SELECT OBJECT(e) FROM EntityBean e WHERE e.field1 = ?1
Bean Provider Application Assembler Deployer Bold: Mandatory elements Red: Default values
<session> <description>Session bean description Display name for tools <small-icon>File name of a JPEG/GIF image File name of a JPEG/GIF image <ejb-name>SomeSessionBean com.company.SessionBeanRemoteHome com.company.SessionBeanRemote com.company.SessionBeanLocalHome com.company.SessionBeanLocal <ejb-class>com.company.SessionBeanEJB <session-type>Stateful / Stateless Container / Bean <env-entry> ... <ejb-ref> ... <ejb-local-ref> ... ... ... <security-role-ref> ... <security-identity> ...
Bean Provider Application Assembler Deployer Bold: Mandatory elements Red: Default values
<message-driven> <description>Message-driven bean description Display name for tools <small-icon>File name of a JPEG/GIF image File name of a JPEG/GIF image <ejb-name>SomeMDBean <ejb-class>com.company.MDBeanEJB Container / Bean <message-selector>Some message selector Auto-acknowledge / Dups-ok-acknowledge <message-driven-destination> <destination-type>javax.jms.Queue / javax.jms.Topic <subscription-durability>Durable / NonDurable <env-entry> ... <ejb-ref> ... <ejb-local-ref> ... ... ... <security-identity> <description>MDB Security identity description. Only run-as!! <description>Run as description Manager
Bean Provider Application Assembler Deployer Bold: Mandatory elements Red: Default values
<description>Relationships description <ejb-relation> <description>EJB Relation description <ejb-relation-name>Entity1-Entity2 <ejb-relationship-role> <description>EJB Relationship role description <ejb-relationship-role-name>Entity1-has-an-Entity2 <multiplicity>One <description>EJB Relationship role source description <ejb-name>SomeEntityBean <description>Container-managed relationship field description cmrField1 java.util.Collection / java.util.Set <ejb-relationship-role> <description>EJB Relationship role description <ejb-relationship-role-name>Entity2-belongs-to-Entity1 <multiplicity>Many <description>EJB Relationship role source description <ejb-name>SomeOtherEntityBean <ejb-relation> ...
Bean Provider Application Assembler Deployer Bold: Mandatory elements Red: Default values
<security-role> <description>Security role description Administrator <method-permission> everyone OR <method> <description>Style 1 Method description <ejb-name>SomeEntityBean <method-intf>Home / Remote / LocalHome / Local <method-name>* <method> <description>Style 2 Method description <ejb-name>SomeEntityBean <method-intf>Home / Remote / LocalHome / Local <method-name>create <method> <description>Style 3 Method description <ejb-name>SomeEntityBean <method-intf>Home / Remote / LocalHome / Local <method-name>createSomething <method-params> <method-param>java.lang.String <description>Container transaction description <method> <ejb-name>SomeEntityBean <method-name>* Required/RequiresNew/Mandatory/Never/Supports/NotSupported <exclude-list> <description>Exclude list description <method> <ejb-name>SomeEntityBean <method-name>method1 <ejb-client-jar>someOtherClientJarFile.jar
Bean Provider Application Assembler Deployer Bold: Mandatory elements Red: Default values