connectors/rocketmq-connect-doris/src/main/java/org/apache/rocketmq/connect/doris/util/ExpressionBuilder.java [203:593]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    public static ExpressionBuilder create() {
        return new ExpressionBuilder();
    }

    protected static final QuoteMethod DEFAULT_QUOTE_METHOD = QuoteMethod.ALWAYS;

    private final IdentifierRules rules;
    private final StringBuilder sb = new StringBuilder();
    private QuoteMethod quoteSqlIdentifiers = DEFAULT_QUOTE_METHOD;

    /**
     * Create a new expression builder with the default {@link IdentifierRules}.
     */
    public ExpressionBuilder() {
        this(null);
    }

    /**
     * Create a new expression builder that uses the specified {@link IdentifierRules}.
     *
     * @param rules the rules; may be null if the default rules are to be used
     */
    public ExpressionBuilder(IdentifierRules rules) {
        this.rules = rules != null ? rules : IdentifierRules.DEFAULT;
    }

    /**
     * Set when this expression builder should quote identifiers, such as table and column names.
     *
     * @param method the quoting method; may be null if the default method
     *               ({@link QuoteMethod#ALWAYS always}) should be used
     * @return this expression builder; never null
     */
    public ExpressionBuilder setQuoteIdentifiers(QuoteMethod method) {
        this.quoteSqlIdentifiers = method != null ? method : DEFAULT_QUOTE_METHOD;
        return this;
    }

    /**
     * Return a new ExpressionBuilder that escapes quotes with the specified prefix.
     * This builder remains unaffected.
     *
     * @param prefix the prefix
     * @return the new ExpressionBuilder, or this builder if the prefix is null or empty
     */
    public ExpressionBuilder escapeQuotesWith(String prefix) {
        if (prefix == null || prefix.isEmpty()) {
            return this;
        }
        return new ExpressionBuilder(this.rules.escapeQuotesWith(prefix));
    }

    /**
     * Append to this builder's expression the delimiter defined by this builder's
     * {@link IdentifierRules}.
     *
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendIdentifierDelimiter() {
        sb.append(rules.identifierDelimiter());
        return this;
    }

    /**
     * Always append to this builder's expression the leading quote character(s) defined by this
     * builder's {@link IdentifierRules}.
     *
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendLeadingQuote() {
        return appendLeadingQuote(QuoteMethod.ALWAYS);
    }


    protected ExpressionBuilder appendLeadingQuote(QuoteMethod method) {
        switch (method) {
            case ALWAYS:
                sb.append(rules.leadingQuoteString());
                break;
            case NEVER:
            default:
                break;
        }
        return this;
    }

    /**
     * Always append to this builder's expression the trailing quote character(s) defined by this
     * builder's {@link IdentifierRules}.
     *
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendTrailingQuote() {
        return appendTrailingQuote(QuoteMethod.ALWAYS);
    }

    protected ExpressionBuilder appendTrailingQuote(QuoteMethod method) {
        switch (method) {
            case ALWAYS:
                sb.append(rules.trailingQuoteString());
                break;
            case NEVER:
            default:
                break;
        }
        return this;
    }

    /**
     * Append to this builder's expression the string quote character ({@code '}).
     *
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendStringQuote() {
        sb.append("'");
        return this;
    }

    /**
     * Append to this builder's expression a string surrounded by single quote characters ({@code '}).
     * Use {@link #appendIdentifier(String, QuoteMethod)} for identifiers,
     * {@link #appendColumnName(String, QuoteMethod)} for column names, or
     * {@link #appendTableName(String, QuoteMethod)} for table names.
     *
     * @param name the object whose string representation is to be appended
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendStringQuoted(Object name) {
        appendStringQuote();
        sb.append(name);
        appendStringQuote();
        return this;
    }

    /**
     * Append to this builder's expression the identifier.
     *
     * @param name   the name to be appended
     * @param quoted true if the name should be quoted, or false otherwise
     * @return this builder to enable methods to be chained; never null
     * @deprecated use {@link #appendIdentifier(String, QuoteMethod)} instead
     */
    @Deprecated
    public ExpressionBuilder appendIdentifier(
            String name,
            boolean quoted
    ) {
        return appendIdentifier(name, quoted ? QuoteMethod.ALWAYS : QuoteMethod.NEVER);
    }

    /**
     * Append to this builder's expression the identifier.
     *
     * @param name   the name to be appended
     * @param quoted true if the name should be quoted, or false otherwise
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendIdentifier(
            String name,
            QuoteMethod quoted
    ) {
        appendLeadingQuote(quoted);
        sb.append(name);
        appendTrailingQuote(quoted);
        return this;
    }

    /**
     * Append to this builder's expression the specified Column identifier, possibly surrounded by
     * the leading and trailing quotes based upon {@link #setQuoteIdentifiers(QuoteMethod)}.
     *
     * @param name the name to be appended
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendTableName(String name) {
        return appendTableName(name, quoteSqlIdentifiers);
    }

    /**
     * Append to this builder's expression the specified Column identifier, possibly surrounded by
     * the leading and trailing quotes based upon {@link #setQuoteIdentifiers(QuoteMethod)}.
     *
     * @param name  the name to be appended
     * @param quote the quote method to be used
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendTableName(String name, QuoteMethod quote) {
        appendLeadingQuote(quote);
        sb.append(name);
        appendTrailingQuote(quote);
        return this;
    }

    /**
     * Append to this builder's expression the specified Column identifier, possibly surrounded by
     * the leading and trailing quotes based upon {@link #setQuoteIdentifiers(QuoteMethod)}.
     *
     * @param name the name to be appended
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendColumnName(String name) {
        return appendColumnName(name, quoteSqlIdentifiers);
    }

    /**
     * Append to this builder's expression the specified Column identifier, possibly surrounded by
     * the leading and trailing quotes based upon {@link #setQuoteIdentifiers(QuoteMethod)}.
     *
     * @param name  the name to be appended
     * @param quote whether to quote the column name; may not be null
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendColumnName(String name, QuoteMethod quote) {
        appendLeadingQuote(quote);
        sb.append(name);
        appendTrailingQuote(quote);
        return this;
    }

    /**
     * Append to this builder's expression the specified identifier, surrounded by the leading and
     * trailing quotes.
     *
     * @param name the name to be appended
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendIdentifierQuoted(String name) {
        appendLeadingQuote();
        sb.append(name);
        appendTrailingQuote();
        return this;
    }

    /**
     * Append to this builder's expression the binary value as a hex string, prefixed and
     * suffixed by a single quote character.
     *
     * @param value the value to be appended
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendBinaryLiteral(byte[] value) {
        return append("x'").append(BytesUtil.toHex(value)).append("'");
    }

    /**
     * Append to this builder's expression a new line.
     *
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder appendNewLine() {
        sb.append(System.lineSeparator());
        return this;
    }

    /**
     * Append to this builder's expression the specified object. If the object is {@link Expressable},
     * then this builder delegates to the object's
     * {@link Expressable#appendTo(ExpressionBuilder, boolean)} method. Otherwise, the string
     * representation of the object is appended to the expression.
     *
     * @param obj       the object to be appended
     * @param useQuotes true if the object should be surrounded by quotes, or false otherwise
     * @return this builder to enable methods to be chained; never null
     * @deprecated use {@link #append(Object, QuoteMethod)} instead
     */
    @Deprecated
    public ExpressionBuilder append(
            Object obj,
            boolean useQuotes
    ) {
        return append(obj, useQuotes ? QuoteMethod.ALWAYS : QuoteMethod.NEVER);
    }

    /**
     * Append to this builder's expression the specified object. If the object is {@link Expressable},
     * then this builder delegates to the object's
     * {@link Expressable#appendTo(ExpressionBuilder, boolean)} method. Otherwise, the string
     * representation of the object is appended to the expression.
     *
     * @param obj       the object to be appended
     * @param useQuotes true if the object should be surrounded by quotes, or false otherwise
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder append(
            Object obj,
            QuoteMethod useQuotes
    ) {
        if (obj instanceof Expressable) {
            ((Expressable) obj).appendTo(this, useQuotes);
        } else if (obj != null) {
            sb.append(obj);
        }
        return this;
    }

    /**
     * Append to this builder's expression the specified object surrounded by quotes. If the object
     * is {@link Expressable}, then this builder delegates to the object's
     * {@link Expressable#appendTo(ExpressionBuilder, boolean)} method. Otherwise, the string
     * representation of the object is appended to the expression.
     *
     * @param obj the object to be appended
     * @return this builder to enable methods to be chained; never null
     */
    public ExpressionBuilder append(Object obj) {
        return append(obj, quoteSqlIdentifiers);
    }

    /**
     * Append to this builder's expression the specified object surrounded by quotes. If the object
     * is {@link Expressable}, then this builder delegates to the object's
     * {@link Expressable#appendTo(ExpressionBuilder, boolean)} method. Otherwise, the string
     * representation of the object is appended to the expression.
     *
     * @param obj       the object to be appended
     * @param transform the transform that should be used on the supplied object to obtain the
     *                  representation that is appended to the expression; may be null
     * @param <T>       the type of object to transform before appending.
     * @return this builder to enable methods to be chained; never null
     */
    public <T> ExpressionBuilder append(
            T obj,
            Transform<T> transform
    ) {
        if (transform != null) {
            transform.apply(this, obj);
        } else {
            append(obj);
        }
        return this;
    }

    protected class BasicListBuilder<T> implements ListBuilder<T> {
        private final String delimiter;
        private final Transform<T> transform;
        private boolean first = true;

        BasicListBuilder() {
            this(", ", null);
        }

        BasicListBuilder(String delimiter, Transform<T> transform) {
            this.delimiter = delimiter;
            this.transform = transform != null ? transform : ExpressionBuilder::append;
        }

        @Override
        public ListBuilder<T> delimitedBy(String delimiter) {
            return new BasicListBuilder<T>(delimiter, transform);
        }

        @Override
        public <R> ListBuilder<R> transformedBy(Transform<R> transform) {
            return new BasicListBuilder<>(delimiter, transform);
        }

        @Override
        public ExpressionBuilder of(Iterable<? extends T> objects) {
            for (T obj : objects) {
                if (first) {
                    first = false;
                } else {
                    append(delimiter);
                }
                append(obj, transform);
            }
            return ExpressionBuilder.this;
        }
    }

    public ListBuilder<Object> appendList() {
        return new BasicListBuilder<>();
    }

    public ExpressionBuilder appendMultiple(
            String delimiter,
            String expression,
            int times
    ) {
        for (int i = 0; i < times; i++) {
            if (i > 0) {
                append(delimiter);
            }
            append(expression);
        }
        return this;
    }

    @Override
    public String toString() {
        return sb.toString();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



connectors/rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/util/ExpressionBuilder.java [100:329]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    public static ExpressionBuilder create() {
        return new ExpressionBuilder();
    }

    protected static final QuoteMethod DEFAULT_QUOTE_METHOD = QuoteMethod.ALWAYS;

    private final IdentifierRules rules;
    private final StringBuilder sb = new StringBuilder();
    private QuoteMethod quoteSqlIdentifiers = DEFAULT_QUOTE_METHOD;

    public ExpressionBuilder() {
        this(null);
    }

    public ExpressionBuilder(IdentifierRules rules) {
        this.rules = rules != null ? rules : IdentifierRules.DEFAULT;
    }

    public ExpressionBuilder setQuoteIdentifiers(QuoteMethod method) {
        this.quoteSqlIdentifiers = method != null ? method : DEFAULT_QUOTE_METHOD;
        return this;
    }

    public ExpressionBuilder escapeQuotesWith(String prefix) {
        if (prefix == null || prefix.isEmpty()) {
            return this;
        }
        return new ExpressionBuilder(this.rules.escapeQuotesWith(prefix));
    }
    public ExpressionBuilder appendIdentifierDelimiter() {
        sb.append(rules.identifierDelimiter());
        return this;
    }

    public ExpressionBuilder appendLeadingQuote() {
        return appendLeadingQuote(QuoteMethod.ALWAYS);
    }


    protected ExpressionBuilder appendLeadingQuote(QuoteMethod method) {
        switch (method) {
            case ALWAYS:
                sb.append(rules.leadingQuoteString());
                break;
            case NEVER:
            default:
                break;
        }
        return this;
    }

    public ExpressionBuilder appendTrailingQuote() {
        return appendTrailingQuote(QuoteMethod.ALWAYS);
    }

    protected ExpressionBuilder appendTrailingQuote(QuoteMethod method) {
        switch (method) {
            case ALWAYS:
                sb.append(rules.trailingQuoteString());
                break;
            case NEVER:
            default:
                break;
        }
        return this;
    }

    public ExpressionBuilder appendStringQuote() {
        sb.append("'");
        return this;
    }

    public ExpressionBuilder appendStringQuoted(Object name) {
        appendStringQuote();
        sb.append(name);
        appendStringQuote();
        return this;
    }

    @Deprecated
    public ExpressionBuilder appendIdentifier(
            String name,
            boolean quoted
    ) {
        return appendIdentifier(name, quoted ? QuoteMethod.ALWAYS : QuoteMethod.NEVER);
    }

    public ExpressionBuilder appendIdentifier(
            String name,
            QuoteMethod quoted
    ) {
        appendLeadingQuote(quoted);
        sb.append(name);
        appendTrailingQuote(quoted);
        return this;
    }

    public ExpressionBuilder appendTableName(String name) {
        return appendTableName(name, quoteSqlIdentifiers);
    }

    public ExpressionBuilder appendTableName(String name, QuoteMethod quote) {
        appendLeadingQuote(quote);
        sb.append(name);
        appendTrailingQuote(quote);
        return this;
    }

    public ExpressionBuilder appendColumnName(String name) {
        return appendColumnName(name, quoteSqlIdentifiers);
    }

    public ExpressionBuilder appendColumnName(String name, QuoteMethod quote) {
        appendLeadingQuote(quote);
        sb.append(name);
        appendTrailingQuote(quote);
        return this;
    }

    public ExpressionBuilder appendIdentifierQuoted(String name) {
        appendLeadingQuote();
        sb.append(name);
        appendTrailingQuote();
        return this;
    }

    public ExpressionBuilder appendBinaryLiteral(byte[] value) {
        return append("x'").append(BytesUtil.toHex(value)).append("'");
    }

    public ExpressionBuilder appendNewLine() {
        sb.append(System.lineSeparator());
        return this;
    }

    @Deprecated
    public ExpressionBuilder append(
            Object obj,
            boolean useQuotes
    ) {
        return append(obj, useQuotes ? QuoteMethod.ALWAYS : QuoteMethod.NEVER);
    }

    public ExpressionBuilder append(
            Object obj,
            QuoteMethod useQuotes
    ) {
        if (obj instanceof Expressable) {
            ((Expressable) obj).appendTo(this, useQuotes);
        } else if (obj != null) {
            sb.append(obj);
        }
        return this;
    }

    public ExpressionBuilder append(Object obj) {
        return append(obj, quoteSqlIdentifiers);
    }

    public <T> ExpressionBuilder append(
            T obj,
            Transform<T> transform
    ) {
        if (transform != null) {
            transform.apply(this, obj);
        } else {
            append(obj);
        }
        return this;
    }

    protected class BasicListBuilder<T> implements ListBuilder<T> {
        private final String delimiter;
        private final Transform<T> transform;
        private boolean first = true;

        BasicListBuilder() {
            this(", ", null);
        }

        BasicListBuilder(String delimiter, Transform<T> transform) {
            this.delimiter = delimiter;
            this.transform = transform != null ? transform : ExpressionBuilder::append;
        }

        @Override
        public ListBuilder<T> delimitedBy(String delimiter) {
            return new BasicListBuilder<T>(delimiter, transform);
        }

        @Override
        public <R> ListBuilder<R> transformedBy(Transform<R> transform) {
            return new BasicListBuilder<>(delimiter, transform);
        }

        @Override
        public ExpressionBuilder of(Iterable<? extends T> objects) {
            for (T obj : objects) {
                if (first) {
                    first = false;
                } else {
                    append(delimiter);
                }
                append(obj, transform);
            }
            return ExpressionBuilder.this;
        }
    }

    public ListBuilder<Object> appendList() {
        return new BasicListBuilder<>();
    }

    public ExpressionBuilder appendMultiple(
            String delimiter,
            String expression,
            int times
    ) {
        for (int i = 0; i < times; i++) {
            if (i > 0) {
                append(delimiter);
            }
            append(expression);
        }
        return this;
    }

    @Override
    public String toString() {
        return sb.toString();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



