1 package fr.ifremer.adagio.synchro.service;
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 java.sql.Timestamp;
27 import java.util.Map;
28 import java.util.Set;
29
30 import com.google.common.collect.ImmutableMap;
31 import com.google.common.collect.ImmutableSet;
32 import com.google.common.collect.Maps;
33 import com.google.common.collect.Sets;
34
35 import fr.ifremer.adagio.synchro.type.ProgressionModel;
36
37
38
39
40
41
42
43 public class SynchroResult {
44
45 protected Exception error;
46
47
48
49
50
51
52 protected final Map<String, Integer> rowHits = Maps.newTreeMap();
53
54
55
56
57
58
59 protected final Map<String, Integer> insertHits = Maps.newTreeMap();
60
61
62
63
64
65
66 protected final Map<String, Integer> updateHits = Maps.newTreeMap();
67
68
69
70
71
72
73 protected final Map<String, Timestamp> updateDateHits = Maps.newTreeMap();
74
75
76
77
78
79
80 protected final Set<String> tableNames = Sets.newHashSet();
81
82
83
84
85
86
87 protected final Map<String, Set<String>> missingOptionalColumnNames = Maps.newTreeMap();
88
89 protected String targetUrl;
90
91 protected String sourceUrl;
92
93 protected final ProgressionModel progressionModel = new ProgressionModel(this);
94
95 public SynchroResult() {
96 }
97
98 public SynchroResult(String targetUrl, String sourceUrl) {
99 this.targetUrl = targetUrl;
100 this.sourceUrl = sourceUrl;
101 }
102
103 public void setLocalUrl(String targetUrl) {
104 this.targetUrl = targetUrl;
105 }
106
107 public void setRemoteUrl(String sourceUrl) {
108 this.sourceUrl = sourceUrl;
109 }
110
111 public boolean isSuccess() {
112 return error == null;
113 }
114
115 public Exception getError() {
116 return error;
117 }
118
119 public void setError(Exception error) {
120 this.error = error;
121 }
122
123 public ProgressionModel getProgressionModel() {
124 return progressionModel;
125 }
126
127 public Set<String> getTableNames() {
128 return ImmutableSet.copyOf(tableNames);
129 }
130
131 public int getTotalRows() {
132 int result = 0;
133 for (Integer nb : rowHits.values()) {
134 result += nb;
135 }
136 return result;
137 }
138
139 public int getTotalInserts() {
140 int result = 0;
141 for (Integer nb : insertHits.values()) {
142 result += nb;
143 }
144 return result;
145 }
146
147 public int getTotalUpdates() {
148 int result = 0;
149 for (Integer nb : updateHits.values()) {
150 result += nb;
151 }
152 return result;
153 }
154
155 public int getNbRows(String tableName) {
156 Integer result = rowHits.get(tableName);
157 if (result == null) {
158 result = 0;
159 }
160 return result;
161 }
162
163 public int getNbInserts(String tableName) {
164 Integer result = insertHits.get(tableName);
165 if (result == null) {
166 result = 0;
167 }
168 return result;
169 }
170
171 public int getNbUpdates(String tableName) {
172 Integer result = updateHits.get(tableName);
173 if (result == null) {
174 result = 0;
175 }
176 return result;
177 }
178
179 public void addRows(String tableName, int nb) {
180 if (nb > 0) {
181 rowHits.put(tableName, getNbRows(tableName) + nb);
182 }
183 }
184
185 public void addUpdates(String tableName, int nb) {
186 if (nb > 0) {
187 updateHits.put(tableName, getNbUpdates(tableName) + nb);
188 }
189 }
190
191 public void addInserts(String tableName, int nb) {
192 if (nb > 0) {
193 insertHits.put(tableName, getNbInserts(tableName) + nb);
194 }
195 }
196
197 public Timestamp getUpdateDate(String tableName) {
198 return updateDateHits.get(tableName);
199 }
200
201 public void setUpdateDate(String tableName, Timestamp t) {
202 updateDateHits.put(tableName, t);
203 }
204
205 public void addTableName(String tableName) {
206 tableNames.add(tableName);
207 }
208
209 public String getLocalUrl() {
210 return targetUrl;
211 }
212
213 public String getRemoteUrl() {
214 return sourceUrl;
215 }
216
217 public void addMissingOptionalColumnName(String tableName, String columnName) {
218 Set<String> columnNames = missingOptionalColumnNames.get(tableName);
219 if (columnNames == null) {
220 columnNames = Sets.newHashSet();
221 missingOptionalColumnNames.put(tableName, columnNames);
222 }
223 columnNames.add(columnName);
224 }
225
226 public Set<String> getMissingOptionalColumnNames(String tableName) {
227 return missingOptionalColumnNames.get(tableName);
228 }
229
230 public Map<String, Set<String>> getMissingOptionalColumnNameMaps() {
231 return ImmutableMap.copyOf(missingOptionalColumnNames);
232 }
233 }