添加SQL统计功能,统计SQL中所使用的表和字段

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@269 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-06-21 15:46:09 +00:00
parent 597383d6af
commit 6ca6031364
10 changed files with 178 additions and 155 deletions
@@ -0,0 +1,158 @@
package com.alibaba.druid.stat;
public class TableStat {
int selectCount = 0;
int updateCount = 0;
int deleteCount = 0;
int insertCount = 0;
public int getSelectCount() {
return selectCount;
}
public void incrementSelectCount() {
selectCount++;
}
public void setSelectCount(int selectCount) {
this.selectCount = selectCount;
}
public int getUpdateCount() {
return updateCount;
}
public void incrementUpdateCount() {
updateCount++;
}
public void setUpdateCount(int updateCount) {
this.updateCount = updateCount;
}
public int getDeleteCount() {
return deleteCount;
}
public void incrementDeleteCount() {
this.deleteCount++;
}
public void setDeleteCount(int deleteCount) {
this.deleteCount = deleteCount;
}
public void incrementInsertCount() {
this.insertCount++;
}
public int getInsertCount() {
return insertCount;
}
public void setInsertCount(int insertCount) {
this.insertCount = insertCount;
}
public String toString() {
StringBuilder buf = new StringBuilder(4);
if (insertCount > 0) {
buf.append("C");
}
if (updateCount > 0) {
buf.append("U");
}
if (selectCount > 0) {
buf.append("R");
}
if (deleteCount > 0) {
buf.append("D");
}
return buf.toString();
}
public static class Column {
private String table;
private String name;
public Column(){
}
public Column(String table, String name){
this.table = table;
this.name = name;
}
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int hashCode() {
int tableHashCode = table != null ? table.toLowerCase().hashCode() : 0;
int nameHashCode = name != null ? name.toLowerCase().hashCode() : 0;
return tableHashCode + nameHashCode;
}
public String toString() {
if (table != null) {
return table + "." + name;
}
return name;
}
public boolean equals(Object obj) {
Column column = (Column) obj;
if (table == null) {
if (column.getTable() != null) {
return false;
}
} else {
if (!table.equalsIgnoreCase(column.getTable())) {
return false;
}
}
if (name == null) {
if (column.getName() != null) {
return false;
}
} else {
if (!name.equalsIgnoreCase(column.getName())) {
return false;
}
}
return true;
}
}
public static enum Mode {
Insert(1), Update(2), Delete(4), Select(8);
public final int mark;
private Mode(int mark){
this.mark = mark;
}
}
}