Java Code Examples for io.debezium.text.MultipleParsingExceptions

Following code examples demonstrate how to use io.debezium.text.MultipleParsingExceptionsfrom debezium. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use io.debezium.text.MultipleParsingExceptionsand various code implementation of this class.

    protected void parsingFailed(Position position, Collection<ParsingException> errors, String msg) {
        if (errors == null || errors.isEmpty()) {
            throw new ParsingException(position, msg + " at line " + position.line() + ", column " + position.column());
        }
        throw new MultipleParsingExceptions(msg + " at line " + position.line() + ", column " + position.column(), errors);
    } 


    
    public boolean applyDdl(SourceInfo source, String databaseName, String ddlStatements,
                            DatabaseStatementStringConsumer statementConsumer) {
        Set<TableId> changes;
        if (ignoredQueryStatements.contains(ddlStatements)) return false;
        try {
            this.ddlChanges.reset();
            this.ddlParser.setCurrentSchema(databaseName);
            this.ddlParser.parse(ddlStatements, tables());
        } catch (ParsingException | MultipleParsingExceptions e) {
            if (skipUnparseableDDL) {
                logger.warn("Ignoring unparseable DDL statement '{}': {}", ddlStatements);
            } else {
                throw e;
            }
        } finally {
            changes = tables().drainChanges();
            if (!storeOnlyMonitoredTablesDdl || !changes.isEmpty()) {
                if (statementConsumer != null) {


                    if (!ddlChanges.isEmpty() && ddlChanges.applyToMoreDatabasesThan(databaseName)) {

                        ddlChanges.groupStatementStringsByDatabase((dbName, ddl) -> {
                            if (filters.databaseFilter().test(dbName) || dbName == null || "".equals(dbName)) {
                                if (dbName == null) dbName = "";
                                statementConsumer.consume(dbName, ddlStatements);
                            }
                        });
                    } else if (filters.databaseFilter().test(databaseName) || databaseName == null || "".equals(databaseName)) {
                        if (databaseName == null) databaseName = "";
                        statementConsumer.consume(databaseName, ddlStatements);
                    }
                }

                try {
                    if (!storeOnlyMonitoredTablesDdl || changes.stream().anyMatch(filters().tableFilter()::test)) {
                        dbHistory.record(source.partition(), source.offset(), databaseName, ddlStatements);
                    } else {
                        logger.debug("Changes for DDL '{}' were filtered and not recorded in database history", ddlStatements);
                    }
                } catch (Throwable e) {
                    throw new ConnectException(
                            "Error recording the DDL statement(s) in the database history " + dbHistory + ": " + ddlStatements, e);
                }
            }
        }

        changes.forEach(tableId -> {
            Table table = tableFor(tableId);
                removeSchema(tableId);
            }
            else {
                buildAndRegisterSchema(table);
            }
        }); 

    protected Collection<ParsingException> accumulateParsingFailure(MultipleParsingExceptions e, Collection<ParsingException> list) {
        if (e == null) return list;
        if (list == null) list = new ArrayList<ParsingException>();
        list.addAll(e.getErrors());
        return list;
    } 

    private void throwParsingException(Collection<ParsingException> errors) {
        if(errors.size() == 1) {
            throw errors.iterator().next();
        }
        else {
            throw new MultipleParsingExceptions(errors);
        }
    } 

Advertisement
Javadoc
Representation of multiple ParsingExceptions. @author Randall Hauch
Advertisement