Browse Source

Fixed issues with the persistence engine not being able to retrieve already processed images.

master
Drew Short 11 years ago
parent
commit
4503ccac99
  1. 8
      src/main/resources/hibernate/Image.hbm.xml
  2. 13
      src/main/scala/com/sothr/imagetools/dao/ImageDAO.scala
  3. 2
      src/main/scala/com/sothr/imagetools/image/ImageService.scala
  4. 8
      src/test/resources/hibernate/Image.hbm.xml

8
src/main/resources/hibernate/Image.hbm.xml

@ -8,9 +8,9 @@
This class contains the image hashes and meta data This class contains the image hashes and meta data
</meta> </meta>
<id name="imagePath" type="string" column="path"/> <id name="imagePath" type="string" column="path"/>
<property name="thumbnailPath" column="thumbnail_path" type="string"/>
<property name="width" column="width" type="int"/>
<property name="height" column="height" type="int"/>
<one-to-one name="hashes" class="com.sothr.imagetools.dto.ImageHashDTO" cascade="save-update, delete"/>
<property name="thumbnailPath" column="thumbnail_path" type="string" not-null="true"/>
<property name="width" column="width" type="int" not-null="true"/>
<property name="height" column="height" type="int" not-null="true"/>
<many-to-one name="hashes" column="hashes" unique="true" class="com.sothr.imagetools.dto.ImageHashDTO" cascade="save-update, delete" not-null="true" lazy="false"/>
</class> </class>
</hibernate-mapping> </hibernate-mapping>

13
src/main/scala/com/sothr/imagetools/dao/ImageDAO.scala

@ -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()
} }

2
src/main/scala/com/sothr/imagetools/image/ImageService.scala

@ -48,7 +48,7 @@ object ImageService extends Logging {
try { try {
imageDAO.save(image) imageDAO.save(image)
} catch { } catch {
case ex:Exception => error(s"Error saving up \'${image.imagePath}\' to database", ex)
case ex:Exception => error(s"Error saving \'${image.imagePath}\' to database", ex)
} }
image image
} }

8
src/test/resources/hibernate/Image.hbm.xml

@ -8,9 +8,9 @@
This class contains the image hashes and meta data This class contains the image hashes and meta data
</meta> </meta>
<id name="imagePath" type="string" column="path"/> <id name="imagePath" type="string" column="path"/>
<property name="thumbnailPath" column="thumbnail_path" type="string"/>
<property name="width" column="width" type="int"/>
<property name="height" column="height" type="int"/>
<one-to-one name="hashes" class="com.sothr.imagetools.dto.ImageHashDTO" cascade="save-update, delete"/>
<property name="thumbnailPath" column="thumbnail_path" type="string" not-null="true"/>
<property name="width" column="width" type="int" not-null="true"/>
<property name="height" column="height" type="int" not-null="true"/>
<many-to-one name="hashes" column="hashes" unique="true" class="com.sothr.imagetools.dto.ImageHashDTO" cascade="save-update, delete" not-null="true" lazy="false"/>
</class> </class>
</hibernate-mapping> </hibernate-mapping>
Loading…
Cancel
Save