+/*\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
import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;\r
import org.springframework.orm.hibernate3.HibernateCallback;\r
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
\r
+/** Hibernate implementation of collections DAO. */\r
public class TreeTestResultCollectionDaoHibernate extends HibernateDaoSupport\r
implements TreeTestResultCollectionDao {\r
\r
getHibernateTemplate().update(ttrCollection);\r
}\r
\r
+ public void delete(TreeTestResultCollection ttrCollection) {\r
+ getHibernateTemplate().delete(ttrCollection);\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
public SortedSet<TreeTestResultCollection> listCollections() {\r
return new TreeSet<TreeTestResultCollection>(getHibernateTemplate()\r
.find("from TreeTestResultCollection"));\r
});\r
}\r
\r
+ @SuppressWarnings("unchecked")\r
+ public List<ResultAttributes> listResultAttributes(String collectionId) {\r
+ List<ResultAttributes> list;\r
+ if (collectionId == null)\r
+ list = getHibernateTemplate().find(\r
+ "select new org.argeo.slc.core.test.tree.ResultAttributes(ttr)"\r
+ + " from TreeTestResult ttr");\r
+ else\r
+ list = getHibernateTemplate()\r
+ .find(\r
+ "select new org.argeo.slc.core.test.tree.ResultAttributes(ttr) "\r
+ + " from TreeTestResult ttr, TreeTestResultCollection ttrc "\r
+ + " where ttr in elements(ttrc.results) and ttrc.id=?",\r
+ collectionId);\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