Identify correct and incorrect statements or examples about container-managed transaction demarcation, and given a list of transaction behaviors, match them with the appropriate transaction attribute.

[Note]

With container-managed transaction (CMT) demarcation, the CONTAINER demarcates transactions per instructions provided by the developer in metadata annotations or in the deployment descriptor. These instructions, called transaction attributes, tell the container whether it should include the work performed by an enterprise bean method in a client's transaction, run the enterprise bean method in a new transaction started by the container, or run the method with "no transaction".

Container-Managed Demarcation

Whenever a client invokes a method on an enterprise bean's business interface (or on the home or component interface of an enterprise bean), the container interposes on the method invocation. The interposition allows the container to control transaction demarcation declaratively through the transaction attribute set by the developer.

For example, if an enterprise bean method is configured with the REQUIRED transaction attribute, the container behaves as follows: If the client request is not associated with a transaction context, the container automatically initiates a transaction whenever a client invokes an enterprise bean method that requires a transaction context. If the client request contains a transaction context, the container includes the enterprise bean method in the client transaction.

The following figure illustrates such a scenario. A non-transactional client invokes the enterprise bean X, and the invoked method has the REQUIRED transaction attribute. Because the message from the client does not include a transaction context, the container starts a new transaction before dispatching the method on X. Bean XтАЩs work is performed in the context of the transaction. When X calls other enterprise beans (Y in our example), the work performed by the other enterprise beans is also automatically included in the transaction (subject to the transaction attribute of the other enterprise bean).

Update of Multiple Databases from Non-Transactional Client

The container automatically commits the transaction at the time X returns a reply to the client.

If a message-driven bean's message listener method is configured with the REQUIRED transaction attribute, the container automatically starts a new transaction before the delivery of the message and, hence, before the invocation of the method.

JMS requires that the transaction be started before the dequeuing of the message.

The container automatically enlists the resource manager associated with the arriving message and all the resource managers accessed by the message listener method with the transaction.

Enterprise Beans Using Container-Managed Transaction Demarcation

The enterprise bean's business methods, message listener methods, business method interceptor methods, lifecycle callback interceptor methods, or timeout callback method MUST NOT use any resource-manager specific transaction management methods that would interfere with the container's demarcation of transaction boundaries. For example, the enterprise bean methods MUST NOT use the following methods of the java.sql.Connection interface: commit, setAutoCommit, and rollback; or the following methods of the javax.jms.Session interface: commit and rollback.

The enterprise bean's business methods, message listener methods, business method interceptor methods, lifecycle callback interceptor methods, or timeout callback method MUST NOT attempt to obtain or use the javax.transaction.UserTransaction interface.

The following is an example of a business method in an enterprise bean with container-managed transaction (CMT) demarcation. The business method updates two databases using JDBC connections. The container provides transaction demarcation as specified by the transaction attribute:

@Stateless public class MySessionBean implements MySession {
	...
	@TransactionAttribute(REQUIRED)
	public void someMethod(...) {
		java.sql.Connection con1;
		java.sql.Connection con2;
		java.sql.Statement stmt1;
		java.sql.Statement stmt2;

		// obtain con1 and con2 connection objects
		con1 = ...;
		con2 = ...;
		stmt1 = con1.createStatement();
		stmt2 = con2.createStatement();

		//
		// Perform some updates on con1 and con2. The container
		// automatically enlists con1 and con2 with the container-
		// managed transaction.
		//
		stmt1.executeQuery(...);
		stmt1.executeUpdate(...);
		stmt2.executeQuery(...);
		stmt2.executeUpdate(...);
		stmt1.executeUpdate(...);
		stmt2.executeUpdate(...);

		// release connections
		con1.close();
		con2.close();
	}
	...
}
					

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine