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=ffe7754e421f8ad5d3a336f54a498f67c6d72839;hp=65fb02de27308c5065c142b2da8ce06cf9aaa405;hpb=27442cdd51bb92778b33ec6899c376cd7d848eec;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 65fb02de2..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,9 +1,29 @@ +/* + * 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; import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao; @@ -13,6 +33,7 @@ import org.hibernate.Session; import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; +/** Hibernate implementation of collections DAO. */ public class TreeTestResultCollectionDaoHibernate extends HibernateDaoSupport implements TreeTestResultCollectionDao { @@ -29,6 +50,11 @@ public class TreeTestResultCollectionDaoHibernate extends HibernateDaoSupport getHibernateTemplate().update(ttrCollection); } + public void delete(TreeTestResultCollection ttrCollection) { + getHibernateTemplate().delete(ttrCollection); + } + + @SuppressWarnings("unchecked") public SortedSet listCollections() { return new TreeSet(getHibernateTemplate() .find("from TreeTestResultCollection")); @@ -64,4 +90,66 @@ public class TreeTestResultCollectionDaoHibernate extends HibernateDaoSupport }); } + @SuppressWarnings("unchecked") + public List listResultAttributes(String collectionId) { + List list; + if (collectionId == null) + list = getHibernateTemplate().find( + "select new org.argeo.slc.core.test.tree.ResultAttributes(ttr)" + + " from TreeTestResult ttr"); + else + list = getHibernateTemplate() + .find( + "select new org.argeo.slc.core.test.tree.ResultAttributes(ttr) " + + " from TreeTestResult ttr, TreeTestResultCollection ttrc " + + " where ttr in elements(ttrc.results) and ttrc.id=?", + collectionId); + + 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; + } }