Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop EJB applications > Develop EJB 2.x entity beans that use access intents


Use the AccessIntent API

This task describes how to programmatically retrieve and call the AccessIntent API during the execution of bean managed persistence (BMP) entity bean methods.


Procedure

  1. Look up the access intent service from the namespace. For example:
    InitialContext ic = new InitialContext();
    AccessIntentService aiService = ic.lookup("java:comp/websphere/AppProfile/AccessIntentService");
    

  2. From a method of the remote or local component interface of the BMP, get the current AccessIntent object using the javax.ejb.EntityContext. This object is passed to the BMP when the container calls the setEntityContext method. Assume the EntityContext was stored in a variable named myEntityCtx. For example:
        AccessIntent ai = aiService.getAccessIntent (myEntityCtx);
    

  3. Use the get() methods of AccessIntent interface to obtain the wanted information. For example:
    int concurrency = ai.getConcurrencyControl();
    int accessType = ai.getAccessType();
    if ( (concurrency == AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC)
       && (accessType == AccessIntent.ACCESS_TYPE_UPDATE) ) {
         int exclusive = ai.getPessimisticUpdateLockHint();
         // . . .
    
    // . . .
    
    For a detailed example of the use of the AccessIntent API, see the topic Example: Using IBM extended APIs to share connections between CMP beans and BMP beans..


Results

The access intent object reference retrieved from the java:comp lookup is current for the duration of the method in which the reference was looked up. Depending on how you configured the application profile, subsequent calls of the same method might not retrieve the same access intent reference. We can only look up the object reference during the call of a BMP entity bean method; the reference does not exist during a request on a container managed persistence (CMP) entity bean. Therefore, do not cache access intent object references beyond, or used outside of, the scope of the execution of any given BMP method.


Related


AccessIntent interface


Related


Access intent policies for EJB 2.x entity beans
Task overview: Application profiling

+

Search Tips   |   Advanced Search