Skip to content

Commit

Permalink
0001397: Conflict detection mechanism USE_CHANGED_DATA should be able…
Browse files Browse the repository at this point in the history
… to specify columns to ignore.
  • Loading branch information
abrougher committed Aug 22, 2013
1 parent 403f490 commit e575626
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
Expand Up @@ -37,11 +37,15 @@ public enum DetectConflict {
public enum ResolveConflict {
NEWER_WINS, MANUAL, IGNORE, FALLBACK
};

public enum PingBack {
OFF, SINGLE_ROW, REMAINING_ROWS
}

public enum DetectExpressionKey {
EXCLUDED_COLUMN_NAMES
}

private String conflictId;
private String targetChannelId;
private String targetCatalogName;
Expand Down Expand Up @@ -105,7 +109,7 @@ public String getTargetTableName() {
public void setTargetTableName(String targetTableName) {
this.targetTableName = targetTableName;
}

public DetectConflict getDetectType() {
return detectType;
}
Expand All @@ -125,15 +129,15 @@ public void setResolveType(ResolveConflict resolveUpdateType) {
public boolean isResolveChangesOnly() {
return resolveChangesOnly;
}

public void setResolveChangesOnly(boolean resolveChangesOnly) {
this.resolveChangesOnly = resolveChangesOnly;
}

public boolean isResolveRowOnly() {
return resolveRowOnly;
}

public void setResolveRowOnly(boolean resolveRowOnly) {
this.resolveRowOnly = resolveRowOnly;
}
Expand All @@ -142,6 +146,21 @@ public String getDetectExpression() {
return detectExpression;
}

public String getDetectExpressionValue(DetectExpressionKey key) {
String value = null;
if (key != null && detectExpression != null) {
String[] parms = detectExpression.split(";");
for (String parm : parms) {
String[] args = parm.split("=");
if (args.length==2 && args[0].trim().equalsIgnoreCase(key.name())) {
value = args[1].trim();
break;
}
}
}
return value;
}

public void setDetectExpression(String conflictColumnName) {
this.detectExpression = conflictColumnName;
}
Expand Down Expand Up @@ -169,11 +188,11 @@ public Date getLastUpdateTime() {
public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}

public void setPingBack(PingBack pingBack) {
this.pingBack = pingBack;
}

public PingBack getPingBack() {
return pingBack;
}
Expand Down
Expand Up @@ -53,6 +53,7 @@
import org.jumpmind.symmetric.io.data.DataEventType;
import org.jumpmind.symmetric.io.data.IDataWriter;
import org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict;
import org.jumpmind.symmetric.io.data.writer.Conflict.DetectExpressionKey;
import org.jumpmind.util.CollectionUtils;
import org.jumpmind.util.FormatUtils;
import org.jumpmind.util.Statistics;
Expand Down Expand Up @@ -668,6 +669,7 @@ protected LoadStatus update(CsvData data, boolean applyChangesOnly, boolean useC
lookupColumns.remove(column);
lookupColumns.add(column);
}
removeExcludedColumns(conflict, lookupColumns);
lookupKeys = lookupColumns;
break;
case USE_OLD_DATA:
Expand Down Expand Up @@ -780,6 +782,27 @@ protected LoadStatus update(CsvData data, boolean applyChangesOnly, boolean useC
}
}

private void removeExcludedColumns(Conflict conflict,
ArrayList<Column> lookupColumns) {
String excludedString = conflict.getDetectExpressionValue(
DetectExpressionKey.EXCLUDED_COLUMN_NAMES);
if (!StringUtils.isBlank(excludedString)) {
String excludedColumns[] = excludedString.split(",");
if (excludedColumns.length > 0) {
Iterator<Column> iter = lookupColumns.iterator();
while (iter.hasNext()) {
Column column = iter.next();
for (String excludedColumn : excludedColumns) {
if (excludedColumn.trim().equalsIgnoreCase(column.getName())) {
iter.remove();
break;
}
}
}
}
}
}

protected void logFailure(SqlException e, CsvData data) {
StringBuilder failureMessage = new StringBuilder();
failureMessage.append("Failed to process a ");
Expand Down

0 comments on commit e575626

Please sign in to comment.