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
10
11
12
13
14
15
16 @Entity
17
18 class PastParameterConfiguration extends ParameterConfiguration{
19 private static final long serialVersionUID = 1648990234116895047L;
20 @Id
21 private long id ;
22
23 @ManyToOne
24 private
25
26 @OneToMany (cascade = CascadeType.PERSIST, fetch=FetchType.EAGER)
27 private List<PastValueEvent> valueEvents ;
28
29
30
31
32 PastParameterConfiguration() {
33 }
34
35
36
37
38
39
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
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
92
93
94
95
96 GhostParameterDescription getParameterDescription() {
97 return parameterDescription;
98 }
99
100 void setParameterDescription(GhostParameterDescription parameterDescription) {
101 this.parameterDescription = parameterDescription;
102 }
103 }