SCBCD - Transactions
1)You require your EJB to be called from within a transactional context. If the caller is not within a transaction you wish an exception to be thrown. Which Transactional level is the correct one to be used to force this behaviour?
1)Required
2)Mandatory
3)Never
4)TransNewError
5)RequiresNew
2)Which one of the following tag elements must the application assembler use to define the transaction attributes for methods of a bean using container-managed transactional demarcation?
1)method-permission
2)container-transaction
3)ejb-transaction
4)cmp-field
5)container-managed
3)Which of the following statements are correct? [Select all correct answers]
1)Entity beans may only have Bean managed transaction demarcation if they use bean managed persitence.
2)Only Session Beans and Message driven beans can be designed to use Bean Managed Transaction demarcation.
3)Session Beans, Message Driven beans and Entity Beans can be designed to use Bean managed transacational demarcation.
4)Entity beans can only be designed to use Container Managed Transaction demarcation.
5)Session beans cannot use bean managed transactions unless they communicate with message driven beans.
4)Which of the following are requirements of a Message Driven Bean with regards to bean managed transactions?
1)It must be responsible for it's own persistence.
2)A message-driven bean instance must commit a transaction before the onMessage()
method returns
3)A message-driven bean must not commit a transaction before the onMessage()
method returns.
4)A message-driven bean must use entity beans for asynchronous communication.
5)A message driven bean cannot use bean managed transactions only container managed transactions.
5)To force a rollback on a Container managed transaction you can? [Select all correct answers]
1)Throw an application exception.
2)Call the setRollbackOnly
method.
3)Throw an EJBException
.
4)Call the rollback method on the UserTransaction
.
6)Which of these statements is true regarding the handling of Transactions within the EJB architecture? [Select all correct answers]
1)The Enterprise JavaBeans architecture supports flat transactions. This means that there is no support for nested transactions.
2)Nested transactions are supported in the Enterprise Javabeans Architecture as mandated by the EJB specification.
3)You can specify whether you would like your EJB to participate within nested transactions using the <nested_trans>
tag in your deployment descriptor.
4)Although the Enterprise Javabean architecture currently does not support nested transactions it may do in the future.
7)What will happen if the method getRollbackOnly() is called on the MessageDrivenContext and the instance that makes the call is not associated with a transaction?
1)The method will return null.
2)A transaction will be created when the method is invoked.
3)A java.lang.IllegalStateException
will be thrown.
4)The method will return the value Boolean.FALSE
.
8)What is the purpose of the SessionSynchronization interface?
1)Provides notification of the events of the transactional context it is involved in.
2)Provides a mechanism for synchronizing access to shared sections of memory.
3)Provides a mechanism of synchronizing access to Session Beans.
4)Allows you to reactivate a Stateful Session bean and to synchronise it's data with another Stateful Session bean.
5)Provides a callback from the Container when the Session bean is transferred to another node in it's cluster (this only happens in distributed EJB Containers).
9)Which of the following statements are correct regarding the responsibilities of the application assembler? [Select all correct answers]
1)The application assembler declares required transactional behaviour of enterprise beans in the deployment descriptor, that use bean managed transactional demarcation.
2)The application assembler declares required transactional behaviour of enterprise beans in the deployment descriptor, that use container managed transactional demarcation.
3)The application assembler declares required transactional behaviour of enterprise beans in the deployment descriptor, that use container managed transactional demarcation and beans that use bean managed transactional demarcation.
4)The application assembler cannot control transactional behaviour of beans that use bean managed transaction demarcation.
10)Which one of the following statements regarding enterprise beans with bean-managed transaction demarcation is correct?
1)A bean using Bean Managed Transactions should not call the EJBContext.setRollbackOnly
or EJBContext.getRollbackOnly
methods.
2)A bean using Bean Managed Transactions should call EJBContext.setRollbackOnly
to force a transaction to rollback.
3)A bean using Bean Managed Transactions is not responsible for it's own persistence.
4)A bean using Bean Managed Transactions is an entity bean.
Answers:
1)2
-
Required
means that if the caller does not have a transactional context the container will provide the EJB with one.Mandatory
requires that the caller must be involved in a transaction before it is called. If the caller is not involved in a transaction the container will throw an exception. This exhibits the required behaviour.Never
means that the EJB will never be involved within a transaction, if there is a transactional context the container will throw an exception.TransNewError
is made up.RequiresNew
forces the container to provide the ejb with a new transactional context whenever it is called.
2)2
-
The
method-permission
element is used by the Application Assembler to specify the methods of the home and component interfaces that each security role is allowed to invoke.ejb-transaction
is not an element that exists within the deployment descriptor.The
container-transaction
element is used to define the transaction attributes by the application assembler. This can be used to specify transaction attributes for the methods of Session and Entity bean home and component interfaces and for theonMessage
methods of message-driven beans. Each container-transaction element has a list of one trans-attribute element and one or more method elements. Thecontainer-transaction
element specifies that all the listed methods are assigned the specified transaction attribute value. All methods specified in a single container-transaction element belong to the same enterprise bean.The
cmp-field
element describes a container-managed field and is used within container-managed persistence not container-managed transactions.container-managed is not a valid element for the deployment descriptor.
3)2,4
-
A Session Bean or a Message-driven Bean can be designed with bean-managed transaction demarcation or with container-managed transaction demarcation (but it cannot be both at the same time).
An Entity Bean must always be designed with container-managed transaction demarcation.
The beans that a Session bean communicates with will not affect the types of transaction they can use in their individual methods.
4)2
A message-driven bean instance must commit a transaction before the onMessage method returns. The reason for this is that a message-driven bean responds to a JMS message and is not coupled with any other calls (from clients or other EJBs). This means that if a transaction were not closed before the return of the onMessage method the transaction handle would not be available to anyone and the transaction would not be able to be committed (this would eventually timeout).
5)2,3
-
Answer 1 is incorrect if an application exception is thrown by an enterprise bean instance the client transaction will not automatically rollback. The client will be given a chance to recover a transaction from an application exception.
Answer 2 and 3 are correct, you can force a container managed transaction rollback by using the
setRollbackOnly
method or if anEJBException
is thrown. If anEJBException
is thrown (signaling that a non application error has occurred) the container will rollback any container managed transactions.Answer 4 is not correct, you cannot use the
UserTransaction
interface if you are using Container managed transactions. Only bean managed transactions can use theUserTransaction
interface. If an instance of an enterprise bean with container-managed transaction demarcation attempts to invoke thegetUserTransaction()
method of theEJBContext
interface, the Container will throwjava.lang.IllegalStateException
.
6)1,4
The Enterprise JavaBeans architecture supports flat transactions. A flat transaction cannot have any child (nested) transactions. As stated in the EJB specification the decision not to support nested transactions allows vendors of existing transaction processing and database management systems to incorporate support for Enterprise Java-Beans. If these vendors provide support for nested transactions in the future, Enterprise Java-Beans may be enhanced to take advantage of nested transactions.
7)3
The
getRollbackOnly
and setRollbackOnly
methods of the MessageDriven-Context
interface should be used only in the message-driven bean methods that execute in the context of a transaction. The Container must throw the java.lang.IllegalState- Exception
if the methods are invoked while the instance is not associated with a transaction. (See EJB specification).8)1
Used to notify Session Beans of events of the transaction context they are participating in. If a Session Bean class implements the
javax.ejb.SessionSynchronization
interface, the Container must invoke the afterBegin()
, beforeCompletion()
, and afterCompletion(...)
callbacks on the instance as part of the transaction commit protocol.9)2,4
-
An application assembler cannot affect transactional behaviour for enterprise beans that use bean-managed transaction demarcation. The application assembler can only affect transactional behaviour of beans that use container-managed transaction demarcation.
The application assembler does not necessarily have to provide the transaction attributes for an enterprise bean the Application Assembler can specify a value of none. If the transaction attributes are not specified for the methods of an enterprise bean, the responsibility rests with the Deployer who will have to specify them.
10)1
-
An enterprise bean with bean-managed transaction demarcation must not use the
getRollbackOnly()
andsetRollbackOnly()
methods of theEJBContext
interface as these are only available for container managed transactions.An enterprise bean that uses bean managed transactions should use the interfaces available on the
UserTransaction
interface i.e.UserTransaction.rollback()
to rollback the transaction andUserTransaction.getStatus()
to see the status of a Bean Managed Transaction.The statement "A bean using Bean Managed Transactions is not responsible for it's own persistence", is incorrect as a bean that uses bean managed transactions will be responsible for it's own persistence. An entity bean cannot use bean managed transactions.
No comments:
Post a Comment