public void deletePicture(Integer pictureId) throws Exception { Session session = HibernateSessionFactory.getSession(); Transaction transaction = session.beginTransaction(); try { PictureDAO pictureDao = new PictureDAO(); List pictures = pictureDao.getPicturesByPictureId(pictureId); if (pictures.size() > 0) { TPicture picture = (TPicture) pictures.get(0); picture.setDeleted(1); pictureDao.savePicture(picture); } transaction.commit(); } catch (Exception e) { transaction.rollback(); throw e; } finally { HibernateSessionFactory.closeSession(); } }
public void setMainPicture(User user, int pictureId) throws Exception { Session session = HibernateSessionFactory.getSession(); Transaction transaction = session.beginTransaction(); try { // update pictures Iterator pictures = user.getPictures().iterator(); while (pictures.hasNext()) { TPicture picture = (TPicture) pictures.next(); if (picture.getPictureId() == pictureId) { picture.setMainPagePic(1); } else { picture.setMainPagePic(0); } PictureDAO pictureDao = new PictureDAO(); pictureDao.savePicture(picture); } transaction.commit(); } catch (Exception e) { transaction.rollback(); throw e; } finally { HibernateSessionFactory.closeSession(); } }
public Integer addPicture(User user, String path) throws Exception { Session session = HibernateSessionFactory.getSession(); Transaction transaction = session.beginTransaction(); try { PictureDAO dao = new PictureDAO(); TPicture picture = new TPicture(); picture.setFilenamePath(path); picture.setUser(user); picture.setMainPagePic(0); picture.setDeleted(0); picture = dao.savePicture(picture); transaction.commit(); return picture.getPictureId(); } catch (Exception e) { transaction.rollback(); throw e; } finally { HibernateSessionFactory.closeSession(); } }