Search in sources :

Example 16 with CsvData

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

the class DatabaseWriterTest method testInsertDetectTimestampNewerWins.

@Test
public void testInsertDetectTimestampNewerWins() {
    Conflict setting = new Conflict();
    setting.setConflictId("unit.test");
    setting.setDetectType(DetectConflict.USE_TIMESTAMP);
    setting.setDetectExpression("time_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[6] = "2012-03-12 06:00:00.0";
    data = new CsvData(DataEventType.INSERT, massageExpectectedResultsForDialect(updateShouldNotBeApplied));
    writeData(data, originalValues);
    String[] updateShouldBeApplied = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
    updateShouldBeApplied[2] = "string3";
    updateShouldBeApplied[6] = "2012-03-12 08:00:00.000";
    data = new CsvData(DataEventType.INSERT, 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)

Example 17 with CsvData

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

the class DatabaseWriterTest method testStringEmpty.

@Test
public void testStringEmpty() throws Exception {
    String[] values = new String[TEST_COLUMNS.length];
    values[0] = getNextId();
    if (!(platform instanceof AseDatabasePlatform)) {
        values[1] = values[2] = "";
    }
    values[3] = values[4] = "";
    String[] expectedValues = (String[]) ArrayUtils.clone(values);
    if (platform.getDatabaseInfo().isRequiredCharColumnEmptyStringSameAsNull()) {
        expectedValues[4] = null;
    }
    writeData(new CsvData(DataEventType.INSERT, values), expectedValues);
}
Also used : AseDatabasePlatform(org.jumpmind.db.platform.ase.AseDatabasePlatform) CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 18 with CsvData

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

the class DatabaseWriterTest method testStringNull.

@Test
public void testStringNull() throws Exception {
    String[] values = new String[TEST_COLUMNS.length];
    values[0] = getNextId();
    String[] expectedValues = (String[]) ArrayUtils.clone(values);
    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 19 with CsvData

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

the class DatabaseWriterTest method testColumnLevelSync.

@Test
public void testColumnLevelSync() throws Exception {
    String[] insertValues = new String[TEST_COLUMNS.length];
    insertValues[2] = insertValues[4] = "column sync";
    insertValues[0] = getNextId();
    String[] updateValues = new String[2];
    updateValues[0] = insertValues[0];
    updateValues[1] = "new value";
    writeData(new CsvData(DataEventType.INSERT, insertValues), insertValues);
    // update a single column
    String[] columns = { "id", "string_value" };
    insertValues[1] = updateValues[1];
    writeData(new CsvData(DataEventType.UPDATE, new String[] { getId() }, updateValues), insertValues, columns);
    // update a single column
    columns = new String[] { "id", "char_value" };
    insertValues[3] = updateValues[1];
    writeData(new CsvData(DataEventType.UPDATE, new String[] { getId() }, updateValues), insertValues, columns);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 20 with CsvData

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

the class DatabaseWriterTest method testDecimalLocale.

@Test
public void testDecimalLocale() throws Exception {
    String[] values = new String[TEST_COLUMNS.length];
    values[0] = getNextId();
    values[10] = "123456,99";
    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)

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