This commit is contained in:
温少
2012-03-19 09:08:52 +08:00
parent 6624603b20
commit ca5679a2be
4 changed files with 74 additions and 48 deletions
@@ -29,6 +29,8 @@ public class WallConfig {
private boolean truncateAllow = false;
private boolean commentAllow = false;
private boolean schemaCheck = true;
private boolean tableCheck = true;
private boolean functionCheck = true;
@@ -238,6 +240,14 @@ public class WallConfig {
// ///////////////////
public boolean isCommentAllow() {
return commentAllow;
}
public void setCommentAllow(boolean commentAllow) {
this.commentAllow = commentAllow;
}
public Set<String> getPermitFunctions() {
return permitFunctions;
}
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.parser.ParserException;
@@ -19,10 +20,12 @@ public abstract class WallProvider {
private int whileListMaxSize = 1024;
private int whiteSqlMaxLength = 1024; // 1k
private int whiteSqlMaxLength = 1024; // 1k
protected final WallConfig config;
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
public WallProvider(WallConfig config){
this.config = config;
}
@@ -31,26 +34,36 @@ public abstract class WallProvider {
return config;
}
public synchronized void addWhiteSql(String sql) {
if (whiteList == null) {
whiteList = new LinkedHashMap<String, Object>(whileListMaxSize, 0.75f, true);
}
public void addWhiteSql(String sql) {
lock.writeLock().lock();
try {
if (whiteList == null) {
whiteList = new LinkedHashMap<String, Object>(whileListMaxSize, 0.75f, true);
}
whiteList.put(sql, PRESENT);
whiteList.put(sql, PRESENT);
} finally {
lock.writeLock().unlock();
}
}
public synchronized boolean whiteContains(String sql) {
if (whiteList == null) {
return false;
}
public boolean whiteContains(String sql) {
lock.readLock().lock();
try {
if (whiteList == null) {
return false;
}
return whiteList.get(sql) != null;
return whiteList.get(sql) != null;
} finally {
lock.readLock().unlock();
}
}
public abstract SQLStatementParser createParser(String sql);
public abstract WallVisitor createWallVisitor();
public boolean checkValid(String sql) {
return check(sql).size() == 0;
}
@@ -63,7 +76,10 @@ public abstract class WallProvider {
}
SQLStatementParser parser = createParser(sql);
parser.getLexer().setAllowComment(false); // permit comment
if (!config.isCommentAllow()) {
parser.getLexer().setAllowComment(false); // permit comment
}
List<SQLStatement> statementList = new ArrayList<SQLStatement>();
@@ -55,44 +55,44 @@ backupset
sysdatabases
sysservers
sysreplicationalerts
MSagent_parameters
Mspublisher_databases
MSagent_profiles
MSreplication_objects
MSarticles
MSreplication_subscriptions
MSdistpublishers
MSrepl_commands
MSdistributiondbs
MSrepl_errors
MSdistribution_agents
MSrepl_originators
MSdistribution_history
MSrepl_transactions
MSdistributor
MSrepl_version
MSlogreader_agents
MSsnapshot_agents
MSlogreader_history
MSsnapshot_history
MSmerge_agents
MSsubscriber_info
MSmerge_history
MSsubscriber_schedule
MSmerge_subscriptions
MSsubscriptions
MSpublication_access
MSsubscription_properties
Mspublications
MSmerge_contents
msagent_parameters
mspublisher_databases
msagent_profiles
msreplication_objects
msarticles
msreplication_subscriptions
msdistpublishers
msrepl_commands
msdistributiondbs
msrepl_errors
msdistribution_agents
msrepl_originators
msdistribution_history
msrepl_transactions
msdistributor
msrepl_version
mslogreader_agents
mssnapshot_agents
mslogreader_history
mssnapshot_history
msmerge_agents
mssubscriber_info
msmerge_history
mssubscriber_schedule
msmerge_subscriptions
mssubscriptions
mspublication_access
mssubscription_properties
mspublications
msmerge_contents
sysmergearticles
MSmerge_delete_conflicts
msmerge_delete_conflicts
sysmergepublications
MSmerge_genhistory
msmerge_genhistory
sysmergeschemachange
MSmerge_replinfo
msmerge_replinfo
sysmergesubscriptions
MSmerge_tombstone
msmerge_tombstone
sysmergesubsetfilters
sysarticles
syspublications
@@ -22,7 +22,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/
<property name="config" ref="wall-filter-config" />
</bean>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
destroy-method="close">
<property name="url">
<value>jdbc:mock:</value>