Search in sources :

Example 1 with JDBCSPWriter

use of org.talend.components.jdbc.runtime.writer.JDBCSPWriter in project components by Talend.

the class JDBCSPTestIT method test_basic_as_output_and_no_input.

@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_output_and_no_input() throws Exception {
    TJDBCSPDefinition definition = new TJDBCSPDefinition();
    TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
    properties.spName.setValue("SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE");
    properties.main.schema.setValue(DBTestUtils.createSPSchema1(tablename));
    properties.spParameterTable.parameterTypes.setValue(Arrays.asList(SPParameterTable.ParameterType.IN.name()));
    properties.spParameterTable.schemaColumns.setValue(Arrays.asList("PARAMETER"));
    JDBCSPSink sink = new JDBCSPSink();
    sink.initialize(null, properties);
    ValidationResult result = sink.validate(null);
    Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
    WriteOperation operation = sink.createWriteOperation();
    JDBCSPWriter writer = (JDBCSPWriter) operation.createWriter(null);
    try {
        writer.open("wid");
        IndexedRecord r1 = new GenericData.Record(properties.main.schema.getValue());
        r1.put(0, 0);
        writer.write(r1);
    } finally {
        writer.close();
    }
}
Also used : JDBCSPSink(org.talend.components.jdbc.runtime.JDBCSPSink) WriteOperation(org.talend.components.api.component.runtime.WriteOperation) IndexedRecord(org.apache.avro.generic.IndexedRecord) TJDBCSPProperties(org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties) JDBCSPWriter(org.talend.components.jdbc.runtime.writer.JDBCSPWriter) IndexedRecord(org.apache.avro.generic.IndexedRecord) TJDBCSPDefinition(org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Example 2 with JDBCSPWriter

use of org.talend.components.jdbc.runtime.writer.JDBCSPWriter in project components by Talend.

the class JDBCSPTestIT method test_basic_as_output_and_input.

@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_output_and_input() throws Exception {
    TJDBCSPDefinition definition = new TJDBCSPDefinition();
    TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
    properties.spName.setValue("SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE");
    Schema schema = DBTestUtils.createSPSchema3(tablename);
    properties.main.schema.setValue(schema);
    properties.schemaFlow.schema.setValue(schema);
    properties.spParameterTable.parameterTypes.setValue(Arrays.asList(SPParameterTable.ParameterType.IN.name()));
    properties.spParameterTable.schemaColumns.setValue(Arrays.asList("PARAMETER1"));
    JDBCSPSink sink = new JDBCSPSink();
    sink.initialize(null, properties);
    ValidationResult result = sink.validate(null);
    Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
    WriteOperation operation = sink.createWriteOperation();
    JDBCSPWriter writer = (JDBCSPWriter) operation.createWriter(null);
    try {
        writer.open("wid");
        IndexedRecord r1 = new GenericData.Record(properties.main.schema.getValue());
        r1.put(0, 0);
        r1.put(1, "wangwei");
        writer.write(r1);
        List<IndexedRecord> writeResult = writer.getSuccessfulWrites();
        Assert.assertEquals(1, writeResult.size());
        IndexedRecord record = writeResult.get(0);
        Assert.assertEquals(Integer.valueOf(0), record.get(0));
        Assert.assertEquals("wangwei", record.get(1));
        writer.cleanWrites();
    } finally {
        writer.close();
    }
}
Also used : JDBCSPSink(org.talend.components.jdbc.runtime.JDBCSPSink) WriteOperation(org.talend.components.api.component.runtime.WriteOperation) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TJDBCSPProperties(org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties) JDBCSPWriter(org.talend.components.jdbc.runtime.writer.JDBCSPWriter) IndexedRecord(org.apache.avro.generic.IndexedRecord) TJDBCSPDefinition(org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Aggregations

IndexedRecord (org.apache.avro.generic.IndexedRecord)2 Test (org.junit.Test)2 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)2 JDBCSPSink (org.talend.components.jdbc.runtime.JDBCSPSink)2 JDBCSPWriter (org.talend.components.jdbc.runtime.writer.JDBCSPWriter)2 TJDBCSPDefinition (org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition)2 TJDBCSPProperties (org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties)2 ValidationResult (org.talend.daikon.properties.ValidationResult)2 Schema (org.apache.avro.Schema)1