This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
HTextFlowTargetHistory.java
266 lines (224 loc) · 9.5 KB
/
HTextFlowTargetHistory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.IndexColumn;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.Type;
import org.zanata.common.ContentState;
import com.google.common.base.Objects;
import lombok.Getter;
import lombok.Setter;
@Entity
@Immutable
@NamedQueries({
@NamedQuery(
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 1,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0"),
@NamedQuery(
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 2,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0 and contents[1] = :content1"),
@NamedQuery(
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 3,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0 and contents[1] = :content1 and contents[2] = :content2"),
@NamedQuery(
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 4,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0 and contents[1] = :content1 and contents[2] = :content2 and contents[3] = :content3"),
@NamedQuery(
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 5,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0 and contents[1] = :content1 and contents[2] = :content2 and contents[3] = :content3 and contents[4] = :content4"),
@NamedQuery(
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 6,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0 and contents[1] = :content1 and contents[2] = :content2 and contents[3] = :content3 and contents[4] = :content4 and contents[5] = :content5") })
public class HTextFlowTargetHistory extends HTextContainer implements
Serializable, ITextFlowTargetHistory {
static final String QUERY_MATCHING_HISTORY =
"HTextFlowTargetHistory.QUERY_MATCHING_HISTORY.";
public static String getQueryNameMatchingHistory(int size) {
return QUERY_MATCHING_HISTORY + size;
}
private static final long serialVersionUID = 1L;
private Long id;
private HTextFlowTarget textFlowTarget;
private Integer versionNum;
private List<String> contents;
private Date lastChanged;
private HPerson lastModifiedBy;
private ContentState state;
private Integer textFlowRevision;
private HPerson translator;
private HPerson reviewer;
@Getter
@Setter
private String revisionComment;
public HTextFlowTargetHistory() {
}
public HTextFlowTargetHistory(HTextFlowTarget target) {
this.lastChanged = target.getLastChanged();
this.lastModifiedBy = target.getLastModifiedBy();
this.state = target.getState();
this.textFlowRevision = target.getTextFlowRevision();
this.textFlowTarget = target;
this.versionNum = target.getVersionNum();
this.translator = target.getTranslator();
this.reviewer = target.getReviewer();
this.setContents(target.getContents());
this.revisionComment = target.getRevisionComment();
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
protected void setId(Long id) {
this.id = id;
}
// TODO PERF @NaturalId(mutable=false) for better criteria caching
@NaturalId
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_id")
public HTextFlowTarget getTextFlowTarget() {
return textFlowTarget;
}
public void setTextFlowTarget(HTextFlowTarget textFlowTarget) {
this.textFlowTarget = textFlowTarget;
}
@Override
// TODO PERF @NaturalId(mutable=false) for better criteria caching
@NaturalId
public
Integer getVersionNum() {
return versionNum;
}
public void setVersionNum(Integer versionNum) {
this.versionNum = versionNum;
}
@Override
@javax.persistence.Lob
@AccessType("field")
@ElementCollection(fetch = FetchType.EAGER)
@JoinTable(name = "HTextFlowTargetContentHistory",
joinColumns = @JoinColumn(name = "text_flow_target_history_id"))
@IndexColumn(name = "pos", nullable = false)
@Column(name = "content", nullable = false)
public List<String> getContents() {
return contents;
}
public void setContents(List<String> contents) {
this.contents = new ArrayList<String>(contents);
}
public Date getLastChanged() {
return lastChanged;
}
public void setLastChanged(Date lastChanged) {
this.lastChanged = lastChanged;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "last_modified_by_id", nullable = true)
@Override
public HPerson getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(HPerson lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
@Override
public ContentState getState() {
return state;
}
public void setState(ContentState state) {
this.state = state;
}
@Override
@Column(name = "tf_revision")
public Integer getTextFlowRevision() {
return textFlowRevision;
}
public void setTextFlowRevision(Integer textFlowRevision) {
this.textFlowRevision = textFlowRevision;
}
@Override
@ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
@JoinColumn(name = "translated_by_id", nullable = true)
public HPerson getTranslator() {
return translator;
}
@Override
@ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
@JoinColumn(name = "reviewed_by_id", nullable = true)
public HPerson getReviewer() {
return reviewer;
}
public void setTranslator(HPerson translator) {
this.translator = translator;
}
public void setReviewer(HPerson reviewer) {
this.reviewer = reviewer;
}
/**
* Determines whether a Text Flow Target has changed when compared to this
* history object.
*
* @param current
* The current Text Flow Target state.
* @return True, if any of the Text Flow Target fields have changed from the
* state recorded in this History object. False, otherwise.
*/
public boolean hasChanged(HTextFlowTarget current) {
return !Objects.equal(current.getContents(), this.contents)
|| !Objects.equal(current.getLastChanged(), this.lastChanged)
|| !Objects.equal(current.getLastModifiedBy(),
this.lastModifiedBy)
|| !Objects.equal(current.getTranslator(), this.translator)
|| !Objects.equal(current.getReviewer(), this.reviewer)
|| !Objects.equal(current.getState(), this.state)
|| !Objects.equal(current.getTextFlowRevision(),
this.textFlowRevision)
|| !Objects.equal(current.getLastChanged(), this.lastChanged)
|| !Objects.equal(current.getTextFlow().getId(),
this.textFlowTarget.getId())
|| !Objects.equal(current.getVersionNum(), this.versionNum)
|| !Objects.equal(current.getRevisionComment(), this.revisionComment);
}
}