Search in sources :

Example 1 with ExceptionContextBuilder

use of org.talend.daikon.exception.ExceptionContext.ExceptionContextBuilder in project components by Talend.

the class SnowflakeRowWriter method validateResultSet.

private boolean validateResultSet() throws SQLException {
    List<Field> fields = mainSchema.getFields();
    ResultSetMetaData rsMetadata = rs.getMetaData();
    if (CUD_RESULT_SET_COLUMN_NAMES.contains(rsMetadata.getColumnName(1))) {
        return false;
    }
    if (fields.size() != rsMetadata.getColumnCount()) {
        throw new ComponentException(new DefaultErrorCode(400, "errorMessage"), new ExceptionContextBuilder().put("errorMessage", I18N_MESSAGES.getMessage("error.resultSetMapping")).build());
    }
    int counter = 0;
    for (int i = 0; i < rsMetadata.getColumnCount(); i++) {
        String rsColumnName = rsMetadata.getColumnName(i + 1);
        for (Field field : fields) {
            if (rsColumnName.equalsIgnoreCase(field.name())) {
                counter++;
            }
        }
    }
    if (counter != rsMetadata.getColumnCount()) {
        throw new ComponentException(new DefaultErrorCode(400, "errorMessage"), new ExceptionContextBuilder().put("errorMessage", I18N_MESSAGES.getMessage("error.resultSetMapping")).build());
    }
    resultSetValidation = true;
    return true;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Field(org.apache.avro.Schema.Field) DefaultErrorCode(org.talend.daikon.exception.error.DefaultErrorCode) ExceptionContextBuilder(org.talend.daikon.exception.ExceptionContext.ExceptionContextBuilder) ComponentException(org.talend.components.api.exception.ComponentException)

Aggregations

ResultSetMetaData (java.sql.ResultSetMetaData)1 Field (org.apache.avro.Schema.Field)1 ComponentException (org.talend.components.api.exception.ComponentException)1 ExceptionContextBuilder (org.talend.daikon.exception.ExceptionContext.ExceptionContextBuilder)1 DefaultErrorCode (org.talend.daikon.exception.error.DefaultErrorCode)1