use of org.jumpmind.symmetric.io.data.transform.TransformedData in project symmetric-ds by JumpMind.
the class DefaultTransformWriterConflictResolver method performFallbackToUpdate.
@Override
protected void performFallbackToUpdate(AbstractDatabaseWriter writer, CsvData data, Conflict conflict, boolean retransform) {
TransformedData transformedData = data.getAttribute(TransformedData.class.getName());
if (transformedData != null && retransform) {
List<TransformedData> newlyTransformedDatas = transformWriter.transform(DataEventType.UPDATE, writer.getContext(), transformedData.getTransformation(), transformedData.getSourceKeyValues(), transformedData.getOldSourceValues(), transformedData.getSourceValues());
for (TransformedData newlyTransformedData : newlyTransformedDatas) {
if (newlyTransformedData.hasSameKeyValues(transformedData.getKeyValues())) {
Table table = newlyTransformedData.buildTargetTable();
writer.start(table);
super.performFallbackToUpdate(writer, newlyTransformedData.buildTargetCsvData(), conflict, retransform);
writer.end(table);
}
}
} else {
super.performFallbackToUpdate(writer, data, conflict, retransform);
}
}
use of org.jumpmind.symmetric.io.data.transform.TransformedData in project symmetric-ds by JumpMind.
the class DefaultTransformWriterConflictResolver method performFallbackToInsert.
@Override
protected void performFallbackToInsert(AbstractDatabaseWriter writer, CsvData data, Conflict conflict, boolean retransform) {
TransformedData transformedData = data.getAttribute(TransformedData.class.getName());
if (transformedData != null && retransform) {
List<TransformedData> newlyTransformedDatas = transformWriter.transform(DataEventType.INSERT, writer.getContext(), transformedData.getTransformation(), transformedData.getSourceKeyValues(), transformedData.getOldSourceValues(), transformedData.getSourceValues());
if (newlyTransformedDatas.size() > 0) {
boolean matchedTransform = false;
for (TransformedData newlyTransformedData : newlyTransformedDatas) {
/*
* If there is only one transform, then process it.
* Otherwise, we need to attempt to match the key values to
* choose the correct transform.
*/
if (newlyTransformedDatas.size() == 1 || newlyTransformedData.hasSameKeyValues(transformedData.getKeyValues()) || newlyTransformedData.isGeneratedIdentityNeeded()) {
matchedTransform = true;
Table table = newlyTransformedData.buildTargetTable();
CsvData newData = newlyTransformedData.buildTargetCsvData();
if (newlyTransformedData.isGeneratedIdentityNeeded()) {
if (log.isDebugEnabled()) {
log.debug("Enabling generation of identity for {}", newlyTransformedData.getTableName());
}
writer.allowInsertIntoAutoIncrementColumns(false, table);
} else if (table.hasAutoIncrementColumn()) {
writer.allowInsertIntoAutoIncrementColumns(true, table);
}
writer.start(table);
super.performFallbackToInsert(writer, newData, conflict, retransform);
writer.end(table);
}
}
if (!matchedTransform) {
log.warn("The attempt to retransform resulted in more than one transform. We tried to choose one " + "by matching on the ordered key values, but could not find a match. Please check that the " + "transformation is configured so that it will return keys in the same order regardless of DML type. " + "The original key values that we tried to match on were: {}" + ArrayUtils.toString(transformedData.getKeyValues()));
}
}
} else {
super.performFallbackToInsert(writer, data, conflict, retransform);
}
}
Aggregations