/
DatabaseWriterSettings.java
315 lines (258 loc) · 10.4 KB
/
DatabaseWriterSettings.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric.io.data.writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.IAlterDatabaseInterceptor;
import org.jumpmind.symmetric.io.data.Batch;
public class DatabaseWriterSettings {
protected long maxRowsBeforeCommit = 10000;
// Milliseconds to sleep between commits.
protected long commitSleepInterval = 5;
protected boolean treatDateTimeFieldsAsVarchar = false;
protected boolean usePrimaryKeysFromSource = true;
protected Conflict defaultConflictSetting;
protected boolean createTableFailOnError = true;
protected boolean alterTable = true;
protected boolean createTableDropFirst = false;
protected boolean applyChangesOnly = true;
protected boolean createTableAlterCaseToMatchDatabaseDefault = false;
protected boolean ignoreMissingTables = true;
protected boolean saveCurrentValueOnError = false;
protected boolean fitToColumn = false;
protected boolean logConflictResolution = false;
protected boolean logSqlParamsOnError = true;
protected boolean loadOnlyNode = false;
protected String textColumnExpression;
protected Map<String, Conflict> conflictSettingsByChannel;
protected Map<String, Conflict> conflictSettingsByTable;
protected List<IDatabaseWriterFilter> databaseWriterFilters;
protected List<IDatabaseWriterErrorHandler> databaseWriterErrorHandlers;
protected List<ResolvedData> resolvedData;
protected IAlterDatabaseInterceptor[] alterDatabaseInterceptors;
protected Set<String> conflictLosingParentRows;
protected boolean ignoreSqlDataEventFailures = false;
public void setAlterDatabaseInterceptors(IAlterDatabaseInterceptor[] alterDatabaseInterceptors) {
this.alterDatabaseInterceptors = alterDatabaseInterceptors;
}
public IAlterDatabaseInterceptor[] getAlterDatabaseInterceptors() {
return alterDatabaseInterceptors;
}
public boolean isAlterTable() {
return alterTable;
}
public void setAlterTable(boolean alterTable) {
this.alterTable = alterTable;
}
public boolean isCreateTableDropFirst() {
return createTableDropFirst;
}
public void setCreateTableDropFirst(boolean createTableDropFirst) {
this.createTableDropFirst = createTableDropFirst;
}
public boolean isCreateTableFailOnError() {
return createTableFailOnError;
}
public void setCreateTableFailOnError(boolean createTableFailOnError) {
this.createTableFailOnError = createTableFailOnError;
}
public long getMaxRowsBeforeCommit() {
return maxRowsBeforeCommit;
}
public void setMaxRowsBeforeCommit(long maxRowsBeforeCommit) {
this.maxRowsBeforeCommit = maxRowsBeforeCommit;
}
public boolean isTreatDateTimeFieldsAsVarchar() {
return treatDateTimeFieldsAsVarchar;
}
public void setTreatDateTimeFieldsAsVarchar(boolean treatDateTimeFieldsAsVarchar) {
this.treatDateTimeFieldsAsVarchar = treatDateTimeFieldsAsVarchar;
}
public boolean isUsePrimaryKeysFromSource() {
return usePrimaryKeysFromSource;
}
public void setUsePrimaryKeysFromSource(boolean usePrimaryKeysFromSource) {
this.usePrimaryKeysFromSource = usePrimaryKeysFromSource;
}
public Conflict getDefaultConflictSetting() {
return defaultConflictSetting;
}
public void setDefaultConflictSetting(Conflict defaultConflictSetting) {
this.defaultConflictSetting = defaultConflictSetting;
}
public boolean isCreateTableAlterCaseToMatchDatabaseDefault() {
return createTableAlterCaseToMatchDatabaseDefault;
}
public void setCreateTableAlterCaseToMatchDatabaseDefault(
boolean createTableAlterCaseToMatchDatabaseDefault) {
this.createTableAlterCaseToMatchDatabaseDefault = createTableAlterCaseToMatchDatabaseDefault;
}
public Map<String, Conflict> getConflictSettingsByChannel() {
return conflictSettingsByChannel;
}
public void setConflictSettingsByChannel(Map<String, Conflict> conflictSettingsByChannel) {
this.conflictSettingsByChannel = conflictSettingsByChannel;
}
public Map<String, Conflict> getConflictSettingsByTable() {
return conflictSettingsByTable;
}
public void setConflictSettingsByTable(Map<String, Conflict> conflictSettingsByTable) {
this.conflictSettingsByTable = conflictSettingsByTable;
}
public List<IDatabaseWriterFilter> getDatabaseWriterFilters() {
return databaseWriterFilters;
}
public void setDatabaseWriterFilters(List<IDatabaseWriterFilter> databaseWriterFilters) {
this.databaseWriterFilters = databaseWriterFilters;
}
public void setResolvedData(ResolvedData... resolvedData) {
this.resolvedData = new ArrayList<ResolvedData>();
if (resolvedData != null) {
for (ResolvedData data : resolvedData) {
this.resolvedData.add(data);
}
}
}
public void setResolvedData(List<ResolvedData> resolvedData) {
this.resolvedData = resolvedData;
}
public List<ResolvedData> getResolvedData() {
return resolvedData;
}
public void setDatabaseWriterErrorHandlers(
List<IDatabaseWriterErrorHandler> databaseWriterErrorHandlers) {
this.databaseWriterErrorHandlers = databaseWriterErrorHandlers;
}
public List<IDatabaseWriterErrorHandler> getDatabaseWriterErrorHandlers() {
return databaseWriterErrorHandlers;
}
public ResolvedData getResolvedData(long rowNumber) {
if (resolvedData != null) {
for (ResolvedData data : resolvedData) {
if (data.getRowNumber() == rowNumber) {
return data;
}
}
}
return null;
}
public void setIgnoreMissingTables(boolean ignoreMissingTables) {
this.ignoreMissingTables = ignoreMissingTables;
}
public boolean isIgnoreMissingTables() {
return ignoreMissingTables;
}
public void addErrorHandler(IDatabaseWriterErrorHandler handler) {
if (this.databaseWriterErrorHandlers == null) {
this.databaseWriterErrorHandlers = new ArrayList<IDatabaseWriterErrorHandler>();
}
this.databaseWriterErrorHandlers.add(handler);
}
public Conflict pickConflict(Table table, Batch batch) {
Conflict settings = null;
String fullyQualifiedName = table.getFullyQualifiedTableNameLowerCase();
if (conflictSettingsByTable != null) {
Conflict found = conflictSettingsByTable.get(fullyQualifiedName);
if (found == null) {
found = conflictSettingsByTable.get(table.getName().toLowerCase());
}
if (found != null
&& (StringUtils.isBlank(found.getTargetChannelId()) || found
.getTargetChannelId().equals(batch.getChannelId()))) {
settings = found;
}
}
if (settings == null && conflictSettingsByChannel != null) {
settings = conflictSettingsByChannel.get(batch.getChannelId());
}
if (settings == null) {
settings = defaultConflictSetting;
}
if (settings == null) {
settings = new Conflict();
}
return settings;
}
public long getCommitSleepInterval() {
return commitSleepInterval;
}
public void setCommitSleepInterval(long commitSleepInterval) {
this.commitSleepInterval = commitSleepInterval;
}
public boolean isSaveCurrentValueOnError() {
return saveCurrentValueOnError;
}
public void setSaveCurrentValueOnError(boolean saveCurrentValueOnError) {
this.saveCurrentValueOnError = saveCurrentValueOnError;
}
public void setFitToColumn(boolean fitToColumn) {
this.fitToColumn = fitToColumn;
}
public boolean isFitToColumn() {
return fitToColumn;
}
public void setLogConflictResolution(boolean logConflictResolution) {
this.logConflictResolution = logConflictResolution;
}
public boolean isLogConflictResolution() {
return logConflictResolution;
}
public void setLogSqlParamsOnError(boolean logSqlParamsOnError) {
this.logSqlParamsOnError = logSqlParamsOnError;
}
public boolean isLogSqlParamsOnError() {
return logSqlParamsOnError;
}
public void setTextColumnExpression(String textColumnExpression) {
this.textColumnExpression = textColumnExpression;
}
public String getTextColumnExpression() {
return textColumnExpression;
}
public void setApplyChangesOnly(boolean applyChangesOnly) {
this.applyChangesOnly = applyChangesOnly;
}
public boolean isApplyChangesOnly() {
return applyChangesOnly;
}
public boolean isLoadOnlyNode() {
return loadOnlyNode;
}
public void setLoadOnlyNode(boolean loadOnlyNode) {
this.loadOnlyNode = loadOnlyNode;
}
public Set<String> getConflictLosingParentRows() {
return conflictLosingParentRows;
}
public void setConflictLosingParentRows(Set<String> conflictLosingParentRows) {
this.conflictLosingParentRows = conflictLosingParentRows;
}
public boolean isIgnoreSqlDataEventFailures() {
return ignoreSqlDataEventFailures;
}
public void setIgnoreSqlDataEventFailures(boolean ignoreSqlDataEventFailures) {
this.ignoreSqlDataEventFailures = ignoreSqlDataEventFailures;
}
}