Search in sources :

Example 1 with TJDBCSPProperties

use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.

the class JDBCSPTestIT method test_basic_no_connector.

@Test
public void test_basic_no_connector() throws Exception {
    TJDBCSPDefinition definition = new TJDBCSPDefinition();
    TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
    properties.spName.setValue("SYSCS_UTIL.SYSCS_EMPTY_STATEMENT_CACHE");
    JDBCSPSourceOrSink sourceOrSink = new JDBCSPSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
}
Also used : JDBCSPSourceOrSink(org.talend.components.jdbc.runtime.JDBCSPSourceOrSink) TJDBCSPProperties(org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties) TJDBCSPDefinition(org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Example 2 with TJDBCSPProperties

use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties 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 3 with TJDBCSPProperties

use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.

the class DBTestUtils method createCommonJDBCSPProperties.

public static TJDBCSPProperties createCommonJDBCSPProperties(AllSetting allSetting, TJDBCSPDefinition definition) {
    TJDBCSPProperties properties = (TJDBCSPProperties) definition.createRuntimeProperties();
    // properties.connection.driverTable.drivers.setValue(Arrays.asList(driverPath));
    properties.connection.driverClass.setValue(allSetting.getDriverClass());
    properties.connection.jdbcUrl.setValue(allSetting.getJdbcUrl());
    properties.connection.userPassword.userId.setValue(allSetting.getUsername());
    properties.connection.userPassword.password.setValue(allSetting.getPassword());
    return properties;
}
Also used : TJDBCSPProperties(org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties)

Example 4 with TJDBCSPProperties

use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties 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)

Example 5 with TJDBCSPProperties

use of org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties in project components by Talend.

the class JDBCSPTestIT method test_basic_as_input.

@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_input() throws Exception {
    TJDBCSPDefinition definition = new TJDBCSPDefinition();
    TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
    properties.isFunction.setValue(true);
    properties.returnResultIn.setValue("PARAMETER");
    properties.spName.setValue("SYSCS_UTIL.SYSCS_GET_DATABASE_NAME");
    Schema schema = DBTestUtils.createSPSchema2(tablename);
    properties.main.schema.setValue(schema);
    properties.schemaFlow.schema.setValue(schema);
    JDBCSPSource source = new JDBCSPSource();
    source.initialize(null, properties);
    ValidationResult result = source.validate(null);
    Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
    Reader reader = source.createReader(null);
    try {
        reader.start();
        IndexedRecord row = (IndexedRecord) reader.getCurrent();
        String v1 = (String) row.get(0);
        Assert.assertEquals("memory:myDB", v1);
        // only output one row when it works as a input component
        Assert.assertFalse(reader.advance());
        reader.close();
    } finally {
        reader.close();
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TJDBCSPProperties(org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties) JDBCSPSource(org.talend.components.jdbc.runtime.JDBCSPSource) Reader(org.talend.components.api.component.runtime.Reader) TJDBCSPDefinition(org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Aggregations

TJDBCSPProperties (org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties)5 Test (org.junit.Test)4 TJDBCSPDefinition (org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition)4 ValidationResult (org.talend.daikon.properties.ValidationResult)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 Schema (org.apache.avro.Schema)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 Reader (org.talend.components.api.component.runtime.Reader)1 JDBCSPSource (org.talend.components.jdbc.runtime.JDBCSPSource)1 JDBCSPSourceOrSink (org.talend.components.jdbc.runtime.JDBCSPSourceOrSink)1