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.ComponentType;
20 import org.figure8.join.businessobjects.artifact.Component;
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 ComponentDao using Hibernate ORM system.
28 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29 * @version $Revision: 1.2 $
30 */
31 public class HibernateComponentDao extends HibernateObjectDao implements ComponentDao{
32
33
34
35 /** Get a commons logger */
36 private static final Log log = LogUtil.getLog(HibernateComponentDao.class);
37
38
39
40
41 /** Creates a new instance of HibernateComponentDao */
42 public HibernateComponentDao(){
43 }
44
45
46
47
48 /**
49 * Retrieve the component having the specified key
50 * @param key The key of component to retrieve
51 * @return The component having this key or null if no one matches
52 */
53 public Component getComponent(String key){
54 Component result = (Component)findSingleObject(
55 findNamedQueryStringParam("join.component_findByKey", "compKey", key));
56 if (result == null)
57 log.info("There is no component with key '" + key + "'");
58 return result;
59 }
60
61 /**
62 * Retrieve components of specified type generated by a specified release
63 * @param type The components type
64 * @param release The release components have been generated for
65 * @return A list of <code>org.figure8.join.businessobjects.artifact.Component</code>s
66 */
67 public List getComponentsByRelease(ComponentType type, Release release){
68 List result = findNamedQueryStringParams("join.component_findByTypeAndRelease",
69 "compType", type, "compRelease", release, true);
70 if (result == null || result.isEmpty())
71 log.debug("There is no components of type '" + type.getKey() + "' generated by release '" + release.getName()+ "'");
72 return result;
73 }
74
75 /**
76 * Retrieve components of specified type contained by a specified release
77 * @param type The components type
78 * @param release The release containing returned components
79 * @return A list of <code>org.figure8.join.businessobjects.artifact.Component</code>s
80 */
81 public List getComponentsInRelease(ComponentType type, Release release){
82 List result = findNamedQueryStringParams("join.component_findByTypeInRelease",
83 "compType", type, "compRelease", release, true);
84 if (result == null || result.isEmpty())
85 log.debug("There is no components of type '" + type.getKey() + "' contained into release '" + release.getName()+ "'");
86 return result;
87 }
88
89
90
91
92 /** @return org.figure8.join.businessobjects.artifact.Component class */
93 public Class getPersistentClass(){
94 return org.figure8.join.businessobjects.artifact.Component.class;
95 }
96 }