Ejbmatrix 11
Ejbmatrix 11
ejbActivate() EB can acquire Transition from EB can acquire Transition from Optionally obtain When client Never called because container creates
additional pooled to ready additional pooled to ready state invokes
resources needed state resources needed state Not allowed
in ready state in ready state during a txn 1
Unspec'd txn ctx Unspecified txn
Container assigns context
ID
ejbPassivate() Container Within a txn p103 Removes bean ID Within a txn p103 Optionally store !"
Not in txn Never called because container
removes bean ID After ejbStore() Unspecified txn After ejbStore() state !"
Timed out or destroys
Container doesn’t Transition from ctx Transition from Release resources !"
LRU
serialize instance 1 ready to pooled ready to pooled (e.g. JDBC !"
App server runs
Unspec'd txn ctx connections) out of free beans1
May serialize
instance1
Unspecified txn
context
ejbRemove() Container Remote interface Do DELETE Clean up state Upon: Not upon:
removes bean ID 1 remove() or EB Release resources !"Bean timeout !"Container crash
Remove entity home.remove() Unspecified txn !"Server failure !"System exceptn
object because Transition from context Not upon: !"Client timeout
pooled to ready
client called !"Container crash while bean
remove() !"System exceptn passivated
Transaction ctx of !"Client timeout May need clean
remove() method while bean up: section 6.6.3
p106 passivated
May need clean
up: section 6.6.3
_______________________________________________________________________________________________________________________________________________________
Last updated 08/03/00 10:09 PM by Eileen Sauer Page 3 of 7
ejbFindByPrimaryK One or more home.findByPrim One or more methods N/A - anonymous to client
ey() Match findByPK aryKey() Match findByPK
Return remote int Do SELECT, if exists, return PK
or Collection Return remote interface or Collection
Txn ctx of find Txn ctx of find method
method
ejbFindXXX() Match findXXX() Match findXXX() N/A
Return remote interface or Collection Do SELECT, if exists, return PK
Txn ctx of find method p133 Return remote interface or Collection
Txn ctx of find method
SessionSynchronization interface
Container-managed transactions
afterBegin() N/A After new txn begun, same txn context N/A - must not implement this
as beforeComp() and business methods interface
beforeCompletion() N/A Before commit; if setRollbackOnly true, not N/A - must not implement this
run else you can cache updated data. Same interface
txn context as afterBegin() and bus methods
afterCompletion() N/A After commit/rollback; clean up state if N/A - must not implement this
rollback causes inconsistency. Status of txn: interface
committed (true) or rolled back (false)
EJBMetaData interface
Allow dynamic invocation of beans
getPrimaryKeyClass N/A - anonymous to client
javax.ejb.Handle interface
general Lifetime/scope implementation specific. At minimum: can store/retrieve across
JVMs p95. Not required to store/retrieve across containers.
serialVersionUID Inherited from java.io.Serializable
getEJBObject() SB exists, get a reference
HomeHandle interface extends java.io.Serializable
general Handle for the home interface
serialVersionUID Inherited from java.io.Serializable N/A
getEJBHome()3 N/A
getHandle() N/A
PK class
general Can be any class that is legal value type in RMI-IIOP, some restrictions 9.2.9 N/A
May be specific to an EB, but multiple EBs can use the same PK p93
implementation primkey-field of DD p134 Must be specified N/A
Can be unspecified p134
equals() Recommended: implement this N/A
hashCode() Recommended: implement this N/A
javax.rmi.PortableRemoteObject
narrow() Must use to convert result of getEJBObject() method invoked on handle to EB's Use for interoperability with EJB containers.
remote or home interface type p94, 96 Cast likely to fail if container implementation uses RMI/IIOP p47
_______________________________________________________________________________________________________________________________________________________
Last updated 08/03/00 10:09 PM by Eileen Sauer Page 4 of 7
Transaction Matrix
Callback Entity Beans Session Beans
Container-managed transactions Container-managed transactions Bean-managed transactions
General
No nested transactions. Container not required to support JTS, only required to support JTA UserTransaction p155. Application exceptions don't automatically cause
rollback p168. Don’t retain state between transactions1 Can provide caching and updates to multiple data sources. Isolation levels p160
EJBContext interface
getCallerPrincipal May be different in each business method (if moved from pooled to ready) p104 Return java.security.Principal - identity of invoker
Container must have client security context Container must have client security context
getEJBHome Return home interface
setRollbackOnly Should only be used if EB methods have transaction context p112 Instance can mark current transaction N/A
for rollback. Container must have
meaningful transaction context p71
getRollbackOnly Should only be used if EB methods have transaction context p112 Instance can check if current N/A
transaction is marked for rollback
Container must have meaningful
transaction context p71
getUserTransaction N/A Return UT interface so bean can:
!"Demarcate transactions
!"Obtain transaction status
isCallerInRole(strin May be different in each business method (if moved from pooled to ready) p104 Does caller have a particular role?
g roleName) Container must have client security context Container must have client security context
EntityContext interface extends EJBContext
getEJBObject Instance can obtain identity of entity object Return remote interface
Identity remains associated until passivated/removed p105
Disallowed in EB methods where there is no ID p112
getPrimaryKey Obtain primary key of entity object N/A
Might be different each time instance is moved from pooled to ready p104
SessionContext interface extends EJBContext
getEJBObject Return remote interface
Transaction Attributes
Client has transaction context Client has NO transaction context
NotSupported Container suspends txn Runs ← Same
May have unspecified txn context May have unspecified txn context
ejbStore(), ejbLoad() unreliable ejbStore(), ejbLoad() unreliable
Required Runs Container creates txn ← Same
Supports set/getRollbackOnly() Supports set/getRollbackOnly()
Supports Runs (code should be txn-insensitive) Runs (code should be txn-insensitive) ← Same
May have unspecified txn context May have unspecified txn context
_______________________________________________________________________________________________________________________________________________________
Last updated 08/03/00 10:09 PM by Eileen Sauer Page 5 of 7
RequiresNew Start one Suspend txn and start new txn ← Same
Supports set/getRollbackOnly() Supports set/getRollbackOnly()
Mandatory Run Throw exception ← Same
Supports set/getRollbackOnly() Supports set/getRollbackOnly()
Never Throw exception Run ← Same
May have unspecified txn context May have unspecified txn context
javax.transaction.UserTransaction (JTA)
general Must not use sql.Connection interface: commit(), setAutoCommit(), rollback(). Must not use UserTransaction p161 Enables programmatic transaction
demarcation. Don't use sql.Connection
begin() N/A Must refresh copy of possibly stale data
commit() N/A Stateless SBs must commit before method
returns p161. Not guaranteed to get same
UserTxn across method calls
Stateful guaranteed to get same UserTxn
until txn terminates 2
getStatus() N/A Use in place of getRollbackOnly()
rollback() N/A Use in place of setRollbackOnly()
1
This information comes from a newsgroup/mailing list – caveat emptor!
2
Danger of long-running transactions if your transaction spans method calls. Not normally done.
3
Source: EJB API.
4
This is because with legacy data, entity objects may exist before the container and entity beans deploy. Also, entity objects may be created by inserting rows into the database, not by
create(). The rows are still accessible via finder methods. p92
5
A handle is an object that identifies an object on network
To join EJB-INTEREST, send email to [email protected] and put in the body of the message: subscribe EJB-INTEREST.
Questions:
!"
FS: What if, in a method, you spawn off 10 threads and join them back up before the end of the method? Legal? p79
!"
How to handle EJBContext?? EJB-INTEREST Transaction context vs session context (application context). Recommendation: use stateful to maintain your application state, short burst
transactions to your underlying persistence. Question about serialization/storing of EJBContext. Same as SessionContext? EntityContext?? Only during stateful beans, activation and
passivation don't apply to stateless.
!"
Stateless session beans good for maintaining open connection to COBOL, legacy system: life of bean instance, not limited to client life cycle, activate/passivate don't affect
!"
Handling large transactions: start, pause, suspend, abort. JMS, can’t multithread. EJB no “oneway” semantics. Need event model?
!"
Spec doesn’t address optimistic concurrency control. Will be part of spec 2.0
!"
Remote debugging API??
_______________________________________________________________________________________________________________________________________________________
Last updated 08/03/00 10:09 PM by Eileen Sauer Page 6 of 7
Recommended Design
Workflow
Intelligent Apps
use case 1 use case 2
Session Bean Session Bean You write – coarse-
grained use cases
Oracle/Sybase/DB2
Gemstone, eXcelon
_______________________________________________________________________________________________________________________________________________________
Last updated 08/03/00 10:09 PM by Eileen Sauer Page 7 of 7