Hitachi

uCosminexus Application Server Compatibility Guide


F.1 Runtime-related contract

The runtime-related contract includes the responsibilities of the container and the responsibilities of the JPA provider.

Organization of this subsection

(1) Responsibilities of the container

(2) Responsibilities of the JPA provider

Whether the entity manager to be used with an application is defined to use the transaction scope persistence context or the extended persistence context, is not transmitted to the JPA provider. The responsibilities of the JPA provider include creating the entity manager when requested by the container and registering Synchronization in the transaction in order to receive the notification about transaction conclusion from the transaction.

(3) javax.transaction.TransactionSynchronizationRegistry interface

The JPA provider can use the TransactionSynchronizationRegistry interface to register Synchronization in a transaction and to mark a transaction for rollback. The TransactionSynchronizationRegistry instance can be looked up with the name java:comp/TransactionSynchronizationRegistry using the JNDI.

The interface definition is as follows:

package javax.transaction;
 
/**
 * This interface is used from system level components 
 * of Application Server such as the
 * JPA provider and resource adapters.
 * Using this interface, you can 
 * register synchronization invoked in a particular order,
 * register the resource object in the current transaction,
 * obtain the current transaction context,
 * obtain the current transaction status,
 * and mark the current transaction for rollback.
 *
 * This interface is implemented by Application Server 
 * as a stateless service object.
 * The same object can be used from multiple components
 * in a multi-thread safe manner.
 *
 * With default Application Server, the instance implementing this 
 * interface can be looked up with the default name using the JNDI.
 * The default name is 
 * java:comp/TransactionSynchronizationRegistry.
 */
public interface TransactionSynchronizationRegistry {
 
 /**
 * When this method is invoked, a unique object expressing the 
 * transaction associated with the current thread is returned.
 * The hashCode and equals method of this object is overridden 
 * and can be used as the hashmap key.
 * If the transaction does not exist, null is returned.
 * 
 * All the objects returned by invoking this method in the same 
 * transaction context of same Application Server have the same 
 * hashCode and the comparison results in the equal method are 
 * true.
 * 
 * The toString method returns the transaction context information 
 * as a string in an easy-to-read format.
 * However, the string format returned by toString is not defined.
 * Also, the compatibility of the toString results between versions 
 * is not guaranteed.
 * 
 * There is no guarantee that the obtained object can be serialized 
 * and the operations when the object is sent outside JavaVM are 
 * not defined.
 *
 * @return Object that uniquely expresses the transaction 
 * associated with the thread when this method is invoked.
 */
 Object getTransactionKey();
 
 /**
 * The object is added or replaced in the resource map 
 * of the transaction associated with the thread used when this 
 * method is invoked.
 * The map key must be a class defined on the method invocation 
 * side so that conflict does not occur.
 * The class used as the key must have the appropriate hashCode 
 * and equals method as the map key.
 * The map key and value is not evaluated and used by this class.
 * The general contract of this method is the same as the put 
 * method of Map and the key must be other than null, but the 
 * value can be set as null.
 * If a value associated with the key already exists, the value 
 * is replaced.
 *
 * @param key Entry key of map
 * @param value Entry value of map
 * @exception IllegalStateException When an active transaction 
 * does not exist
 * @exception NullPointerException When the argument key is null
 */
 void putResource(Object key, Object value);
 
 /**
 * The object is extracted from the resource map of the transaction
 * associated with the thread used when this method is invoked.
 * The key must be the same as the object specified in the 
 * putResource method beforehand, in the same transaction.
 * If the specified key does not exist in the current resource 
 * map, null is returned.
 * The general contract of this method is the same as the put 
 * method of Map and the key must be other than null, but the 
 * value can be set as null.
 * If the key is not stored in the map or if a null value is stored 
 * for the key, the return value is null.
 * @param key Entry key of map
 * @return Value associated with the key
 * @exception IllegalStateException When an active transaction 
 * does not exist
 * @exception NullPointerException When the argument key is null
 */
 Object getResource(Object key);
 
 /**
 * Registers the synchronization instances invoked in a particular 
 * order.
 * beforeCompletion of Synchronization registered with this 
 * method is invoked after 
 * SessionSynchronization.beforeCompletion, and 
 * Synchronization.beforeCompletion, which is directly 
 * registered in a transaction, are invoked, and before the 2-phase 
 * commit processing starts.
 * Similarly, afterCompletion of Synchronization registered with 
 * this method is invoked after the completion of 2-phase commit 
 * processing and before SessionSynchronization.afterCompletion 
 * and Synchronization.afterCompletion, which is directly 
 * registered in the transaction, are invoked.
 * 
 * beforeCompletion is invoked by the transaction context 
 * associated with the thread when this method is invoked.
 * With beforeCompletion, access to resources such as connector 
 * is permitted, but access is not permitted to user components 
 * such as timer service and bean methods.
 * This is because the data managed on the invocation side and 
 * the data that is already flushed by other Synchronization 
 * registered with registerInterposedSynchronization might be 
 * changed.
 * The general context becomes the context of the component 
 * that invokes registerInterposedSynchronization.
 * 
 * The context when afterCompletion is invoked is not defined.
 * Note that access to user components is not allowed.
 * Also, the resource can be closed, but 
 * transactional operations cannot be performed for the resource.
 * 
 * If this method is invoked when the transaction is not active,
 * IllegalStateException is thrown.
 *
 * If this method is invoked after the 2-phase commit processing 
 * starts, IllegalStateException is thrown.
 * 
 * @param sync Instance of Synchronization to be registered
 * @exception IllegalStateException When an active transaction 
 * does not exist
 */
 void registerInterposedSynchronization(Synchronization sync);
 
 /**
 * When this method is invoked, the status of the transaction 
 * associated with the thread is returned.
 * The return value of this method is the same as the result of  * TransactionManager.getStatus().
 *
 * @return Status of the transaction associated with
 * the thread when this method is invoked.
 */
 int getTransactionStatus();
 
 /**
 * When this method is invoked, the transaction associated with 
 * the thread is marked for rollback.
 *
 * @exception IllegalStateException When an active transaction 
 * does not exist
 */
 void setRollbackOnly();
 
 /**
 * When this method is invoked, returns information about whether 
 * the transaction associated with the thread is marked for 
 * rollback.
 *
 * @return true if the transaction is marked for rollback
 * @exception IllegalStateException When an active transaction
 * does not exist
 */
 boolean getRollbackOnly();
}