/
Trigger.java
841 lines (656 loc) · 25.8 KB
/
Trigger.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
/**
* 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.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.Table;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.util.FormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Defines the trigger via which a table will be synchronized.
*/
public class Trigger implements Serializable {
private static final long serialVersionUID = 1L;
static final Logger log = LoggerFactory.getLogger(Trigger.class);
private static final String DEFAULT_CONDITION = "1=1";
private String triggerId;
private String sourceTableName;
private String sourceTableNameLowerCase;
private String sourceSchemaName;
private String sourceCatalogName;
private boolean isSourceTableNameWildCarded;
private boolean isSourceSchemaWildCarded;
private boolean isSourceCatalogWildCarded;
private String sourceTableNameUnescaped;
private String sourceSchemaNameUnescaped;
private String sourceCatalogNameUnescaped;
private String channelId = Constants.CHANNEL_DEFAULT;
private String reloadChannelId = Constants.CHANNEL_RELOAD;
private boolean syncOnUpdate = true;
private boolean syncOnInsert = true;
private boolean syncOnDelete = true;
private boolean syncOnIncomingBatch = false;
private boolean useStreamLobs = false;
private boolean useCaptureLobs = false;
private boolean useCaptureOldData = true;
private boolean useHandleKeyUpdates = true;
private boolean streamRow = false;
private String nameForInsertTrigger;
private String nameForUpdateTrigger;
private String nameForDeleteTrigger;
private String syncOnUpdateCondition = DEFAULT_CONDITION;
private String syncOnInsertCondition = DEFAULT_CONDITION;
private String syncOnDeleteCondition = DEFAULT_CONDITION;
private String channelExpression = null;
private String customBeforeUpdateText;
private String customBeforeInsertText;
private String customBeforeDeleteText;
private String customOnUpdateText;
private String customOnInsertText;
private String customOnDeleteText;
private String excludedColumnNames = null;
private String includedColumnNames = null;
private String syncKeyNames = null;
/**
* This is a SQL expression that creates a unique id which the sync process
* can use to 'group' events together and commit together.
*/
private String txIdExpression = null;
private String externalSelect = null;
private Date createTime;
private Date lastUpdateTime;
private String lastUpdateBy;
public Trigger() {
}
public Trigger(String tableName, String channelId) {
this.triggerId = tableName;
setSourceTableName(tableName);
this.channelId = channelId;
}
public Trigger(String tableName, String channelId, boolean syncOnIncomingBatch) {
this(tableName, channelId);
this.syncOnIncomingBatch = syncOnIncomingBatch;
}
final public String qualifiedSourceTableName() {
return qualifiedSourceTablePrefix() + sourceTableName;
}
final public String qualifiedSourceTablePrefix() {
String schemaPlus = (getSourceSchemaName() != null ? getSourceSchemaName() + "." : "");
String catalogPlus = (getSourceCatalogName() != null ? getSourceCatalogName() + "." : "")
+ schemaPlus;
return catalogPlus;
}
public void nullOutBlankFields() {
if (StringUtils.isBlank(sourceCatalogName)) {
sourceCatalogName = null;
isSourceCatalogWildCarded = false;
}
if (StringUtils.isBlank(sourceSchemaName)) {
sourceSchemaName = null;
isSourceSchemaWildCarded = false;
}
syncOnInsertCondition = StringUtils.defaultString(StringUtils.trimToNull(syncOnInsertCondition), DEFAULT_CONDITION);
syncOnUpdateCondition = StringUtils.defaultString(StringUtils.trimToNull(syncOnUpdateCondition), DEFAULT_CONDITION);
syncOnDeleteCondition = StringUtils.defaultString(StringUtils.trimToNull(syncOnDeleteCondition), DEFAULT_CONDITION);
externalSelect = StringUtils.trimToNull(externalSelect);
excludedColumnNames = StringUtils.trimToNull(excludedColumnNames);
includedColumnNames = StringUtils.trimToNull(includedColumnNames);
syncKeyNames = StringUtils.trimToNull(syncKeyNames);
channelExpression = StringUtils.trimToNull(channelExpression);
}
public Column[] filterExcludedAndIncludedColumns(Column[] src) {
return filterIncludedColumns(filterExcludedColumns(src));
}
public Column[] filterExcludedColumns(Column[] src) {
if (src != null) {
List<String> excludedColumnNames = getExcludedColumnNamesAsList();
List<Column> filtered = new ArrayList<Column>(src.length);
for (int i = 0; i < src.length; i++) {
Column col = src[i];
if (!excludedColumnNames.contains(col.getName().toLowerCase())) {
filtered.add(col);
}
}
return filtered.toArray(new Column[filtered.size()]);
} else {
return new Column[0];
}
}
public Column[] filterIncludedColumns(Column[] src) {
if (src != null) {
List<String> includedColumnNames = getIncludedColumnNamesAsList();
if (includedColumnNames.size() == 0) {
return src;
}
List<Column> filtered = new ArrayList<Column>(src.length);
for (int i = 0; i < src.length; i++) {
Column col = src[i];
if (includedColumnNames.contains(col.getName().toLowerCase())) {
filtered.add(col);
}
}
return filtered.toArray(new Column[filtered.size()]);
} else {
return new Column[0];
}
}
public Column[] getSyncKeysColumnsForTable(Table table) {
List<String> syncKeys = getSyncKeyNamesAsList();
if (syncKeys.size() > 0) {
List<Column> columns = new ArrayList<Column>();
for (String syncKey : syncKeys) {
Column col = table.getColumnWithName(syncKey);
if (col != null) {
columns.add(col);
} else {
log.error("The sync key column '{}' was specified for the '{}' trigger but was not found in the table", syncKey, triggerId);
}
}
if (columns.size() > 0) {
return columns.toArray(new Column[columns.size()]);
} else {
return table.getPrimaryKeyColumns();
}
} else {
return table.getPrimaryKeyColumns();
}
}
/**
* When dealing with columns, always use this method to order the columns so
* that the primary keys are first.
*/
public Column[] orderColumnsForTable(Table table) {
if (table != null) {
Column[] pks = getSyncKeysColumnsForTable(table);
Column[] cols = table.getColumns();
List<Column> orderedColumns = new ArrayList<Column>(cols.length);
for (int i = 0; i < pks.length; i++) {
orderedColumns.add(pks[i]);
}
for (int i = 0; i < cols.length; i++) {
boolean syncKey = false;
for (int j = 0; j < pks.length; j++) {
if (cols[i].getName().equals(pks[j].getName())) {
syncKey = true;
break;
}
}
if (!syncKey) {
orderedColumns.add(cols[i]);
}
}
Column[] result = orderedColumns.toArray(new Column[orderedColumns.size()]);
return filterExcludedAndIncludedColumns(result);
} else {
return new Column[0];
}
}
@SuppressWarnings("unchecked")
private List<String> getExcludedColumnNamesAsList() {
if (StringUtils.isNotBlank(excludedColumnNames)) {
StringTokenizer tokenizer = new StringTokenizer(excludedColumnNames, ",");
List<String> columnNames = new ArrayList<String>(tokenizer.countTokens());
while (tokenizer.hasMoreTokens()) {
columnNames.add(tokenizer.nextToken().toLowerCase().trim());
}
return columnNames;
} else {
return Collections.EMPTY_LIST;
}
}
@SuppressWarnings("unchecked")
private List<String> getIncludedColumnNamesAsList() {
if (StringUtils.isNotBlank(includedColumnNames)) {
StringTokenizer tokenizer = new StringTokenizer(includedColumnNames, ",");
List<String> columnNames = new ArrayList<String>(tokenizer.countTokens());
while (tokenizer.hasMoreTokens()) {
columnNames.add(tokenizer.nextToken().toLowerCase().trim());
}
return columnNames;
} else {
return Collections.EMPTY_LIST;
}
}
public boolean hasChangedSinceLastTriggerBuild(Date lastTriggerBuildTime) {
return lastTriggerBuildTime == null || getLastUpdateTime() == null
|| lastTriggerBuildTime.before(getLastUpdateTime());
}
public String getTriggerId() {
return triggerId;
}
public void setTriggerId(String triggerId) {
this.triggerId = triggerId;
}
public String getSourceTableName() {
return sourceTableName;
}
public String getSourceTableNameLowerCase() {
return sourceTableNameLowerCase;
}
public String getSourceTableNameUnescaped() {
return sourceTableNameUnescaped;
}
public boolean isSourceWildCarded() {
return isSourceTableNameWildCarded() || isSourceCatalogNameWildCarded() || isSourceSchemaNameWildCarded();
}
public boolean isSourceTableNameWildCarded() {
return isSourceTableNameWildCarded;
}
public boolean isSourceCatalogNameWildCarded() {
return isSourceCatalogWildCarded;
}
public boolean isSourceSchemaNameWildCarded() {
return isSourceSchemaWildCarded;
}
public String getChannelExpression() {
return channelExpression;
}
public void setChannelExpression(String channelExpression) {
this.channelExpression = channelExpression;
}
public void setSourceTableName(String sourceTableName) {
this.sourceTableName = sourceTableName;
this.sourceTableNameLowerCase = sourceTableName == null ? null : sourceTableName.toLowerCase();
this.isSourceTableNameWildCarded = FormatUtils.isWildCarded(sourceTableName);
if (!this.isSourceTableNameWildCarded) {
this.sourceTableNameUnescaped = FormatUtils.unescapeWildCards(sourceTableName);
}
}
public String getSourceSchemaName() {
return sourceSchemaName;
}
public String getSourceSchemaNameUnescaped() {
return sourceSchemaNameUnescaped;
}
public void setSourceSchemaName(String sourceSchemaName) {
this.sourceSchemaName = sourceSchemaName;
this.isSourceSchemaWildCarded = FormatUtils.isWildCarded(sourceSchemaName);
if (!this.isSourceSchemaWildCarded) {
this.sourceSchemaNameUnescaped = FormatUtils.unescapeWildCards(sourceSchemaName);
}
}
public String getSourceCatalogName() {
return sourceCatalogName;
}
public String getSourceCatalogNameUnescaped() {
return sourceCatalogNameUnescaped;
}
public void setSourceCatalogName(String sourceCatalogName) {
this.sourceCatalogName = sourceCatalogName;
this.isSourceCatalogWildCarded = FormatUtils.isWildCarded(sourceCatalogName);
if (!this.isSourceCatalogWildCarded) {
this.sourceCatalogNameUnescaped = FormatUtils.unescapeWildCards(sourceCatalogName);
}
}
public String getChannelId() {
return channelId;
}
public void setChannelId(String channelId) {
this.channelId = channelId;
}
public String getReloadChannelId() {
return reloadChannelId;
}
public void setReloadChannelId(String reloadChannelId) {
this.reloadChannelId = reloadChannelId;
}
public boolean isSyncOnUpdate() {
return syncOnUpdate;
}
public void setSyncOnUpdate(boolean syncOnUpdate) {
this.syncOnUpdate = syncOnUpdate;
}
public boolean isSyncOnInsert() {
return syncOnInsert;
}
public void setSyncOnInsert(boolean syncOnInsert) {
this.syncOnInsert = syncOnInsert;
}
public boolean isSyncOnDelete() {
return syncOnDelete;
}
public void setSyncOnDelete(boolean syncOnDelete) {
this.syncOnDelete = syncOnDelete;
}
public boolean isSyncOnIncomingBatch() {
return syncOnIncomingBatch;
}
public void setSyncOnIncomingBatch(boolean syncOnIncomingBatch) {
this.syncOnIncomingBatch = syncOnIncomingBatch;
}
public String getNameForInsertTrigger() {
return nameForInsertTrigger;
}
public void setNameForInsertTrigger(String nameForInsertTrigger) {
this.nameForInsertTrigger = nameForInsertTrigger;
}
public String getNameForUpdateTrigger() {
return nameForUpdateTrigger;
}
public void setNameForUpdateTrigger(String nameForUpdateTrigger) {
this.nameForUpdateTrigger = nameForUpdateTrigger;
}
public String getNameForDeleteTrigger() {
return nameForDeleteTrigger;
}
public void setNameForDeleteTrigger(String nameForDeleteTrigger) {
this.nameForDeleteTrigger = nameForDeleteTrigger;
}
public String getSyncOnUpdateCondition() {
return syncOnUpdateCondition;
}
public void setSyncOnUpdateCondition(String syncOnUpdateCondition) {
this.syncOnUpdateCondition = syncOnUpdateCondition;
}
public String getSyncOnInsertCondition() {
return syncOnInsertCondition;
}
public void setSyncOnInsertCondition(String syncOnInsertCondition) {
this.syncOnInsertCondition = syncOnInsertCondition;
}
public String getSyncOnDeleteCondition() {
return syncOnDeleteCondition;
}
public void setSyncOnDeleteCondition(String syncOnDeleteCondition) {
this.syncOnDeleteCondition = syncOnDeleteCondition;
}
public String getCustomBeforeUpdateText() {
return customBeforeUpdateText;
}
public void setCustomBeforeUpdateText(String customBeforeUpdateText) {
this.customBeforeUpdateText = customBeforeUpdateText;
}
public String getCustomBeforeInsertText() {
return customBeforeInsertText;
}
public void setCustomBeforeInsertText(String customBeforeInsertText) {
this.customBeforeInsertText = customBeforeInsertText;
}
public String getCustomBeforeDeleteText() {
return customBeforeDeleteText;
}
public void setCustomBeforeDeleteText(String customBeforeDeleteText) {
this.customBeforeDeleteText = customBeforeDeleteText;
}
public String getCustomOnUpdateText() {
return customOnUpdateText;
}
public void setCustomOnUpdateText(String customOnUpdateText) {
this.customOnUpdateText = customOnUpdateText;
}
public String getCustomOnInsertText() {
return customOnInsertText;
}
public void setCustomOnInsertText(String customOnInsertText) {
this.customOnInsertText = customOnInsertText;
}
public String getCustomOnDeleteText() {
return customOnDeleteText;
}
public void setCustomOnDeleteText(String customOnDeleteText) {
this.customOnDeleteText = customOnDeleteText;
}
public String getExcludedColumnNames() {
return excludedColumnNames;
}
public void setExcludedColumnNames(String excludedColumnNames) {
this.excludedColumnNames = excludedColumnNames;
}
public String getIncludedColumnNames() {
return includedColumnNames;
}
public void setIncludedColumnNames(String includedColumnNames) {
this.includedColumnNames = includedColumnNames;
}
public String getTxIdExpression() {
return txIdExpression;
}
public void setTxIdExpression(String txIdExpression) {
this.txIdExpression = txIdExpression;
}
public String getExternalSelect() {
return externalSelect;
}
public void setExternalSelect(String externalSelect) {
this.externalSelect = externalSelect;
}
public void setLastUpdateBy(String updatedBy) {
this.lastUpdateBy = updatedBy;
}
public String getLastUpdateBy() {
return lastUpdateBy;
}
public Date getLastUpdateTime() {
return lastUpdateTime;
}
public void setLastUpdateTime(Date lastModifiedOn) {
this.lastUpdateTime = lastModifiedOn;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createdOn) {
this.createTime = createdOn;
}
public void setUseStreamLobs(boolean useStreamLobs) {
this.useStreamLobs = useStreamLobs;
}
public boolean isUseStreamLobs() {
return useStreamLobs;
}
public void setUseCaptureLobs(boolean useCaptureLobs) {
this.useCaptureLobs = useCaptureLobs;
}
public boolean isUseCaptureLobs() {
return useCaptureLobs;
}
public boolean isUseHandleKeyUpdates() {
return useHandleKeyUpdates;
}
public void setUseHandleKeyUpdates(boolean useHandleKeyUpdates) {
this.useHandleKeyUpdates = useHandleKeyUpdates;
}
public void setUseCaptureOldData(boolean useCaptureOldData) {
this.useCaptureOldData = useCaptureOldData;
}
public boolean isUseCaptureOldData() {
return useCaptureOldData;
}
public void setSyncKeyNames(String syncKeys) {
this.syncKeyNames = syncKeys;
}
public String getSyncKeyNames() {
return syncKeyNames;
}
public boolean isStreamRow() {
return streamRow;
}
public void setStreamRow(boolean streamRow) {
this.streamRow = streamRow;
}
@SuppressWarnings("unchecked")
private List<String> getSyncKeyNamesAsList() {
if (StringUtils.isNotBlank(syncKeyNames)) {
StringTokenizer tokenizer = new StringTokenizer(syncKeyNames, ",");
List<String> columnNames = new ArrayList<String>(tokenizer.countTokens());
while (tokenizer.hasMoreTokens()) {
columnNames.add(tokenizer.nextToken().toLowerCase().trim());
}
return columnNames;
} else {
return Collections.EMPTY_LIST;
}
}
public String getFullyQualifiedSourceTableName() {
return Table.getFullyQualifiedTableName(sourceCatalogName, sourceSchemaName, sourceTableName);
}
public long toHashedValue() {
long hashedValue = triggerId != null ? triggerId.hashCode() : 0;
if (null != sourceTableName) {
hashedValue += sourceTableName.hashCode();
}
if (null != channelId) {
hashedValue += channelId.hashCode();
}
if (null != sourceSchemaName) {
hashedValue += sourceSchemaName.hashCode();
}
if (null != sourceCatalogName) {
hashedValue += sourceCatalogName.hashCode();
}
hashedValue += syncOnUpdate ? "syncOnUpdate".hashCode() : 0;
hashedValue += syncOnInsert ? "syncOnInsert".hashCode() : 0;
hashedValue += syncOnDelete ? "syncOnDelete".hashCode() : 0;
hashedValue += syncOnIncomingBatch ? "syncOnIncomingBatch".hashCode() : 0;
hashedValue += useStreamLobs ? "useStreamLobs".hashCode() : 0;
hashedValue += useCaptureLobs ? "useCaptureLobs".hashCode() : 0;
hashedValue += useCaptureOldData ? "useCaptureOldData".hashCode() : 0;
hashedValue += useHandleKeyUpdates ? "useHandleKeyUpdates".hashCode() : 0;
if (null != nameForInsertTrigger) {
hashedValue += nameForInsertTrigger.hashCode();
}
if (null != nameForUpdateTrigger) {
hashedValue += nameForUpdateTrigger.hashCode();
}
if (null != nameForDeleteTrigger) {
hashedValue += nameForDeleteTrigger.hashCode();
}
if (null != syncOnUpdateCondition) {
hashedValue += syncOnUpdateCondition.hashCode();
}
if (null != syncOnInsertCondition) {
hashedValue += syncOnInsertCondition.hashCode();
}
if (null != syncOnDeleteCondition) {
hashedValue += syncOnDeleteCondition.hashCode();
}
if (null != customBeforeUpdateText) {
hashedValue += customBeforeUpdateText.hashCode();
}
if (null != customBeforeInsertText) {
hashedValue += customBeforeInsertText.hashCode();
}
if (null != customBeforeDeleteText) {
hashedValue += customBeforeDeleteText.hashCode();
}
if (null != customOnUpdateText) {
hashedValue += customOnUpdateText.hashCode();
}
if (null != customOnInsertText) {
hashedValue += customOnInsertText.hashCode();
}
if (null != customOnDeleteText) {
hashedValue += customOnDeleteText.hashCode();
}
if (null != excludedColumnNames) {
hashedValue += excludedColumnNames.hashCode();
}
if (null != externalSelect) {
hashedValue += externalSelect.hashCode();
}
if (null != txIdExpression) {
hashedValue += txIdExpression.hashCode();
}
if (null != syncKeyNames) {
hashedValue += syncKeyNames.hashCode();
}
return hashedValue;
}
public boolean matchesCatalogName(String catalogName, boolean ignoreCase) {
return matches(sourceCatalogName, catalogName, ignoreCase);
}
public boolean matchesSchemaName(String schemaName, boolean ignoreCase) {
return matches(sourceSchemaName, schemaName, ignoreCase);
}
protected boolean matches(String match, String target, boolean ignoreCase) {
boolean matches = false;
String[] wildcardTokens = match.split(",");
for (String wildcardToken : wildcardTokens) {
if (FormatUtils.isWildCardMatch(target, wildcardToken, ignoreCase)) {
if (!wildcardToken.startsWith(FormatUtils.NEGATE_TOKEN)) {
matches = true;
} else {
matches = false;
break;
}
}
}
return matches;
}
public boolean matches(Table table, String defaultCatalog, String defaultSchema,
boolean ignoreCase) {
boolean catalogMatch = false;
if (isSourceCatalogWildCarded) {
catalogMatch = matches(sourceCatalogName, table.getCatalog(), ignoreCase);
} else {
catalogMatch = (StringUtils.equals(sourceCatalogNameUnescaped, table.getCatalog()) ||
(StringUtils.isBlank(sourceCatalogName) && StringUtils.equals(defaultCatalog, table.getCatalog())));
}
boolean schemaMatch = false;
if (isSourceSchemaWildCarded) {
schemaMatch = matches(sourceSchemaName, table.getSchema(), ignoreCase);
} else {
schemaMatch = (StringUtils.equals(sourceSchemaNameUnescaped, table.getSchema()) ||
(StringUtils.isBlank(sourceSchemaName) && StringUtils.equals(defaultSchema, table.getSchema())));
}
boolean tableMatch = false;
if (isSourceTableNameWildCarded) {
tableMatch = matches(sourceTableName, table.getName(), ignoreCase);
} else {
tableMatch = ignoreCase ? table.getName().equalsIgnoreCase(sourceTableNameUnescaped)
: table.getName().equals(sourceTableNameUnescaped);
}
return catalogMatch && schemaMatch && tableMatch;
}
public boolean matches(Trigger trigger) {
return StringUtils.equals(sourceCatalogName, trigger.sourceCatalogName)
&& StringUtils.equals(sourceSchemaName, trigger.sourceSchemaName)
&& trigger.sourceTableName.equalsIgnoreCase(sourceTableName);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Trigger && triggerId != null) {
return triggerId.equals(((Trigger) obj).triggerId);
} else {
return super.equals(obj);
}
}
@Override
public int hashCode() {
return triggerId != null ? triggerId.hashCode() : super.hashCode();
}
@Override
public String toString() {
if (triggerId != null) {
return triggerId;
} else {
return super.toString();
}
}
}