Commit c1703d87 authored by yanzg's avatar yanzg

处理SQL语句

parent f995b489
......@@ -50,7 +50,7 @@ public class DbExecuteImpl implements DbExecute {
row = jdbc.update(sql, paras);
return row;
} finally {
printSql.print(targetClass, sqlName, row, sql, paras, start);
printSql.print(targetClass, sqlName, start, row, sql, paras);
}
}
......@@ -81,7 +81,7 @@ public class DbExecuteImpl implements DbExecute {
}
});
} finally {
printSql.print(targetClass, sqlName, row.value, sql, paras, start);
printSql.print(targetClass, sqlName, start, row.value, sql, paras);
}
}
......@@ -109,7 +109,7 @@ public class DbExecuteImpl implements DbExecute {
row = ret.size();
return ret;
} finally {
printSql.print(targetClass, sqlName, row, sql, paras, start);
printSql.print(targetClass, sqlName, start, row, sql, paras);
}
}
......@@ -147,7 +147,7 @@ public class DbExecuteImpl implements DbExecute {
}
return null;
} finally {
printSql.print(targetClass, sqlName, row, sql, paras, start);
printSql.print(targetClass, sqlName, start, row, sql, paras);
}
}
......
......@@ -14,23 +14,13 @@ public class DbPrintSql {
private ConfigDb configDb;
/**
* 打印SQL语句
* 获取参数处理之后的SQL语句
*
* @param targetClass 触发类
* @param sqlName SQL语句名称
* @param sql SQL语句
* @param sql 带参数的SQL语句
* @param paras 参数
* @return 不带参数的SQL语句
*/
public void print(Class targetClass, String sqlName, int row, String sql, Object... paras) {
// 日志表忽略打印
if (!configDb.isPrintSql()) {
return;
}
if (!StringHelper.isEmpty(configDb.getPrintSqlFilter())) {
if (sql.matches(configDb.getPrintSqlFilter())) {
return;
}
}
public String getStringSql(String sql, Object... paras) {
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
for (Object item : paras) {
String str = StringHelper.toString(item);
......@@ -40,12 +30,37 @@ public class DbPrintSql {
} else {
sql = sql.replaceFirst("\\?", str);
}
} else {
sql = sql.replaceFirst("\\?", "'" + str.replace("'", "''") + "'");
}
}
return sql;
}
/**
* 打印SQL语句
*
* @param targetClass 触发类
* @param sqlName SQL语句名称
* @param start 开始执行的语句
* @param row SQL语句
* @param sql SQL语句
* @param paras 参数
*/
public void print(Class targetClass, String sqlName, long start, int row, String sql, Object... paras) {
// 日志表忽略打印
if (!configDb.isPrintSql()) {
return;
}
if (!StringHelper.isEmpty(configDb.getPrintSqlFilter())) {
if (sql.matches(configDb.getPrintSqlFilter())) {
return;
}
}
sql = getStringSql(sql, paras);
// 打印SQL语句
Log.infoTag(DbPrintSql.class, String.format("%d row %s.%s", row, targetClass.getSimpleName(), sqlName), sql);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment