예제 #1
0
 @Override
 public void updatePageImage(PageImage pageImage) throws PageImageNotFoundException {
   SessionFactory factory = DaoManager.createSessionFactory();
   Session session = factory.openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     PageImage page = (PageImage) session.get(PageImage.class, pageImage.getIdPageImage());
     if (page != null) {
       page.setPath(pageImage.getPath());
       session.update(page);
     } else {
       throw new PageImageNotFoundException();
     }
     tx.commit();
   } catch (HibernateException e) {
     if (tx != null) tx.rollback();
     e.printStackTrace();
   } finally {
     session.close();
   }
 }
예제 #2
0
 @Override
 public Long addPageImage(PageImage pageImage) throws NullModelAttributesException {
   SessionFactory factory = DaoManager.createSessionFactory();
   Session session = factory.openSession();
   Transaction tx = null;
   Long pageID = null;
   try {
     tx = session.beginTransaction();
     if (pageImage.validate()) {
       pageID = (Long) session.save(pageImage);
     } else throw new NullModelAttributesException();
     tx.commit();
   } catch (HibernateException e) {
     if (tx != null) tx.rollback();
     e.printStackTrace();
   } finally {
     session.close();
   }
   return pageID;
 }