Search in sources :

Example 36 with CsvData

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

the class OracleBulkDatabaseWriterTest method testInsertTimestampTZ_timestampWithTimeZoneNull.

@Test
public void testInsertTimestampTZ_timestampWithTimeZoneNull() 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. -08:00", "", " ", null };
        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");
        Assert.assertNull(rowData.get("TIMESTAMPTZ3_VALUE"));
        Assert.assertNull(rowData.get("TIMESTAMPTZ6_VALUE"));
        Assert.assertNull(rowData.get("TIMESTAMPTZ9_VALUE"));
        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 37 with CsvData

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

the class AbstractBulkDatabaseWriterTest method insertAndVerify.

protected void insertAndVerify(String[] values) {
    List<CsvData> data = new ArrayList<CsvData>();
    data.add(new CsvData(DataEventType.INSERT, (String[]) ArrayUtils.clone(values)));
    writeData(data);
    assertTestTableEquals(values[0], values);
}
Also used : ArrayList(java.util.ArrayList) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 38 with CsvData

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

the class CsvDataTest method testGetCsvData.

@Test
public void testGetCsvData() {
    final String TEST = "\"This is a test\", laughs Kunal.\n\r";
    CsvData data = new CsvData(DataEventType.INSERT, new String[] { TEST });
    String rowData = data.getCsvData(CsvData.ROW_DATA);
    CsvData newData = new CsvData();
    newData.putCsvData(CsvData.ROW_DATA, rowData);
    String result = newData.getParsedData(CsvData.ROW_DATA)[0];
    assertEquals(TEST, result);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData) Test(org.junit.Test)

Example 39 with CsvData

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

the class SymXmlDataReader method readNext.

protected Object readNext() {
    try {
        Map<String, String> rowData = new LinkedHashMap<String, String>();
        String columnName = null;
        Table lastTable = this.table;
        int eventType = parser.next();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch(eventType) {
                case XmlPullParser.TEXT:
                    if (columnName != null) {
                        rowData.put(columnName, parser.getText());
                        columnName = null;
                    }
                    break;
                case XmlPullParser.START_TAG:
                    String name = parser.getName();
                    if ("row".equalsIgnoreCase(name)) {
                        table = new Table();
                        data = new CsvData();
                        for (int i = 0; i < parser.getAttributeCount(); i++) {
                            String attributeName = parser.getAttributeName(i);
                            String attributeValue = parser.getAttributeValue(i);
                            if (attributeName.equalsIgnoreCase("entity")) {
                                table.setName(attributeValue);
                            } else if (attributeName.equalsIgnoreCase("catalog")) {
                                table.setCatalog(attributeValue);
                            } else if (attributeName.equalsIgnoreCase("schema")) {
                                table.setSchema(attributeValue);
                            } else if (attributeName.equalsIgnoreCase("dml")) {
                                if (attributeValue.equals("I")) {
                                    data.setDataEventType(DataEventType.INSERT);
                                } else if (attributeValue.equals("U")) {
                                    data.setDataEventType(DataEventType.UPDATE);
                                } else if (attributeValue.equals("D")) {
                                    data.setDataEventType(DataEventType.DELETE);
                                } else if (attributeValue.equals("C")) {
                                    data.setDataEventType(DataEventType.CREATE);
                                } else if (attributeValue.equals("S")) {
                                    data.setDataEventType(DataEventType.SQL);
                                } else if (attributeValue.equals("B")) {
                                    data.setDataEventType(DataEventType.BSH);
                                } else if (attributeValue.equals("R")) {
                                    data.setDataEventType(DataEventType.RELOAD);
                                }
                            }
                        }
                    } else if ("data".equalsIgnoreCase(name)) {
                        boolean nullValue = false;
                        for (int i = 0; i < parser.getAttributeCount(); i++) {
                            String attributeName = parser.getAttributeName(i);
                            String attributeValue = parser.getAttributeValue(i);
                            if ("key".equalsIgnoreCase(attributeName)) {
                                columnName = attributeValue;
                            } else if ("xsi:nil".equalsIgnoreCase(attributeName)) {
                                nullValue = true;
                            }
                        }
                        if (nullValue) {
                            rowData.put(columnName, null);
                            columnName = null;
                        }
                    } else if ("batch".equalsIgnoreCase(name)) {
                        batch = new Batch();
                        for (int i = 0; i < parser.getAttributeCount(); i++) {
                            String attributeName = parser.getAttributeName(i);
                            String attributeValue = parser.getAttributeValue(i);
                            if ("binary".equalsIgnoreCase(attributeName)) {
                                batch.setBinaryEncoding(BinaryEncoding.valueOf(attributeValue));
                            } else if ("nodeid".equalsIgnoreCase(attributeName)) {
                                batch.setSourceNodeId(attributeValue);
                            }
                        }
                        return batch;
                    }
                    break;
                case XmlPullParser.END_TAG:
                    name = parser.getName();
                    if ("row".equalsIgnoreCase(name)) {
                        String[] columnNames = rowData.keySet().toArray(new String[rowData.keySet().size()]);
                        for (String colName : columnNames) {
                            table.addColumn(new Column(colName));
                        }
                        String[] columnValues = rowData.values().toArray(new String[rowData.values().size()]);
                        data.putParsedData(CsvData.ROW_DATA, columnValues);
                        rowData = new LinkedHashMap<String, String>();
                        if (lastTable == null || !lastTable.equals(table)) {
                            return table;
                        } else {
                            return data;
                        }
                    } else if ("data".equalsIgnoreCase(name)) {
                        columnName = null;
                    }
                    break;
            }
            eventType = parser.next();
        }
        return null;
    } catch (IOException ex) {
        throw new IoException(ex);
    } catch (XmlPullParserException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Table(org.jumpmind.db.model.Table) IOException(java.io.IOException) CsvData(org.jumpmind.symmetric.io.data.CsvData) LinkedHashMap(java.util.LinkedHashMap) Batch(org.jumpmind.symmetric.io.data.Batch) Column(org.jumpmind.db.model.Column) IoException(org.jumpmind.exception.IoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 40 with CsvData

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

the class SymXmlDataReader method nextData.

public CsvData nextData() {
    if (next instanceof CsvData) {
        CsvData data = (CsvData) next;
        next = null;
        return data;
    } else {
        next = readNext();
        if (next instanceof CsvData) {
            CsvData data = (CsvData) next;
            next = null;
            return data;
        }
    }
    return null;
}
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