Search in sources :

Example 1 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 2 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 3 with CsvData

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

the class DatabaseWriterTest method testStringSpaces.

@Test
public void testStringSpaces() throws Exception {
    String[] values = new String[TEST_COLUMNS.length];
    values[0] = getNextId();
    values[1] = "  two spaces before";
    if (!(platform instanceof AseDatabasePlatform)) {
        values[2] = "two spaces after  ";
    }
    values[3] = " one space before";
    values[4] = "one space after ";
    writeData(new CsvData(DataEventType.INSERT, values), values);
}
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 4 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 5 with CsvData

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

the class DatabaseWriterTest method testUpdateDetectTimestampNewerWins.

@Test
public void testUpdateDetectTimestampNewerWins() {
    Conflict setting = new Conflict();
    setting.setConflictId("unit.test");
    setting.setDetectType(DetectConflict.USE_TIMESTAMP);
    setting.setDetectExpression("time_value");
    setting.setResolveRowOnly(true);
    setting.setResolveChangesOnly(true);
    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.UPDATE, 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.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)57 Test (org.junit.Test)39 AbstractWriterTest (org.jumpmind.symmetric.io.AbstractWriterTest)26 Table (org.jumpmind.db.model.Table)16 ArrayList (java.util.ArrayList)15 Column (org.jumpmind.db.model.Column)7 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)5 CommonsDbcpNativeJdbcExtractor (org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor)5 Connection (java.sql.Connection)4 DataSource (javax.sql.DataSource)4 TableCsvData (org.jumpmind.symmetric.io.AbstractWriterTest.TableCsvData)4 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)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