Import and Export
Taylor Commons provides an Import/Export capability for JPA entities based on Betwixt.
Betwixt is a framework for mapping JavaBeans to and from XML based on reflection. As such very little configuration is required, if any.
To support polymorphism, the src/main/resources/betwixt-config.xml file is generated per model with the necessary metadata.
The export feature is available on all search screens. Use filtering to determine what will be exported. Then select the export action. This will open a new browser window to render the xml. Then use the browser's Save As menu to save the file to the desired location.
The export xml file will contain the entire entity graph.
Each search screen has an Import action. This is usually restricted by an Admin role.
- Any entity can be imported from any search screen.
- TODO Create global import screen.
The net.taylor.seam.ImportInit component can be configured in a components.xml file to load multiple files at start up.
Betwixt is just responsible for transforming the XML into JavaBeans.
Then there is logic necessary to determine if the entities need to be inserted, updated, or associated. This logic is provided by the net.taylor.seam.ImportUtil class.
Several JPA and Hibernate annotations provide the needed metadata.
This Hibernate annotation identifies the business key that is used to look up each entity. If it does not exist it will be inserted.
These JPA annotations represent composition and will direct how child entities will be inserted or overwritten.
These JPA annotations represent references to other data. If the referenced data does not exist then it will be inserted. If it already exists then the existing entity will be associated with the imported entity.