mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql-wall
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.druid.wall;
|
||||
|
||||
import static com.alibaba.druid.util.JdbcSqlStatUtils.get;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -29,7 +31,7 @@ public class WallSqlStat {
|
||||
"executeCount");
|
||||
final static AtomicLongFieldUpdater<WallSqlStat> effectRowCountUpdater = AtomicLongFieldUpdater.newUpdater(WallSqlStat.class,
|
||||
"effectRowCount");
|
||||
|
||||
|
||||
private final Map<String, WallSqlTableStat> tableStats;
|
||||
|
||||
private final List<Violation> violations;
|
||||
@@ -38,6 +40,8 @@ public class WallSqlStat {
|
||||
|
||||
private final boolean syntaxError;
|
||||
|
||||
private String sample;
|
||||
|
||||
public WallSqlStat(Map<String, WallSqlTableStat> tableStats, Map<String, WallSqlFunctionStat> functionStats,
|
||||
boolean syntaxError){
|
||||
this(tableStats, functionStats, Collections.<Violation> emptyList(), syntaxError);
|
||||
@@ -51,6 +55,14 @@ public class WallSqlStat {
|
||||
this.syntaxError = syntaxError;
|
||||
}
|
||||
|
||||
public String getSample() {
|
||||
return sample;
|
||||
}
|
||||
|
||||
public void setSample(String sample) {
|
||||
this.sample = sample;
|
||||
}
|
||||
|
||||
public long incrementAndGetExecuteCount() {
|
||||
return executeCountUpdater.incrementAndGet(this);
|
||||
}
|
||||
@@ -58,15 +70,15 @@ public class WallSqlStat {
|
||||
public long getExecuteCount() {
|
||||
return executeCount;
|
||||
}
|
||||
|
||||
|
||||
public long incrementAndGetEffectRowCount() {
|
||||
return effectRowCountUpdater.incrementAndGet(this);
|
||||
}
|
||||
|
||||
|
||||
public long addAndGetEffectRowCount(long delta) {
|
||||
return effectRowCountUpdater.addAndGet(this, delta);
|
||||
}
|
||||
|
||||
|
||||
public long getEffectRowCount() {
|
||||
return effectRowCount;
|
||||
}
|
||||
@@ -86,4 +98,19 @@ public class WallSqlStat {
|
||||
public boolean isSyntaxError() {
|
||||
return syntaxError;
|
||||
}
|
||||
|
||||
public WallSqlStatValue getStatValue(boolean reset) {
|
||||
final WallSqlStatValue statValue = new WallSqlStatValue();
|
||||
|
||||
statValue.setExecuteCount(get(this, executeCountUpdater, reset));
|
||||
statValue.setEffectRowCount(get(this, effectRowCountUpdater, reset));
|
||||
statValue.setSyntaxError(this.syntaxError);
|
||||
statValue.setSqlSample(sample);
|
||||
if (violations.size() > 0) {
|
||||
String violationMessage = violations.get(0).getMessage();
|
||||
statValue.setViolationMessage(violationMessage);
|
||||
}
|
||||
|
||||
return statValue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user