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 a mapping between an Enterprise Information System
22   * resource (a {@link EIS} of any {@link EISType}) and a gateway infrastructure resource.
23   * <br/>
24   * EISMappings 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_eismappings" lazy="true"
31   * @hiberante.cache usage="read-write"
32   *
33   * @hibernate.query name="join.eismapping_findByDateAndEis"
34   *    query="from EISMapping mapping left join fetch mapping.gateway"
35   *             where mapping.startDate <= :endDate and (mapping.endDate >= :startDate or mapping.endDate is null)
36   *                and mapping.EIS = :eis order by mapping.startDate asc
37   * @hibernate.query name="join.eismapping_findByDateAndGateway"
38   *    query="from EISMapping mapping left join fetch mapping.EIS
39   *             where mapping.startDate <= :endDate and (mapping.endDate >= :startDate or mapping.endDate is null)
40   *                and mapping.gateway = :gateway order by mapping.startDate asc"
41   */
42  public class EISMapping extends EntityObject{
43  
44     // Attributes ---------------------------------------------------------------
45  
46     /** The date this mapping has started being active */
47     private Date startDate;
48     /** The date this mapping has stopped being active */
49     private Date endDate;
50  
51     /** The EIS this mapping is for */
52     private EIS eis;
53     /** The gateway this mapping is for */
54     private Gateway gateway;
55  
56  
57     // Constructors -------------------------------------------------------------
58  
59     /** Creates a new instance of ResourceMapping */
60     public EISMapping(){
61     }
62  
63     /**
64      * Creates a new ResourceMapping with mandatory parameters.
65      * @param eis The resource this mapping is for
66      * @param gateway The physical environment this mapping is for
67      */
68     public EISMapping(EIS eis, Gateway gateway){
69        this.eis = eis;
70        this.gateway = gateway;
71        // Set the start date as current date.
72        startDate = new Date();
73     }
74  
75  
76     // Public -------------------------------------------------------------------
77  
78     /**
79      * @hibernate.property column="d_start"
80      *    not-null="true" type="timestamp"
81      *    update="false"
82      * @return The date this mapping has started being active
83      */
84     public Date getStartDate(){
85        return startDate;
86     }
87     /** @param startDate The date this mapping has started being active */
88     public void setStartDate(Date startDate){
89        this.startDate = startDate;
90     }
91  
92     /**
93      * @hibernate.property column="d_end" type="timestamp"
94      * @return The date this mapping has stopped being active
95      */
96     public Date getEndDate(){
97        return endDate;
98     }
99     /** @param endDate The date this mapping has stopped being active */
100    public void setEndDate(Date endDate){
101       this.endDate = endDate;
102    }
103 
104    /**
105     * @hibernate.many-to-one column="n_eis_fk" not-null="true"
106     * @return The resource this mapping is for
107     */
108    public EIS getEIS(){
109       return eis;
110    }
111    /** @param eis The EIS this mapping is for */
112    public void setEIS(EIS eis){
113       this.eis = eis;
114    }
115 
116    /**
117     * @hibernate.many-to-one column="n_gateway_fk" not-null="true"
118     * @return The gateway this mapping is for
119     */
120    public Gateway getGateway(){
121       return gateway;
122    }
123    /** @param gateway The gateway this mapping is for */
124    public void setGateway(Gateway gateway){
125       this.gateway = gateway;
126    }
127 
128    /** @return Flag telling if this mapping is currently active */
129    public boolean isActive(){
130       return (endDate == null);
131    }
132 
133    /** Close this mapping (ie. make it inactive) */
134    public void close(){
135       // Remove current mapping from active ones.
136       gateway.getActiveEISMappings().remove(this);
137       setEndDate(new Date());
138    }
139 }