Sun GlassFish Mobility Platform 1.1 Developer's Guide for Enterprise Connectors

Extending the InsertCommand, UpdateCommand, and DeleteCommand Classes to Access a Sun JCA Adapter


Note –

For a JAX-RS Enterprise Connector, make similar changes in your implementation of the MyBusinessObjectResource.putBusinessObject and MyBusinessObjectResource.deleteBusinessObject methods.


For the three command classes, you need to use generated classes and methods from the OTD. For a SAP BAPI application, for example, you need to import the following packages for the CustomerInsertCommand implementation:

import customer.Customer.CreateFromData1;
import customer.Customer.CreateFromData1.ExportParams.RETURN;

You then use the first of the imported classes in the class constructor, which takes two arguments instead of the single argument of the default implementation:

    public CustomerInsertCommand(Customer bobject, CreateFromData1 cfd) {
        super(bobject);
        mCreateFromData = cfd;
        logger.debug("Creating instance " + this);
    }

The CreateFromData1 object passed to the constructor is the returned value from the Customer class's getInsertCustomer method.

You implement the execute command by calling the class's own execute method and retrieving any return value through the second imported class:

    @Override
    public void execute() {
        try {
            mCreateFromData.execute();
            RETURN ret = mCreateFromData.getExportParams().getRETURN();
            String retMsg = ret.getMESSAGE();
            String message = "SAP (" + ret.getNUMBER() + "): " + retMsg;
            logger.info(message);
            if (retMsg.length() > 0) {
                throw new RuntimeException(message);
            }
        }
        catch (RuntimeException e) {
            throw e;
        }
        catch (Exception e) {
            logger.severe(e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }

For both the CustomerDeleteCommand and the CustomerUpdateCommand implementations, you import the following:

import customer.Customer.ChangeFromData1;
import customer.Customer.ChangeFromData1.ExportParams.RETURN;

The constructors and the execute methods for these classes use the ChangeFromData1 object returned from the Customer.getUpdateCustomer and Customer.getDeleteCustomer methods. Otherwise the class implementations are identical to those of the CustomerInsertCommand implementation.