View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.businessobjects.artifact.persistence;
16  
17  import org.figure8.join.core.persistence.HibernateObjectDao;
18  import org.figure8.join.businessobjects.commons.Release;
19  import org.figure8.join.businessobjects.artifact.DeliverableType;
20  import org.figure8.join.businessobjects.artifact.Deliverable;
21  import org.figure8.join.util.LogUtil;
22  
23  import org.apache.commons.logging.Log;
24  
25  import java.util.List;
26  /**
27   * Implementation of DeliverableDao using Hibernate ORM system.
28   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29   * @version $Revision: 1.1 $
30   */
31  public class HibernateDeliverableDao extends HibernateObjectDao implements DeliverableDao{
32  
33     // Static -------------------------------------------------------------------
34  
35     /** Get a commons logger */
36     private static final Log log = LogUtil.getLog(HibernateDeliverableDao.class);
37  
38  
39     // Constructors -------------------------------------------------------------
40     
41     /** Creates a new instance of HibernateDeliverableDao */
42     public HibernateDeliverableDao(){
43     }
44  
45  
46     // Implementation of DeliverableDao -----------------------------------------
47  
48     /**
49      * Retrieve a deliverable using its unique business key
50      * @param key The key of deliverable to retrieve
51      * @return The deliverable having this ey or null if key not found
52      */
53     public Deliverable getDeliverable(String key){
54        Deliverable result = (Deliverable)findSingleObject(
55                findNamedQueryStringParam("join.deliverable_findByKey", "delKey", key));
56        if (result == null)
57           log.info("There is no deliverable with key '" + key + "'");
58        return result;
59     }
60  
61     /**
62      * Retrieve the last deliverables for a specified type. 'Last' are the one with
63      * most recent delivery creation date. Limit the result size with <b>maxResult</b>
64      * @param type The deliverables type
65      * @param maxResult The maximum number of returned deliverables
66      * @return A list of <code>org.figure8.join.businessobjects.artifact.Deliverable</code>s
67      */
68     public List getLastDeliverables(DeliverableType type, int maxResult){
69        List result = findNamedQueryStringParam("join.deliverable_findByType", "delType", type, false, maxResult);
70        if (result == null || result.isEmpty())
71           log.debug("There is no deliverables of type '" + type.getKey() + "'");
72        return result;
73     }
74  
75     /**
76      * Retrieve deliverables of specified type for a specified release
77      * @param type The deliverables type
78      * @param release The release deliverables have been done for
79      * @return A list of <code>org.figure8.join.businessobjects.artifact.Deliverable</code>s
80      */
81     public List getDeliverablesByRelease(DeliverableType type, Release release){
82        List result = findNamedQueryStringParams("join.deliverable_findByTypeAndRelease", "delType", type, "delRelease", release, true);
83        if (result == null || result.isEmpty())
84           log.debug("There is no deliverables of type '" + type.getKey() + "' for release '" + release.getName()+ "'");
85        return result;
86     }
87  
88     /**
89      * Retrieve deliverables supplied by a specified user
90      * @param userId The unique identifier of the supplier
91      * @return A list of <code>org.figure8.join.businessobjects.artifact.Deliverable</code>s
92      */
93     public List getDeliverablesSuppliedByUser(String userId){
94        List result = findNamedQueryStringParam("join.deliverable_findBySupplierId", "userId", userId);
95        if (result == null || result.isEmpty())
96           log.debug("There is no deliverables supplied by user '" + userId + "'");
97        return result;
98     }
99  
100 
101    // Implementation of ObjectDao ----------------------------------------------
102 
103    /** @return org.figure8.join.businessobjects.artifact.Deliverable class */
104    public Class getPersistentClass(){
105       return org.figure8.join.businessobjects.artifact.Deliverable.class;
106    }
107 }