1 /**
2 * Copyright 2005-2007 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;
16
17 import org.figure8.join.core.EntityObject;
18 import org.figure8.join.businessobjects.commons.Release;
19
20 import java.util.Date;
21 import java.util.List;
22 import java.util.ArrayList;
23 /**
24 *
25 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26 * @version $Revision: 1.3 $
27 *
28 * @see org.figure8.join.businessobjects.commons.Release
29 * @see org.figure8.join.businessobjects.artifact.Assembly
30 * @see org.figure8.join.businessobjects.artifact.ComponentType
31 *
32 * @hibernate.class table="join_components" lazy="true"
33 * @hibernate.cache usage="read-write"
34 *
35 * @hibernate.query name="join.component_findByKey"
36 * query="from Component comp where comp.key = :compKey"
37 * @hibernate.query name="join.component_findByTypeAndRelease"
38 * query="from Component comp where comp.componentType = :compType and comp.assembly.release = :compRelease
39 * order by comp.creationDate desc"
40 * @hibernate.query name="join.component_findByTypeInRelease"
41 * query="select comp from Component comp join comp.assemblies ass
42 * where comp.componentType = :compType and ass.release = :compRelease order by comp.creationDate desc"
43 */
44 public class Component extends EntityObject implements Artifact{
45
46
47
48 /** The component key */
49 private String key;
50 /** Component version info */
51 private String versionInfo;
52 /** The component creation date */
53 private Date creationDate;
54 /** The component size (in bytes) */
55 private long size;
56 /** A list of <code>Build</code> objects containing component */
57 private List builds = new ArrayList();
58 /** A list of <code>Assembly</code> objects containing component */
59 private List assemblies = new ArrayList();
60
61 /** The assembly that has generated component */
62 private Assembly assembly;
63 /** The component type */
64 private ComponentType componentType;
65
66
67
68
69 /** Creates a new instance of Component */
70 public Component(){
71 }
72
73 /**
74 * Creates a new instance of Component with mandatory attributes
75 * @param versionInfo Information on this component version
76 * @param size The size of this component (in bytes)
77 * @param type The type of this component
78 */
79 public Component(String versionInfo, long size, ComponentType type){
80
81 this.versionInfo = versionInfo;
82 this.size = size;
83 this.componentType = type;
84 this.creationDate = new Date();
85
86 this.key = componentType.generateComponentKey(this);
87 }
88
89
90
91
92 /**
93 * @hibernate.property column="s_key"
94 * length="50" not-null="true"
95 * unique="true" update="false"
96 * @return This component unique key
97 */
98 public String getKey(){
99 return key;
100 }
101 /** @param key This component unique key */
102 public void setKey(String key){
103 this.key = key;
104 }
105
106 /** @param info Version information for this component */
107 public void setVersionInfo(String info){
108 this.versionInfo = info;
109 }
110
111 /**
112 * @hibernate.property column="d_creation"
113 * not-null="true" type="timestamp"
114 * update="false"
115 * @return Creation date of this component
116 */
117 public Date getCreationDate(){
118 return creationDate;
119 }
120 /** @param creationDate The component creation timestamp */
121 public void setCreationDate(Date creationDate){
122 this.creationDate = creationDate;
123 }
124
125 /**
126 * @hibernate.property column="n_size" type="long"
127 * @return The size of this component (in bytes)
128 */
129 public long getSize(){
130 return size;
131 }
132 /** @param size The size of this component (in bytes) */
133 public void setSize(long size){
134 this.size = size;
135 }
136
137 /**
138 * @hibernate.bag lazy="true" cascade="save-update" inverse="true" table="builds_components"
139 * @hibernate.collection-key column="n_component_fk"
140 * @hibernate.collection-many-to-many column="n_build_fk"
141 * class="org.figure8.join.businessobjects.artifact.Build"
142 * @return A set of {@code Build} objects containing this component
143 */
144 public List getBuilds(){
145 return builds;
146 }
147 /** @param builds A set of builds containing this component */
148 public void setBuilds(List builds){
149 this.builds = builds;
150 }
151
152 /**
153 * @hibernate.bag lazy="true" cascade="save-update" inverse="true" table="assemblies_components"
154 * @hibernate.collection-key column="n_component_fk"
155 * @hibernate.collection-many-to-many column="n_assembly_fk"
156 * class="org.figure8.join.businessobjects.artifact.Assembly"
157 * @return A set of {@code Assembly} objects containing this component
158 */
159 public List getAssemblies(){
160 return assemblies;
161 }
162 /** @param assemblies A set of assemblies containing this component */
163 public void setAssemblies(List assemblies){
164 this.assemblies = assemblies;
165 }
166
167 /**
168 * @hibernate.many-to-one column="s_assembly_fk"
169 * @return The assembly that has generated this component
170 */
171 public Assembly getAssembly(){
172 return assembly;
173 }
174 /** @param assembly The assembly that has generated this component */
175 public void setAssembly(Assembly assembly){
176 this.assembly = assembly;
177 }
178
179 /**
180 * @hibernate.many-to-one column="s_componenttype_fk" not-null="true"
181 * @return The type of this deliverable
182 */
183 public ComponentType getComponentType(){
184 return componentType;
185 }
186 /** @param type The type of this deliverable */
187 public void setComponentType(ComponentType type){
188 this.componentType = type;
189 }
190
191
192
193
194 /**
195 * Retrieve the unique identifier of this artifact. (ie : it's key)
196 * @return The unique identifier of this component
197 */
198 public String getUniqueId(){
199 return key;
200 }
201
202 /**
203 * Retrieve the version information on this component.
204 * @hibernate.property column="s_version"
205 * length="20" not-null="true"
206 * @return Version information as character string
207 */
208 public String getVersionInfo(){
209 return versionInfo;
210 }
211
212 /**
213 * Return the category information on this component, ie :
214 * the key of its associated {@link ComponentType}
215 * @return The category information as character string
216 */
217 public String getCategoryInfo(){
218 return componentType.getKey();
219 }
220
221 /**
222 * Retrieve the release that has cause this artifact creation
223 * @return The release this artifact has been realized for
224 */
225 public Release getRelease(){
226 return assembly.getRelease();
227 }
228 }