\r
import java.sql.SQLException;\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.SortedSet;\r
import java.util.TreeSet;\r
\r
+import org.argeo.slc.SlcException;\r
import org.argeo.slc.core.test.tree.ResultAttributes;\r
import org.argeo.slc.core.test.tree.TreeTestResult;\r
import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
import org.hibernate.HibernateException;\r
import org.hibernate.LockMode;\r
import org.hibernate.Session;\r
+import org.hibernate.criterion.DetachedCriteria;\r
import org.springframework.orm.hibernate3.HibernateCallback;\r
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
\r
\r
return list;\r
}\r
+\r
+ @SuppressWarnings("unchecked")\r
+ public List<TreeTestResult> listResults(String collectionId,\r
+ Map<String, String> attributes) {\r
+ List<TreeTestResult> list;\r
+\r
+ if (collectionId == null) {\r
+ if (attributes == null || attributes.size() == 0)\r
+ list = getHibernateTemplate().find("from TreeTestResult");\r
+ else if (attributes.size() == 1) {\r
+ Map.Entry<String, String> entry = attributes.entrySet()\r
+ .iterator().next();\r
+ Object[] args = { entry.getKey(), entry.getValue() };\r
+ list = getHibernateTemplate().find(\r
+ "select ttr from TreeTestResult ttr"\r
+ + " where attributes[?]=?", args);\r
+ } else {\r
+ throw new SlcException(\r
+ "Multiple attributes filter are currently not supported.");\r
+ }\r
+ } else {\r
+ if (attributes == null || attributes.size() == 0)\r
+ list = getHibernateTemplate()\r
+ .find(\r
+ "select ttr "\r
+ + " from TreeTestResult ttr, TreeTestResultCollection ttrc "\r
+ + " where ttr in elements(ttrc.results) and ttrc.id=?",\r
+ collectionId);\r
+ else if (attributes.size() == 1) {\r
+ Map.Entry<String, String> entry = attributes.entrySet()\r
+ .iterator().next();\r
+ Object[] args = { collectionId, entry.getKey(),\r
+ entry.getValue() };\r
+ list = getHibernateTemplate()\r
+ .find(\r
+ "select ttr from TreeTestResult ttr, TreeTestResultCollection ttrc "\r
+ + " where ttr in elements(ttrc.results) and ttrc.id=?"\r
+ + " and attributes[?]=?", args);\r
+ } else {\r
+ throw new SlcException(\r
+ "Multiple attributes filter are currently not supported.");\r
+ }\r
+ }\r
+ return list;\r
+ }\r
}\r