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=dc99deecfc47d6ceec5e47a20b2332a3a197c6f8;hb=a5b25ca3e5efc8de3571993f6bfc1671c0e2f3ba;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..dc99deecf 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,28 @@ +/* + * Copyright (C) 2007-2012 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 +32,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 +49,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 +89,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; + } }