Red Hat Training

A Red Hat training course is available for Red Hat Fuse

6.4. Processing and Persisting an Order

  1. To process and persist an XML "order" message, you should bind the order data into the Order entities (Order, OrderLine and Product). To do this, create and populate the Order and OrderLine entities using the Java Binding framework.
  2. Wire each OrderLine instance into the Order instance.
  3. In each OrderLine instance, you should lookup and wire in the associated order line Product entity.
  4. Finally, insert (persist) the Order instance as seen below:
    <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" 
                          xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.4.xsd" 
                          xmlns:dao="http://www.milyn.org/xsd/smooks/persistence-1.2.xsd">
     
        <jb:bean beanId="order" class="example.entity.Order" createOnElement="order">
            <jb:value property="ordernumber" data="ordernumber" />
            <jb:value property="customerId" data="customer" />
            <jb:wiring setterMethod="addOrderLine" beanIdRef="orderLine" />
        </jb:bean>
     
        <jb:bean beanId="orderLine" class="example.entity.OrderLine" createOnElement="order-item">
            <jb:value property="quantity" data="quantity" />
            <jb:wiring property="order" beanIdRef="order" />
            <jb:wiring property="product" beanIdRef="product" />
        </jb:bean>
     
        <dao:locator beanId="product" lookupOnElement="order-item" onNoResult="EXCEPTION" uniqueResult="true">
            <dao:query>from Product p where p.id = :id</dao:query>
            <dao:params>
                <dao:value name="id" data="product" decoder="Integer" />
            </dao:params>
        </dao:locator>
     
        <dao:inserter beanId="order" insertOnElement="order" />
     
    </smooks-resource-list>
    
  5. If you want to use the named query productById instead of the query string, the DAO locator configuration will look like this:
    <dao:locator beanId="product" lookupOnElement="order-item" lookup="product.byId" onNoResult="EXCEPTION" uniqueResult="true">
        <dao:params>
            <dao:value name="id" data="product" decoder="Integer"/>
        </dao:params>
    </dao:locator>