class HibernateTemplateDAO extends HibernatePersistentObjectDAO<Template> implements TemplateDAO {

	@Override
	public boolean delete(long id, int code) throws PersistenceException {
		if (!checkStoringAspect())
			return false;

		boolean result = true;
		Template template = (Template) findById(id);

		if (countDocs(id) > 0)
			throw new PersistenceException(String.format("Some documents are referencing the template %s (%d)",
					template.getName(), template.getId()));

		if (countFolders(id) > 0)
			throw new PersistenceException(String.format("Some folders are referencing the template %s (%d)",
					template.getName(), template.getId()));

		if (template != null) {
			template.setDeleted(code);
			template.setName(template.getName() + "." + template.getId());
			saveOrUpdate(template);
		}

		return result;
	}

	public  HibernateTemplateDAO();

}