Search in sources :

Example 1 with JDBCTableMetadata

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());
    }
}
Also used : JDBCTableMetadata(org.talend.components.common.avro.JDBCTableMetadata) Connection(java.sql.Connection) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) SQLException(java.sql.SQLException) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException)

Example 2 with JDBCTableMetadata

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;
}
Also used : JDBCTableMetadata(org.talend.components.common.avro.JDBCTableMetadata) SQLException(java.sql.SQLException) Schema(org.apache.avro.Schema) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 JDBCTableMetadata (org.talend.components.common.avro.JDBCTableMetadata)2 Connection (java.sql.Connection)1 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)1 Schema (org.apache.avro.Schema)1 ComponentException (org.talend.components.api.exception.ComponentException)1 SnowflakeConnectionProperties (org.talend.components.snowflake.SnowflakeConnectionProperties)1