use of org.talend.components.common.avro.JDBCTableMetadata in project components by Talend.
the class JDBCSourceOrSink method getEndpointSchema.
@Override
public Schema getEndpointSchema(RuntimeContainer runtime, String tableName) throws IOException {
try (Connection conn = connect(runtime)) {
JDBCTableMetadata tableMetadata = new JDBCTableMetadata();
tableMetadata.setDatabaseMetaData(conn.getMetaData()).setTablename(tableName);
return infer(tableMetadata, runtime);
} catch (Exception e) {
throw CommonUtils.newComponentException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e, ExceptionContext.withBuilder().put("message", e.getMessage()).build());
}
}
use of org.talend.components.common.avro.JDBCTableMetadata in project components by Talend.
the class SnowflakeSourceOrSink method getSchema.
protected Schema getSchema(RuntimeContainer container, Connection connection, String tableName) throws IOException {
Schema tableSchema = null;
SnowflakeConnectionProperties connProps = getEffectiveConnectionProperties(container);
try {
JDBCTableMetadata tableMetadata = new JDBCTableMetadata();
tableMetadata.setDatabaseMetaData(connection.getMetaData()).setCatalog(getCatalog(connProps)).setDbSchema(getDbSchema(connProps)).setTablename(tableName);
tableSchema = getSnowflakeAvroRegistry().inferSchema(tableMetadata);
if (tableSchema == null)
throw new IOException(i18nMessages.getMessage("error.tableNotFound", tableName));
} catch (SQLException se) {
throw new IOException(se);
}
return tableSchema;
}
Aggregations