Converting an Existing Business Framework
If there is an existing data layer (e.g. DAO) that needs to be converted to Cayenne, currently most of the mapping tasks will have to be done manually using the Modeler.
Note for EOF Users CayenneModeler provides import function for the EOModels. So most of the mapping conversions should be automatic. |
In any case there is a good chance of reusing business methods already defined in a persistence framework. And definitely any existing database can be used as is. One possible approach to conversion is to follow these steps:
- Reverse engineer the database schema into a new Cayenne mapping project.
- Update class names and packages match the names of the existing classes.
- Run class generation using "generation gap" pattern (to create subclass/superclass pair for each entity). This would only create superclasses with set/get methods for persistent properties, without touching the existing classes.
- Modify existing DAO classes to change the superclass to a corresponding generated one (e.g. "Employee extends _Employee").
- Remove any persistent properties with their setters and getters from the subclass.
- Remove all the DAO-specific persistence code.
- Rewrite any other "business" methods to use DataContext for data operations.
See the following topics explaining individual tasks involved:
- Create New Project
- Create DataNode
- Create New DataMap by reverse engineering database
- Generate Java Classes