Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
6.6. Persisting an Order with DAO
- The sample code below demonstrates how to persist an order with DAO. This example will read an XML file containing order information (this works the same for EDI, CSV, and so on). Using the Javabean cartridge, it will bind the XML data into a set of entity beans. It will locate the product entities and bind them to the order entity bean using the ID of the products within the order items (the product element). Finally, the order bean will be persisted.The order XML message looks like this:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Use a custom DAO such as the example below to persist the Order entity:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow When looking at this class you should notice the @Dao and @Insert annotations. The @Dao annotation declares that the OrderDao is a DAO object. The @Insert annotation declares that the insertOrder method should be used to insert Order entities. - Use a custom DAO as shown in the following example to lookup the Product entities:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow When looking at this class, notice the @Lookup and @Param annotation. The @Lookup annotation declares that the ProductDao.findProductById() method is used to lookup Product entities. The name parameter in the @Lookup annotation sets the lookup name reference for that method. When the name isn’t declared, the method name will be used. The optional @Param annotation lets you name the parameters. This creates a better abstraction between Smooks and the DAO. If you don’t declare the @Param annotation the parameters are resolved by their position. - When you have configured your order as shown above, the resulting Smooks configuration will look like this:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Use the following code to execute Smooks:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow