improve sql

This commit is contained in:
wenshao
2013-07-31 19:14:18 +08:00
parent b559684c9f
commit c8697e213d
4 changed files with 55 additions and 21 deletions
@@ -143,6 +143,8 @@ public abstract class WallProvider {
}
public void addUpdateCount(WallSqlStat sqlStat, long updateCount) {
sqlStat.addUpdateCount(updateCount);
Map<String, WallSqlTableStat> sqlTableStats = sqlStat.getTableStats();
if (sqlTableStats == null) {
return;
@@ -168,7 +170,7 @@ public abstract class WallProvider {
}
public void addFetchRowCount(WallSqlStat sqlStat, long fetchRowCount) {
sqlStat.addAndGetEffectRowCount(fetchRowCount);
sqlStat.addAndFetchRowCount(fetchRowCount);
Map<String, WallSqlTableStat> sqlTableStats = sqlStat.getTableStats();
if (sqlTableStats == null) {
@@ -25,13 +25,15 @@ import java.util.concurrent.atomic.AtomicLongFieldUpdater;
public class WallSqlStat {
private volatile long executeCount;
private volatile long effectRowCount;
final static AtomicLongFieldUpdater<WallSqlStat> executeCountUpdater = AtomicLongFieldUpdater.newUpdater(WallSqlStat.class,
"executeCount");
final static AtomicLongFieldUpdater<WallSqlStat> effectRowCountUpdater = AtomicLongFieldUpdater.newUpdater(WallSqlStat.class,
"effectRowCount");
private volatile long fetchRowCount;
private volatile long updateCount;
final static AtomicLongFieldUpdater<WallSqlStat> executeCountUpdater = AtomicLongFieldUpdater.newUpdater(WallSqlStat.class,
"executeCount");
final static AtomicLongFieldUpdater<WallSqlStat> fetchRowCountUpdater = AtomicLongFieldUpdater.newUpdater(WallSqlStat.class,
"fetchRowCount");
final static AtomicLongFieldUpdater<WallSqlStat> updateCountUpdater = AtomicLongFieldUpdater.newUpdater(WallSqlStat.class,
"updateCount");
private final Map<String, WallSqlTableStat> tableStats;
private final List<Violation> violations;
@@ -71,16 +73,24 @@ public class WallSqlStat {
return executeCount;
}
public long incrementAndGetEffectRowCount() {
return effectRowCountUpdater.incrementAndGet(this);
public long incrementAndGetFetchRowCount() {
return fetchRowCountUpdater.incrementAndGet(this);
}
public long addAndGetEffectRowCount(long delta) {
return effectRowCountUpdater.addAndGet(this, delta);
public long addAndFetchRowCount(long delta) {
return fetchRowCountUpdater.addAndGet(this, delta);
}
public long getEffectRowCount() {
return effectRowCount;
return fetchRowCount;
}
public long getUpdateCount() {
return updateCount;
}
public void addUpdateCount(long delta) {
updateCountUpdater.addAndGet(this, delta);
}
public Map<String, WallSqlTableStat> getTableStats() {
@@ -103,7 +113,8 @@ public class WallSqlStat {
final WallSqlStatValue statValue = new WallSqlStatValue();
statValue.setExecuteCount(get(this, executeCountUpdater, reset));
statValue.setEffectRowCount(get(this, effectRowCountUpdater, reset));
statValue.setFetchRowCount(get(this, fetchRowCountUpdater, reset));
statValue.setUpdateCount(get(this, updateCountUpdater, reset));
statValue.setSyntaxError(this.syntaxError);
statValue.setSqlSample(sample);
if (violations.size() > 0) {
@@ -23,7 +23,8 @@ public class WallSqlStatValue {
private String sql;
private String sqlSample;
private long executeCount;
private long effectRowCount;
private long fetchRowCount;
private long updateCount;
private boolean syntaxError;
private String violationMessage;
@@ -55,12 +56,20 @@ public class WallSqlStatValue {
this.executeCount = executeCount;
}
public long getEffectRowCount() {
return effectRowCount;
public long getFetchRowCount() {
return fetchRowCount;
}
public void setEffectRowCount(long effectRowCount) {
this.effectRowCount = effectRowCount;
public void setFetchRowCount(long fetchRowCount) {
this.fetchRowCount = fetchRowCount;
}
public long getUpdateCount() {
return updateCount;
}
public void setUpdateCount(long updateCount) {
this.updateCount = updateCount;
}
public boolean isSyntaxError() {
@@ -86,8 +95,18 @@ public class WallSqlStatValue {
sqlStatMap.put("sample", sqlSample);
}
sqlStatMap.put("executeCount", getExecuteCount());
sqlStatMap.put("effectRowCount", getEffectRowCount());
sqlStatMap.put("violationMessage", getViolationMessage());
if (fetchRowCount > 0) {
sqlStatMap.put("fetchRowCount", fetchRowCount);
}
if (updateCount > 0) {
sqlStatMap.put("updateCount", updateCount);
}
if (violationMessage != null) {
sqlStatMap.put("violationMessage", violationMessage);
}
return sqlStatMap;
}
@@ -164,7 +164,7 @@ public class WallTableStatValue {
public void setFetchRowCount(long fetchRowCount) {
this.fetchRowCount = fetchRowCount;
}
public Map<String, Object> toMap() {
Map<String, Object> map = new LinkedHashMap<String, Object>();
toMap(map);
@@ -172,6 +172,8 @@ public class WallTableStatValue {
}
public Map<String, Object> toMap(Map<String, Object> map) {
map.put("name", name);
if (selectCount > 0) {
map.put("selectCount", selectCount);
}