Example 1 - nsmulti with a Single (List) Parameter

Consider an operation in the input meta-model to list every single transaction in the system whose amount was for less than one dollar.

The following struct is defined in the model and will be used to contain the information about each transaction. The type of each attribute of the struct is not relevant here and has been omitted for clarity.

The table below shows an entity defined in the model with some of the attributes, which will be used by the nsmulti operation getMinorTransactions(), returning an instance of MinorTxDetails.

The SQL for the operation (which must be supplied in the model by the developer) is as follows in Example 1 - nsmulti with a Single (List) Parameter:

Figure 1. SQL for nsmulti with a single (list) parameter
SELECT txAccountNumber, txDate, txAmount
INTO
  :txAccountNumber,
  :txDate,
  :txAmount
FROM    BankAccount
WHERE   txAmount < 1;

This is all that has to be provided by the developer, the remainder is produced by the generator and is shown below for illustrative purposes.

The following pseudo code in Example 1 - nsmulti with a Single (List) Parameter describes the structs used in this operation. The actual Java structs corresponding to the structs defined in the model are produced by the code generator.

Figure 2. Pseudocode for generated structs for use by nsmulti operation
struct MinorTxDetails {
  txDate;
  txAccountNumber;
  txAmount;
};

// this is a generated list wrapper:
struct MinorTxDetailsList {
  sequence <MinorTxDetails> dtls;
};

// this is the standard details struct for the entity
// just to show where its attributes are kept:
struct BankAccountDtls {
  txAccountNumber;
  txDate;
  txAmount;
  txTellerNumber;
}

The Java interface for this entity class - complete with the nsmulti operation is produced by the code generator and would look like this:

Figure 3. Generated Java interface for nsmulti operation
          public interface BankAccount {

  // This is our "nsmulti" operation. Note how the
  // generator has transformed the parameter of this function
  // from "MinorTxDetails" to a "MinorTxDetails
           List 
          "
  public MinorTxDetailsList getMinorTransactions()
    throws AppException, InformationalException;
};

Example 1 - nsmulti with a Single (List) Parameter demonstrates how the developer would write handcrafted Java code to call this method and to iterate through each element returned by the method:

Figure 4. Calling a nsmulti operation from handcrafted Java code (one parameter)
<ProjectPackage>.intf.BankAccount bankAccount
  = <ProjectPackage>.fact.BankAccountFactory.newInstance()

double theTotalAmount = 0;

// Call the operation:
MinorTxDetailsList txList
  = bankAccount.getMinorTransactions();

// iterate through the set of results.
for (int i = 0; i < txList.dtls.size(); i++) {
  MinorTxDetails currentTx = txList.dtls.item(i);

  theTotalAmount += currentTx.txAmount;
}