Search in sources :

Example 6 with TransformedData

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);
    }
}
Also used : Table(org.jumpmind.db.model.Table) TransformedData(org.jumpmind.symmetric.io.data.transform.TransformedData)

Example 7 with TransformedData

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);
    }
}
Also used : Table(org.jumpmind.db.model.Table) TransformedData(org.jumpmind.symmetric.io.data.transform.TransformedData) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Aggregations

TransformedData (org.jumpmind.symmetric.io.data.transform.TransformedData)7 ArrayList (java.util.ArrayList)3 Table (org.jumpmind.db.model.Table)3 TransformColumn (org.jumpmind.symmetric.io.data.transform.TransformColumn)3 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)3 HashMap (java.util.HashMap)2 CsvData (org.jumpmind.symmetric.io.data.CsvData)2 DataEventType (org.jumpmind.symmetric.io.data.DataEventType)2 IgnoreRowException (org.jumpmind.symmetric.io.data.transform.IgnoreRowException)2 JavaColumnTransform (org.jumpmind.symmetric.io.data.transform.JavaColumnTransform)2 TransformPoint (org.jumpmind.symmetric.io.data.transform.TransformPoint)2 Test (org.junit.Test)2 List (java.util.List)1 IgnoreColumnException (org.jumpmind.symmetric.io.data.transform.IgnoreColumnException)1 NewAndOldValue (org.jumpmind.symmetric.io.data.transform.NewAndOldValue)1 IncludeOnType (org.jumpmind.symmetric.io.data.transform.TransformColumn.IncludeOnType)1 Statistics (org.jumpmind.util.Statistics)1