Search in sources :

Example 21 with CsvData

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

the class XmlPublisherFilterTest method testSimpleTransform.

@Test
public void testSimpleTransform() {
    XmlPublisherDatabaseWriterFilter filter = new XmlPublisherDatabaseWriterFilter();
    filter.setTimeStringGenerator(new XmlPublisherDatabaseWriterFilter.ITimeGenerator() {

        public String getTime() {
            return "test";
        }
    });
    HashSet<String> tableNames = new HashSet<String>();
    tableNames.add(TABLE_TEST);
    filter.setTableNamesToPublishAsGroup(tableNames);
    List<String> columns = new ArrayList<String>();
    columns.add("ID1");
    columns.add("ID2");
    filter.setGroupByColumnNames(columns);
    Output output = new Output();
    filter.setPublisher(output);
    String[][] datas = { { "1", "1", "The Angry Brown", "3", "2008-10-24 00:00:00.0" }, { "1", "2", "test embedding an &", "3", null } };
    for (String[] strings : datas) {
        CsvData data = new CsvData(DataEventType.INSERT, strings);
        filter.beforeWrite(context, table, data);
        filter.batchComplete(context);
    }
    assertEquals(TEST_SIMPLE_TRANSFORM_RESULTS.trim(), output.toString().trim());
}
Also used : ArrayList(java.util.ArrayList) CsvData(org.jumpmind.symmetric.io.data.CsvData) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with CsvData

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

the class OracleBulkDatabaseWriterTest method testInsertTimestampTZ_timestamp.

@Test
public void testInsertTimestampTZ_timestamp() throws Exception {
    if (platform != null && platform instanceof OracleDatabasePlatform) {
        NativeJdbcExtractor jdbcExtractor = new CommonsDbcpNativeJdbcExtractor();
        platform.getSqlTemplate().update("truncate table test_bulkload_table_1");
        List<CsvData> datas = new ArrayList<CsvData>();
        String id = getNextId();
        String[] values = { id, "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747663", "2007-01-02 03:20:10.000", "2007-01-02 03:20:10.000", "2007-01-02 03:20:10.000", "2007-01-02 03:20:10.000" };
        CsvData data = new CsvData(DataEventType.INSERT, values);
        datas.add(data);
        long count = writeData(new TableCsvData(platform.getTableFromCache("test_bulkload_table_1", false), datas));
        Map<String, Object> rowData = queryForRow(id);
        DataSource datasource = (DataSource) platform.getDataSource();
        Connection connection = datasource.getConnection();
        Connection oracleConnection = jdbcExtractor.getNativeConnection(connection);
        final String[] EXPECTED_TIMESTAMPTZ = { "2007-01-02 03:20:10.0 America/New_York", "2007-01-02 03:20:10.0 US/Eastern" };
        checkTimestampTZ(rowData.get("TIMESTAMPTZ0_VALUE"), oracleConnection, EXPECTED_TIMESTAMPTZ);
        checkTimestampTZ(rowData.get("TIMESTAMPTZ3_VALUE"), oracleConnection, EXPECTED_TIMESTAMPTZ);
        checkTimestampTZ(rowData.get("TIMESTAMPTZ6_VALUE"), oracleConnection, EXPECTED_TIMESTAMPTZ);
        checkTimestampTZ(rowData.get("TIMESTAMPTZ9_VALUE"), oracleConnection, EXPECTED_TIMESTAMPTZ);
        Assert.assertEquals(count, countRows("test_bulkload_table_1"));
    }
}
Also used : OracleDatabasePlatform(org.jumpmind.db.platform.oracle.OracleDatabasePlatform) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) CommonsDbcpNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor) NativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor) CommonsDbcpNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor) CsvData(org.jumpmind.symmetric.io.data.CsvData) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 23 with CsvData

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

the class OracleBulkDatabaseWriterTest method testInsert1000Rows.

@Test
public void testInsert1000Rows() {
    if (platform != null && platform instanceof OracleDatabasePlatform) {
        platform.getSqlTemplate().update("truncate table test_bulkload_table_1");
        List<CsvData> datas = new ArrayList<CsvData>();
        for (int i = 0; i < 1000; i++) {
            String[] values = { getNextId(), "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747663" };
            CsvData data = new CsvData(DataEventType.INSERT, values);
            datas.add(data);
        }
        long count = writeData(new TableCsvData(platform.getTableFromCache("test_bulkload_table_1", false), datas));
        Assert.assertEquals(count, countRows("test_bulkload_table_1"));
    }
}
Also used : OracleDatabasePlatform(org.jumpmind.db.platform.oracle.OracleDatabasePlatform) ArrayList(java.util.ArrayList) CsvData(org.jumpmind.symmetric.io.data.CsvData) Test(org.junit.Test)

Example 24 with CsvData

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

the class OracleBulkDatabaseWriterTest method testInsertTimestampTZ_timestampWithTimeZone.

@Test
public void testInsertTimestampTZ_timestampWithTimeZone() throws Exception {
    if (platform != null && platform instanceof OracleDatabasePlatform) {
        NativeJdbcExtractor jdbcExtractor = new CommonsDbcpNativeJdbcExtractor();
        platform.getSqlTemplate().update("truncate table test_bulkload_table_1");
        List<CsvData> datas = new ArrayList<CsvData>();
        String id = getNextId();
        String[] values = { id, "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747663", "2007-01-02 03:20:10.123456789 -08:00", "2007-01-02 03:20:10.123456789 -08:00", "2007-01-02 03:20:10.123456789 -08:00", "2007-01-02 03:20:10.123456789 -08:00" };
        CsvData data = new CsvData(DataEventType.INSERT, values);
        datas.add(data);
        long count = writeData(new TableCsvData(platform.getTableFromCache("test_bulkload_table_1", false), datas));
        Map<String, Object> rowData = queryForRow(id);
        DataSource datasource = (DataSource) platform.getDataSource();
        Connection connection = datasource.getConnection();
        Connection oracleConnection = jdbcExtractor.getNativeConnection(connection);
        checkTimestampTZ(rowData.get("TIMESTAMPTZ0_VALUE"), oracleConnection, "2007-01-02 03:20:10.0 -8:00");
        checkTimestampTZ(rowData.get("TIMESTAMPTZ3_VALUE"), oracleConnection, "2007-01-02 03:20:10.123 -8:00");
        checkTimestampTZ(rowData.get("TIMESTAMPTZ6_VALUE"), oracleConnection, "2007-01-02 03:20:10.123457 -8:00");
        checkTimestampTZ(rowData.get("TIMESTAMPTZ9_VALUE"), oracleConnection, "2007-01-02 03:20:10.123456789 -8:00");
        Assert.assertEquals(count, countRows("test_bulkload_table_1"));
    }
}
Also used : OracleDatabasePlatform(org.jumpmind.db.platform.oracle.OracleDatabasePlatform) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) CommonsDbcpNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor) NativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor) CommonsDbcpNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor) CsvData(org.jumpmind.symmetric.io.data.CsvData) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 25 with CsvData

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

the class PostgresBulkDatabaseWriterTest method testInsert1000Rows.

@Test
public void testInsert1000Rows() {
    if (platform != null && platform instanceof PostgreSqlDatabasePlatform) {
        platform.getSqlTemplate().update("truncate table test_bulkload_table_1");
        List<CsvData> datas = new ArrayList<CsvData>();
        for (int i = 0; i < 1000; i++) {
            String[] values = { getNextId(), "stri'ng2", "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);
            datas.add(data);
        }
        long count = writeData(new TableCsvData(platform.getTableFromCache("test_bulkload_table_1", false), datas));
        Assert.assertEquals(count, countRows("test_bulkload_table_1"));
    }
}
Also used : TableCsvData(org.jumpmind.symmetric.io.AbstractWriterTest.TableCsvData) ArrayList(java.util.ArrayList) PostgreSqlDatabasePlatform(org.jumpmind.db.platform.postgresql.PostgreSqlDatabasePlatform) CsvData(org.jumpmind.symmetric.io.data.CsvData) TableCsvData(org.jumpmind.symmetric.io.AbstractWriterTest.TableCsvData) 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