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  
19  import java.util.Date;
20  /**
21   * This is an entity representing a mapping between a physical infrastructure resource
22   * (of any category and any type) and a physical environment.
23   * <br/>
24   * ResourceMappings are by definition volatile : they have a <code>startDate</code>
25   * and an <code>endDate</code> when mapping ends. Active mappings are those having
26   * endDate not set.
27   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28   * @version $Revision: 1.2 $
29   *
30   * @hibernate.class table="join_resmappings" lazy="true"
31   * @hiberante.cache usage="read-write"
32   *
33   * @hibernate.query name="join.resmapping_findByIntervalAndResource"
34   *    query="from ResourceMapping mapping left join fetch mapping.physicalEnvironment"
35   *             where mapping.startDate <= :endDate and (mapping.endDate >= :startDate or mapping.endDate is null)
36   *                and mapping.resource = :resource order by mapping.startDate asc
37   * @hibernate.query name="join.resmapping_findByDateAndEnvironment"
38   *    query="from ResourceMapping mapping left join fetch mapping.resource
39   *             where mapping.startDate <= :date and (mapping.endDate >= :date or mapping.endDate is null)
40   *                and mapping.physicalEnvironment = :physicalEnv order by mapping.startDate asc"
41   * @hibernate.query name="join.resmapping_findByIntervalAndEnvironment"
42   *    query="from ResourceMapping mapping left join fetch mapping.resource
43   *             where mapping.startDate <= :endDate and (mapping.endDate >= :startDate or mapping.endDate is null)
44   *                and mapping.physicalEnvironment = :physicalEnv order by mapping.startDate asc"
45   */
46  public class ResourceMapping extends EntityObject{
47     
48     // Attributes ---------------------------------------------------------------
49  
50     /** The date this mapping has started being active */
51     private Date startDate;
52     /** The date this mapping has stopped being active */
53     private Date endDate;
54     
55     /** The resource this mapping is for */
56     private AbstractResource resource;
57     /** The physical environment this mapping is for */
58     private PhysicalEnvironment physicalEnvironment;
59     
60     
61     // Constructors -------------------------------------------------------------
62     
63     /** Creates a new instance of ResourceMapping */
64     public ResourceMapping(){
65     }
66     
67     /**
68      * Creates a new ResourceMapping with mandatory parameters.
69      * @param resource The resource this mapping is for
70      * @param physicalEnv The physical environment this mapping is for
71      */
72     public ResourceMapping(AbstractResource resource, PhysicalEnvironment physicalEnv){
73        this.resource = resource;
74        this.physicalEnvironment = physicalEnv;
75        // Set the start date as current date.
76        startDate = new Date();
77     }
78     
79     
80     // Public -------------------------------------------------------------------
81  
82     /**
83      * @hibernate.property column="d_start"
84      *    not-null="true" type="timestamp"
85      *    update="false"
86      * @return The date this mapping has started being active
87      */
88     public Date getStartDate(){
89        return startDate;
90     }
91     /** @param startDate The date this mapping has started being active */
92     public void setStartDate(Date startDate){
93        this.startDate = startDate;
94     }
95  
96     /**
97      * @hibernate.property column="d_end" type="timestamp"
98      * @return The date this mapping has stopped being active
99      */
100    public Date getEndDate(){
101       return endDate;
102    }
103    /** @param endDate The date this mapping has stopped being active */
104    public void setEndDate(Date endDate){
105       this.endDate = endDate;
106    }
107    
108    /**
109     * @hibernate.many-to-one column="n_resource_fk" not-null="true"
110     * @return The resource this mapping is for
111     */
112    public AbstractResource getResource(){
113       return resource;
114    }
115    /** @param resource The resource this mapping is for */
116    public void setResource(AbstractResource resource){
117       this.resource = resource;
118    }
119    
120    /**
121     * @hibernate.many-to-one column="n_physicalenv_fk" not-null="true"
122     * @return The physical environment this mapping is for
123     */
124    public PhysicalEnvironment getPhysicalEnvironment(){
125       return physicalEnvironment;
126    }
127    /** @param physicalEnvironment The physical environment this mapping is for */
128    public void setPhysicalEnvironment(PhysicalEnvironment physicalEnvironment){
129       this.physicalEnvironment = physicalEnvironment;
130    }
131 
132    /** @return Flag telling if this mapping is currently active */
133    public boolean isActive(){
134       return (endDate == null);
135    }
136 
137    /** Close this mapping (ie. make it inactive) */
138    public void close(){
139       // Remove current mapping from active ones.
140       physicalEnvironment.getActiveResourceMappings().remove(this);
141       setEndDate(new Date());
142    }
143 }