概述
Author:ddwcyl
今天,同事反应在使用P6SPY跟踪SQL时感觉不愉快的是对每条查询结果,P6SPY总将其输出,如果查询结果集多的情况下,非常难以调试;另外,在调试时主要关注,替换绑定变量后真实的SQL,来检验业务的正确性,对变更的SQL,并不是太在意。
因为这两个问题的原因,查看了一下P6SPY的源代码,将其涉及的P6ResultSet和FormattedLogger两个类进行了修改,以满足项目调试的需要。
P6ResultSet 相关函数next()修改如下,修改的地方用红色粗体标出:
原始代码为:
public boolean next() throws SQLException {
// only dump the data on subsequent calls to next
if (currRow > -1){
long startTime = System.currentTimeMillis();
StringBuffer buffer = new StringBuffer();
String comma = "";
for (Iterator itr = resultMap.keySet().iterator(); itr.hasNext();){
String index = (String)itr.next();
buffer.append(comma);
buffer.append(index);
buffer.append(" = ");
buffer.append((String)resultMap.get(index));
comma = ", ";
}
P6LogQuery.log("resultset", query, buffer.toString());
resultMap.clear();
}
currRow++;
return passthru.next();
}
修改后代码为:
public boolean next() throws SQLException {
// only dump the data on subsequent calls to next
if (currRow > -1){
long startTime = System.currentTimeMillis();
StringBuffer buffer = new StringBuffer();
String comma = "";
for (Iterator itr = resultMap.keySet().iterator(); itr.hasNext();){
String index = (String)itr.next();
buffer.append(comma);
buffer.append(index);
buffer.append(" = ");
buffer.append((String)resultMap.get(index));
comma = ", ";
}
//to avoid resultset always display,
//mod P6LogQuery.log to P6LogQuery.logElapsed
//it will be controlled by includecategories,exportcategories
// by ddwcyl 2007-08-31
P6Connection p6connection = (P6Connection)this.statement.getConnection();
P6LogQuery.logElapsed(p6connection.getId(), startTime, "resultset", preparedQuery, query);
resultMap.clear();
}
currRow++;
return passthru.next();
}
经过修改后,就可以在spy.properties文件中,的includecategories 或者 exportcategories 的属性中,增加resultset的策略来控制是否显示
FormattedLogger相关函数logSQL 修改如下,修改的地方用红色粗体标出:
原始代码为:
public void logSQL(int connectionId, String now, long elapsed, String category, String prepared, String sql) {
String logEntry = now + "|"+ elapsed + "|"+(connectionId==-1 ? "" : String.valueOf(connectionId))+"|"+category+"|"+prepared+"|"+sql;
logText(logEntry);
}
修改后代码为:
public void logSQL(int connectionId, String now, long elapsed, String category, String prepared, String sql) {
//change logEntry not include prepared SQL
//by ddwcyl 2007-08-31
String logEntry = now + "|"+ elapsed + "|"+(connectionId==-1 ? "" : String.valueOf(connectionId))+"|"+category+"|"+sql;
logText(logEntry);
}
修改后,将prepared(即绑定变量的SQL)去掉不进行显示.
最后
以上就是冷傲乌冬面为你收集整理的修改P6SPY增强ResultSet输出控制的功能的全部内容,希望文章能够帮你解决修改P6SPY增强ResultSet输出控制的功能所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复