In the past I used to think that the internet routers and database management systems were separate systems and didn't share many of the same design patterns. Routers routed information to different locations based on the content of the data in documents and database management systems stored data in different collections. But when building web applications with the new XRX web application architecture architecture you may start to see overlapping design patterns.
Recently I have been trying to auto-generate a large number of XForms applications directly from XML Schema files. The process is not too difficult since XML Schemas (when combined with a nice set of metadata registry services) have almost all the information you need to create an XForms application with XRX. But generating all of the paths in the submission element for creating new records and updating records was a little complex. I have been experimenting with using a new design that allows me to move much of the logic in the XForms submission element to the server. This makes the task of XForms auto-generation just a little bit easier.
At the core of this design is the Content Routing pattern. My new forms all use a single "save" web service. The save-service looks at the content of every submitted XML document and just "does the right thing". It does this by looking at the content of the submitted document and then saves the submitted data the appropriate collection in my eXistdatabase.
The save-service is smart enough to look at the document type by evaluating an XPath expression on the submitted document. I then looks up in an XML file where the document should be stored. If the incoming document does not have an appropriate document ID, it goes to a table of ids and assigned the document the next ID is a sequence. All the information the save service needs is stored in a single XML rules configuration file in the eXist database.
In the past each of my forms had separate XQueries for storing new files and doing updates. I found that making copies of these files took away from the process of solving the business problem I was working on. Changing the update submissions to archive old versions or to put the old documents into a version control database was also very time consuming. Now I just need to change a single rule in a configuration file.
My next step will be to create a user-friendly XForms application to manage the configuration file that does the saves and updates.
What this has taught me is that the content routing pattern is both powerful and easy to implement with XQuery. It save me a lot of code and increases my flexibility for adding new services. It also make the process of auto-generating XForms applications easier and makes those forms much easier to maintain.
What about you? Does your database management system implement the content routing pattern? How would your applications be different if content routing were "baked in" to each database server? Would a rules-based approach to object-persistence make your systems more flexible?