Dear Folks,
I am trying to come up with rationale for the allowed and not allowed operations for entity beans to better recollect them. Most of the Whys and Why nots I don't know and most of the ones I have come up with maybe inaccurate. I am using Valentine Cretazz's cheat sheet and looking for help from all of you to fill in the blanks and expand upon it and give your reasons, please. If there is a resource that better explains this please direct me to it.
ENTITY BEANS:
METHOD: setEntityConext(ec)
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2)
java:comp/env
X3) getRollBackOnly()/setRollBackOnly
X4) getCallerPrincipal()/getPrimaryKey()
X5) java:comp/jdbc, java:comp/ejb
X6) getEJBObject()/ getEJBLocalObject()
REASONS:
1) How can it call the Home Object when its the container of a CMP Entity bean that creates and sets the context and the bean and puts them back into the pool ? (as per page 326 of HFEJB)
2) I can't think of a reason why java:comp/env access ought to be available or the other access unavailable.
3) Transactions are not allowed at setEntityContext(ec) because the bean is not ready for transactions yet considering its context could have been created and set just for the pool by the container to be later initialized with entity data.
4) Client information cannot be accessed at setEntityContext(ec) because the client could not have existed at a stage when the bean and its context could have been created and set just for the pool by the container to be later initialized with entity data.
5) Database connections and other
EJB access are not allowed at setEntityContext(ec) because the bean and its context do not even know what entity data they will be initialized with and have been created and set just for the pool by the container.
6) The EJBObject/ EJBLocalObject calls are not allowed because the EJB Object does not exist at this point in the lifecycle of the entity bean because the container is creating and setting the context and the bean just to pool it.
METHOD: ejbHome<METHOD>(args) (Home Business Method)
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
X6) getEJBObject()/ getEJBLocalObject()
REASONS:
1) I can't think of a reason why getEJBHome()/ getEJBLocalHome() access ought to be available or the other access unavailable? Why would it need access to EJB Home ? to remove itself at this stage ? to get EJBMetaData about itself? to get a handle to itself at this stage?
2) I can't think of a reason why java:comp/env access ought to be available or the other access unavailable.
3) It is conceivable that the home business method could be in the middle of a transaction at this stage because even though its pooled it does contain the entity information since passivated entity beans are live objects on the heap.
4) Since an entity bean is bound to have a client the home business method at this stage, because only a client can call this method, the bean can request security information of the client.
5) It is conceivable that the home business method could would a DB connection or reference to another EJB because even though its pooled and it does contain the entity information since passivate entity beans are live objects on the heap.
6) Since you are calling the Home Business Method of a pooled bean there is no reason why it should have access to the EJBObject. It is self sufficient in its data manipulation at this point.
METHOD: ejbCreate<Method>(args)
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
X6) getEJBObject()/ getEJBLocalObject()
REASONS:
1) Its conceivable that a DB row being created might want to get hold of getEJBHome()/ getEJBLocalHome() to run some finder or select or business home methods which might determine the data being inserted into the database.
2) Its conceivable that a DB row being created might want to get hold of an environment variable with data which it could use to initialize its columns before they are inserted into the database.
3) It is conceivable that the create method could be in the middle of a transaction at this stage because data insertion, update and delete could be tied to a transaction where either all succeeds or all fails and is rolled back. For example transfer of money (delete money from Account A only if Account B's money is deleted).
4) Since an entity bean is bound to have a client if its asking the container to insert data into the database the bean can request security information of the client.
5) It is conceivable that the create method could want a DB connection since its after all inserting a row into the DB. It is likely that a reference to another EJB maybe requested since that other bean could hold information that might influence the data inserted.
6) At ejbCreate<Method>(args) the primary key is generated and therefore you cannot call getPrimaryKey from the EJBObject/ EJBLocalObject. You cannot access EJBObject because in entity beans the EJBObject is created and sent back to the client only after the row is inserted into the database.
METHOD: ejbPostCreate<Method>(args)
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
6) getEJBObject()/ getEJBLocalObject()
REASONS:
1) Its conceivable that a DB row being created might want to get hold of getEJBHome()/ getEJBLocalHome() to run some finder or select or business home methods which might determine the data being inserted into the database.
2) Its conceivable that a DB row being created might want to get hold of an environment variable with data which it could use to initialize its columns before they are inserted into the database.
3) It is conceivable that the create method could be in the middle of a transaction at this stage because data insertion, update and delete could be tied to a transaction where either all succeeds or all fails and is rolled back. For example transfer of money (delete money from Account A only if Account B's money is deleted).
4) Since an entity bean is bound to have a client if its asking the container to insert data into the database the bean can request security information of the client.
5) It is conceivable that the create method could want a DB connection since its after all inserting a row into the DB. It is likely that a reference to another EJB maybe requested since that other bean could hold information that might influence the data inserted.
6) At ejbCreate<Method>(args) the primary key is generated and therefore you cannot call getPrimaryKey from the EJBObject/ EJBLocalObject. You cannot access EJBObject because in entity beans the EJBObject is created and sent back to the client only after the row is inserted into the database.
METHOD: ejbPostCreate<Method>(args)
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
6) getEJBObject()/ getEJBLocalObject()
REASONS:
1)
2)
3)
4)
5)
6)
METHOD: ejbRemove
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
6) getEJBObject()/ getEJBLocalObject()
REASONS:
1)
2)
3)
4)
5)
6)
METHOD: ejbActivate
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
6) getEJBObject()/ getEJBLocalObject()
REASONS:
1)
2)
3)
4)
5)
6)
METHOD: ejbPassivate
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
6) getEJBObject()/ getEJBLocalObject()
REASONS:
1)
2)
3)
4)
5)
6)
METHOD: ejbFind<Method>(args)/ejbSelect<Method>(args) (in the Pooled bean state)
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
6) getEJBObject()/ getEJBLocalObject()
REASONS:
1)
2)
3)
4)
5)
6)
METHOD: ejbSelect<Method>(args) (in the ready state)
ALLOWED OPERATIONS:
1) getEJBHome()/ getEJBLocalHome()
2) java:comp/env
3) getRollBackOnly()/setRollBackOnly
4) getCallerPrincipal()/getPrimaryKey()
5) java:comp/jdbc, java:comp/ejb
6) getEJBObject()/ getEJBLocalObject()
REASONS:
1)
2)
3)
4)
5)
6)