Search in sources :

Example 41 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class ProtocolDataReader method nextData.

public CsvData nextData() {
    if (next instanceof CsvData) {
        CsvData data = (CsvData) next;
        next = null;
        return data;
    } else {
        do {
            next = readNext();
            if (next instanceof CsvData) {
                CsvData data = (CsvData) next;
                next = null;
                return data;
            }
        } while (next != null && !(next instanceof Batch) && !(next instanceof Table));
    }
    return null;
}
Also used : Table(org.jumpmind.db.model.Table) Batch(org.jumpmind.symmetric.io.data.Batch) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 42 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData 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)

Example 43 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class DatabaseWriterTest method testLargeDouble.

@Test
public void testLargeDouble() throws Exception {
    String[] values = new String[TEST_COLUMNS.length];
    values[0] = getNextId();
    values[10] = "-0.0747663551401869";
    String[] expectedValues = (String[]) ArrayUtils.clone(values);
    massageExpectectedResultsForDialect(expectedValues);
    if (platform.getDatabaseInfo().isRequiredCharColumnEmptyStringSameAsNull()) {
        expectedValues[4] = AbstractDatabasePlatform.REQUIRED_FIELD_NULL_SUBSTITUTE;
    }
    writeData(new CsvData(DataEventType.INSERT, values), expectedValues);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 44 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class DatabaseWriterTest method testStringBackslash.

@Test
public void testStringBackslash() throws Exception {
    String[] values = new String[TEST_COLUMNS.length];
    values[0] = getNextId();
    values[1] = "Here's a \\, a (backslash)";
    values[2] = "Fix TODO";
    // TODO: Fix backslashing alphanumeric
    // values[2] = "\\a\\b\\c\\ \\1\\2\\3";
    values[3] = "Tick quote \\'\\\"";
    values[4] = "Comma quote \\,\\\"";
    writeData(new CsvData(DataEventType.INSERT, values), values);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 45 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class DatabaseWriterTest method testUpdateDetectVersionNewWins.

@Test
public void testUpdateDetectVersionNewWins() {
    Conflict setting = new Conflict();
    setting.setConflictId("unit.test");
    setting.setDetectType(DetectConflict.USE_VERSION);
    setting.setDetectExpression("integer_value");
    setting.setResolveRowOnly(true);
    setting.setResolveChangesOnly(false);
    setting.setResolveType(ResolveConflict.NEWER_WINS);
    writerSettings.setDefaultConflictSetting(setting);
    String id = getNextId();
    String[] originalValues = massageExpectectedResultsForDialect(new String[] { id, "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.000", "2012-03-12 07:00:00.000", "0", "47", "67.89", "-0.0747663" });
    CsvData data = new CsvData(DataEventType.INSERT, originalValues);
    writeData(data, originalValues);
    String[] updateShouldNotBeApplied = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
    updateShouldNotBeApplied[2] = "updated string";
    updateShouldNotBeApplied[8] = "46";
    data = new CsvData(DataEventType.UPDATE, massageExpectectedResultsForDialect(updateShouldNotBeApplied));
    writeData(data, originalValues);
    String[] updateShouldBeApplied = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
    updateShouldBeApplied[2] = "string3";
    updateShouldBeApplied[8] = "48";
    data = new CsvData(DataEventType.UPDATE, massageExpectectedResultsForDialect(updateShouldBeApplied));
    writeData(data, updateShouldBeApplied);
}
Also used : ResolveConflict(org.jumpmind.symmetric.io.data.writer.Conflict.ResolveConflict) DetectConflict(org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict) CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Aggregations

CsvData (org.jumpmind.symmetric.io.data.CsvData)54 Test (org.junit.Test)36 AbstractWriterTest (org.jumpmind.symmetric.io.AbstractWriterTest)23 ArrayList (java.util.ArrayList)15 Table (org.jumpmind.db.model.Table)13 OracleDatabasePlatform (org.jumpmind.db.platform.oracle.OracleDatabasePlatform)7 Batch (org.jumpmind.symmetric.io.data.Batch)7 DetectConflict (org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict)7 ResolveConflict (org.jumpmind.symmetric.io.data.writer.Conflict.ResolveConflict)6 Statistics (org.jumpmind.util.Statistics)6 CommonsDbcpNativeJdbcExtractor (org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor)5 Connection (java.sql.Connection)4 DataSource (javax.sql.DataSource)4 Column (org.jumpmind.db.model.Column)4 NativeJdbcExtractor (org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor)4 IOException (java.io.IOException)3 IoException (org.jumpmind.exception.IoException)3 DataContext (org.jumpmind.symmetric.io.data.DataContext)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2