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=00d30446d6a8d3eca09ebcf45aa2581fc6ac842f;hb=1fdb1b4e7b1d2b0cabb6483238301b857a6392fa;hp=c1679b8231c5629d353ebdecee43920ad2efe92e;hpb=cf1811ce269e135c8e1a79070b97dc15487d2377;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..00d30446d 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 @@ -1,10 +1,28 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 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; @@ -89,4 +107,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; + } }