+/*\r
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
package org.argeo.slc.hibernate.test.tree;\r
\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
\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