Creating a Transaction in a Published Business Service

A published business service class has a public method and a protected method that work together to expose a web service operation. The public method is exposed as the web service and acts as a wrapper method that passes a null to the context and connection parameters of the protected method. By passing null for these objects, the wrapper method identifies that this is the outermost call; that is, this is the web service. When a null context is passed, the protected method creates a context object that contains either a default manual connection or an auto commit connection for processing a transaction. Two methods with the same context name but different parameters exist. The context object that is used depends on whether you initiate a manual commit or auto commit connection. After the context object is created, the protected method starts processing by calling startPublishedMethod. All calls after startPublishedMethod are tied together by the context object. By passing null for the connection object, the wrapper method indicates that the default connection should be used for all operations. If a JD Edwards EnterpriseOne customer needs to extend a published business service by creating their own published business service and calling an existing JD Edwards EnterpriseOne published business service, the connection must be passed and it would not be null.

See Auto Commit.

The context object and the connection object are passed to the business service method where the business function call is made. After returning from the business service, the context object is sent to finishPublishedMethod to commit the default transaction in the case of manual commit, and then to the close method to close and clean up all outstanding connections.

This code sample shows creating and passing the context object:

 public ConfirmAddAddressBook addAddressBook(AddAddressBook vo) 
throws BusinessServiceException {
       return (addAddressBook(null,null, vo));
   }
    protected ConfirmAddAddressBook addAddressBook
                                (IContext context,IConnection 
                                connection, AddAddressBook vo) throws 
                                BusinessServiceException{
       //perform all work within try block, finally will clean up any 
       //connections
       try {
           // call start published method, passing null, 
           //will return context object so BSFN can be called later
           //used to indicate transaction boundary as well as used for 
           //logging
           //RI: Start Implicit Transaction
           context = startPublishedMethod(context, 
                "addAddressBook");
           // create a new internal vo based on the external vo passed 
           InternalAddAddressBook internalVO= new 
              InternalAddAddressBook();
           messages.addMessages(vo.mapFromPublished(context, 
              internalVO));
          // start business service addAddressBook passing context 
             and internal VO
           //RI: Published Business Service Calling Business Service
           E1MessageList messages = AddressBookProcessor.addAddressBook
           (context,connection,internalVO);
           // Published Business Service will send either warnings in 
              the Confirm Value Object or throw a published business 
              service Exception.
           //a return status of 2 is an error, throw the exception
           if (messages.hasErrors()) {
               // get the string representation of all the messages
                //RI: Error Handling
               String error = messages.getMessagesAsString()); 
               // Throw new BusinessServiceException(error);
               throw new BusinessServiceException(error,context);
           }
           // exception was not thrown, so create the confirm VO from 
              internal VO
           ConfirmAddAddressBook confirmVO = new ConfirmAddAddressBook
             (internalVO);
           confirmVO.setE1MessageList(messages);
           // call finish published method, passing the context  
           //to commit transaction(if no exceptions), as well as use 
           //in logging
           finishPublishedMethod(context, "addAddressBook");
           // return confirm VO, filled with return values and messages
           return confirmVO;
       } finally {
           //clean up any remaining connections and resources.  
           close(context,"addAddressBook");
       }