Search in sources :

Example 16 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class JdbcRowTestIT method test_use_preparedstatement_no_connector.

@Test
public void test_use_preparedstatement_no_connector() throws Exception {
    TJDBCRowDefinition definition = new TJDBCRowDefinition();
    TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue("insert into " + tablename + " values(?, ?)");
    properties.dieOnError.setValue(true);
    randomCommit(properties);
    properties.usePreparedStatement.setValue(true);
    properties.preparedStatementTable.indexs.setValue(Arrays.asList(1, 2));
    properties.preparedStatementTable.types.setValue(Arrays.asList(PreparedStatementTable.Type.Int.name(), PreparedStatementTable.Type.String.name()));
    properties.preparedStatementTable.values.setValue(Arrays.<Object>asList(4, "momo"));
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(ExecutionEngine.DI, properties, ConnectorTopology.NONE), properties.getClass().getClassLoader())) {
        JDBCRowSourceOrSink sourceOrSink = (JDBCRowSourceOrSink) sandboxedInstance.getInstance();
        sourceOrSink.initialize(null, properties);
        ValidationResult result = sourceOrSink.validate(null);
        Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
    }
    TJDBCInputDefinition definition1 = new TJDBCInputDefinition();
    TJDBCInputProperties properties1 = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition1);
    List<IndexedRecord> records = DBTestUtils.fetchDataByReaderFromTable(tablename, DBTestUtils.createTestSchema(tablename), definition1, properties1);
    assertThat(records, hasSize(4));
    Assert.assertEquals(new Integer(4), records.get(3).get(0));
    Assert.assertEquals("momo", records.get(3).get(1));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) TJDBCRowDefinition(org.talend.components.jdbc.tjdbcrow.TJDBCRowDefinition) IndexedRecord(org.apache.avro.generic.IndexedRecord) JDBCRowSourceOrSink(org.talend.components.jdbc.runtime.JDBCRowSourceOrSink) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) TJDBCRowProperties(org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties) Test(org.junit.Test)

Example 17 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class CommonUtilsTest method testGetMainSchemaFromOutputConnector.

@Test
public void testGetMainSchemaFromOutputConnector() {
    TJDBCInputProperties properties = new TJDBCInputProperties("input");
    properties.init();
    Schema schema = CommonUtils.getMainSchemaFromOutputConnector(properties);
    Assert.assertNotNull(schema);
}
Also used : Schema(org.apache.avro.Schema) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) Test(org.junit.Test)

Example 18 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class CommonUtilsTest method testGetOutputSchema.

@Test
public void testGetOutputSchema() {
    TJDBCInputProperties properties = new TJDBCInputProperties("input");
    properties.init();
    Schema schema = CommonUtils.getOutputSchema(properties);
    Assert.assertNotNull(schema);
}
Also used : Schema(org.apache.avro.Schema) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) Test(org.junit.Test)

Example 19 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class JDBCInputTestIT method testGetSchemaNamesWithException.

@Test(expected = ComponentException.class)
public void testGetSchemaNamesWithException() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.connection.driverClass.setValue("notexist");
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    try {
        source.getSchemaNames(null);
    } catch (ComponentException e) {
        String message = CommonUtils.getClearExceptionInfo(e);
        assertTrue(message.contains("notexist"));
        throw e;
    }
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) Test(org.junit.Test)

Example 20 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class JDBCInputTestIT method testGetSchemaFromQueryWithException1.

@Test(expected = ComponentException.class)
public void testGetSchemaFromQueryWithException1() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    try {
        source.getSchemaFromQuery(null, "select * from notexist");
    } catch (ComponentException e) {
        String message = CommonUtils.getClearExceptionInfo(e);
        assertTrue(message != null && !message.isEmpty());
        throw e;
    }
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) Test(org.junit.Test)

Aggregations

TJDBCInputProperties (org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties)35 TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)32 Test (org.junit.Test)30 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 Schema (org.apache.avro.Schema)19 TJDBCOutputDefinition (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputDefinition)12 TJDBCOutputProperties (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputProperties)12 JDBCOutputWriter (org.talend.components.jdbc.runtime.writer.JDBCOutputWriter)11 JDBCSource (org.talend.components.jdbc.runtime.JDBCSource)9 Reader (org.talend.components.api.component.runtime.Reader)6 ComponentException (org.talend.components.api.exception.ComponentException)6 ValidationResult (org.talend.daikon.properties.ValidationResult)6 TJDBCRowDefinition (org.talend.components.jdbc.tjdbcrow.TJDBCRowDefinition)5 TJDBCRowProperties (org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties)5 Field (org.apache.avro.Schema.Field)4 JDBCRowSourceOrSink (org.talend.components.jdbc.runtime.JDBCRowSourceOrSink)4 IOException (java.io.IOException)3 BigDecimal (java.math.BigDecimal)3 SQLException (java.sql.SQLException)3 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)3