use of org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink 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;
}
use of org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink 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;
}
}
use of org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink 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;
}
use of org.talend.components.jdbc.runtime.setting.JdbcRuntimeSourceOrSink 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;
}
}
Aggregations