]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/test/tree/TreeTestResultDaoHibernate.java
Stabilize attachments and events
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.hibernate / src / main / java / org / argeo / slc / hibernate / test / tree / TreeTestResultDaoHibernate.java
index a217638e202fe60605f5e10e550bfd11b2504db3..def44a8a15d94b78de11fee4fce67aa7e46e6406 100644 (file)
@@ -19,6 +19,7 @@ import org.hibernate.HibernateException;
 import org.hibernate.Session;\r
 import org.springframework.orm.hibernate3.HibernateCallback;\r
 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
+import org.springframework.util.Assert;\r
 \r
 /**\r
  * The Hibernate implementation for tree-based result of the test result dao.\r
@@ -107,6 +108,17 @@ public class TreeTestResultDaoHibernate extends HibernateDaoSupport implements
                                        throws HibernateException, SQLException {\r
                                TreeTestResult treeTestResult = getTreeTestResult(session,\r
                                                testResultId);\r
+\r
+                               // Check is there is already such an attachment\r
+                               Assert.notNull(attachment, "attachment is null");\r
+                               Assert.notNull(session, "session is null");\r
+                               SimpleAttachment att = (SimpleAttachment) session.get(\r
+                                               attachment.getClass(), attachment.getUuid());\r
+                               if (att != null)\r
+                                       throw new SlcException(\r
+                                                       "There is already an attachement with id "\r
+                                                                       + attachment.getUuid());\r
+\r
                                treeTestResult.getAttachments().add(attachment);\r
                                session.update(treeTestResult);\r
                                return treeTestResult;\r