1 package org.lsst.ccs.localdb.statusdb.model;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import javax.persistence.Column;
8 import javax.persistence.Entity;
9 import javax.persistence.GeneratedValue;
10 import javax.persistence.GenerationType;
11 import javax.persistence.Id;
12 import javax.persistence.OneToMany;
13 import javax.persistence.Table;
14 import javax.persistence.Transient;
15
16 import org.hibernate.annotations.NaturalId;
17
18 @Entity
19 @org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
20 @Table(name = "datadesc")
21 public class DataDesc implements Serializable {
22
23 private static final long serialVersionUID = 2636311585766032024L;
24 private long id;
25 private String name;
26
27
28
29
30
31
32
33 @Transient
34 public String[] getPath() {
35 String[] namePath = getSrcName().split("/");
36 String[] result = new String[namePath.length + 1];
37 result[0] = getSrcSubsystem();
38 for (int i = 1; i < result.length; i++) {
39 result[i] = namePath[i - 1];
40 }
41 return result;
42 }
43
44 public static String encodePath(String[] path) {
45
46 StringBuilder result = new StringBuilder();
47 for (int i = 0; i < path.length; i++) {
48 result.append('/');
49 result.append(path[i].replaceAll("/", "\\\\/"));
50 }
51 return result.toString();
52 }
53
54 public static String[] decodePath(String path) {
55 if (path.startsWith("/")) {
56 path = path.substring(1);
57 }
58 String[] elts = path.split("(?<!\\\\)/");
59 for (int i = 0; i < elts.length; i++) {
60 elts[i] = elts[i].replaceAll("\\\\/", "/");
61 }
62 return elts;
63 }
64
65 private String srcSubsystem;
66 private String srcName;
67 private int maxSamplingMillis = 0;
68 private String dataType;
69 private long preservationDelay;
70 private List<StatDesc> derived = new ArrayList<StatDesc>();
71
72
73
74
75 @Id()
76 @GeneratedValue(strategy = GenerationType.AUTO)
77 public long getId() {
78 return id;
79 }
80
81
82
83
84
85 public void setId(long id) {
86 this.id = id;
87 }
88
89
90
91
92 @NaturalId
93 @Column(unique = true)
94 public String getName() {
95 return name;
96 }
97
98
99
100
101
102 public void setName(String name) {
103 this.name = name;
104 }
105
106
107
108
109 public String getSrcSubsystem() {
110 return srcSubsystem;
111 }
112
113
114
115
116
117 public void setSrcSubsystem(String srcSubsystem) {
118 this.srcSubsystem = srcSubsystem;
119 }
120
121
122
123
124 public String getSrcName() {
125 return srcName;
126 }
127
128
129
130
131
132 public void setSrcName(String srcName) {
133 this.srcName = srcName;
134 }
135
136
137
138
139 @Column(columnDefinition = "int default 0")
140 public int getMaxSamplingMillis() {
141 return maxSamplingMillis;
142 }
143
144
145
146
147
148 public void setMaxSamplingMillis(int maxSamplingMillis) {
149 this.maxSamplingMillis = maxSamplingMillis;
150 }
151
152
153
154
155 @Column(length = 1)
156 public String getDataType() {
157 return dataType;
158 }
159
160
161
162
163
164 public void setDataType(String dataType) {
165 this.dataType = dataType;
166 }
167
168
169
170
171 @Column(columnDefinition = "int default 0")
172 public long getPreservationDelay() {
173 return preservationDelay;
174 }
175
176
177
178
179
180 public void setPreservationDelay(long preservationDelay) {
181 this.preservationDelay = preservationDelay;
182 }
183
184
185
186
187 @OneToMany(mappedBy = "rawDescr")
188 public List<StatDesc> getDerived() {
189 return derived;
190 }
191
192
193
194
195
196 public void setDerived(List<StatDesc> derived) {
197 this.derived = derived;
198 }
199 }