/**
 *    Copyright 2009-2019 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.logging.jdbc;

import java.sql.Array;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.reflection.ArrayUtil;

/**
 * Base class for proxies to do logging.
 *
 * @author Clinton Begin
 * @author Eduardo Macarron
 */
public abstract class BaseJdbcLogger {

  protected static final Set<String> SET_METHODS = new HashSet<>();
  protected static final Set<String> EXECUTE_METHODS = new HashSet<>();

  private final Map<Object, Object> columnMap = new HashMap<>();

  private final List<Object> columnNames = new ArrayList<>();
  private final List<Object> columnValues = new ArrayList<>();

  protected Log statementLog;
  protected int queryStack;

  /*
   * Default constructor
   */
  public BaseJdbcLogger(Log log, int queryStack) {
    this.statementLog = log;
    if (queryStack == 0) {
      this.queryStack = 1;
    } else {
      this.queryStack = queryStack;
    }
  }

  static {
    SET_METHODS.add("setString");
    SET_METHODS.add("setNString");
    SET_METHODS.add("setInt");
    SET_METHODS.add("setByte");
    SET_METHODS.add("setShort");
    SET_METHODS.add("setLong");
    SET_METHODS.add("setDouble");
    SET_METHODS.add("setFloat");
    SET_METHODS.add("setTimestamp");
    SET_METHODS.add("setDate");
    SET_METHODS.add("setTime");
    SET_METHODS.add("setArray");
    SET_METHODS.add("setBigDecimal");
    SET_METHODS.add("setAsciiStream");
    SET_METHODS.add("setBinaryStream");
    SET_METHODS.add("setBlob");
    SET_METHODS.add("setBoolean");
    SET_METHODS.add("setBytes");
    SET_METHODS.add("setCharacterStream");
    SET_METHODS.add("setNCharacterStream");
    SET_METHODS.add("setClob");
    SET_METHODS.add("setNClob");
    SET_METHODS.add("setObject");
    SET_METHODS.add("setNull");

    EXECUTE_METHODS.add("execute");
    EXECUTE_METHODS.add("executeUpdate");
    EXECUTE_METHODS.add("executeQuery");
    EXECUTE_METHODS.add("addBatch");
  }

  protected void setColumn(Object key, Object value) {
    columnMap.put(key, value);
    columnNames.add(key);
    columnValues.add(value);
  }

  protected Object getColumn(Object key) {
    return columnMap.get(key);
  }

  protected String getParameterValueString() {
    List<Object> typeList = new ArrayList<>(columnValues.size());
    for (Object value : columnValues) {
      if (value == null) {
        typeList.add("null");
      } else {
        typeList.add(objectValueString(value) + "(" + value.getClass().getSimpleName() + ")");
      }
    }
    final String parameters = typeList.toString();
    return parameters.substring(1, parameters.length() - 1);
  }

  protected String objectValueString(Object value) {
    if (value instanceof Array) {
      try {
        return ArrayUtil.toString(((Array) value).getArray());
      } catch (SQLException e) {
        return value.toString();
      }
    }
    return value.toString();
  }

  protected String getColumnString() {
    return columnNames.toString();
  }

  protected void clearColumnInfo() {
    columnMap.clear();
    columnNames.clear();
    columnValues.clear();
  }

  protected String removeBreakingWhitespace(String original) {
    StringTokenizer whitespaceStripper = new StringTokenizer(original);
    StringBuilder builder = new StringBuilder();
    while (whitespaceStripper.hasMoreTokens()) {
      builder.append(whitespaceStripper.nextToken());
      builder.append(" ");
    }
    return builder.toString();
  }

  protected boolean isDebugEnabled() {
    return statementLog.isDebugEnabled();
  }

  protected boolean isTraceEnabled() {
    return statementLog.isTraceEnabled();
  }

  protected void debug(String text, boolean input) {
    if (statementLog.isDebugEnabled()) {
      statementLog.debug(prefix(input) + text);
    }
  }

  protected void trace(String text, boolean input) {
    if (statementLog.isTraceEnabled()) {
      statementLog.trace(prefix(input) + text);
    }
  }

  private String prefix(boolean isInput) {
    char[] buffer = new char[queryStack * 2 + 2];
    Arrays.fill(buffer, '=');
    buffer[queryStack * 2 + 1] = ' ';
    if (isInput) {
      buffer[queryStack * 2] = '>';
    } else {
      buffer[0] = '<';
    }
    return new String(buffer);
  }

}

@@ -700,17 +700,85 @@
 ava.
-sql.Array
+lang.reflect.Method;%0Aimport java.sql.Array;%0Aimport java.sql.PreparedStatement
 ;%0Aim
@@ -1010,16 +1010,52 @@
 kenizer;
+%0Aimport java.util.stream.Collectors;
 %0A%0Aimport
@@ -1327,34 +1327,16 @@
 _METHODS
- = new HashSet%3C%3E()
 ;%0A  prot
@@ -1913,823 +1913,272 @@
 HODS
-.add(%22setString%22);%0A    SET_METHODS.add(%22setNString%22);%0A    SET_METHODS.add(%22setInt%22);%0A    SET_METHODS.add(%22setByte%22);%0A    SET_METHODS.add(%22s
+ = Arrays.stream(PreparedStatement.class.getDeclaredM
 et
-S
 ho
-rt%22);%0A    SET_METHODS.add(%22setLong%22);%0A    SET_METHODS.add(%22setDouble%22);%0A    SET_METHODS.add(%22setFloat%22);%0A    SET_METHODS.add(%22setTimestamp%22);%0A    SET_METHODS.add(%22setDate%22);%0A    SET_METHODS.add
+ds())%0A            .filter(method -%3E method.getName().startsWith
 (%22set
-Time
 %22)
-;
+)
 %0A    
-SET_METHODS.add(%22setArray%22);%0A    SET_METHODS.add(%22setBigDecimal%22);%0A    SET_METHODS.add(%22setAsciiStream%22);%0A    SET_METHODS.add(%22setBinaryStream%22);%0A    SET_METHODS.add(%22setBlob%22);%0A    SET_METHODS.add(%22setBoolean%22);%0A    SET_METHODS.add(%22setBytes%22);%0A    SET_METHODS.add(%22setCharacterStream%22);%0A    SET_METHODS.add(%22setNCharacterStream%22);%0A    SET_METHODS.add(%22setClob%22);%0A    SET_METHODS.add(%22setNClob%22);%0A    SET_METHODS.add(%22setObject%22);%0A    SET_METHODS.add(%22setNull%22
+        .filter(method -%3E method.getParameterCount() %3E 1)%0A            .map(Method::getName)%0A            .collect(Collectors.toSet()
 );%0A%0A

Change way that define a setter method to bind to PreparedStatement