X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.hibernate%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fhibernate%2Ftest%2Ftree%2FTreeTestResultCollectionDaoHibernate.java;h=75470e247a00cc954a5a93bf2a9beec30eb3bd81;hb=f6d658f7db2cad552bd68f7a1ea485f280f05568;hp=c1679b8231c5629d353ebdecee43920ad2efe92e;hpb=d87e2f0331afc9d26679f1d6ac69f752c80e0bf8;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/test/tree/TreeTestResultCollectionDaoHibernate.java b/runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/test/tree/TreeTestResultCollectionDaoHibernate.java index c1679b823..75470e247 100644 --- a/runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/test/tree/TreeTestResultCollectionDaoHibernate.java +++ b/runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/test/tree/TreeTestResultCollectionDaoHibernate.java @@ -2,9 +2,11 @@ package org.argeo.slc.hibernate.test.tree; import java.sql.SQLException; import java.util.List; +import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; +import org.argeo.slc.SlcException; import org.argeo.slc.core.test.tree.ResultAttributes; import org.argeo.slc.core.test.tree.TreeTestResult; import org.argeo.slc.core.test.tree.TreeTestResultCollection; @@ -12,6 +14,7 @@ import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao; import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.Session; +import org.hibernate.criterion.DetachedCriteria; import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; @@ -89,4 +92,49 @@ public class TreeTestResultCollectionDaoHibernate extends HibernateDaoSupport return list; } + + @SuppressWarnings("unchecked") + public List listResults(String collectionId, + Map attributes) { + List list; + + if (collectionId == null) { + if (attributes == null || attributes.size() == 0) + list = getHibernateTemplate().find("from TreeTestResult"); + else if (attributes.size() == 1) { + Map.Entry entry = attributes.entrySet() + .iterator().next(); + Object[] args = { entry.getKey(), entry.getValue() }; + list = getHibernateTemplate().find( + "select ttr from TreeTestResult ttr" + + " where attributes[?]=?", args); + } else { + throw new SlcException( + "Multiple attributes filter are currently not supported."); + } + } else { + if (attributes == null || attributes.size() == 0) + list = getHibernateTemplate() + .find( + "select ttr " + + " from TreeTestResult ttr, TreeTestResultCollection ttrc " + + " where ttr in elements(ttrc.results) and ttrc.id=?", + collectionId); + else if (attributes.size() == 1) { + Map.Entry entry = attributes.entrySet() + .iterator().next(); + Object[] args = { collectionId, entry.getKey(), + entry.getValue() }; + list = getHibernateTemplate() + .find( + "select ttr from TreeTestResult ttr, TreeTestResultCollection ttrc " + + " where ttr in elements(ttrc.results) and ttrc.id=?" + + " and attributes[?]=?", args); + } else { + throw new SlcException( + "Multiple attributes filter are currently not supported."); + } + } + return list; + } }