mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve wall filter
This commit is contained in:
@@ -15,17 +15,40 @@
|
||||
*/
|
||||
package com.alibaba.druid.wall;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WallContext {
|
||||
|
||||
private final static ThreadLocal<WallContext> contextLocal = new ThreadLocal<WallContext>();
|
||||
|
||||
private WallSqlStat sqlState;
|
||||
private Map<String, WallSqlTableStat> tableStats;
|
||||
private final String dbType;
|
||||
|
||||
public WallContext(String dbType){
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public WallSqlTableStat getTableStat(String tableName) {
|
||||
if (tableStats == null) {
|
||||
tableStats = new HashMap<String, WallSqlTableStat>(2);
|
||||
}
|
||||
|
||||
String lowerCaseName = tableName.toLowerCase();
|
||||
|
||||
WallSqlTableStat stat = tableStats.get(lowerCaseName);
|
||||
if (stat == null) {
|
||||
if (tableStats.size() > 10000) {
|
||||
return null;
|
||||
}
|
||||
|
||||
stat = new WallSqlTableStat();
|
||||
tableStats.put(tableName, stat);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static WallContext createIfNotExists(String dbType) {
|
||||
WallContext context = contextLocal.get();
|
||||
if (context == null) {
|
||||
@@ -35,6 +58,12 @@ public class WallContext {
|
||||
return context;
|
||||
}
|
||||
|
||||
public static WallContext create(String dbType) {
|
||||
WallContext context = new WallContext(dbType);
|
||||
contextLocal.set(context);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static WallContext current() {
|
||||
return contextLocal.get();
|
||||
}
|
||||
@@ -51,6 +80,10 @@ public class WallContext {
|
||||
this.sqlState = sqlState;
|
||||
}
|
||||
|
||||
public Map<String, WallSqlTableStat> getTableStats() {
|
||||
return tableStats;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user