* store all templates
*/
for (TemplateTree template : templates) {
// we get the template tree ("Public Templates") from the database
TemplateTree tdb;
try {
tdb = (TemplateTree) em.createQuery("select n from TemplateTree n where name = :name")
.setParameter("name", template.getName()).getSingleResult();
} catch (NoResultException e) {
tdb = new TemplateTree(template.getName(), null);
}
if (tdb != null) {
// we get the templates and add them to the tree
// and store them
for (TreeNode n : template.getRoot().getChildren()) {
tdb.getRoot().addChild(n);
em.persist(n);
}
em.persist(em.merge(tdb));
em.flush();