예제 #1
0
 @Override
 public void deleteTopic(Long id) throws DAOException {
   Session session = HibernateUtil.createSessionFactory().getCurrentSession();
   try {
     session.beginTransaction();
     Topic topic = (Topic) session.get(Topic.class, id);
     session.delete(topic);
     session.getTransaction().commit();
   } catch (HibernateException e) {
     session.getTransaction().rollback();
     throw new DAOException(e);
   }
 }
예제 #2
0
 @Override
 public Topic findTopicById(Long id) throws DAOException {
   Session session = HibernateUtil.createSessionFactory().getCurrentSession();
   Topic topic;
   try {
     session.beginTransaction();
     topic = (Topic) session.get(Topic.class, id);
     session.getTransaction().commit();
   } catch (HibernateException e) {
     session.getTransaction().rollback();
     throw new DAOException(e);
   }
   return topic;
 }
예제 #3
0
 @Override
 public List<Topic> findAllTopics() throws DAOException {
   Session session = HibernateUtil.createSessionFactory().getCurrentSession();
   session.beginTransaction();
   List<Topic> topics;
   try {
     Criteria criteria = session.createCriteria(Topic.class);
     topics = criteria.list();
     session.getTransaction().commit();
   } catch (HibernateException e) {
     throw new DAOException(e);
   }
   return topics;
 }
예제 #4
0
 @Override
 public void updateTopic(Topic topic) throws DAOException {
   Session session = HibernateUtil.createSessionFactory().getCurrentSession();
   session.beginTransaction();
   Topic existingTopic = (Topic) session.get(Topic.class, topic.getId());
   existingTopic.setName(topic.getName());
   try {
     session.save(existingTopic);
     session.getTransaction().commit();
   } catch (HibernateException e) {
     session.getTransaction().rollback();
     throw new DAOException(e);
   }
 }
예제 #5
0
 @Override
 public void createTopic(Topic topic) throws DAOException {
   Session session = HibernateUtil.createSessionFactory().getCurrentSession();
   try {
     session.beginTransaction();
     if (topic != null) {
       session.save(topic);
     }
     session.getTransaction().commit();
   } catch (HibernateException e) {
     session.getTransaction().rollback();
     throw new DAOException(e);
   }
 }