Search in sources :

Example 6 with JDBCSourceOrSink

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

the class JDBCConnectionTestIT method testConnectionWithEmptyDriver.

@Test
public void testConnectionWithEmptyDriver() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = (TJDBCConnectionProperties) definition.createRuntimeProperties();
    properties.connection.jdbcUrl.setValue(allSetting.getJdbcUrl());
    properties.connection.driverClass.setValue(null);
    properties.connection.userPassword.userId.setValue(allSetting.getUsername());
    properties.connection.userPassword.password.setValue(allSetting.getPassword());
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.ERROR);
    assertTrue(result.getMessage() != null && result.getMessage().contains("Driver Class"));
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Example 7 with JDBCSourceOrSink

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

the class JDBCConnectionTestIT method testConnectionWithWrongURL.

@Test
public void testConnectionWithWrongURL() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = (TJDBCConnectionProperties) definition.createRuntimeProperties();
    properties.connection.driverClass.setValue(allSetting.getDriverClass());
    properties.connection.jdbcUrl.setValue("wrongUrl");
    properties.connection.userPassword.userId.setValue(allSetting.getUsername());
    properties.connection.userPassword.password.setValue(allSetting.getPassword());
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.ERROR);
    assertTrue(result.getMessage() != null && !result.getMessage().isEmpty());
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Example 8 with JDBCSourceOrSink

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

the class JDBCConnectionTestIT method testAutoCommit.

@Test
public void testAutoCommit() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = DBTestUtils.createCommonJDBCConnectionProperties(allSetting, definition);
    properties.useAutoCommit.setValue(true);
    properties.autocommit.setValue(true);
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.OK);
    try (Connection conn = sourceOrSink.getConnection(null)) {
        assertTrue(conn.getAutoCommit());
        assertTrue(!conn.isClosed());
    } catch (ClassNotFoundException | SQLException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Example 9 with JDBCSourceOrSink

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

the class JDBCDatasetTestIT method testGetSchemaFromTable.

@Test
public void testGetSchemaFromTable() throws IOException {
    JDBCDatasetProperties dataset = createDatasetProperties(false);
    JDBCDatasetRuntime runtime = new JDBCDatasetRuntime();
    runtime.initialize(null, dataset);
    JDBCSourceOrSink jss = new JDBCSourceOrSink();
    jss.initialize(null, dataset);
    Schema schema = jss.getEndpointSchema(null, tablename);
    Assert.assertNotNull(schema);
    DBTestUtils.testMetadata(schema.getFields(), true);
    jss.getEndpointSchema(null, tablename_all_type);
// TODO assert the result
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime) Schema(org.apache.avro.Schema) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) Test(org.junit.Test)

Example 10 with JDBCSourceOrSink

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

the class JDBCDatasetRuntime method getSchema.

@Override
public Schema getSchema() {
    JDBCSourceOrSink jss = new JDBCSourceOrSink();
    jss.initialize(container, dataset);
    return jss.getSchemaFromQuery(container, dataset.getRuntimeSetting().getSql());
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink)

Aggregations

JDBCSourceOrSink (org.talend.components.jdbc.runtime.JDBCSourceOrSink)15 ValidationResult (org.talend.daikon.properties.ValidationResult)13 Test (org.junit.Test)12 TJDBCConnectionDefinition (org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition)12 TJDBCConnectionProperties (org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties)12 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)4 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)2 JDBCCommitSourceOrSink (org.talend.components.jdbc.runtime.JDBCCommitSourceOrSink)2 JDBCRollbackSourceOrSink (org.talend.components.jdbc.runtime.JDBCRollbackSourceOrSink)2 JDBCSink (org.talend.components.jdbc.runtime.JDBCSink)2 JDBCOutputInsertWriter (org.talend.components.jdbc.runtime.writer.JDBCOutputInsertWriter)2 TJDBCCommitDefinition (org.talend.components.jdbc.tjdbccommit.TJDBCCommitDefinition)2 TJDBCCommitProperties (org.talend.components.jdbc.tjdbccommit.TJDBCCommitProperties)2 TJDBCOutputDefinition (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputDefinition)2 TJDBCOutputProperties (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputProperties)2 TJDBCRollbackDefinition (org.talend.components.jdbc.tjdbcrollback.TJDBCRollbackDefinition)2