Search in sources :

Example 1 with ItemAta

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;
}
Also used : AcaoDTO(com.tomasio.projects.trainning.dto.AcaoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ItemAta(com.tomasio.projects.trainning.model.ItemAta) CoreException(com.tomasio.projects.trainning.exeption.CoreException) ComentarioDTO(com.tomasio.projects.trainning.dto.ComentarioDTO) DecisaoDTO(com.tomasio.projects.trainning.dto.DecisaoDTO) ItemAtaDAO(com.tomasio.projects.trainning.dao.ItemAtaDAO) Comentario(com.tomasio.projects.trainning.model.Comentario) Acao(com.tomasio.projects.trainning.model.Acao) Decisao(com.tomasio.projects.trainning.model.Decisao) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ItemAta

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"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) ItemAta(com.tomasio.projects.trainning.model.ItemAta) HibernateException(org.hibernate.HibernateException) ItemAtaDTO(com.tomasio.projects.trainning.dto.ItemAtaDTO) ArrayList(java.util.ArrayList) Session(org.hibernate.Session)

Example 3 with ItemAta

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"));
    }
}
Also used : AcaoDTO(com.tomasio.projects.trainning.dto.AcaoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ItemAta(com.tomasio.projects.trainning.model.ItemAta) ComentarioDTO(com.tomasio.projects.trainning.dto.ComentarioDTO) HibernateException(org.hibernate.HibernateException) DecisaoDTO(com.tomasio.projects.trainning.dto.DecisaoDTO) Comentario(com.tomasio.projects.trainning.model.Comentario) Session(org.hibernate.Session) Acao(com.tomasio.projects.trainning.model.Acao) Decisao(com.tomasio.projects.trainning.model.Decisao)

Example 4 with ItemAta

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"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) ItemAta(com.tomasio.projects.trainning.model.ItemAta) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Example 5 with ItemAta

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"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) ItemAta(com.tomasio.projects.trainning.model.ItemAta) HibernateException(org.hibernate.HibernateException) ItemAtaDTO(com.tomasio.projects.trainning.dto.ItemAtaDTO) ArrayList(java.util.ArrayList) Comentario(com.tomasio.projects.trainning.model.Comentario) Session(org.hibernate.Session) Acao(com.tomasio.projects.trainning.model.Acao) Decisao(com.tomasio.projects.trainning.model.Decisao)

Aggregations

DAOException (com.tomasio.projects.trainning.exception.DAOException)6 ItemAta (com.tomasio.projects.trainning.model.ItemAta)6 HibernateException (org.hibernate.HibernateException)5 Session (org.hibernate.Session)5 ItemAtaDTO (com.tomasio.projects.trainning.dto.ItemAtaDTO)3 Acao (com.tomasio.projects.trainning.model.Acao)3 Comentario (com.tomasio.projects.trainning.model.Comentario)3 Decisao (com.tomasio.projects.trainning.model.Decisao)3 ArrayList (java.util.ArrayList)3 AcaoDTO (com.tomasio.projects.trainning.dto.AcaoDTO)2 ComentarioDTO (com.tomasio.projects.trainning.dto.ComentarioDTO)2 DecisaoDTO (com.tomasio.projects.trainning.dto.DecisaoDTO)2 ItemAtaDAO (com.tomasio.projects.trainning.dao.ItemAtaDAO)1 CoreException (com.tomasio.projects.trainning.exeption.CoreException)1 Transactional (org.springframework.transaction.annotation.Transactional)1