Publishing multiple BODs

In the examples above, a single BOD document was published at each scheduled read action. To include one order instance in each BOD message, your stored procedure must return multiple DataArea nodes.

Note: Publishing multiple BODs is required in these cases:
  • The size of the BOD gets too big to handle if all records are returned in a single BOD message.
  • The Process verb is used, because a Process BOD must contain only one instance.
  • Receiving applications expect only one instance of a noun per BOD message.

To publish multiple BODs, you can change the query as follows:

SELECT(SELECT MySalesOrder.orderNumber as orderID, 
              MySalesOrder.orderStatus, MySalesOrder.orderDateTime, 
              MySalesOrder.customer,
              MySalesOrderLine.lineNumber, MySalesOrderLine.item, 
              MySalesOrderLine.quantity, MySalesOrderLine.price
       FROM   Orders as MySalesOrder, OrderLines as MySalesOrderLine
       WHERE  MySalesOrderLine.orderNumber = MySalesOrder.orderNumber and
              MySalesOrder.lastModification >= @lastTime and 
              MySalesOrder.lastModification < @currentTime
       FOR XML AUTO, ELEMENTS, type).query(
              'for $i in /MySalesOrder return <DataArea>{$i}</DataArea>');

Depending on the used database, you possibly must follow additional conventions and syntax. For example, in SQL Server the SET ARITHABORT ON flag must be enabled. In that case you must create a stored procedure because multiple statements are used.

The stored procedure GetOrders can contain this code:

BEGIN
  SET ARITHABORT ON

  -- At this point the same query as above
END

Then in ION, the following statement is defined to read the database:

EXEC GetOrders;
Note: Although multiple BODs are published, the data is retrieved using a single XML. So, to avoid memory problems, you must limit the amount of data returned at once.

See A simple query.