View Javadoc

1   package org.lsst.ccs.config;
2   
3   import javax.persistence.*;
4   import java.util.Collection;
5   import java.util.Collections;
6   import java.util.HashSet;
7   import java.util.Set;
8   
9   /**
10   * a "zombie" that represents subsystem description that can be alive (end timestamp is STILL_ALIVE)
11   * or dead (end timestamp is a realistic date).
12   * <P>
13   *  "ghost" data is necessary because there can be references to subsystem description
14   *  that becomes deprecated while the description is "alive"; when later this description "dies"
15   *  it's not necessary to change the references to this data (only the end time stamp is changed).
16   *  <P>
17   *   so ghosts are created at the same time as the original "living" data and anticipate death;
18   *   their id is the same as the "living" object.
19   * @author bamade
20   */
21  // Date: 10/04/12
22  
23      @Entity
24      // not immutable since endtime can be modified!
25      //@Table(name="SubsystemHistory")
26  class GhostSubsystemDescription  extends SubsystemDescription{
27      private static final long serialVersionUID = -8567707918287105248L;
28      @Id
29      private long id ;
30  
31  
32      // here the combination "name + tag" is not unique so is not a naturalId
33      // TODO: a map<Path, XXX> instead
34      // IMMUTABLE!
35      @OneToMany(cascade = CascadeType.ALL, fetch= FetchType.EAGER)
36      protected /*@NonNull*/ Set<GhostParameterDescription> paramDescriptions  ;
37  
38      //////////// CONSTRUCTORS
39  
40       GhostSubsystemDescription() {
41      }
42  
43      /**
44       * creates a ghost from a living subsystem description.
45       * @param other
46       * @throws IllegalArgumentException if argument is not registered in database
47       */
48      public GhostSubsystemDescription(ASubsystemDescription other) {
49          super(other);
50          this.id = other.getId();
51          //post control
52          if(this.id == 0 ){
53              throw new IllegalArgumentException(
54                      "cannot create ghost from non registered object (where id is not initialized by database)");
55          }
56          this.setStartTimestamp(other.getStartTimestamp());
57          Set<GhostParameterDescription> set = new HashSet<GhostParameterDescription>();
58          // copy the ParameterDescription
59          for(ParameterDescription parmDesc: other.getParamDescriptions()) {
60              AParameterDescription realDesc = (AParameterDescription) parmDesc ;
61              set.add(new GhostParameterDescription(realDesc)) ;
62          }
63          this.paramDescriptions = Collections.unmodifiableSet(set) ;
64          this.setPreviousDescriptionID(other.getPreviousDescriptionID());
65      }
66  
67  
68      /////////////////////// ACCESSORS/ MUTATORS
69  
70      @Override
71      public long getId() {
72          return id;
73      }
74  
75      @Override
76      void setId(long id) {
77         this.id = id ;
78      }
79  
80      /**
81       * calls <TT>getParamDescriptions()</TT>
82       * @return
83       */
84      @Override
85      public Set<? extends ParameterDescription> getParamDescriptionSet() {
86          return getParamDescriptions() ;
87      }
88  
89  
90      /**
91       *
92       * @return an immutable list of ghosts for Parameter descriptions
93       */
94      public Set<GhostParameterDescription> getParamDescriptions() {
95          return paramDescriptions;
96      }
97  
98       void setParamDescriptions(Set<GhostParameterDescription> paramDescriptions) {
99          this.paramDescriptions = Collections.unmodifiableSet(paramDescriptions);
100     }
101 
102     @Override
103      void setEndTimestamp(long endTimestamp) {
104         super.setEndTimestamp(endTimestamp);
105     }
106 
107     @Override
108     public void addParameterDescriptions(ParameterDescription... descriptions) {
109         throw new UnsupportedOperationException("immutable description") ;
110     }
111 
112     @Override
113     public void addParameterDescriptions(Collection<ParameterDescription> descriptions) {
114         throw new UnsupportedOperationException("immutable description") ;
115     }
116 
117     @Override
118     public void removeParameterDescriptions(ParameterDescription... descriptions) {
119         throw new UnsupportedOperationException("immutable description") ;
120     }
121 
122 
123 }