use of com.tomasio.projects.trainning.model.ItemAta in project trainning by fernandotomasio.
the class AtaServiceSimpleImpl method createItemAta.
@Override
@Transactional
public Long createItemAta(ItemAtaDTO itemAta) {
ItemAtaDAO dao = factory.getItemAtaDAO();
ItemAta _itemAta = null;
if (itemAta instanceof AcaoDTO) {
_itemAta = new Acao((AcaoDTO) itemAta);
}
if (itemAta instanceof DecisaoDTO) {
_itemAta = new Decisao((DecisaoDTO) itemAta);
}
if (itemAta instanceof ComentarioDTO) {
_itemAta = new Comentario((ComentarioDTO) itemAta);
}
Long id = null;
try {
id = dao.create(_itemAta);
} catch (DAOException ex) {
throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
}
return id;
}
use of com.tomasio.projects.trainning.model.ItemAta in project trainning by fernandotomasio.
the class HibernateItemAtaDAO method findAll.
@SuppressWarnings("unchecked")
@Override
public List<ItemAtaDTO> findAll() throws DAOException {
Session session = sessionFactory.getCurrentSession();
try {
List<ItemAta> itens_atas = session.createQuery("from ItemAta itemAta order by itemAta.dataCriacao desc").list();
List<ItemAtaDTO> dto = new ArrayList<ItemAtaDTO>();
for (ItemAta item_ata : itens_atas) {
dto.add(item_ata.createDTO());
}
return dto;
} catch (HibernateException e) {
Logger.getLogger(HibernateItemAtaDAO.class.getName()).log(Level.SEVERE, null, e);
throw new DAOException(MessageHelper.getMessage("itens_atas.find.list.error"));
}
}
use of com.tomasio.projects.trainning.model.ItemAta in project trainning by fernandotomasio.
the class HibernateItemAtaDAO method update.
@Override
public void update(ItemAtaDTO itemAta) throws DAOException {
Session session = sessionFactory.getCurrentSession();
try {
ItemAta _itemAta;
if (itemAta instanceof AcaoDTO) {
_itemAta = new Acao((AcaoDTO) itemAta);
} else if (itemAta instanceof DecisaoDTO) {
_itemAta = new Decisao((DecisaoDTO) itemAta);
} else if (itemAta instanceof ComentarioDTO) {
_itemAta = new Comentario((ComentarioDTO) itemAta);
} else {
_itemAta = null;
}
session.update(_itemAta);
} catch (HibernateException e) {
Logger.getLogger(HibernateItemAtaDAO.class.getName()).log(Level.SEVERE, null, e);
throw new DAOException(MessageHelper.getMessage("itens_atas.update.error"));
}
}
use of com.tomasio.projects.trainning.model.ItemAta in project trainning by fernandotomasio.
the class HibernateItemAtaDAO method remove.
@Override
public void remove(Long id) throws DAOException {
Session session = sessionFactory.getCurrentSession();
// Find retorna DTO e ItemAta é abstract, não pode ser instanciada
ItemAta _item_ata = (ItemAta) session.get(ItemAta.class, id);
try {
session.delete(_item_ata);
} catch (HibernateException e) {
Logger.getLogger(HibernateItemAtaDAO.class.getName()).log(Level.SEVERE, null, e);
throw new DAOException(MessageHelper.getMessage("itens_atas.remove.error"));
}
}
use of com.tomasio.projects.trainning.model.ItemAta in project trainning by fernandotomasio.
the class HibernateItemAtaDAO method findAllByItemPlanejamentoId.
@SuppressWarnings("unchecked")
@Override
public List<ItemAtaDTO> findAllByItemPlanejamentoId(Long itemPlanejamentoId) throws DAOException {
Session session = sessionFactory.getCurrentSession();
try {
List<ItemAta> itens_atas = session.createQuery("from ItemAta itemAta" + " where itemAta.itemPlanejamento.id =:itemPlanejamentoId order by itemAta.dataCriacao asc").setLong("itemPlanejamentoId", itemPlanejamentoId).list();
List<ItemAtaDTO> dto = new ArrayList<ItemAtaDTO>();
for (ItemAta item_ata : itens_atas) {
if (item_ata instanceof Acao) {
dto.add(((Acao) item_ata).createDTO());
}
if (item_ata instanceof Decisao) {
dto.add(((Decisao) item_ata).createDTO());
}
if (item_ata instanceof Comentario) {
dto.add(((Comentario) item_ata).createDTO());
}
}
return dto;
} catch (HibernateException e) {
Logger.getLogger(HibernateItemAtaDAO.class.getName()).log(Level.SEVERE, null, e);
throw new DAOException(MessageHelper.getMessage("itens_atas.find.list.error"));
}
}
Aggregations