View Javadoc

1   package org.lsst.ccs.config;
2   
3   import javax.persistence.*;
4   import java.util.ArrayList;
5   import java.util.Collections;
6   import java.util.List;
7   
8   /**
9    * A parameter configuration in history.
10   * Those can be resuscitated using the <TT>repair</TT> methods of
11   * <TT>ConfigFacade</TT>
12   * @author bamade
13   */
14  // Date: 11/04/12
15  
16      @Entity
17  //@Table(name="ParmConfigurationHistory")
18  class PastParameterConfiguration extends ParameterConfiguration{
19      private static final long serialVersionUID = 1648990234116895047L;
20      @Id
21      private long id ; // not generated
22      //TODO: EAGER not obvious
23      @ManyToOne //(fetch=FetchType.EAGER)
24      private /*@NotNull*/ GhostParameterDescription parameterDescription ;
25  
26      @OneToMany (cascade = CascadeType.PERSIST, fetch=FetchType.EAGER)
27      private List<PastValueEvent> valueEvents ;
28  
29      //////////////////////////// CONSTRUCTOR
30  
31  
32      PastParameterConfiguration() {
33      }
34  
35      /**
36       * creates historic data from a Parameter configuration and the "ghost" corresponding to its description.
37       * @param ghostDescription
38       * @param oldConfig
39       * @throws IllegalArgumentException if ghost and description do not match!
40       */
41      PastParameterConfiguration(GhostParameterDescription ghostDescription,AParameterConfiguration oldConfig) {
42          super(oldConfig.getValue());
43          if(oldConfig.getId() == 0L) {
44              throw new IllegalArgumentException("trying to create historical data with a non-registered object") ;
45          }
46          if(ghostDescription.getId() != oldConfig.getDescription().getId()) {
47              throw new IllegalArgumentException("description and its ghost with different ids") ;
48          }
49          this.id = oldConfig.getId() ;
50          this.parameterDescription = ghostDescription;
51          List<AValueEvent> listEvents = oldConfig.valueEvents ;
52          if(listEvents != null) {
53              int size = listEvents.size() ;
54              ArrayList<PastValueEvent> newList = new ArrayList<PastValueEvent>(size) ;
55              for(AValueEvent oldEvent : listEvents) {
56                  newList.add(new PastValueEvent(oldEvent)) ;
57              }
58              setValueEvents(newList);
59          }
60  
61      }
62  
63      //////////////////////////// ACCESSORS/MUTATORS
64      @Override
65      public long getId() {
66          return id;
67      }
68  
69      @Override
70      protected void setId(long id) {
71          this.id = id ;
72      }
73  
74      @Override
75      public ParameterDescription getDescription() {
76          return parameterDescription;
77      }
78  
79      @Override
80      public List<? extends ValueEvent> getValueEvents() {
81          return valueEvents;
82      }
83  
84      void setValueEvents(List<PastValueEvent> valueEventList) {
85          if(valueEventList != null) {
86              this.valueEvents = Collections.unmodifiableList(valueEventList) ;
87          }
88      }
89  
90      /*
91      @Override
92      public void addValueEvent(ValueEvent event) {
93          throw new ImmutableStateException("no modification of deprecated data") ;
94      } */
95  
96      GhostParameterDescription getParameterDescription() {
97          return parameterDescription;
98      }
99  
100      void setParameterDescription(GhostParameterDescription parameterDescription) {
101         this.parameterDescription = parameterDescription;
102     }
103 }