mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #122 from wenshao/master
修正sonar规则检查中发现的违例警告,补充测试,去除无用代码
This commit is contained in:
@@ -26,8 +26,6 @@ import java.util.Properties;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.proxy.config.AbstractDruidFilterConfig;
|
||||
import com.alibaba.druid.proxy.config.EncodingDruidFilterConfig;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
@@ -46,14 +44,6 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
private String clientEncoding;
|
||||
private String serverEncoding;
|
||||
|
||||
public void loadConfig(AbstractDruidFilterConfig druidFilterConfig) {
|
||||
EncodingDruidFilterConfig druidEncodingFilterConfig = (EncodingDruidFilterConfig) druidFilterConfig;
|
||||
if (druidEncodingFilterConfig != null) {
|
||||
clientEncoding = druidEncodingFilterConfig.getClientEncoding();
|
||||
serverEncoding = druidEncodingFilterConfig.getServerEncoding();
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
|
||||
ConnectionProxy conn = chain.connection_connect(info);
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.proxy.config;
|
||||
|
||||
/**
|
||||
* @author gang.su
|
||||
*/
|
||||
public abstract class AbstractDruidFilterConfig {
|
||||
|
||||
private String name;
|
||||
private String clazz;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public void setClazz(String clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.proxy.config;
|
||||
|
||||
/**
|
||||
* @author gang.su
|
||||
*/
|
||||
public class DruidFilterConfig extends AbstractDruidFilterConfig {
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.proxy.config;
|
||||
|
||||
/**
|
||||
* druid filter配置 来源于配置文件
|
||||
*
|
||||
* @author gang.su
|
||||
*/
|
||||
public class EncodingDruidFilterConfig extends AbstractDruidFilterConfig {
|
||||
|
||||
private String clientEncoding;
|
||||
|
||||
private String serverEncoding;
|
||||
|
||||
public String getClientEncoding() {
|
||||
return clientEncoding;
|
||||
}
|
||||
|
||||
public void setClientEncoding(String clientEncoding) {
|
||||
this.clientEncoding = clientEncoding;
|
||||
}
|
||||
|
||||
public String getServerEncoding() {
|
||||
return serverEncoding;
|
||||
}
|
||||
|
||||
public void setServerEncoding(String serverEncoding) {
|
||||
this.serverEncoding = serverEncoding;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -686,7 +686,7 @@ public class OracleSelectParser extends SQLSelectParser {
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
lexer.nextToken();
|
||||
OracleSelectSubqueryTableSource tableSource;
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
if (lexer.token() == Token.SELECT || lexer.token() == Token.WITH) {
|
||||
tableSource = new OracleSelectSubqueryTableSource(select());
|
||||
} else if (lexer.token() == (Token.LPAREN)) {
|
||||
tableSource = new OracleSelectSubqueryTableSource(select());
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class FilterChainImplTest extends TestCase {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat,log4j,wall");
|
||||
dataSource.setFilters("stat,log4j,wall,encoding");
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
});
|
||||
dataSource.setDbType("mysql");
|
||||
|
||||
@@ -20,7 +20,7 @@ public class FilterChainImplTest2 extends TestCase {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat,log4j,wall");
|
||||
dataSource.setFilters("stat,log4j,wall,encoding");
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {} );
|
||||
dataSource.setDbType("mysql");
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class FilterChainImplTest3 extends TestCase {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat,log4j,wall");
|
||||
dataSource.setFilters("stat,log4j,wall,encoding");
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {} );
|
||||
dataSource.setDbType("mysql");
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import junit.framework.TestCase;
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.proxy.DruidDriver;
|
||||
import com.alibaba.druid.proxy.config.AbstractDruidFilterConfig;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.oracle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
|
||||
public class OracleSelectTest38 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"select * from " +
|
||||
"(with vw_kreis_statics_t as" +
|
||||
" (select substr(xzqh,1,6) xzqh,swrslx,sum(swrs_count) acd_totle from" +
|
||||
" (select xzqh,sglx,case when (swrs7 < 3) then '1'" +
|
||||
" when (swrs7 < 5) then '2' when (swrs7 <= 9) then '3' else '4' end swrslx,1 swrs_count" +
|
||||
" from acduser.vw_acd_info where sglx='1' " +
|
||||
" " +
|
||||
" and sgfssj >= ?" +
|
||||
" " +
|
||||
" " +
|
||||
" )" +
|
||||
" group by substr(xzqh,1,6),swrslx)" +
|
||||
"" +
|
||||
" select e.\"XZQH\",e.\"LESS3\",e.\"F3TO5\",e.\"F5TO9\",e.\"MORE9\",kreis_code, kreis_name,px1,py1,px2,py2 from" +
|
||||
" ( select" +
|
||||
" xzqh," +
|
||||
" nvl(max(decode(swrslx,'1',acd_totle)),0) less3," +
|
||||
" nvl(max(decode(swrslx,'2',acd_totle)),0) f3to5," +
|
||||
" nvl(max(decode(swrslx,'3',acd_totle)),0) f5to9," +
|
||||
" nvl(max(decode(swrslx,'4',acd_totle)),0) more9" +
|
||||
" from( select * from acduser.vw_kreis_statics_t) group by xzqh " +
|
||||
" ) e" +
|
||||
"" +
|
||||
" left join" +
|
||||
" acduser.vw_sc_kreis_code_lv2 f on e.xzqh = f.short_kreis_code) " +
|
||||
" where kreis_code in" +
|
||||
"(select * from " +
|
||||
" (select tbek_code from acduser.vw_kreis_code start with tbek_code = ? connect by prior tbek_pk=tbek_parent ) " +
|
||||
"where tbek_code != ?)"; //
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(4, visitor.getTables().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("acduser.vw_acd_info")));
|
||||
|
||||
Assert.assertEquals(15, visitor.getColumns().size());
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "sglx")));
|
||||
|
||||
// Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user