Unione dei dati da messaggi XML e tabelle del database

E' possibile utilizzare istruzioni SELECT che interagiscono con i database ed i dati del messaggio. E' anche possibile nidificare un'istruzione SELECT che interagisce con un tipo di dati all'interno di una SELECT che interagisce con l'altro tipo.

Considerare il seguente messaggio di input, che contiene informazioni di fatturazione per due clienti:

<Data>
  <Invoice>
    <CustomerNumber>1234</CustomerNumber>
    <Item>
      <PartNumber>1</PartNumber>
      <Quantity>9876</Quantity>
    </Item>
    <Item>
      <PartNumber>2</PartNumber>
      <Quantity>8765</Quantity>
    </Item>
</Invoice>
  <Invoice>
    <CustomerNumber>2345</CustomerNumber>
    <Item>
      <PartNumber>2</PartNumber>
      <Quantity>7654</Quantity>
    </Item>
    <Item>
      <PartNumber>1</PartNumber>
    <Quantity>6543</Quantity>
    </Item>
</Invoice>
</Data>

Considerare le seguenti tabelle del database Prices ed Addresses ed il relativo contenuto:

PARTNO      PRICE                   
----------- ------------------------
          1            +2.50000E+001
          2            +6.50000E+00



PARTNO      STREET                CITY             COUNTRY  
------      -------------------   --------------   ------- 
1234        22 Railway Cuttings   East Cheam       England
2345        The Warren            Watership Down   England

Se si utilizza la seguente trasformazione ESQL:

-- Create a valid output message
SET OutputRoot.MQMD = InputRoot.MQMD; 

-- Select suitable invoices
SET OutputRoot.XML.Data.Statement[] =
   (SELECT I.CustomerNumber                  AS Customer.Number,
           A.Street                                 AS Customer.Street,
           A.City                                   AS Customer.Town,
           A.Country                                AS Customer.Country,

        -- Select suitable items
          (SELECT II.PartNumber AS PartNumber,
                  II.Quantity   AS Quantity,
                  PI.Price      AS Price
           FROM Database.db2admin.Prices AS PI,
               I.Item[]                 AS II
           WHERE II.PartNumber = PI.PartNo     )    AS Purchases.Item[]
      
    FROM Database.db2admin.Addresses  AS A,
         InputRoot.XML.Data.Invoice[] AS I
           
    WHERE I.CustomerNumber = A.PartNo
    );

viene generato il seguente messaggio di output. Al messaggio di input vengono aggiunte le informazioni relative a prezzo ed indirizzo dalla tabella del database:

<Data>
  <Statement>
    			<Customer>
      <Number>1234</Number>
      <Street>22 Railway Cuttings</Street>
      <Town>East Cheam</Town>
      <Country>England</Country>
    			</Customer>
    			<Purchases>
      <Item>
        <PartNumber>1</PartNumber>
        <Quantity>9876</Quantity>
        <Price>2.5E+1</Price>
      </Item>
      <Item>
        <PartNumber>2</PartNumber>
        <Quantity>8765</Quantity>
        <Price>6.5E+1</Price>
      </Item>
    			</Purchases>
  		</Statement>
  <Statement>
    			<Customer>
      <Number>2345</Number>
      <Street>The Warren</Street>
      <Town>Watership Down</Town>
      <Country>England</Country>
    			</Customer>
    			<Purchases>
      <Item>
        <PartNumber>1</PartNumber>
        <Quantity>6543</Quantity>
        <Price>2.5E+1</Price></Item>
      <Item>
        <PartNumber>2</PartNumber>
        <Quantity>7654</Quantity>
        <Price>6.5E+1</Price>
      </Item>
    			</Purchases>
  		</Statement>
</Data>

E' possibile nidificare l'istruzione SELECT del database all'interno dell'istruzione SELECT del messaggio. Nella maggior parte dei casi, questa operazione non è efficace come l'esempio precedente, ma è migliore se i messaggi sono di dimensioni ridotte e le tabelle del database sono di dimensioni elevate.

-- Create a valid output message
SET OutputRoot.MQMD = InputRoot.MQMD; 

-- Select suitable invoices
SET OutputRoot.XML.Data.Statement[] =
    (SELECT I.CustomerNumber                  AS Customer.Number,

        -- Look up the address
        THE ( SELECT 
                  A.Street,
                  A.City    AS Town,
                  A.Country
                FROM Database.db2admin.Addresses AS A
                WHERE A.PartNo = I.CustomerNumber
            )                             AS Customer,

        -- Select suitable items
        (SELECT 
            II.PartNumber AS PartNumber,
            II.Quantity   AS Quantity,

            -- Look up the price
            THE (SELECT ITEM P.Price
              FROM Database.db2admin.Prices AS P
              WHERE P.PartNo = II.PartNumber
            )             AS Price               

          FROM I.Item[] AS II           ) AS Purchases.Item[]
      
    FROM InputRoot.XML.Data.Invoice[] AS I
    );
Concetti correlati
Panoramica dei flussi di messaggi
Panoramica di ESQL
Creazione di modelli di messaggio
Attività correlate
Progettazione di un flusso di messaggi
Definizione del contenuto del flusso di messaggi
Gestione dei file ESQL
Riferimenti correlati
Nodo Compute
Nodo Database
Nodo Filter
Riferimento ESQL
Funzione SELECT
Istruzione SET
Informazioni particolari | Marchi | Download | Libreria | Supporto | Commenti
Copyright IBM Corporation 1999, 2006 Ultimo aggiornamento: ago 17, 2006
ak05780_