Search in sources :

Example 26 with CsvData

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

the class PostgresBulkDatabaseWriterTest method testInsertCollision.

@Test
public void testInsertCollision() {
    if (platform != null && platform instanceof OracleDatabasePlatform) {
        platform.getSqlTemplate().update("truncate table test_bulkload_table_1");
        String[] values = { getNextId(), "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.0", "2007-02-03 04:05:06.0", "0", "47", "67.89", "-0.0747663" };
        CsvData data = new CsvData(DataEventType.INSERT, values);
        writeData(data, values);
        Assert.assertEquals(1, countRows("test_bulkload_table_1"));
        try {
            setErrorExpected(true);
            List<CsvData> datas = new ArrayList<CsvData>();
            datas.add(data);
            for (int i = 0; i < 10; i++) {
                values = new String[] { getNextId(), "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.0", "2007-02-03 04:05:06.0", "0", "47", "67.89", "-0.0747663" };
                data = new CsvData(DataEventType.INSERT, values);
                datas.add(data);
            }
            // we should collide and rollback
            writeData(new TableCsvData(platform.getTableFromCache("test_bulkload_table_1", false), datas));
            Assert.assertEquals(1, countRows("test_bulkload_table_1"));
        } finally {
            setErrorExpected(false);
        }
    }
}
Also used : TableCsvData(org.jumpmind.symmetric.io.AbstractWriterTest.TableCsvData) OracleDatabasePlatform(org.jumpmind.db.platform.oracle.OracleDatabasePlatform) ArrayList(java.util.ArrayList) CsvData(org.jumpmind.symmetric.io.data.CsvData) TableCsvData(org.jumpmind.symmetric.io.AbstractWriterTest.TableCsvData) Test(org.junit.Test)

Example 27 with CsvData

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

the class SymmetricPushClient method delete.

public void delete(Table table, String[] pkData) {
    writer.start(table);
    writer.write(new CsvData(DataEventType.DELETE, pkData, null));
    writer.end(table);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 28 with CsvData

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

the class AbstractBulkDatabaseWriterTest method testInsertAcrossMaxFlush.

@Test
public void testInsertAcrossMaxFlush() {
    if (shouldTestRun(platform)) {
        platform.getSqlTemplate().update("truncate table " + getTestTable());
        List<CsvData> data = new ArrayList<CsvData>();
        for (int i = 0; i < 30; i++) {
            String[] values = { getNextId(), "stri'ng2", "string not null2", "char2", "char not null2", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747663", encode("string") };
            data.add(new CsvData(DataEventType.INSERT, values));
        }
        Assert.assertEquals(writeData(data), countRows(getTestTable()));
    }
}
Also used : ArrayList(java.util.ArrayList) CsvData(org.jumpmind.symmetric.io.data.CsvData) Test(org.junit.Test) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest)

Example 29 with CsvData

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

the class MsSqlBulkDatabaseWriterTest method testInsertReorderColumns.

@Test
public void testInsertReorderColumns() throws Exception {
    if (shouldTestRun(platform)) {
        String id = getNextId();
        String[] values = { "string with space in it", "string-with-no-space", "string with space in it", "string-with-no-space", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747663", encode("string with space in it"), id };
        List<CsvData> data = new ArrayList<CsvData>();
        data.add(new CsvData(DataEventType.INSERT, (String[]) ArrayUtils.clone(values)));
        Table table = (Table) platform.getTableFromCache(getTestTable(), false).clone();
        Column firstColumn = table.getColumn(0);
        table.removeColumn(firstColumn);
        table.addColumn(firstColumn);
        writeData(new MsSqlBulkDatabaseWriter(platform, stagingManager, new CommonsDbcpNativeJdbcExtractor(), 1000, false, uncPath, null, null), new TableCsvData(table, data));
        values = (String[]) ArrayUtils.remove(values, values.length - 1);
        values = (String[]) ArrayUtils.add(values, 0, id);
        assertTestTableEquals(id, values);
    }
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) MsSqlBulkDatabaseWriter(org.jumpmind.symmetric.io.MsSqlBulkDatabaseWriter) ArrayList(java.util.ArrayList) CommonsDbcpNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor) CsvData(org.jumpmind.symmetric.io.data.CsvData) Test(org.junit.Test)

Example 30 with CsvData

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

the class SymmetricPushClient method insert.

public void insert(Table table, String[] data) {
    writer.start(table);
    writer.write(new CsvData(DataEventType.INSERT, data));
    writer.end(table);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData)

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