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
</meta>
<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>
</hibernate-mapping>

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

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

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

@ -48,7 +48,7 @@ object ImageService extends Logging {
try {
imageDAO.save(image)
} 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
}

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

@ -8,9 +8,9 @@
This class contains the image hashes and meta data
</meta>
<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>
</hibernate-mapping>
Loading…
Cancel
Save