Search in sources :

Example 1 with JdbcParameter

use of com.alibaba.druid.proxy.jdbc.JdbcParameter in project druid by alibaba.

the class StatFilter method buildSlowParameters.

private String buildSlowParameters(StatementProxy statement) {
    JSONWriter out = new JSONWriter();
    out.writeArrayStart();
    for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) {
        JdbcParameter parameter = statement.getParameter(i);
        if (i != 0) {
            out.writeComma();
        }
        if (parameter == null) {
            continue;
        }
        Object value = parameter.getValue();
        if (value == null) {
            out.writeNull();
        } else if (value instanceof String) {
            String text = (String) value;
            if (text.length() > 100) {
                out.writeString(text.substring(0, 97) + "...");
            } else {
                out.writeString(text);
            }
        } else if (value instanceof Number) {
            out.writeObject(value);
        } else if (value instanceof java.util.Date) {
            out.writeObject(value);
        } else if (value instanceof Boolean) {
            out.writeObject(value);
        } else if (value instanceof InputStream) {
            out.writeString("<InputStream>");
        } else if (value instanceof NClob) {
            out.writeString("<NClob>");
        } else if (value instanceof Clob) {
            out.writeString("<Clob>");
        } else if (value instanceof Blob) {
            out.writeString("<Blob>");
        } else {
            out.writeString('<' + value.getClass().getName() + '>');
        }
    }
    out.writeArrayEnd();
    return out.toString();
}
Also used : JSONWriter(com.alibaba.druid.support.json.JSONWriter) NClob(java.sql.NClob) Blob(java.sql.Blob) JdbcParameter(com.alibaba.druid.proxy.jdbc.JdbcParameter) Date(java.util.Date) InputStream(java.io.InputStream) Savepoint(java.sql.Savepoint) NClob(java.sql.NClob) Clob(java.sql.Clob)

Example 2 with JdbcParameter

use of com.alibaba.druid.proxy.jdbc.JdbcParameter in project druid by alibaba.

the class LogFilter method logExecutableSql.

private void logExecutableSql(StatementProxy statement, String sql) {
    if (!isStatementExecutableSqlLogEnable()) {
        return;
    }
    int parametersSize = statement.getParametersSize();
    if (parametersSize == 0) {
        statementLog("{conn-" + statement.getConnectionProxy().getId() + ", " + stmtId(statement) + "} executed. " + sql);
        return;
    }
    List<Object> parameters = new ArrayList<Object>(parametersSize);
    for (int i = 0; i < parametersSize; ++i) {
        JdbcParameter jdbcParam = statement.getParameter(i);
        parameters.add(jdbcParam != null ? jdbcParam.getValue() : null);
    }
    String dbType = statement.getConnectionProxy().getDirectDataSource().getDbType();
    String formattedSql = SQLUtils.format(sql, dbType, parameters, this.statementSqlFormatOption);
    statementLog("{conn-" + statement.getConnectionProxy().getId() + ", " + stmtId(statement) + "} executed. " + formattedSql);
}
Also used : JdbcParameter(com.alibaba.druid.proxy.jdbc.JdbcParameter) ArrayList(java.util.ArrayList) Savepoint(java.sql.Savepoint)

Aggregations

JdbcParameter (com.alibaba.druid.proxy.jdbc.JdbcParameter)2 Savepoint (java.sql.Savepoint)2 JSONWriter (com.alibaba.druid.support.json.JSONWriter)1 InputStream (java.io.InputStream)1 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 NClob (java.sql.NClob)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1