1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.series.impl.persistence;
23
24 import java.util.Collections;
25 import java.util.Date;
26 import java.util.Map;
27 import java.util.TreeMap;
28
29 import javax.persistence.Access;
30 import javax.persistence.AccessType;
31 import javax.persistence.CollectionTable;
32 import javax.persistence.Column;
33 import javax.persistence.ElementCollection;
34 import javax.persistence.Entity;
35 import javax.persistence.GeneratedValue;
36 import javax.persistence.GenerationType;
37 import javax.persistence.Id;
38 import javax.persistence.IdClass;
39 import javax.persistence.Index;
40 import javax.persistence.JoinColumn;
41 import javax.persistence.Lob;
42 import javax.persistence.MapKeyColumn;
43 import javax.persistence.NamedQueries;
44 import javax.persistence.NamedQuery;
45 import javax.persistence.Table;
46 import javax.persistence.Temporal;
47 import javax.persistence.TemporalType;
48 import javax.persistence.UniqueConstraint;
49
50
51
52
53
54
55
56 @Entity(name = "SeriesEntity")
57 @IdClass(SeriesEntityId.class)
58 @Access(AccessType.FIELD)
59 @Table(name = "oc_series",
60 indexes = {
61 @Index(name = "IX_oc_series_modified_date", columnList = ("modified_date")),
62 }
63 )
64 @NamedQueries({
65 @NamedQuery(
66 name = "Series.findAll",
67 query = "select s from SeriesEntity s where s.deletionDate is null"
68 ),
69 @NamedQuery(
70 name = "Series.getCount",
71 query = "select COUNT(s) from SeriesEntity s where s.deletionDate is null"
72 ),
73 @NamedQuery(
74 name = "seriesById",
75 query = "select s from SeriesEntity as s where s.seriesId=:seriesId and s.organization=:organization"
76 ),
77 @NamedQuery(
78 name = "Series.getAllModifiedSince",
79 query = "select s from SeriesEntity as s "
80 + "where s.modifiedDate >= :since and s.organization=:organization "
81 + "order by s.modifiedDate asc"
82 ),
83 @NamedQuery(
84 name = "Series.getAllModifiedInRange",
85 query = "select s from SeriesEntity as s "
86 + "where s.modifiedDate >= :from and s.modifiedDate < :to and s.organization=:organization "
87 + "order by s.modifiedDate asc"
88 ),
89 })
90 public class SeriesEntity {
91
92
93 @Id
94 @GeneratedValue(strategy = GenerationType.AUTO)
95 @Column(name = "id", length = 128)
96 protected String seriesId;
97
98
99 @Id
100 @Column(name = "organization", length = 128)
101 protected String organization;
102
103
104 @Lob
105 @Column(name = "dublin_core", length = 65535)
106 protected String dublinCoreXML;
107
108
109 @Lob
110 @Column(name = "access_control", length = 65535)
111 protected String accessControl;
112
113 @Column(name = "modified_date", nullable = false)
114 @Temporal(TemporalType.TIMESTAMP)
115 protected Date modifiedDate = new Date();
116
117 @Column(name = "deletion_date")
118 @Temporal(TemporalType.TIMESTAMP)
119 protected Date deletionDate = null;
120
121 @Lob
122 @ElementCollection(targetClass = String.class)
123 @MapKeyColumn(name = "name", nullable = false)
124 @Column(name = "value", length = 65535)
125 @CollectionTable(name = "oc_series_property", uniqueConstraints = {
126 @UniqueConstraint(name = "UNQ_series_properties", columnNames = {"series", "organization", "name"})
127 }, joinColumns = {
128 @JoinColumn(name = "series", referencedColumnName = "id", nullable = false),
129 @JoinColumn(name = "organization", referencedColumnName = "organization", nullable = false) })
130 protected Map<String, String> properties;
131
132 @ElementCollection
133 @MapKeyColumn(name = "type", length = 128, nullable = false)
134 @Column(name = "data")
135 @CollectionTable(name = "oc_series_elements", uniqueConstraints = {
136 @UniqueConstraint(name = "UNQ_series_elements", columnNames = {"series", "organization", "type"})
137 }, joinColumns = {
138 @JoinColumn(name = "series", referencedColumnName = "id", nullable = false),
139 @JoinColumn(name = "organization", referencedColumnName = "organization", nullable = false) })
140 protected Map<String, byte[]> elements;
141
142
143
144
145 public SeriesEntity() {
146 }
147
148
149
150
151
152
153 public String getSeriesId() {
154 return seriesId;
155 }
156
157
158
159
160
161
162 public void setSeriesId(String seriesId) {
163 if (seriesId == null) {
164 throw new IllegalArgumentException("Series id can't be null");
165 }
166 if (seriesId.length() > 128) {
167 throw new IllegalArgumentException("Series id can't be longer than 128 characters");
168 }
169 this.seriesId = seriesId;
170 }
171
172
173
174
175
176
177 public String getDublinCoreXML() {
178 return dublinCoreXML;
179 }
180
181
182
183
184
185
186
187 public void setSeries(String dublinCoreXML) {
188 this.dublinCoreXML = dublinCoreXML;
189 }
190
191
192
193
194
195
196 public String getAccessControl() {
197 return accessControl;
198 }
199
200
201
202
203
204
205
206 public void setAccessControl(String accessControl) {
207 this.accessControl = accessControl;
208 }
209
210
211
212
213 public String getOrganization() {
214 return organization;
215 }
216
217
218
219
220
221 public void setOrganization(String organization) {
222 this.organization = organization;
223 }
224
225 public Date getModifiedDate() {
226 return this.modifiedDate;
227 }
228
229 public void setModifiedDate(Date date) {
230 this.modifiedDate = date;
231 }
232
233 public Date getDeletionDate() {
234 return this.deletionDate;
235 }
236
237 public void setDeletionDate(Date date) {
238 this.deletionDate = date;
239 }
240
241 public boolean isDeleted() {
242 return this.deletionDate != null;
243 }
244
245 public Map<String, String> getProperties() {
246 return new TreeMap<String, String>(properties);
247 }
248
249 public void setProperties(Map<String, String> properties) {
250 this.properties = properties;
251 }
252
253 public Map<String, byte[]> getElements() {
254 return Collections.unmodifiableMap(elements);
255 }
256
257 public void addElement(String type, byte[] data) {
258 elements.put(type, data);
259 }
260
261 public void removeElement(String type) {
262 elements.remove(type);
263 }
264 }