You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. package com.sothr.imagetools.engine.dao
  2. import com.sothr.imagetools.engine.image.Image
  3. import org.hibernate.{Session, SessionFactory}
  4. /**
  5. * Interact with stored images
  6. *
  7. * Created by drew on 2/8/14.
  8. */
  9. class ImageDAO {
  10. private val sessionFactory: SessionFactory = HibernateUtil.getSessionFactory
  11. def find(path: String): Image = {
  12. val session: Session = sessionFactory.getCurrentSession
  13. session.getTransaction.begin()
  14. val result = session.get(classOf[Image], path).asInstanceOf[Image]
  15. session.getTransaction.commit()
  16. result
  17. }
  18. def save(image: Image) = {
  19. val session: Session = sessionFactory.getCurrentSession
  20. session.getTransaction.begin()
  21. session.saveOrUpdate(image)
  22. session.getTransaction.commit()
  23. }
  24. def save(images: List[Image]) = {
  25. val session: Session = sessionFactory.getCurrentSession
  26. session.getTransaction.begin()
  27. for (image <- images) session.saveOrUpdate(image)
  28. session.getTransaction.commit()
  29. }
  30. def delete(image: Image) = {
  31. val session: Session = sessionFactory.getCurrentSession
  32. session.getTransaction.begin()
  33. session.delete(image)
  34. session.getTransaction.commit()
  35. }
  36. }