Using UML 2 & Model Driven Architecture (MDA) Transforms to Generate a Persistence Layer for Java Web Applications and Web Services
Agile Development and Rapid Prototyping
I’m doing some rapid prototyping of Web applications and Web services in Java, and because I need to redesign often, I want the design and implementation processes to be as agile and lightweight as possible. I.e. each change I make to the design should take little or no effort to implement & deploy.
The biggest problem I’ve encountered so far is persistence. I need to implement applications with persistent data. However, I’m coding (at least on the server side) in Java. Implementing persistence for Java applications typically requires an object-relational mapping, which if coded by hand, costs effort. There are alternatives for handling persistence more-or-less automatically, like J2EE’s annotations. However, I’m also very much in favour of coding with POJOs, injecting dependencies wherever possible, and decoupling application code from any implementation-specific considerations to do with persistence.
Data Access Objects (DAOs)
A popular design pattern for persistence is the use of Data Access Objects (DAOs) which abstract the data access and manipulation operations from the implementation-specific details, allowing the persistence platform to be swapped out without affecting application logic.
UML 2 & MDA Transforms
I’ve also been working recently with UML 2 and Model Driven Architecture (MDA) transforms. The tool I’ve been using is Enterprise Architect, which encourages the development of a Platform Independent Model (PIM), which can then be transformed into class models tailored to various programming languages (Java, C# etc.). A PIM can also be transformed into database models tailored to various database platforms (Oracle, Postgres, MySQL etc.). From these platform-specific models, you can then generate actual code or DDL scripts.
So the dream is this: I design the data model for my application in a totally platform-independent way, using UML; I then use MDA transforms to generate a database model, a Java class model, and at least the interfaces for a set of Java DAOs (ideally the implementations as well); I then use code generation to automatically generate the DDL scripts and Java class/interface definitions.
I.e. I want to go from a PIM to a fully-implemented persistence layer at the press of one or two buttons.
Oh, and I don’t want to pay any money for any of this 🙂
This where I’ve got to so far…