Search in sources :

Example 1 with Anotacao

use of com.tomasio.projects.trainning.model.Anotacao in project trainning by fernandotomasio.

the class HibernateAnotacaoDAO method findAll.

@Override
public List<AnotacaoDTO> findAll() throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    try {
        @SuppressWarnings("unchecked") List<Anotacao> anotacoes = session.createQuery("from Anotacao anotacao order by anotacao.dataCriacao desc").list();
        List<AnotacaoDTO> dto = new ArrayList<AnotacaoDTO>();
        for (Anotacao anotacao : anotacoes) {
            dto.add(anotacao.createDTO());
        }
        return dto;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateAnotacaoDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("anotacoes.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) HibernateException(org.hibernate.HibernateException) Anotacao(com.tomasio.projects.trainning.model.Anotacao) AnotacaoDTO(com.tomasio.projects.trainning.dto.AnotacaoDTO) ArrayList(java.util.ArrayList) Session(org.hibernate.Session)

Example 2 with Anotacao

use of com.tomasio.projects.trainning.model.Anotacao in project trainning by fernandotomasio.

the class HibernateAnotacaoDAO method findAllByUser.

@Override
public List<AnotacaoDTO> findAllByUser(String user) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    try {
        @SuppressWarnings("unchecked") List<Anotacao> anotacoes = session.createQuery("from Anotacao anotacao" + " where anotacao.user=:user order by anotacao.dataCriacao desc").setString("user", user).list();
        List<AnotacaoDTO> dto = new ArrayList<AnotacaoDTO>();
        for (Anotacao anotacao : anotacoes) {
            dto.add(anotacao.createDTO());
        }
        return dto;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateAnotacaoDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("anotacoes.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) HibernateException(org.hibernate.HibernateException) Anotacao(com.tomasio.projects.trainning.model.Anotacao) AnotacaoDTO(com.tomasio.projects.trainning.dto.AnotacaoDTO) ArrayList(java.util.ArrayList) Session(org.hibernate.Session)

Example 3 with Anotacao

use of com.tomasio.projects.trainning.model.Anotacao in project trainning by fernandotomasio.

the class HibernateAnotacaoDAO method remove.

@Override
public void remove(Long id) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    Anotacao anotacao = (Anotacao) session.get(Anotacao.class, id);
    try {
        session.delete(anotacao);
    } catch (HibernateException e) {
        Logger.getLogger(HibernateAnotacaoDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("anotacoes.remove.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) HibernateException(org.hibernate.HibernateException) Anotacao(com.tomasio.projects.trainning.model.Anotacao) Session(org.hibernate.Session)

Example 4 with Anotacao

use of com.tomasio.projects.trainning.model.Anotacao in project trainning by fernandotomasio.

the class HibernateAnotacaoDAO method update.

@Override
public void update(AnotacaoDTO anotacao) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    try {
        Anotacao _anotacao = new Anotacao(anotacao);
        session.update(_anotacao);
    } catch (HibernateException e) {
        Logger.getLogger(HibernateAnotacaoDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("anotacoes.update.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) HibernateException(org.hibernate.HibernateException) Anotacao(com.tomasio.projects.trainning.model.Anotacao) Session(org.hibernate.Session)

Example 5 with Anotacao

use of com.tomasio.projects.trainning.model.Anotacao in project trainning by fernandotomasio.

the class HibernateAnotacaoDAO method findAllByObjectId.

@Override
public List<AnotacaoDTO> findAllByObjectId(String user, String objectId) throws DAOException {
    Session session = sessionFactory.getCurrentSession();
    try {
        @SuppressWarnings("unchecked") List<Anotacao> anotacoes = session.createQuery("from Anotacao anotacao" + " where anotacao.user=:user" + " and anotacao.objectId=:object order by anotacao.dataCriacao desc").setString("object", objectId).setString("user", user).list();
        List<AnotacaoDTO> dto = new ArrayList<AnotacaoDTO>();
        for (Anotacao anotacao : anotacoes) {
            dto.add(anotacao.createDTO());
        }
        return dto;
    } catch (HibernateException e) {
        Logger.getLogger(HibernateAnotacaoDAO.class.getName()).log(Level.SEVERE, null, e);
        throw new DAOException(MessageHelper.getMessage("anotacoes.find.list.error"));
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) HibernateException(org.hibernate.HibernateException) Anotacao(com.tomasio.projects.trainning.model.Anotacao) AnotacaoDTO(com.tomasio.projects.trainning.dto.AnotacaoDTO) ArrayList(java.util.ArrayList) Session(org.hibernate.Session)

Aggregations

DAOException (com.tomasio.projects.trainning.exception.DAOException)6 Anotacao (com.tomasio.projects.trainning.model.Anotacao)6 HibernateException (org.hibernate.HibernateException)6 Session (org.hibernate.Session)6 AnotacaoDTO (com.tomasio.projects.trainning.dto.AnotacaoDTO)3 ArrayList (java.util.ArrayList)3