View Javadoc

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.environment;
16  
17  import org.figure8.join.core.EntityObject;
18  
19  import java.util.Date;
20  /**
21   * This is an entity representing an update of a physical infrastructure resource
22   * (of VersionedResource category) with a resource version.
23   * <br/>
24   * VersionedResourceUpdates are by definition volatile : they have a <code>startDate</code>
25   * and an <code>endDate</code> when update ends to be valid. Active updates 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_resourceupdates" lazy="true"
31   * @hiberante.cache usage="read-write"
32   *
33   * @hibernate.query name="join.resourceupdate_findByDateAndResource"
34   *    query="from VersionedResourceUpdate update left join fetch update.version
35   *             where update.startDate <= :date and (update.endDate >= :date or update.endDate is null)
36   *                and update.resource = :resource order by update.startDate desc"
37   * @hibernate.query name="join.resourceupdate_findByIntervalAndResource"
38   *    query="from VersionedResourceUpdate update left join fetch update.version
39   *             where (update.startDate <= :endDate or :endDate is null)
40   *                and (update.endDate >= :startDate or update.endDate is null)
41   *                and update.resource = :resource order by update.startDate asc"
42   */
43  public class VersionedResourceUpdate extends EntityObject{
44  
45     // Attributes ---------------------------------------------------------------
46  
47     /** The date this update has started being active */
48     private Date startDate;
49     /** The date this update has stopped being active */
50     private Date endDate;
51  
52     /** The version resource has been updated with */
53     private ResourceVersion version;
54     /** The versioned resource this update is for */
55     private VersionedResource resource;
56  
57  
58     // Constructors -------------------------------------------------------------
59  
60     /** Creates a new instance of VersionedResourceUpdate. */
61     public VersionedResourceUpdate(){
62     }
63  
64     /**
65      * Creates a new instance of VersionedResourceUpdate.
66      * @param version The version resource has been updated with
67      * @param resource The versioned resource this update is for
68      */
69     public VersionedResourceUpdate(ResourceVersion version, VersionedResource resource){
70        this.version = version;
71        this.resource = resource;
72        // Set the start date as current date.
73        startDate = new Date();
74     }
75  
76  
77     // Public -------------------------------------------------------------------
78  
79     /**
80      * @hibernate.property column="d_start"
81      *    not-null="true" type="timestamp"
82      *    update="false"
83      * @return The date this update has started being active
84      */
85     public Date getStartDate(){
86        return startDate;
87     }
88     /** @param startDate The date this update has started being active */
89     public void setStartDate(Date startDate){
90        this.startDate = startDate;
91     }
92  
93     /**
94      * @hibernate.property column="d_end" type="timestamp"
95      * @return The date this update has stopped being active
96      */
97     public Date getEndDate(){
98        return endDate;
99     }
100    /** @param endDate The date this update has stopped being active */
101    public void setEndDate(Date endDate){
102       this.endDate = endDate;
103    }
104 
105    /**
106     * @hibernate.many-to-one column="n_version_fk" not-null="true"
107     * @return The version resource has been updated with
108     */
109    public ResourceVersion getVersion(){
110       return version;
111    }
112    /** @param version The version resource has been updated with */
113    public void setVersion(ResourceVersion version){
114       this.version = version;
115    }
116 
117    /**
118     * @hibernate.many-to-one column="n_resource_fk" not-null="true" outer-join="false"
119     * @return The resource this update is for
120     */
121    public VersionedResource getResource(){
122       return resource;
123    }
124    /** @param resource The resource this update is for */
125    public void setResource(VersionedResource resource){
126       this.resource = resource;
127    }
128 
129    /** @return Flag telling if this update is currently active */
130    public boolean isActive(){
131       return (endDate == null);
132    }
133 
134    /** Close this update (ie. make it inactive) */
135    public void close(){
136       // Remove current update from active ones.
137       resource.getActiveVersionUpdates().remove(this);
138       setEndDate(new Date());
139    }
140 }