View Javadoc

1   /*
2   * Copyright 2005 Arnaud Prost
3   * 
4   * Arnaud.prost@gmail.com
5   * 
6   * This software is a computer program whose purpose is to ease the 
7   * management of software project.
8   * 
9   * This software is governed by the CeCILL  license under French law and
10  * abiding by the rules of distribution of free software.  You can  use, 
11  * modify and/ or redistribute the software under the terms of the CeCILL
12  * license as circulated by CEA, CNRS and INRIA at the following URL
13  * "http://www.cecill.info". 
14  * 
15  * As a counterpart to the access to the source code and  rights to copy,
16  * modify and redistribute granted by the license, users are provided only
17  * with a limited warranty  and the software's author,  the holder of the
18  * economic rights,  and the successive licensors  have only  limited
19  * liability. 
20  * 
21  * In this respect, the user's attention is drawn to the risks associated
22  * with loading,  using,  modifying and/or developing or reproducing the
23  * software by the user in light of its specific status of free software,
24  * that may mean  that it is complicated to manipulate,  and  that  also
25  * therefore means  that it is reserved for developers  and  experienced
26  * professionals having in-depth computer knowledge. Users are therefore
27  * encouraged to load and test the software's suitability as regards their
28  * requirements in conditions enabling the security of their systems and/or 
29  * data to be ensured and,  more generally, to use and operate it in the 
30  * same conditions as regards security. 
31  * 
32  * The fact that you are presently reading this means that you have had
33  * knowledge of the CeCILL license and that you accept its terms.
34  */
35  
36  package net.sf.pmr.agilePlanning.data.story;
37  
38  import java.util.HashSet;
39  import java.util.Iterator;
40  import java.util.List;
41  import java.util.Set;
42  
43  import net.sf.pmr.agilePlanning.domain.story.Story;
44  import net.sf.pmr.agilePlanning.domain.story.StoryImpl;
45  
46  import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
47  
48  /***
49   * @author Arnaud Prost (arnaud.prost@gmail.com)
50   */
51  public class StoryMapperImpl extends HibernateDaoSupport implements StoryMapper {
52  
53      /***
54       * @see net.sf.pmr.keopsframework.data.EntityMapper#findById(int)
55       */
56      public Object findById(final int id) {
57          
58          return getHibernateTemplate().get(StoryImpl.class,
59                                            new Integer(id));
60          
61      }
62  
63      /*** 
64       * @see net.sf.pmr.keopsframework.data.DomainObjectRootAggregateMapper#addOrUpdate(java.lang.Object)
65       */
66      public void addOrUpdate(final Object story) {
67  
68          Story storyToAddorUpdate = (Story) story;
69          
70          // Si aucune iteration n'est associée à la story (persistanceId = 0)
71          // elle est mise à null (sinon hibernate essai de l'enregistrer en base, mais ne la trouve pas -> exception)
72          // TODO Comment tester cela unitairement ??
73          if (storyToAddorUpdate.getIteration() != null && storyToAddorUpdate.getIteration().getPersistanceId() == 0) {
74              storyToAddorUpdate.setIteration(null);
75          }
76          
77          getHibernateTemplate().saveOrUpdate(storyToAddorUpdate);
78  
79      }
80  
81      /*** 
82       * @see net.sf.pmr.keopsframework.data.DomainObjectRootAggregateMapper#delete(java.lang.Object)
83       */
84      public void delete(final Object story) {
85          
86          getHibernateTemplate().delete((Story) story);
87          
88      }
89  
90      /*** 
91       * @see net.sf.pmr.agilePlanning.data.story.StoryMapper#findByProjectPersistanceId(int)
92       */
93      public Set findByProjectPersistanceId(final int projetPersistanceId) {
94  
95          List list = getHibernateTemplate()
96                  .find(
97                          "from net.sf.pmr.agilePlanning.domain.story.StoryImpl story where story.BasicProject.PersistanceId = ?",
98                          new Integer(projetPersistanceId));
99  
100         Set setToReturn = new HashSet();
101 
102         for (Iterator iterator = list.iterator(); iterator.hasNext();) {
103             Story story = (Story) iterator.next();
104 
105             setToReturn.add(story);
106 
107         }
108 
109         return setToReturn;
110     }
111 }