1 package fr.ifremer.quadrige3.synchro.service.referential;
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 import com.google.common.base.Joiner;
27 import com.google.common.collect.Multimap;
28 import fr.ifremer.common.synchro.service.SynchroContext;
29 import fr.ifremer.quadrige3.synchro.service.SynchroDirection;
30
31 import java.io.File;
32 import java.util.Set;
33
34
35
36
37
38
39
40 public class ReferentialSynchroContext extends SynchroContext<ReferentialSynchroDatabaseConfiguration> {
41
42 private Integer userId;
43
44 private SynchroDirection direction;
45
46
47
48
49 private boolean enableDelete = true;
50
51
52
53
54 private boolean enableInsertOrUpdate = true;
55
56
57
58
59 private Set<String> statusCodeIncludes;
60
61
62
63
64 private File changeLogFile;
65
66
67
68
69 private Set<String> programCodes;
70
71
72
73
74 private Multimap<String, String> pkIncludes;
75
76
77
78
79
80
81 private Set<String> tableNamesForced;
82
83
84
85
86
87
88 public ReferentialSynchroContext() {
89 super();
90 }
91
92
93
94
95
96
97
98
99
100
101
102 public ReferentialSynchroContext(SynchroDirection direction, Integer userId) {
103 super();
104 this.userId = userId;
105 this.direction = direction;
106 }
107
108
109
110
111
112
113
114
115 public boolean isEnableDelete() {
116 return enableDelete;
117 }
118
119
120
121
122
123
124
125
126
127 public void setEnableDelete(boolean enableDelete) {
128 this.enableDelete = enableDelete;
129 }
130
131
132
133
134
135
136
137
138 public boolean isEnableInsertOrUpdate() {
139 return enableInsertOrUpdate;
140 }
141
142
143
144
145
146
147
148
149
150 public void setEnableInsertOrUpdate(boolean enableInsertOrUpdate) {
151 this.enableInsertOrUpdate = enableInsertOrUpdate;
152 }
153
154
155
156
157
158
159
160
161 public Set<String> getStatusCodeIncludes() {
162 return statusCodeIncludes;
163 }
164
165
166
167
168
169
170
171
172
173 public void setStatusCodeIncludes(Set<String> statusCodeIncludes) {
174 this.statusCodeIncludes = statusCodeIncludes;
175 }
176
177
178
179
180
181
182
183
184 public Integer getUserId() {
185 return userId;
186 }
187
188
189
190
191
192
193
194
195
196 public void setUserId(Integer userId) {
197 this.userId = userId;
198 }
199
200
201
202
203
204
205
206
207 public SynchroDirection getDirection() {
208 return direction;
209 }
210
211
212
213
214
215
216
217
218
219 public void setDirection(SynchroDirection direction) {
220 this.direction = direction;
221 }
222
223
224
225
226
227
228
229
230 public Multimap<String, String> getPkIncludes() {
231 return pkIncludes;
232 }
233
234
235
236
237
238
239
240
241
242 public void setPkIncludes(Multimap<String, String> pkIncludes) {
243 this.pkIncludes = pkIncludes;
244 }
245
246
247
248
249
250
251
252
253 public File getChangeLogFile() {
254 return changeLogFile;
255 }
256
257
258
259
260
261
262
263
264
265 public void setChangeLogFile(File changeLogFile) {
266 this.changeLogFile = changeLogFile;
267 }
268
269
270
271
272
273
274
275
276 public Set<String> getProgramCodes() {
277 return programCodes;
278 }
279
280
281
282
283
284
285
286
287
288 public void setProgramCodes(Set<String> programCodes) {
289 this.programCodes = programCodes;
290 }
291
292
293
294
295
296
297
298
299
300 public void setTableNamesForced(Set<String> tableNamesForced) {
301 this.tableNamesForced = tableNamesForced;
302 }
303
304
305
306
307
308
309
310
311 public Set<String> getTableNamesForced() {
312 return tableNamesForced;
313 }
314
315
316 @SuppressWarnings("unchecked")
317 @Override
318 public void copy(SynchroContext otherBean) {
319 super.copy(otherBean);
320
321
322 if (otherBean.getTarget() != null) {
323 setTarget(new ReferentialSynchroDatabaseConfiguration(this, otherBean.getTarget()));
324 }
325 if (otherBean.getSource() != null) {
326 setSource(new ReferentialSynchroDatabaseConfiguration(this, otherBean.getSource()));
327 }
328
329 if (otherBean instanceof ReferentialSynchroContext) {
330 this.direction = ((ReferentialSynchroContext) otherBean).direction;
331 this.enableDelete = ((ReferentialSynchroContext) otherBean).enableDelete;
332 this.enableInsertOrUpdate = ((ReferentialSynchroContext) otherBean).enableInsertOrUpdate;
333 this.statusCodeIncludes = ((ReferentialSynchroContext) otherBean).statusCodeIncludes;
334 this.userId = ((ReferentialSynchroContext) otherBean).userId;
335 this.pkIncludes = ((ReferentialSynchroContext) otherBean).pkIncludes;
336 this.changeLogFile = ((ReferentialSynchroContext) otherBean).changeLogFile;
337 this.programCodes = ((ReferentialSynchroContext) otherBean).programCodes;
338 this.tableNamesForced = ((ReferentialSynchroContext) otherBean).tableNamesForced;
339 }
340 }
341
342
343 @Override
344 public String toString() {
345 return new StringBuilder()
346 .append(super.toString())
347 .append("\n direction: ").append(direction)
348 .append("\n enable update/insert: ").append(isEnableInsertOrUpdate())
349 .append("\n enable delete: ").append(isEnableDelete())
350 .append("\n programs: ").append(programCodes == null ? "all" : programCodes.toString())
351 .append("\n change log file: ").append(changeLogFile == null ? "disable" : changeLogFile.getPath())
352 .append("\n status codes: ").append(statusCodeIncludes == null ? "all" : Joiner.on('\'').join(statusCodeIncludes))
353 .append("\n user: ").append(getUserId())
354 .append("\n pkIncludes: ").append(pkIncludes == null ? "all" : pkIncludes.toString())
355 .toString();
356 }
357
358 }