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.environment;
16  
17  import org.figure8.join.core.EntityObject;
18  import org.figure8.join.businessobjects.commons.Target;
19  
20  import java.util.Date;
21  /**
22   * This entity represents a wrapper around available value for a
23   * deployment parameter ({@link Parameter}). Such a value is defined
24   * for a specific physical environment and for specific deployment target.
25   * @author <a href="mailto:jerome.evrard@gmail.com">Jerome Evrard</a>
26   * @version $Revision: 1.2 $
27   *
28   * @see org.figure8.join.businessobjects.commons.Target
29   *
30   * @hibernate.class table="join_parametervalues"
31   * @hibernate.cache usage="read-write"
32   *
33   * @hibernate.query name="join.paramvalue_findCurrentByEnvironmentAndTargetKeys"
34   *    query="from ParameterValue value where value.status = 'current' and value.target.name = :targetName
35   *          and value.environment.key = :environmentKey order by value.parameter.name asc"
36   * @hibernate.query name="join.paramvalue_findHistoricalByParameterNameAndEnvironmentKey"
37   *    query="from ParameterValue value where value.parameter.name = :paramName
38   *          and value.environment.key = :environmentKey order by value.deprecationDate desc"
39   */
40  public class ParameterValue extends EntityObject{
41  
42     // Static -------------------------------------------------------------------
43  
44     /** Constant representing a currently available value */
45     public static final String CURRENT = "current";
46     /** Constant representing an historical value */
47     public static final String HISTORICAL = "historical";
48     /** Constant representing a deleted value */
49     public static final String DELETED = "deleted";
50  
51  
52     // Attributes ---------------------------------------------------------------
53     
54     /** The parameter value */
55     private String value;
56     /** The status of this value wrapper */
57     private String status = CURRENT;
58     /** The date this value has been deprecated */
59     private Date deprecationDate;
60  
61     /** The variable of the value */
62     private Parameter parameter;
63     /** The target for this value */
64     private Target target;
65     /** The environment for this value */
66     private PhysicalEnvironment environment;
67  
68  
69     // Constructors -------------------------------------------------------------
70  
71     /** Creates a new instance of ParameterValue. */
72     public ParameterValue(){
73     }
74     
75     /**
76      * Creates a new instance of ParameterValue with mandatory attributes.
77      * @param value The value to set.
78      * @param parameter The parameter instance corresponding to this value
79      * @param target The target this parameter value is available for.
80      * @param environment The environment this parameter value is available for.
81      */
82     public ParameterValue(String value, Parameter parameter, Target target, PhysicalEnvironment environment){
83        this.value = value;
84        this.target = target;
85        this.parameter = parameter;
86        this.environment = environment;
87     }
88  
89  
90     // Public -------------------------------------------------------------------
91     
92     /**
93      * Get the parameter value
94      * @hibernate.property column="s_value"
95      *    not-null="true" length="255"
96      * @return The parameter value
97      */   
98     public String getValue(){
99        return value;
100    }
101    /** @param value The parameter value wrapped */
102    public void setValue(String value){
103       this.value = value;
104    }
105 
106    /**
107     * @hibernate.property column="s_status"
108     *    not-null="true" length="10"
109     * @return The status of this value wrapper (one of CURRENT, HISTORICAL or DELETED)
110     */
111    public String getStatus(){
112       return status;
113    }
114    /** @param status The status of this value wrapper (one of CURRENT, HISTORICAL or DELETED) */
115    public void setStatus(String status){
116       this.status = status;
117    }
118 
119    /**
120     * @hibernate.property column="d_deprecation"
121     *    type="timestamp" update="false"
122     * @return The date this value has been deprecated
123     */
124    public Date getDeprecationDate(){
125       return deprecationDate;
126    }
127    /** @param deprecation The date this value has been deprecated */
128    public void setDeprecationDate(Date deprecation){
129       this.deprecationDate = deprecation;
130    }
131 
132    /**
133     * Delete this parameter value. Set the status to
134     * deleted and set the deprecation date to the current date.
135     */
136    public void delete(){
137       setStatus(DELETED);
138       setDeprecationDate(new Date());
139    }
140    
141    /**
142     * Deprecate this parameter value. Set the status to
143     * historical and set the deprecation date to the current date.
144     */
145    public void deprecate(){
146       setStatus(HISTORICAL);
147       setDeprecationDate(new Date());
148    }
149 
150    /**
151     * Get the parameter of the value.
152     * @hibernate.many-to-one column="n_parameter_fk" not-null="true"
153     * @return The parameter value
154     */   
155    public Parameter getParameter(){
156       return parameter;
157    }
158    /** @param parameter The parameter definition corresponding to this value wrapper */
159    public void setParameter(Parameter parameter){
160       this.parameter = parameter;
161    }
162    
163    /**
164     * Get the environment to whom this value applies.
165     * @hibernate.many-to-one column="n_environment_fk"
166     *    not-null="true" outer-join="false"
167     * @return The environment corresponding to parameter value
168     */   
169    public PhysicalEnvironment getEnvironment(){
170       return environment;
171    }
172    /** @param environment The environment to whom this value applies */
173    public void setEnvironment(PhysicalEnvironment environment){
174       this.environment = environment;
175    }
176    
177    /**
178     * Get the target of the value
179     * @hibernate.many-to-one column="n_target_fk"
180     *    not-null="true" outer-join="false"
181     * @return The target corresponding to parameter value
182     */      
183    public Target getTarget(){
184       return target;
185    }
186    /** @param target The target to whom this value applies */
187    public void setTarget(Target target){
188       this.target = target;
189    }
190 
191 
192    // Override of Object -------------------------------------------------------
193 
194    /** @return A string representation of this value */
195    public String toString(){
196       StringBuffer buffer = new StringBuffer("[parameter: " + parameter.getName());
197       buffer.append(", environment: " + environment.getName());
198       buffer.append(", target: " + target.getName());
199       buffer.append(", status: " + status);
200       buffer.append(", value: " + value + "]");
201       return buffer.toString();
202    }
203 }