Search in sources :

Example 1 with JdbcRuntimeInfo

use of org.talend.components.jdbc.JdbcRuntimeInfo in project components by Talend.

the class TJDBCInputProperties method afterFetchSchemaFromQuery.

public ValidationResult afterFetchSchemaFromQuery(RuntimeContext runtimeContext) {
    Object mappingFileLocation = runtimeContext.getData(ComponentConstants.MAPPING_LOCATION);
    if (mappingFileLocation == null) {
        return new ValidationResult(ValidationResult.Result.ERROR, "can't find the mapping files directory");
    }
    JdbcRuntimeInfo jdbcRuntimeInfo = new JdbcRuntimeInfo(this, "org.talend.components.jdbc.runtime.JDBCSource");
    try (SandboxedInstance sandboxI = RuntimeUtil.createRuntimeClass(jdbcRuntimeInfo, connection.getClass().getClassLoader())) {
        JdbcRuntimeSourceOrSink ss = (JdbcRuntimeSourceOrSink) sandboxI.getInstance();
        ss.initialize(null, this);
        try {
            ss.setDBTypeMapping(CommonUtils.getMapping((String) mappingFileLocation, this.getRuntimeSetting(), null, dbMapping.getValue()));
            Schema schema = ss.getSchemaFromQuery(null, sql.getValue());
            main.schema.setValue(schema);
        } catch (Exception e) {
            LOG.error("failed to retrieve the schema :", e);
            return new ValidationResult(ValidationResult.Result.ERROR, CommonUtils.getClearExceptionInfo(e));
        }
    }
    return ValidationResult.OK;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) JdbcRuntimeSourceOrSink(org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink) JdbcRuntimeInfo(org.talend.components.jdbc.JdbcRuntimeInfo) Schema(org.apache.avro.Schema) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 2 with JdbcRuntimeInfo

use of org.talend.components.jdbc.JdbcRuntimeInfo in project components by Talend.

the class JDBCConnectionWizardProperties method afterFormFinishMain.

public ValidationResult afterFormFinishMain(Repository<Properties> repo) throws Exception {
    JdbcRuntimeInfo jdbcRuntimeInfo = new JdbcRuntimeInfo(this, "org.talend.components.jdbc.runtime.JDBCSourceOrSink");
    try (SandboxedInstance sandboxI = RuntimeUtil.createRuntimeClass(jdbcRuntimeInfo, connection.getClass().getClassLoader())) {
        JdbcRuntimeSourceOrSink sourceOrSink = (JdbcRuntimeSourceOrSink) sandboxI.getInstance();
        sourceOrSink.initialize(null, this);
        ValidationResult vr = sourceOrSink.validate(null);
        if (vr.getStatus() != ValidationResult.Result.OK) {
            return vr;
        }
        repo.storeProperties(this, this.name.getValue(), repositoryLocation, null);
        // no need to store the schemas, tup will do it by the old way, so only need to store the connection properties
        return ValidationResult.OK;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) JdbcRuntimeSourceOrSink(org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink) JdbcRuntimeInfo(org.talend.components.jdbc.JdbcRuntimeInfo) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 3 with JdbcRuntimeInfo

use of org.talend.components.jdbc.JdbcRuntimeInfo in project components by Talend.

the class JDBCTableSelectionModule method beforeTablename.

public ValidationResult beforeTablename() throws IOException {
    JdbcRuntimeInfo jdbcRuntimeInfo = new JdbcRuntimeInfo(connection, "org.talend.components.jdbc.runtime.JDBCSource");
    try (SandboxedInstance sandboxI = RuntimeUtil.createRuntimeClass(jdbcRuntimeInfo, connection.getClass().getClassLoader())) {
        SourceOrSink ss = (SourceOrSink) sandboxI.getInstance();
        ss.initialize(null, (ComponentProperties) connection);
        List<NamedThing> tablenames = ss.getSchemaNames(null);
        tablename.setPossibleNamedThingValues(tablenames);
    } catch (ComponentException ex) {
        return ex.getValidationResult();
    }
    return ValidationResult.OK;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) JdbcRuntimeInfo(org.talend.components.jdbc.JdbcRuntimeInfo) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing)

Example 4 with JdbcRuntimeInfo

use of org.talend.components.jdbc.JdbcRuntimeInfo in project components by Talend.

the class TJDBCOutputProperties method afterFetchSchemaFromTable.

public ValidationResult afterFetchSchemaFromTable(RuntimeContext runtimeContext) {
    Object mappingFileLocation = runtimeContext.getData(ComponentConstants.MAPPING_LOCATION);
    if (mappingFileLocation == null) {
        return new ValidationResult(ValidationResult.Result.ERROR, "can't find the mapping files directory");
    }
    JdbcRuntimeInfo jdbcRuntimeInfo = new JdbcRuntimeInfo(this, "org.talend.components.jdbc.runtime.JDBCSource");
    try (SandboxedInstance sandboxI = RuntimeUtil.createRuntimeClass(jdbcRuntimeInfo, connection.getClass().getClassLoader())) {
        JdbcRuntimeSourceOrSink ss = (JdbcRuntimeSourceOrSink) sandboxI.getInstance();
        ss.initialize(null, this);
        Schema schema = null;
        try {
            ss.setDBTypeMapping(CommonUtils.getMapping((String) mappingFileLocation, this.getRuntimeSetting(), null, null));
            schema = ss.getEndpointSchema(null, tableSelection.tablename.getValue());
        } catch (Exception e) {
            return new ValidationResult(ValidationResult.Result.ERROR, CommonUtils.getClearExceptionInfo(e));
        }
        main.schema.setValue(schema);
        updateOutputSchemas();
    }
    return ValidationResult.OK;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) JdbcRuntimeSourceOrSink(org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink) JdbcRuntimeInfo(org.talend.components.jdbc.JdbcRuntimeInfo) Schema(org.apache.avro.Schema) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 5 with JdbcRuntimeInfo

use of org.talend.components.jdbc.JdbcRuntimeInfo in project components by Talend.

the class JDBCConnectionWizardProperties method validateTestConnection.

public ValidationResult validateTestConnection() {
    JdbcRuntimeInfo jdbcRuntimeInfo = new JdbcRuntimeInfo(this, "org.talend.components.jdbc.runtime.JDBCSourceOrSink");
    try (SandboxedInstance sandboxI = RuntimeUtil.createRuntimeClass(jdbcRuntimeInfo, connection.getClass().getClassLoader())) {
        JdbcRuntimeSourceOrSink sourceOrSink = (JdbcRuntimeSourceOrSink) sandboxI.getInstance();
        sourceOrSink.initialize(null, this);
        ValidationResult vr = sourceOrSink.validate(null);
        if (vr.getStatus() == ValidationResult.Result.OK) {
            vr = new ValidationResult(ValidationResult.Result.OK, "Connection successful");
            getForm(Form.MAIN).setAllowFinish(true);
        } else {
            getForm(Form.MAIN).setAllowFinish(false);
        }
        return vr;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) JdbcRuntimeSourceOrSink(org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink) JdbcRuntimeInfo(org.talend.components.jdbc.JdbcRuntimeInfo) ValidationResult(org.talend.daikon.properties.ValidationResult)

Aggregations

JdbcRuntimeInfo (org.talend.components.jdbc.JdbcRuntimeInfo)5 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)5 JdbcRuntimeSourceOrSink (org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink)4 ValidationResult (org.talend.daikon.properties.ValidationResult)4 Schema (org.apache.avro.Schema)2 SourceOrSink (org.talend.components.api.component.runtime.SourceOrSink)1 ComponentException (org.talend.components.api.exception.ComponentException)1 NamedThing (org.talend.daikon.NamedThing)1