|
@ -9,31 +9,26 @@ import com.sothr.imagetools.image.Image |
|
|
class ImageDAO { |
|
|
class ImageDAO { |
|
|
|
|
|
|
|
|
private val sessionFactory:SessionFactory = HibernateUtil.getSessionFactory() |
|
|
private val sessionFactory:SessionFactory = HibernateUtil.getSessionFactory() |
|
|
private val example:Image = new Image() |
|
|
|
|
|
|
|
|
|
|
|
def find(path:String):Image = { |
|
|
def find(path:String):Image = { |
|
|
val session:Session = sessionFactory.getCurrentSession |
|
|
val session:Session = sessionFactory.getCurrentSession |
|
|
session.beginTransaction |
|
|
|
|
|
val result = session.get(example.getClass, path).asInstanceOf[Image] |
|
|
|
|
|
|
|
|
session.getTransaction.begin() |
|
|
|
|
|
val result = session.get(classOf[Image], path).asInstanceOf[Image] |
|
|
session.getTransaction.commit() |
|
|
session.getTransaction.commit() |
|
|
result |
|
|
result |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def save(image:Image) = { |
|
|
def save(image:Image) = { |
|
|
val session:Session = sessionFactory.getCurrentSession |
|
|
val session:Session = sessionFactory.getCurrentSession |
|
|
session.beginTransaction |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session.getTransaction.begin() |
|
|
session.saveOrUpdate(image) |
|
|
session.saveOrUpdate(image) |
|
|
|
|
|
|
|
|
session.getTransaction.commit() |
|
|
session.getTransaction.commit() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def save(images:List[Image]) = { |
|
|
def save(images:List[Image]) = { |
|
|
val session:Session = sessionFactory.getCurrentSession |
|
|
val session:Session = sessionFactory.getCurrentSession |
|
|
session.beginTransaction |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session.getTransaction.begin() |
|
|
for (image <- images) session.saveOrUpdate(image) |
|
|
for (image <- images) session.saveOrUpdate(image) |
|
|
|
|
|
|
|
|
session.getTransaction.commit() |
|
|
session.getTransaction.commit() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|