Merge pull request #364 from wenshao/master

request for bulk integrate
This commit is contained in:
温高铁
2013-06-09 08:37:19 -07:00
62 changed files with 18366 additions and 17378 deletions
File diff suppressed because it is too large Load Diff
@@ -33,7 +33,7 @@ public class FilterManager {
private final static Log LOG = LogFactory.getLog(FilterManager.class);
private static final ConcurrentHashMap<String, String> aliasMap = new ConcurrentHashMap<String, String>();
private static final ConcurrentHashMap<String, String> aliasMap = new ConcurrentHashMap<String, String>(16, 0.75f, 1);
static {
try {
File diff suppressed because it is too large Load Diff
@@ -21,7 +21,6 @@ import java.sql.Savepoint;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.filter.FilterEventAdapter;
@@ -507,15 +506,16 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM
return;
}
Map<Integer, JdbcParameter> parameterMap = statement.getParameters();
if (parameterMap == null || parameterMap.size() == 0) {
int parametersSize = statement.getParametersSize();
if (parametersSize == 0) {
statementLog("{conn-" + statement.getConnectionProxy().getId() + ", " + stmtId(statement) + "} executed. "
+ sql);
return;
}
List<Object> parameters = new ArrayList<Object>(parameterMap.size());
for (JdbcParameter jdbcParam : parameterMap.values()) {
List<Object> parameters = new ArrayList<Object>(parametersSize);
for (int i = 0; i < parametersSize; ++i) {
JdbcParameter jdbcParam = statement.getParameter(i);
parameters.add(jdbcParam.getValue());
}
@@ -737,11 +737,16 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM
buf.append(stmtId(statement));
buf.append("}");
buf.append(" Parameters : [");
int parameterIndex = 0;
for (JdbcParameter parameter : statement.getParameters().values()) {
if (parameterIndex != 0) {
for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) {
JdbcParameter parameter = statement.getParameter(i);
if (i != 0) {
buf.append(", ");
}
if (parameter == null) {
continue;
}
int sqlType = parameter.getSqlType();
Object value = parameter.getValue();
switch (sqlType) {
@@ -752,7 +757,6 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM
buf.append(String.valueOf(value));
break;
}
parameterIndex++;
}
buf.append("]");
statementLog(buf.toString());
@@ -765,14 +769,16 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM
buf.append(stmtId(statement));
buf.append("}");
buf.append(" Types : [");
int parameterIndex = 0;
for (JdbcParameter parameter : statement.getParameters().values()) {
if (parameterIndex != 0) {
for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) {
JdbcParameter parameter = statement.getParameter(i);
if (i != 0) {
buf.append(", ");
}
if (parameter == null) {
continue;
}
int sqlType = parameter.getSqlType();
buf.append(JdbcUtils.getTypeName(sqlType));
parameterIndex++;
}
buf.append("]");
statementLog(buf.toString());
File diff suppressed because it is too large Load Diff
@@ -17,6 +17,8 @@ package com.alibaba.druid.pool;
import java.util.Properties;
import com.alibaba.druid.support.logging.Log;
/**
* @author wenshao<szujobs@hotmail.com>
* @since 0.2.19
@@ -30,4 +32,8 @@ public interface DruidDataSourceStatLogger {
* @since 0.2.21
*/
void configFromProperties(Properties properties);
void setLogger(Log logger);
void setLoggerName(String loggerName);
}
@@ -17,12 +17,14 @@ package com.alibaba.druid.pool;
import java.util.Properties;
import com.alibaba.druid.support.logging.Log;
/**
*
* @author wenshao<szujobs@hotmail.com>
* @since 0.2.21
*/
public abstract class DruidDataSourceStatLoggerAdapter implements DruidDataSourceStatLogger {
public class DruidDataSourceStatLoggerAdapter implements DruidDataSourceStatLogger {
@Override
public void log(DruidDataSourceStatValue statValue) {
@@ -34,4 +36,14 @@ public abstract class DruidDataSourceStatLoggerAdapter implements DruidDataSourc
}
@Override
public void setLogger(Log logger) {
}
@Override
public void setLoggerName(String loggerName) {
}
}
@@ -56,20 +56,30 @@ public class DruidDataSourceStatLoggerImpl extends DruidDataSourceStatLoggerAdap
return logger;
}
@Override
public void setLoggerName(String loggerName) {
logger = LogFactory.getLog(loggerName);
}
@Override
public void setLogger(Log logger) {
if (logger == null) {
throw new IllegalArgumentException("logger can not be null");
}
this.logger = logger;
}
public boolean isLogEnable() {
return logger.isInfoEnabled();
}
public void log(String value) {
logger.info(value);
}
@Override
public void log(DruidDataSourceStatValue statValue) {
if (logger.isInfoEnabled()) {
if (isLogEnable()) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("url", statValue.url);
@@ -225,7 +235,7 @@ public class DruidDataSourceStatLoggerImpl extends DruidDataSourceStatLoggerAdap
String text = JSONUtils.toJSONString(map);
logger.info(text);
log(text);
}
}
File diff suppressed because it is too large Load Diff
@@ -145,7 +145,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
return;
}
if (holder.isPoolPreparedStatements()) {
if (stmt.isPooled()) {
try {
rawStatement.clearParameters();
} catch (SQLException ex) {
@@ -159,7 +159,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
}
stmt.getPreparedStatementHolder().decrementInUseCount();
if (holder.isPoolPreparedStatements()) {
if (stmt.isPooled() && holder.isPoolPreparedStatements()) {
holder.getStatementPool().put(stmt.getPreparedStatementHolder());
stmt.clearResultSet();
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -53,7 +53,7 @@ public class DruidDriver implements Driver, DruidDriverMBean {
private final static DruidDriver instance = new DruidDriver();
private final static ConcurrentMap<String, DataSourceProxyImpl> proxyDataSources = new ConcurrentHashMap<String, DataSourceProxyImpl>();
private final static ConcurrentMap<String, DataSourceProxyImpl> proxyDataSources = new ConcurrentHashMap<String, DataSourceProxyImpl>(16, 0.75f, 1);
private final static AtomicInteger dataSourceIdSeed = new AtomicInteger(0);
private final static AtomicInteger sqlStatIdSeed = new AtomicInteger(0);
File diff suppressed because it is too large Load Diff
@@ -20,7 +20,7 @@ import java.util.Calendar;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public class JdbcParameter {
public interface JdbcParameter {
public static final int BinaryInputStream = 10001;
public static final int AsciiInputStream = 10002;
@@ -28,56 +28,6 @@ public class JdbcParameter {
public static final int NCharacterInputStream = 10004;
public static final int URL = 10005;
private final int sqlType;
private final Object value;
private final long length;
private final Calendar calendar;
private final int scaleOrLength;
public JdbcParameter(int sqlType, Object value, long length, Calendar calendar, int scaleOrLength){
this.sqlType = sqlType;
this.value = value;
this.length = length;
this.calendar = calendar;
this.scaleOrLength = scaleOrLength;
}
public JdbcParameter(int sqlType, Object value, long length, Calendar calendar){
this(sqlType, value, -1, null, -1);
}
public JdbcParameter(int sqlType, Object value){
this(sqlType, value, -1, null);
}
public JdbcParameter(int sqlType, Object value, long length){
this(sqlType, value, length, null);
}
public JdbcParameter(int sqlType, Object value, Calendar calendar){
this(sqlType, value, -1, calendar);
}
public int getScaleOrLength() {
return scaleOrLength;
}
public Object getValue() {
return value;
}
public long getLength() {
return length;
}
public Calendar getCalendar() {
return calendar;
}
public int getSqlType() {
return sqlType;
}
public static interface TYPE {
public static final int BinaryInputStream = 10001;
@@ -89,4 +39,12 @@ public class JdbcParameter {
public static final int BYTES = 10007;
}
Object getValue();
long getLength();
Calendar getCalendar();
int getSqlType();
}
@@ -0,0 +1,49 @@
/*
* 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.jdbc;
import java.sql.Types;
import java.util.Calendar;
import java.util.Date;
public final class JdbcParameterDate implements JdbcParameter {
private final Date value;
public JdbcParameterDate(Date value){
this.value = value;
}
@Override
public Object getValue() {
return value;
}
@Override
public long getLength() {
return 0;
}
@Override
public Calendar getCalendar() {
return null;
}
@Override
public int getSqlType() {
return Types.DATE;
}
}
@@ -0,0 +1,70 @@
/*
* 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.jdbc;
import java.math.BigDecimal;
import java.sql.Types;
import java.util.Calendar;
public final class JdbcParameterDecimal implements JdbcParameter {
private final BigDecimal value;
public static JdbcParameterDecimal NULL = new JdbcParameterDecimal(null);
public static JdbcParameterDecimal ZERO = new JdbcParameterDecimal(BigDecimal.ZERO);
public static JdbcParameterDecimal TEN = new JdbcParameterDecimal(BigDecimal.TEN);
private JdbcParameterDecimal(BigDecimal value){
this.value = value;
}
public static JdbcParameterDecimal valueOf(BigDecimal x) {
if (x == null) {
return NULL;
}
if (x == BigDecimal.ZERO) {
return ZERO;
}
if (x == BigDecimal.TEN) {
return TEN;
}
return new JdbcParameterDecimal(x);
}
@Override
public Object getValue() {
return value;
}
@Override
public long getLength() {
return 0;
}
@Override
public Calendar getCalendar() {
return null;
}
@Override
public int getSqlType() {
return Types.DECIMAL;
}
}
@@ -0,0 +1,71 @@
/*
* 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.jdbc;
import java.util.Calendar;
public final class JdbcParameterImpl implements JdbcParameter {
private final int sqlType;
private final Object value;
private final long length;
private final Calendar calendar;
private final int scaleOrLength;
public JdbcParameterImpl(int sqlType, Object value, long length, Calendar calendar, int scaleOrLength){
this.sqlType = sqlType;
this.value = value;
this.length = length;
this.calendar = calendar;
this.scaleOrLength = scaleOrLength;
}
public JdbcParameterImpl(int sqlType, Object value, long length, Calendar calendar){
this(sqlType, value, -1, null, -1);
}
public JdbcParameterImpl(int sqlType, Object value){
this(sqlType, value, -1, null);
}
public JdbcParameterImpl(int sqlType, Object value, long length){
this(sqlType, value, length, null);
}
public JdbcParameterImpl(int sqlType, Object value, Calendar calendar){
this(sqlType, value, -1, calendar);
}
public int getScaleOrLength() {
return scaleOrLength;
}
public Object getValue() {
return value;
}
public long getLength() {
return length;
}
public Calendar getCalendar() {
return calendar;
}
public int getSqlType() {
return sqlType;
}
}
@@ -0,0 +1,67 @@
/*
* 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.jdbc;
import java.sql.Types;
import java.util.Calendar;
public final class JdbcParameterInt implements JdbcParameter {
private static JdbcParameterInt[] cache;
static {
int cacheSize = 127;
cache = new JdbcParameterInt[cacheSize];
for (int i = 0; i < cache.length; ++i) {
cache[i] = new JdbcParameterInt(i);
}
}
private final int value;
private JdbcParameterInt(int value){
this.value = value;
}
public static JdbcParameterInt valueOf(int value) {
if (value >= 0 && value < cache.length) {
return cache[value];
}
return new JdbcParameterInt(value);
}
@Override
public Object getValue() {
return value;
}
@Override
public long getLength() {
return 0;
}
@Override
public Calendar getCalendar() {
return null;
}
@Override
public int getSqlType() {
return Types.INTEGER;
}
}
@@ -0,0 +1,66 @@
/*
* 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.jdbc;
import java.sql.Types;
import java.util.Calendar;
public final class JdbcParameterLong implements JdbcParameter {
private static JdbcParameterLong[] cache;
static {
int cacheSize = 127;
cache = new JdbcParameterLong[cacheSize];
for (int i = 0; i < cache.length; ++i) {
cache[i] = new JdbcParameterLong(i);
}
}
private final long value;
private JdbcParameterLong(long value){
this.value = value;
}
public static JdbcParameterLong valueOf(long value) {
if (value >= 0 && value < cache.length) {
return cache[(int) value];
}
return new JdbcParameterLong(value);
}
@Override
public Object getValue() {
return value;
}
@Override
public long getLength() {
return 0;
}
@Override
public Calendar getCalendar() {
return null;
}
@Override
public int getSqlType() {
return Types.BIGINT;
}
}
@@ -0,0 +1,118 @@
/*
* 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.jdbc;
import java.sql.Types;
import java.util.Calendar;
public final class JdbcParameterNull implements JdbcParameter {
private final int sqlType;
public final static JdbcParameterNull CHAR = new JdbcParameterNull(Types.CHAR);
public final static JdbcParameterNull VARCHAR = new JdbcParameterNull(Types.VARCHAR);
public final static JdbcParameterNull NVARCHAR = new JdbcParameterNull(Types.NVARCHAR);
public final static JdbcParameterNull BINARY = new JdbcParameterNull(Types.BINARY);
public final static JdbcParameterNull VARBINARY = new JdbcParameterNull(Types.VARBINARY);
public final static JdbcParameterNull TINYINT = new JdbcParameterNull(Types.TINYINT);
public final static JdbcParameterNull SMALLINT = new JdbcParameterNull(Types.SMALLINT);
public final static JdbcParameterNull INTEGER = new JdbcParameterNull(Types.INTEGER);
public final static JdbcParameterNull BIGINT = new JdbcParameterNull(Types.BIGINT);
public final static JdbcParameterNull DECIMAL = new JdbcParameterNull(Types.DECIMAL);
public final static JdbcParameterNull NUMERIC = new JdbcParameterNull(Types.NUMERIC);
public final static JdbcParameterNull FLOAT = new JdbcParameterNull(Types.FLOAT);
public final static JdbcParameterNull DOUBLE = new JdbcParameterNull(Types.DOUBLE);
public final static JdbcParameterNull NULL = new JdbcParameterNull(Types.NULL);
public final static JdbcParameterNull DATE = new JdbcParameterNull(Types.DATE);
public final static JdbcParameterNull TIME = new JdbcParameterNull(Types.TIME);
public final static JdbcParameterNull TIMESTAMP = new JdbcParameterNull(Types.TIMESTAMP);
private JdbcParameterNull(int sqlType){
this.sqlType = sqlType;
}
@Override
public Object getValue() {
return null;
}
@Override
public long getLength() {
return 0;
}
@Override
public Calendar getCalendar() {
return null;
}
@Override
public int getSqlType() {
return sqlType;
}
public static JdbcParameterNull valueOf(int sqlType) {
switch (sqlType) {
case Types.TINYINT:
return INTEGER;
case Types.SMALLINT:
return SMALLINT;
case Types.INTEGER:
return INTEGER;
case Types.BIGINT:
return BIGINT;
case Types.DECIMAL:
return DECIMAL;
case Types.NUMERIC:
return NUMERIC;
case Types.FLOAT:
return FLOAT;
case Types.DOUBLE:
return DOUBLE;
case Types.CHAR:
return CHAR;
case Types.VARCHAR:
return VARCHAR;
case Types.NVARCHAR:
return NVARCHAR;
case Types.BINARY:
return BINARY;
case Types.VARBINARY:
return VARBINARY;
case Types.TIME:
return TIME;
case Types.DATE:
return DATE;
case Types.TIMESTAMP:
return TIMESTAMP;
case Types.NULL:
return NULL;
default:
return new JdbcParameterNull(sqlType);
}
}
}
@@ -0,0 +1,49 @@
/*
* 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.jdbc;
import java.sql.Types;
import java.util.Calendar;
public final class JdbcParameterString implements JdbcParameter {
private final String value;
public JdbcParameterString(String value){
this.value = value;
}
@Override
public Object getValue() {
return value;
}
@Override
public long getLength() {
return 0;
}
@Override
public Calendar getCalendar() {
return null;
}
@Override
public int getSqlType() {
return Types.VARCHAR;
}
}
@@ -0,0 +1,50 @@
/*
* 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.jdbc;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
public final class JdbcParameterTimestamp implements JdbcParameter {
private final Timestamp value;
public JdbcParameterTimestamp(Timestamp value){
this.value = value;
}
@Override
public Object getValue() {
return value;
}
@Override
public long getLength() {
return 0;
}
@Override
public Calendar getCalendar() {
return null;
}
@Override
public int getSqlType() {
return Types.TIMESTAMP;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,56 +1,59 @@
/*
* 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.jdbc;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.stat.JdbcSqlStat;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public interface StatementProxy extends Statement, WrapperProxy {
ConnectionProxy getConnectionProxy();
Statement getRawObject();
List<String> getBatchSqlList();
String getBatchSql();
JdbcSqlStat getSqlStat();
StatementExecuteType getLastExecuteType();
void setSqlStat(JdbcSqlStat sqlStat);
String getLastExecuteSql();
long getLastExecuteStartNano();
void setLastExecuteStartNano(long lastExecuteStartNano);
void setLastExecuteStartNano();
long getLastExecuteTimeNano();
void setLastExecuteTimeNano(long nano);
void setLastExecuteTimeNano();
Map<Integer, JdbcParameter> getParameters();
boolean isFirstResultSet();
}
/*
* 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.jdbc;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.stat.JdbcSqlStat;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public interface StatementProxy extends Statement, WrapperProxy {
ConnectionProxy getConnectionProxy();
Statement getRawObject();
List<String> getBatchSqlList();
String getBatchSql();
JdbcSqlStat getSqlStat();
StatementExecuteType getLastExecuteType();
void setSqlStat(JdbcSqlStat sqlStat);
String getLastExecuteSql();
long getLastExecuteStartNano();
void setLastExecuteStartNano(long lastExecuteStartNano);
void setLastExecuteStartNano();
long getLastExecuteTimeNano();
void setLastExecuteTimeNano(long nano);
void setLastExecuteTimeNano();
Map<Integer, JdbcParameter> getParameters();
int getParametersSize();
JdbcParameter getParameter(int i);
boolean isFirstResultSet();
}
File diff suppressed because it is too large Load Diff
@@ -1,31 +1,39 @@
/*
* 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.jdbc;
import java.sql.Wrapper;
import java.util.Map;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public interface WrapperProxy extends Wrapper {
long getId();
Object getRawObject();
Map<String, Object> getAttributes();
}
/*
* 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.jdbc;
import java.sql.Wrapper;
import java.util.Map;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public interface WrapperProxy extends Wrapper {
long getId();
Object getRawObject();
int getAttributesSize();
void clearAttributes();
Map<String, Object> getAttributes();
Object getAttribute(String key);
void putAttribute(String key, Object value);
}
@@ -1,82 +1,116 @@
/*
* 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.jdbc;
import java.sql.SQLException;
import java.sql.Wrapper;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.druid.filter.FilterChain;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public abstract class WrapperProxyImpl implements WrapperProxy {
private final Wrapper raw;
private final long id;
private final Map<String, Object> attributes = new HashMap<String, Object>(4); // 不需要线程安全
public WrapperProxyImpl(Wrapper wrapper, long id){
this.raw = wrapper;
this.id = id;
}
public long getId() {
return this.id;
}
public Object getRawObject() {
return raw;
}
public abstract FilterChain createChain();
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface == null) {
return false;
}
if (iface == this.getClass()) {
return true;
}
return createChain().isWrapperFor(raw, iface);
}
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface == null) {
return null;
}
if (iface == this.getClass()) {
return (T) this;
}
return createChain().unwrap(raw, iface);
}
public Map<String, Object> getAttributes() {
return this.attributes;
}
}
/*
* 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.jdbc;
import java.sql.SQLException;
import java.sql.Wrapper;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.druid.filter.FilterChain;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public abstract class WrapperProxyImpl implements WrapperProxy {
private final Wrapper raw;
private final long id;
private Map<String, Object> attributes; // 不需要线程安全
public WrapperProxyImpl(Wrapper wrapper, long id){
this.raw = wrapper;
this.id = id;
}
public long getId() {
return this.id;
}
public Object getRawObject() {
return raw;
}
public abstract FilterChain createChain();
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface == null) {
return false;
}
if (iface == this.getClass()) {
return true;
}
return createChain().isWrapperFor(raw, iface);
}
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface == null) {
return null;
}
if (iface == this.getClass()) {
return (T) this;
}
return createChain().unwrap(raw, iface);
}
public int getAttributesSize() {
if (attributes == null) {
return 0;
}
return attributes.size();
}
public void clearAttributes() {
if (this.attributes == null) {
return;
}
this.attributes.clear();
}
public Map<String, Object> getAttributes() {
if (attributes == null) {
attributes = new HashMap<String, Object>(4);
}
return this.attributes;
}
public void putAttribute(String key, Object value) {
if (attributes == null) {
attributes = new HashMap<String, Object>(4);
}
this.attributes.put(key, value);
}
public Object getAttribute(String key){
if (attributes == null) {
return null;
}
return this.attributes.get(key);
}
}
@@ -48,6 +48,10 @@ public abstract class SQLObjectImpl implements SQLObject, Serializable {
protected abstract void accept0(SQLASTVisitor visitor);
protected final void acceptChild(SQLASTVisitor visitor, List<? extends SQLObject> children) {
if (children == null) {
return;
}
for (SQLObject child : children) {
acceptChild(visitor, child);
}
@@ -1,57 +1,67 @@
/*
* 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.sql.ast.statement;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLHint;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTableSource {
private static final long serialVersionUID = 1L;
protected String alias;
protected List<SQLHint> hints = new ArrayList<SQLHint>(2);
public SQLTableSourceImpl(){
}
public SQLTableSourceImpl(String alias){
this.alias = alias;
}
public String getAlias() {
return this.alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public List<SQLHint> getHints() {
return hints;
}
public void setHints(List<SQLHint> hints) {
this.hints = hints;
}
}
/*
* 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.sql.ast.statement;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLHint;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTableSource {
private static final long serialVersionUID = 1L;
protected String alias;
protected List<SQLHint> hints;
public SQLTableSourceImpl(){
}
public SQLTableSourceImpl(String alias){
this.alias = alias;
}
public String getAlias() {
return this.alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public int getHintsSize() {
if (hints == null) {
return 0;
}
return hints.size();
}
public List<SQLHint> getHints() {
if (hints == null) {
hints = new ArrayList<SQLHint>(2);
}
return hints;
}
public void setHints(List<SQLHint> hints) {
this.hints = hints;
}
}
@@ -1,252 +1,266 @@
/*
* 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.sql.dialect.mysql.ast.statement;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLCommentHint;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObject;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@SuppressWarnings("serial")
public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlObject {
private boolean hignPriority;
private boolean straightJoin;
private boolean smallResult;
private boolean bigResult;
private boolean bufferResult;
private Boolean cache;
private boolean calcFoundRows;
private SQLOrderBy orderBy;
private Limit limit;
private SQLName procedureName;
private List<SQLExpr> procedureArgumentList = new ArrayList<SQLExpr>();
private boolean forUpdate = false;
private boolean lockInShareMode = false;
private List<SQLCommentHint> hints = new ArrayList<SQLCommentHint>();
public MySqlSelectQueryBlock(){
}
public List<SQLCommentHint> getHints() {
return hints;
}
public void setHints(List<SQLCommentHint> hints) {
this.hints = hints;
}
public boolean isForUpdate() {
return forUpdate;
}
public void setForUpdate(boolean forUpdate) {
this.forUpdate = forUpdate;
}
public boolean isLockInShareMode() {
return lockInShareMode;
}
public void setLockInShareMode(boolean lockInShareMode) {
this.lockInShareMode = lockInShareMode;
}
public SQLName getProcedureName() {
return procedureName;
}
public void setProcedureName(SQLName procedureName) {
this.procedureName = procedureName;
}
public List<SQLExpr> getProcedureArgumentList() {
return procedureArgumentList;
}
public void setProcedureArgumentList(List<SQLExpr> procedureArgumentList) {
this.procedureArgumentList = procedureArgumentList;
}
public boolean isHignPriority() {
return hignPriority;
}
public void setHignPriority(boolean hignPriority) {
this.hignPriority = hignPriority;
}
public boolean isStraightJoin() {
return straightJoin;
}
public void setStraightJoin(boolean straightJoin) {
this.straightJoin = straightJoin;
}
public boolean isSmallResult() {
return smallResult;
}
public void setSmallResult(boolean smallResult) {
this.smallResult = smallResult;
}
public boolean isBigResult() {
return bigResult;
}
public void setBigResult(boolean bigResult) {
this.bigResult = bigResult;
}
public boolean isBufferResult() {
return bufferResult;
}
public void setBufferResult(boolean bufferResult) {
this.bufferResult = bufferResult;
}
public Boolean getCache() {
return cache;
}
public void setCache(Boolean cache) {
this.cache = cache;
}
public boolean isCalcFoundRows() {
return calcFoundRows;
}
public void setCalcFoundRows(boolean calcFoundRows) {
this.calcFoundRows = calcFoundRows;
}
public SQLOrderBy getOrderBy() {
return orderBy;
}
public void setOrderBy(SQLOrderBy orderBy) {
this.orderBy = orderBy;
}
public Limit getLimit() {
return limit;
}
public void setLimit(Limit limit) {
if (limit != null) {
limit.setParent(this);
}
this.limit = limit;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
accept0((MySqlASTVisitor) visitor);
return;
}
if (visitor.visit(this)) {
acceptChild(visitor, this.selectList);
acceptChild(visitor, this.from);
acceptChild(visitor, this.where);
acceptChild(visitor, this.groupBy);
acceptChild(visitor, this.orderBy);
acceptChild(visitor, this.limit);
acceptChild(visitor, this.procedureName);
acceptChild(visitor, this.procedureArgumentList);
acceptChild(visitor, this.into);
}
visitor.endVisit(this);
}
@Override
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.selectList);
acceptChild(visitor, this.from);
acceptChild(visitor, this.where);
acceptChild(visitor, this.groupBy);
acceptChild(visitor, this.orderBy);
acceptChild(visitor, this.limit);
acceptChild(visitor, this.procedureName);
acceptChild(visitor, this.procedureArgumentList);
acceptChild(visitor, this.into);
}
visitor.endVisit(this);
}
public static class Limit extends SQLObjectImpl {
public Limit(){
}
private SQLExpr rowCount;
private SQLExpr offset;
public SQLExpr getRowCount() {
return rowCount;
}
public void setRowCount(SQLExpr rowCount) {
this.rowCount = rowCount;
}
public SQLExpr getOffset() {
return offset;
}
public void setOffset(SQLExpr offset) {
this.offset = offset;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
MySqlASTVisitor mysqlVisitor = (MySqlASTVisitor) visitor;
if (mysqlVisitor.visit(this)) {
acceptChild(visitor, offset);
acceptChild(visitor, rowCount);
}
}
}
}
}
/*
* 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.sql.dialect.mysql.ast.statement;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLCommentHint;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObject;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@SuppressWarnings("serial")
public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlObject {
private boolean hignPriority;
private boolean straightJoin;
private boolean smallResult;
private boolean bigResult;
private boolean bufferResult;
private Boolean cache;
private boolean calcFoundRows;
private SQLOrderBy orderBy;
private Limit limit;
private SQLName procedureName;
private List<SQLExpr> procedureArgumentList;
private boolean forUpdate = false;
private boolean lockInShareMode = false;
private List<SQLCommentHint> hints;
public MySqlSelectQueryBlock(){
}
public int getHintsSize() {
if (hints == null) {
return 0;
}
return hints.size();
}
public List<SQLCommentHint> getHints() {
if (hints == null) {
hints = new ArrayList<SQLCommentHint>(2);
}
return hints;
}
public void setHints(List<SQLCommentHint> hints) {
this.hints = hints;
}
public boolean isForUpdate() {
return forUpdate;
}
public void setForUpdate(boolean forUpdate) {
this.forUpdate = forUpdate;
}
public boolean isLockInShareMode() {
return lockInShareMode;
}
public void setLockInShareMode(boolean lockInShareMode) {
this.lockInShareMode = lockInShareMode;
}
public SQLName getProcedureName() {
return procedureName;
}
public void setProcedureName(SQLName procedureName) {
this.procedureName = procedureName;
}
public List<SQLExpr> getProcedureArgumentList() {
if (procedureArgumentList == null) {
procedureArgumentList = new ArrayList<SQLExpr>(2);
}
return procedureArgumentList;
}
public void setProcedureArgumentList(List<SQLExpr> procedureArgumentList) {
this.procedureArgumentList = procedureArgumentList;
}
public boolean isHignPriority() {
return hignPriority;
}
public void setHignPriority(boolean hignPriority) {
this.hignPriority = hignPriority;
}
public boolean isStraightJoin() {
return straightJoin;
}
public void setStraightJoin(boolean straightJoin) {
this.straightJoin = straightJoin;
}
public boolean isSmallResult() {
return smallResult;
}
public void setSmallResult(boolean smallResult) {
this.smallResult = smallResult;
}
public boolean isBigResult() {
return bigResult;
}
public void setBigResult(boolean bigResult) {
this.bigResult = bigResult;
}
public boolean isBufferResult() {
return bufferResult;
}
public void setBufferResult(boolean bufferResult) {
this.bufferResult = bufferResult;
}
public Boolean getCache() {
return cache;
}
public void setCache(Boolean cache) {
this.cache = cache;
}
public boolean isCalcFoundRows() {
return calcFoundRows;
}
public void setCalcFoundRows(boolean calcFoundRows) {
this.calcFoundRows = calcFoundRows;
}
public SQLOrderBy getOrderBy() {
return orderBy;
}
public void setOrderBy(SQLOrderBy orderBy) {
this.orderBy = orderBy;
}
public Limit getLimit() {
return limit;
}
public void setLimit(Limit limit) {
if (limit != null) {
limit.setParent(this);
}
this.limit = limit;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
accept0((MySqlASTVisitor) visitor);
return;
}
if (visitor.visit(this)) {
acceptChild(visitor, this.selectList);
acceptChild(visitor, this.from);
acceptChild(visitor, this.where);
acceptChild(visitor, this.groupBy);
acceptChild(visitor, this.orderBy);
acceptChild(visitor, this.limit);
acceptChild(visitor, this.procedureName);
acceptChild(visitor, this.procedureArgumentList);
acceptChild(visitor, this.into);
}
visitor.endVisit(this);
}
@Override
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.selectList);
acceptChild(visitor, this.from);
acceptChild(visitor, this.where);
acceptChild(visitor, this.groupBy);
acceptChild(visitor, this.orderBy);
acceptChild(visitor, this.limit);
acceptChild(visitor, this.procedureName);
acceptChild(visitor, this.procedureArgumentList);
acceptChild(visitor, this.into);
}
visitor.endVisit(this);
}
public static class Limit extends SQLObjectImpl {
public Limit(){
}
private SQLExpr rowCount;
private SQLExpr offset;
public SQLExpr getRowCount() {
return rowCount;
}
public void setRowCount(SQLExpr rowCount) {
this.rowCount = rowCount;
}
public SQLExpr getOffset() {
return offset;
}
public void setOffset(SQLExpr offset) {
this.offset = offset;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
MySqlASTVisitor mysqlVisitor = (MySqlASTVisitor) visitor;
if (mysqlVisitor.visit(this)) {
acceptChild(visitor, offset);
acceptChild(visitor, rowCount);
}
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -39,6 +39,10 @@ public class ParameterizedOutputVisitorUtils {
public static String parameterize(String sql, String dbType) {
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> statementList = parser.parseStatementList();
if (statementList.size() == 0) {
return sql;
}
SQLStatement stmt = statementList.get(0);
StringBuilder out = new StringBuilder();
File diff suppressed because it is too large Load Diff
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.visitor;
import static com.alibaba.druid.sql.visitor.SQLEvalVisitor.EVAL_EXPR;
import static com.alibaba.druid.sql.visitor.SQLEvalVisitor.EVAL_VALUE;
import static com.alibaba.druid.sql.visitor.SQLEvalVisitor.EVAL_VALUE_NULL;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -580,7 +581,7 @@ public class SQLEvalVisitorUtils {
}
public static boolean visit(SQLEvalVisitor visitor, SQLNullExpr x) {
x.getAttributes().put(EVAL_VALUE, null);
x.getAttributes().put(EVAL_VALUE, EVAL_VALUE_NULL);
return false;
}
@@ -839,6 +840,14 @@ public class SQLEvalVisitorUtils {
x.putAttribute(EVAL_VALUE, value);
break;
case Is:
if (rightValue == EVAL_VALUE_NULL) {
if (leftValue != null) {
value = (leftValue == EVAL_VALUE_NULL);
x.putAttribute(EVAL_VALUE, value);
break;
}
}
break;
case Equality:
value = eq(leftValue, rightValue);
x.putAttribute(EVAL_VALUE, value);
@@ -938,6 +947,9 @@ public class SQLEvalVisitorUtils {
boolean containsValue = attributes.containsKey(EVAL_VALUE);
if (!containsValue) {
Object value = visitor.getParameters().get(varIndex);
if (value == null) {
value = EVAL_VALUE_NULL;
}
attributes.put(EVAL_VALUE, value);
}
}
@@ -66,7 +66,7 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
//
});
private final ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = new ConcurrentHashMap<Long, JdbcConnectionStat.Entry>();
private final ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = new ConcurrentHashMap<Long, JdbcConnectionStat.Entry>(16, 0.75f, 1);
private final AtomicLong clobOpenCount = new AtomicLong();
@@ -56,7 +56,7 @@ public class WebAppStat {
private final AtomicLong jdbcCommitCount = new AtomicLong();
private final AtomicLong jdbcRollbackCount = new AtomicLong();
private final ConcurrentMap<String, WebURIStat> uriStatMap = new ConcurrentHashMap<String, WebURIStat>();
private final ConcurrentMap<String, WebURIStat> uriStatMap = new ConcurrentHashMap<String, WebURIStat>(16, 0.75f, 1);
private final LRUCache<String, WebSessionStat> sessionStatMap;
private final ReadWriteLock sessionStatLock = new ReentrantReadWriteLock();
@@ -39,7 +39,7 @@ public class SqlMapClientImplWrapper extends SqlMapClientImpl {
private static Method getLocalSqlMapSessionMethod = null;
private ConcurrentMap<String, IbatisStatementInfo> statementInfoMap = new ConcurrentHashMap<String, IbatisStatementInfo>();
private ConcurrentMap<String, IbatisStatementInfo> statementInfoMap = new ConcurrentHashMap<String, IbatisStatementInfo>(16, 0.75f, 1);
public SqlMapClientImplWrapper(SqlMapClientImpl raw) {
super(raw.getDelegate());
@@ -35,10 +35,10 @@ public class SLF4JImpl implements Log {
private int infoCount;
private LocationAwareLogger log;
public SLF4JImpl(Class<?> clazz){
this.log = (LocationAwareLogger) LoggerFactory.getLogger(clazz);
public SLF4JImpl(LocationAwareLogger log){
this.log = log;
}
public SLF4JImpl(String loggerName){
this.log = (LocationAwareLogger) LoggerFactory.getLogger(loggerName);
}
@@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentMap;
public class SpringStat {
private ConcurrentMap<SpringMethodInfo, SpringMethodStat> methodStats = new ConcurrentHashMap<SpringMethodInfo, SpringMethodStat>();
private ConcurrentMap<SpringMethodInfo, SpringMethodStat> methodStats = new ConcurrentHashMap<SpringMethodInfo, SpringMethodStat>(16, 0.75f, 1);
public SpringStat(){
File diff suppressed because it is too large Load Diff
@@ -59,8 +59,8 @@ public abstract class WallProvider {
private static final ThreadLocal<Boolean> privileged = new ThreadLocal<Boolean>();
private final ConcurrentMap<String, WallFunctionStat> functionStats = new ConcurrentHashMap<String, WallFunctionStat>();
private final ConcurrentMap<String, WallTableStat> tableStats = new ConcurrentHashMap<String, WallTableStat>();
private final ConcurrentMap<String, WallFunctionStat> functionStats = new ConcurrentHashMap<String, WallFunctionStat>(16, 0.75f, 1);
private final ConcurrentMap<String, WallTableStat> tableStats = new ConcurrentHashMap<String, WallTableStat>(16, 0.75f, 1);
public final WallDenyStat commentDeniedStat = new WallDenyStat();
@@ -30,6 +30,7 @@ import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl;
import com.alibaba.druid.proxy.jdbc.ClobProxy;
import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl;
import com.alibaba.druid.util.JdbcUtils;
public class FilterChainTest_Clob_2 extends TestCase {
@@ -51,7 +52,7 @@ public class FilterChainTest_Clob_2 extends TestCase {
}
};
statement = new CallableStatementProxyImpl(null, mockStmt, "", 1);
statement = new CallableStatementProxyImpl(new ConnectionProxyImpl(null, null, null, 0), mockStmt, "", 1);
}
@@ -69,16 +70,15 @@ public class FilterChainTest_Clob_2 extends TestCase {
Assert.assertTrue(clob instanceof ClobProxy);
Assert.assertEquals(1, invokeCount);
}
public void test_getClob_1() throws Exception {
FilterChainImpl chain = new FilterChainImpl(dataSource);
Clob clob = chain.callableStatement_getClob(statement, "1");
Assert.assertTrue(clob instanceof ClobProxy);
Assert.assertEquals(1, invokeCount);
}
public void test_getObject() throws Exception {
FilterChainImpl chain = new FilterChainImpl(dataSource);
@@ -88,30 +88,30 @@ public class FilterChainTest_Clob_2 extends TestCase {
Assert.assertTrue(clob instanceof ClobProxy);
Assert.assertEquals(1, invokeCount);
}
public void test_getObject_1() throws Exception {
FilterChainImpl chain = new FilterChainImpl(dataSource);
Clob clob = (Clob) chain.callableStatement_getObject(statement, "1");
Assert.assertTrue(clob instanceof ClobProxy);
Assert.assertEquals(1, invokeCount);
}
public void test_getObject_2() throws Exception {
FilterChainImpl chain = new FilterChainImpl(dataSource);
Clob clob = (Clob) chain.callableStatement_getObject(statement, 1, Collections.<String, Class<?>>emptyMap());
Clob clob = (Clob) chain.callableStatement_getObject(statement, 1, Collections.<String, Class<?>> emptyMap());
Assert.assertTrue(clob instanceof ClobProxy);
Assert.assertEquals(1, invokeCount);
}
public void test_getObject_3() throws Exception {
FilterChainImpl chain = new FilterChainImpl(dataSource);
Clob clob = (Clob) chain.callableStatement_getObject(statement, "1", Collections.<String, Class<?>>emptyMap());
Clob clob = (Clob) chain.callableStatement_getObject(statement, "1", Collections.<String, Class<?>> emptyMap());
Assert.assertTrue(clob instanceof ClobProxy);
Assert.assertEquals(1, invokeCount);
}
@@ -29,6 +29,7 @@ import com.alibaba.druid.mock.MockNClob;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl;
import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl;
import com.alibaba.druid.proxy.jdbc.NClobProxy;
import com.alibaba.druid.util.JdbcUtils;
@@ -51,7 +52,7 @@ public class FilterChainTest_NClob_2 extends TestCase {
}
};
statement = new CallableStatementProxyImpl(null, mockStmt, "", 1);
statement = new CallableStatementProxyImpl(new ConnectionProxyImpl(null, null, null, 0), mockStmt, "", 1);
}
@@ -1,56 +1,56 @@
/*
* 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.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.spi.MySqlWallProvider;
/**
* SQLServerWallTest
*
* @author RaymondXiu
* @version 1.0, 2012-3-18
* @see
*/
public class MySqlWallTest71 extends TestCase {
public void test_false() throws Exception {
WallProvider provider = new MySqlWallProvider();
provider.getConfig().setCommentAllow(true);
Assert.assertTrue(provider.checkValid(//
"update order_return set return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00 where id=1319"));
Assert.assertEquals(1, provider.getTableStats().size());
}
public void test_false1() throws Exception {
WallProvider provider = new MySqlWallProvider();
provider.getConfig().setCommentAllow(true);
Assert.assertFalse(provider.checkValid(//
"select * from order_return where return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00"));
Assert.assertEquals(1, provider.getTableStats().size());
}
}
/*
* 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.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.spi.MySqlWallProvider;
/**
* SQLServerWallTest
*
* @author RaymondXiu
* @version 1.0, 2012-3-18
* @see
*/
public class MySqlWallTest71 extends TestCase {
public void test_false() throws Exception {
WallProvider provider = new MySqlWallProvider();
provider.getConfig().setCommentAllow(true);
Assert.assertFalse(provider.checkValid(//
"update order_return set return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00 where id=1319"));
Assert.assertEquals(1, provider.getTableStats().size());
}
public void test_false1() throws Exception {
WallProvider provider = new MySqlWallProvider();
provider.getConfig().setCommentAllow(true);
Assert.assertFalse(provider.checkValid(//
"select * from order_return where return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00"));
Assert.assertEquals(1, provider.getTableStats().size());
}
}
@@ -1,143 +1,143 @@
/*
* 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.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.spi.SQLServerWallProvider;
/**
* SQLServerWallTest
*
* @author RaymondXiu
* @version 1.0, 2012-3-18
* @see
*/
public class SQLServerWallTest_0 extends TestCase {
private WallProvider initWallProvider() {
WallProvider provider = new SQLServerWallProvider();
provider.getConfig().setUseAllow(true);
provider.getConfig().setStrictSyntaxCheck(false);
provider.getConfig().setMultiStatementAllow(true);
provider.getConfig().setConditionAndAlwayTrueAllow(true);
provider.getConfig().setNoneBaseStatementAllow(true);
provider.getConfig().setSelectUnionCheck(false);
provider.getConfig().setSchemaCheck(true);
provider.getConfig().setLimitZeroAllow(true);
provider.getConfig().setCommentAllow(true);
return provider;
}
public void test_false() {
WallProvider provider = initWallProvider();
{
String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 And (Select Top 1 unicode(substring(isNull(cast(name as varchar(8000)),char(32)),7,1)) From (Select Top 9 [dbid],[name] From master..sysdatabases Order by [dbid] desc) T Order by [dbid]) between 105 and 105";
Assert.assertFalse(provider.checkValid(sql));
}
{
String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 and (select unicode(substring(isNull(cast(db_name() as varchar(8000)),char(32)),1,1))) between 105 and 108";
Assert.assertFalse(provider.checkValid(sql));
}
}
public void test_false1() throws Exception {
WallProvider provider = initWallProvider();
{
String sql = "select OrderId,Order_Time,oResult,oState,show_Exp_Num,Is_Exp_Print,sel_Exp_Id,Order_Th,Th_Audit_Time,Th_Delay_Days from Pro_Order_List where OrderId='2012110125252' AND HOST_NAME()=HOST_NAME() AND 'kbwg'='kbwg'";
Assert.assertFalse(provider.checkValid(sql));
}
}
public void test_true1() throws Exception {
WallProvider provider = initWallProvider();
{
String sql = "select Fg.name as TableFg, dsp.name as TexImageFg, FtCat.name as FulltextCatalog, OBJECTPROPERTY(tbl.object_id, 'TableTextInRowLimit') as TextInrowLimit, OBJECTPROPERTY(tbl.object_id, 'IsIndexable'), user_name(tbl.principal_id) as DirectOwner, tbl.is_replicated, tbl.lock_escalation_desc from sys.tables tbl left outer join sys.data_spaces dsp on dsp.data_space_id = tbl.lob_data_space_id left outer join (sys.fulltext_indexes fti inner join sys.fulltext_catalogs FtCat on FtCat.fulltext_catalog_id = fti.fulltext_catalog_id ) on fti.object_id = tbl.object_id inner join (sys.indexes idx inner join sys.data_spaces Fg on (idx.index_id = 0 or idx.index_id = 1) and Fg.data_space_id = idx.data_space_id) on idx.object_id = tbl.object_id and (idx.index_id = 0 or idx.index_id = 1) where tbl.object_id = object_id(N'dbo.nqh_TelOrder') ";
Assert.assertTrue(provider.checkValid(sql));
}
}
public void test_true() throws Exception {
WallProvider provider = initWallProvider();
{
String sql = "SELECT 'Server[@Name=' + quotename(CAST(serverproperty(N'Servername') AS sysname),'''') + ']' + '/Collation[@Name=' + quotename(cl.name,'''') + ']' AS [Urn], cl.name AS [Name], CAST(COLLATIONPROPERTY(name, 'CodePage') AS int) AS [CodePage], CAST(COLLATIONPROPERTY(name, 'LCID') AS int) AS [LocaleID], CAST(COLLATIONPROPERTY(name, 'ComparisonStyle') AS int) AS [ComparisonStyle], cl.description AS [Description], CAST(COLLATIONPROPERTY(name, 'Version') AS int) AS [CollationVersion] FROM sys.fn_helpcollations() cl ORDER BY [Name] ASC";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT bp.Class_desc, bp.Permission_name, bp.Type, bp.Covering_permission_name, bp.Parent_class_desc, bp.Parent_covering_permission_name FROM sys.fn_builtin_permissions(null) as bp order by bp.class_desc";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select isExist = case when exists(select * from dbo.sysobjects where id = object_id ('SYS_LOG_2005')) then 1 else 0 end";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select length from syscolumns(nolock) where id = object_id('boat') and (name in ('boat_bag','skill_state'))";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from INFORMATION_SCHEMA.KEY_COLUMN_USAGE c join INFORMATION_SCHEMA.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_0 and SCHEMA_NAME(tbl.schema_id)=@_msparam_1)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_2 and SCHEMA_NAME(tbl.schema_id)=@_msparam_3)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_4 and SCHEMA_NAME(tbl.schema_id)=@_msparam_5)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_6 and SCHEMA_NAME(tbl.schema_id)=@_msparam_7)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_8 and SCHEMA_NAME(tbl.schema_id)=@_msparam_9)";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from sys.KEY_COLUMN_USAGE c join sys.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT user_name(), @@MAX_PRECISION, is_member('db_owner'), permissions(), DatabasePropertyEx(db_name(), N'collation'), SERVERPROPERTY('IsFullTextInstalled'), schema_name()";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select col.name, col.column_id, st.name as DT_name, schema_name(st.schema_id) as DT_schema, col.max_length, col.precision, col.scale, bt.name as BT_name, col.collation_name, col.is_nullable, col.is_ansi_padded, col.is_rowguidcol, col.is_identity, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.seed_value) end, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.increment_value) end, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, convert(bit, ColumnProperty(col.object_id, col.name, N'IsIdNotForRepl')) as IsIdNotForRepl, col.is_replicated, col.is_non_sql_subscribed, col.is_merge_published, col.is_dts_replicated, col.rule_object_id, robj.name as Rul_name, schema_name(robj.schema_id) as Rul_schema, col.default_object_id, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, dobj.name as def_name, schema_name(dobj.schema_id) as def_schema, CONVERT(bit, case when (ftc.column_id is null) then 0 else 1 end) as is_FullTextCol, col_name(col.object_id, ftc.type_column_id) FT_type_column, ftc.language_id as FT_language_id, case when(cmc.column_id is null) then null else cmc.definition end as formular, case when(cmc.column_id is null) then null else cmc.is_persisted end as is_persisted, defCst.definition, COLUMNPROPERTY(col.object_id, col.name, 'IsDeterministic') as IsDeterministic, xmlcoll.name as xmlSchema_name, schema_name(xmlcoll.schema_id) as xmlSchema_schema, col.is_xml_document, col.is_sparse, col.is_column_set from sys.columns col left outer join sys.types st on st.user_type_id = col.user_type_id left outer join sys.types bt on bt.user_type_id = col.system_type_id left outer join sys.objects robj on robj.object_id = col.rule_object_id and robj.type = 'R' left outer join sys.objects dobj on dobj.object_id = col.default_object_id and dobj.type = 'D' left outer join sys.default_constraints defCst on defCst.parent_object_id = col.object_id and defCst.parent_column_id = col.column_id left outer join sys.identity_columns idc o";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT * FROM `www_subject` WHERE subject like '哎%' or subject like '%' ORDER BY aid desc LIMIT 30 ";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT COUNT(*) FROM syscolumns WHERE id=OBJECT_ID(N'taobao_order') AND name='r3_billtype'";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "update master.dbo.dml_health_check set id=1";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select col.name, st.name as DT_name, case when (st.name in ('nchar', 'nvarchar') and (col.max_length > 0)) then col.max_length / 2 else col.max_length end, col.precision, col.scale, bt.name as BT_name, col.is_nullable, col.is_identity,col.is_rowguidcol, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, case when(cmc.column_id is null) then null else cmc.definition end as formular, col.collation_name, col.system_type_id from nowshop.sys.all_columns col left outer join nowshop.sys.types st on st.user_type_id = col.user_type_id left outer join nowshop.sys.types bt on bt.user_type_id = col.system_type_id left outer join nowshop.sys.identity_columns idc on idc.object_id = col.object_id and idc.column_id = col.column_id left outer join nowshop.sys.computed_columns cmc on cmc.object_id = col.object_id and cmc.column_id = col.column_id where col.object_id = object_id(N'nowshop.dbo.hr_shop') order by col.column_id";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "update dbo.dml_health_check set name='123' where id=OBJECT_ID(N'taobao_order')";
Assert.assertFalse(provider.checkValid(sql));
}
{
String sql = "select * from tb_product_word where name='' or CONCAT(name,style)='' or CONCAT(shop,style)='' or CONCAT(ename,style)=''";
Assert.assertTrue(provider.checkValid(sql));
}
}
}
/*
* 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.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.spi.SQLServerWallProvider;
/**
* SQLServerWallTest
*
* @author RaymondXiu
* @version 1.0, 2012-3-18
* @see
*/
public class SQLServerWallTest_0 extends TestCase {
private WallProvider initWallProvider() {
WallProvider provider = new SQLServerWallProvider();
provider.getConfig().setUseAllow(true);
provider.getConfig().setStrictSyntaxCheck(false);
provider.getConfig().setMultiStatementAllow(true);
provider.getConfig().setConditionAndAlwayTrueAllow(true);
provider.getConfig().setNoneBaseStatementAllow(true);
provider.getConfig().setSelectUnionCheck(false);
provider.getConfig().setSchemaCheck(true);
provider.getConfig().setLimitZeroAllow(true);
provider.getConfig().setCommentAllow(true);
return provider;
}
public void test_false() {
WallProvider provider = initWallProvider();
{
String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 And (Select Top 1 unicode(substring(isNull(cast(name as varchar(8000)),char(32)),7,1)) From (Select Top 9 [dbid],[name] From master..sysdatabases Order by [dbid] desc) T Order by [dbid]) between 105 and 105";
Assert.assertFalse(provider.checkValid(sql));
}
{
String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 and (select unicode(substring(isNull(cast(db_name() as varchar(8000)),char(32)),1,1))) between 105 and 108";
Assert.assertFalse(provider.checkValid(sql));
}
}
public void test_false1() throws Exception {
WallProvider provider = initWallProvider();
{
String sql = "select OrderId,Order_Time,oResult,oState,show_Exp_Num,Is_Exp_Print,sel_Exp_Id,Order_Th,Th_Audit_Time,Th_Delay_Days from Pro_Order_List where OrderId='2012110125252' AND HOST_NAME()=HOST_NAME() AND 'kbwg'='kbwg'";
Assert.assertFalse(provider.checkValid(sql));
}
{
String sql = "update dbo.dml_health_check set name='123' where id=OBJECT_ID(N'taobao_order')";
Assert.assertFalse(provider.checkValid(sql));
}
}
public void test_true1() throws Exception {
WallProvider provider = initWallProvider();
{
String sql = "select Fg.name as TableFg, dsp.name as TexImageFg, FtCat.name as FulltextCatalog, OBJECTPROPERTY(tbl.object_id, 'TableTextInRowLimit') as TextInrowLimit, OBJECTPROPERTY(tbl.object_id, 'IsIndexable'), user_name(tbl.principal_id) as DirectOwner, tbl.is_replicated, tbl.lock_escalation_desc from sys.tables tbl left outer join sys.data_spaces dsp on dsp.data_space_id = tbl.lob_data_space_id left outer join (sys.fulltext_indexes fti inner join sys.fulltext_catalogs FtCat on FtCat.fulltext_catalog_id = fti.fulltext_catalog_id ) on fti.object_id = tbl.object_id inner join (sys.indexes idx inner join sys.data_spaces Fg on (idx.index_id = 0 or idx.index_id = 1) and Fg.data_space_id = idx.data_space_id) on idx.object_id = tbl.object_id and (idx.index_id = 0 or idx.index_id = 1) where tbl.object_id = object_id(N'dbo.nqh_TelOrder') ";
Assert.assertTrue(provider.checkValid(sql));
}
}
public void test_true() throws Exception {
WallProvider provider = initWallProvider();
{
String sql = "SELECT 'Server[@Name=' + quotename(CAST(serverproperty(N'Servername') AS sysname),'''') + ']' + '/Collation[@Name=' + quotename(cl.name,'''') + ']' AS [Urn], cl.name AS [Name], CAST(COLLATIONPROPERTY(name, 'CodePage') AS int) AS [CodePage], CAST(COLLATIONPROPERTY(name, 'LCID') AS int) AS [LocaleID], CAST(COLLATIONPROPERTY(name, 'ComparisonStyle') AS int) AS [ComparisonStyle], cl.description AS [Description], CAST(COLLATIONPROPERTY(name, 'Version') AS int) AS [CollationVersion] FROM sys.fn_helpcollations() cl ORDER BY [Name] ASC";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT bp.Class_desc, bp.Permission_name, bp.Type, bp.Covering_permission_name, bp.Parent_class_desc, bp.Parent_covering_permission_name FROM sys.fn_builtin_permissions(null) as bp order by bp.class_desc";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select isExist = case when exists(select * from dbo.sysobjects where id = object_id ('SYS_LOG_2005')) then 1 else 0 end";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select length from syscolumns(nolock) where id = object_id('boat') and (name in ('boat_bag','skill_state'))";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from INFORMATION_SCHEMA.KEY_COLUMN_USAGE c join INFORMATION_SCHEMA.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_0 and SCHEMA_NAME(tbl.schema_id)=@_msparam_1)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_2 and SCHEMA_NAME(tbl.schema_id)=@_msparam_3)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_4 and SCHEMA_NAME(tbl.schema_id)=@_msparam_5)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_6 and SCHEMA_NAME(tbl.schema_id)=@_msparam_7)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_8 and SCHEMA_NAME(tbl.schema_id)=@_msparam_9)";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from sys.KEY_COLUMN_USAGE c join sys.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT user_name(), @@MAX_PRECISION, is_member('db_owner'), permissions(), DatabasePropertyEx(db_name(), N'collation'), SERVERPROPERTY('IsFullTextInstalled'), schema_name()";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select col.name, col.column_id, st.name as DT_name, schema_name(st.schema_id) as DT_schema, col.max_length, col.precision, col.scale, bt.name as BT_name, col.collation_name, col.is_nullable, col.is_ansi_padded, col.is_rowguidcol, col.is_identity, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.seed_value) end, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.increment_value) end, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, convert(bit, ColumnProperty(col.object_id, col.name, N'IsIdNotForRepl')) as IsIdNotForRepl, col.is_replicated, col.is_non_sql_subscribed, col.is_merge_published, col.is_dts_replicated, col.rule_object_id, robj.name as Rul_name, schema_name(robj.schema_id) as Rul_schema, col.default_object_id, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, dobj.name as def_name, schema_name(dobj.schema_id) as def_schema, CONVERT(bit, case when (ftc.column_id is null) then 0 else 1 end) as is_FullTextCol, col_name(col.object_id, ftc.type_column_id) FT_type_column, ftc.language_id as FT_language_id, case when(cmc.column_id is null) then null else cmc.definition end as formular, case when(cmc.column_id is null) then null else cmc.is_persisted end as is_persisted, defCst.definition, COLUMNPROPERTY(col.object_id, col.name, 'IsDeterministic') as IsDeterministic, xmlcoll.name as xmlSchema_name, schema_name(xmlcoll.schema_id) as xmlSchema_schema, col.is_xml_document, col.is_sparse, col.is_column_set from sys.columns col left outer join sys.types st on st.user_type_id = col.user_type_id left outer join sys.types bt on bt.user_type_id = col.system_type_id left outer join sys.objects robj on robj.object_id = col.rule_object_id and robj.type = 'R' left outer join sys.objects dobj on dobj.object_id = col.default_object_id and dobj.type = 'D' left outer join sys.default_constraints defCst on defCst.parent_object_id = col.object_id and defCst.parent_column_id = col.column_id left outer join sys.identity_columns idc o";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT * FROM `www_subject` WHERE subject like '哎%' or subject like '%' ORDER BY aid desc LIMIT 30 ";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "SELECT COUNT(*) FROM syscolumns WHERE id=OBJECT_ID(N'taobao_order') AND name='r3_billtype'";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "update master.dbo.dml_health_check set id=1";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select col.name, st.name as DT_name, case when (st.name in ('nchar', 'nvarchar') and (col.max_length > 0)) then col.max_length / 2 else col.max_length end, col.precision, col.scale, bt.name as BT_name, col.is_nullable, col.is_identity,col.is_rowguidcol, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, case when(cmc.column_id is null) then null else cmc.definition end as formular, col.collation_name, col.system_type_id from nowshop.sys.all_columns col left outer join nowshop.sys.types st on st.user_type_id = col.user_type_id left outer join nowshop.sys.types bt on bt.user_type_id = col.system_type_id left outer join nowshop.sys.identity_columns idc on idc.object_id = col.object_id and idc.column_id = col.column_id left outer join nowshop.sys.computed_columns cmc on cmc.object_id = col.object_id and cmc.column_id = col.column_id where col.object_id = object_id(N'nowshop.dbo.hr_shop') order by col.column_id";
Assert.assertTrue(provider.checkValid(sql));
}
{
String sql = "select * from tb_product_word where name='' or CONCAT(name,style)='' or CONCAT(shop,style)='' or CONCAT(ename,style)=''";
Assert.assertTrue(provider.checkValid(sql));
}
}
}
@@ -0,0 +1,46 @@
/*
* 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.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.spi.SQLServerWallProvider;
/**
* SQLServerWallTest
*
* @author RaymondXiu
* @version 1.0, 2012-3-18
* @see
*/
public class SQLServerWallTest_7 extends TestCase {
public void test_true() throws Exception {
WallProvider provider = new SQLServerWallProvider();
provider.getConfig().setSelectHavingAlwayTrueCheck(true);
Assert.assertTrue(provider.checkValid(//
"select * from (select top 3000 jol.id as primaryKeyIds, jo.orderNo as 委托单号, bm.custname as 委托方名称, manuCustInfo.custname as 出证方, jo.chkerDate as 委托日期, bcc.connectName as 联系人, bcc.mobile as 电话,jol.barcode as 样品条码, jol.name as 样品名称, jol.qtysub as 套件数量,jol.OnlyCode as 唯一识别码,jol.manufacture as 制造厂商,jol.sprc as 规格型号, jol.outno as 出厂编号, djod.name as 任务状态, djoc.name 委托类别, dct.name as 证书类型,bdp.organ_name as 分配室组, jol.task_id as 任务ID, be.user_name as 检定人员, verifyUser.user_name as 核验员, checkUser.user_name as 批准员, jol.ddate 交款日期,cjcs.name as 缴款状态, jc.moneys as 应收费, jc.moneystotal as 实收费, be.organ_id from jl_OrderList jol left outer join jl_CheckList jc on jol.checkList_id = jc.id left outer join jl_Order jo on jol.orderid = jo.id left outer join ba_dptinfo bdp on jol.dptid = bdp.id left outer join jl_Task jt on jol.task_id = jt.id left outer join ba_manucustinfo bm on jo.entrustCustId = bm.id left outer join ba_manucustinfo manuCustInfo on jo.custid = manuCustInfo.id left outer join ba_custconnect bcc on jo.linkPerson = bcc.id left outer join ba_employeeinfo be on jt.jdUserId = be.id left outer join ba_employeeinfo verifyUser on jt.verifyUser = verifyUser.id left outer join ba_employeeinfo checkUser on jt.checkUser = checkUser.id left outer join dict_jl_order_doType djod on jol.dotypeid = djod.id left outer join dict_jl_order_class djoc on jo.orderclassid = djoc.id left outer join dict_certificate_type dct on jt.certificatetype = dct.id left outer join dict_jl_chargestatus cjcs on jol.chargestatus = cjcs.id where jol.id >= (select min(primaryKeyId) from (select top 3000 jol.id as primaryKeyId from jl_OrderList jol left outer join jl_CheckList jc on jol.checkList_id = jc.id left outer join jl_Order jo on jol.orderid = jo.id left outer join ba_dptinfo bdp on jol.dptid = bdp.id left outer join jl_Task jt on jol.task_id = jt.id left outer join ba_manucustinfo bm on jo.entrustCustId = bm.id left outer join ba_manucustinfo manuCustInfo on jo.custid = manuCustInfo.id left outer join ba_custconnect bcc on jo.linkPerson = bcc.id left outer join ba_employeeinfo be on jt.jdUserId = be.id left outer join ba_employeeinfo verifyUser on jt.verifyUser = verifyUser.id left outer join ba_employeeinfo checkUser on jt.checkUser = checkUser.id left outer join dict_jl_order_doType djod on jol.dotypeid = djod.id left outer join dict_jl_order_class djoc on jo.orderclassid = djoc.id left outer join dict_certificate_type dct on jt.certificatetype = dct.id left outer join dict_jl_chargestatus cjcs on jol.chargestatus = cjcs.id where jo.chkerDate >= ? and jo.chkerDate <= ? and jol.ddate >= ? order by jol.id desc, jo.id DESC) as T) and jo.chkerDate >= ? and jo.chkerDate <= ? and jol.ddate >= ? order by jol.id asc, jo.id DESC) as T1 order by T1.primaryKeyIds desc"));
// Assert.assertEquals(12, provider.getTableStats().size());
// Assert.assertTrue(provider.getTableStats().containsKey("jl_OrderList"));
}
}
@@ -37,40 +37,40 @@ public class PreparedStatementProxyImplTest extends TestCase {
stmt.setObject(3, (int) 1);
stmt.setObject(4, (long) 1);
stmt.setObject(5, (float) 1);
stmt.setObject(6, (double) 1);
stmt.setObject(7, new BigDecimal(1));
stmt.setObject(8, true);
stmt.setObject(9, "xxx");
stmt.setObject(10, new java.sql.Date(System.currentTimeMillis()));
stmt.setObject(11, new java.util.Date(System.currentTimeMillis()));
stmt.setObject(12, new java.sql.Timestamp(System.currentTimeMillis()));
stmt.setObject(13, new java.sql.Time(System.currentTimeMillis()));
stmt.execute();
PreparedStatementProxy stmtProxy = stmt.unwrap(PreparedStatementProxy.class);
Assert.assertNotNull(stmtProxy);
Assert.assertEquals(Types.TINYINT, stmtProxy.getParameters().get(1).getSqlType());
Assert.assertEquals(Types.SMALLINT, stmtProxy.getParameters().get(2).getSqlType());
Assert.assertEquals(Types.INTEGER, stmtProxy.getParameters().get(3).getSqlType());
Assert.assertEquals(Types.BIGINT, stmtProxy.getParameters().get(4).getSqlType());
Assert.assertEquals(Types.FLOAT, stmtProxy.getParameters().get(5).getSqlType());
Assert.assertEquals(Types.DOUBLE, stmtProxy.getParameters().get(6).getSqlType());
Assert.assertEquals(Types.DECIMAL, stmtProxy.getParameters().get(7).getSqlType());
Assert.assertEquals(Types.BOOLEAN, stmtProxy.getParameters().get(8).getSqlType());
Assert.assertEquals(Types.VARCHAR, stmtProxy.getParameters().get(9).getSqlType());
Assert.assertEquals(Types.DATE, stmtProxy.getParameters().get(10).getSqlType());
Assert.assertEquals(Types.DATE, stmtProxy.getParameters().get(11).getSqlType());
Assert.assertEquals(Types.TIMESTAMP, stmtProxy.getParameters().get(12).getSqlType());
Assert.assertEquals(Types.TIME, stmtProxy.getParameters().get(13).getSqlType());
Assert.assertEquals(Types.TINYINT, stmtProxy.getParameter(0).getSqlType());
Assert.assertEquals(Types.SMALLINT, stmtProxy.getParameter(1).getSqlType());
Assert.assertEquals(Types.INTEGER, stmtProxy.getParameter(2).getSqlType());
Assert.assertEquals(Types.BIGINT, stmtProxy.getParameter(3).getSqlType());
Assert.assertEquals(Types.FLOAT, stmtProxy.getParameter(4).getSqlType());
Assert.assertEquals(Types.DOUBLE, stmtProxy.getParameter(5).getSqlType());
Assert.assertEquals(Types.DECIMAL, stmtProxy.getParameter(6).getSqlType());
Assert.assertEquals(Types.BOOLEAN, stmtProxy.getParameter(7).getSqlType());
Assert.assertEquals(Types.VARCHAR, stmtProxy.getParameter(8).getSqlType());
Assert.assertEquals(Types.DATE, stmtProxy.getParameter(9).getSqlType());
Assert.assertEquals(Types.DATE, stmtProxy.getParameter(10).getSqlType());
Assert.assertEquals(Types.TIMESTAMP, stmtProxy.getParameter(11).getSqlType());
Assert.assertEquals(Types.TIME, stmtProxy.getParameter(12).getSqlType());
stmt.close();
conn.close();
}
}
@@ -22,9 +22,10 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.mock.MockDriver;
import com.alibaba.druid.mock.MockPreparedStatement;
import com.alibaba.druid.pool.DruidDataSource;
@@ -264,7 +265,7 @@ public class ConnectionTest4 extends TestCase {
PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
Assert.assertSame(raw, stmt.unwrap(MockPreparedStatement.class));
stmt.close();
}
@@ -32,19 +32,29 @@ import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.mock.MockCallableStatement;
import com.alibaba.druid.mock.MockConnection;
import com.alibaba.druid.pool.DruidConnectionHolder;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledCallableStatement;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
import com.alibaba.druid.pool.PreparedStatementHolder;
public class PoolableCallableStatementTest extends TestCase {
protected MockCallableStatement raw;
private DruidDataSource dataSource = new DruidDataSource();
protected DruidPooledConnection conn;
protected MockCallableStatement raw;
protected DruidPooledCallableStatement stmt;
protected void setUp() throws Exception {
MockConnection mockConn = new MockConnection();
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn);
conn = new DruidPooledConnection(connHolder);
raw = new MockCallableStatement(null, null);
stmt = new DruidPooledCallableStatement(null,
new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {
stmt = new DruidPooledCallableStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null,
null, 0, 0,
0), raw)) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
@@ -24,23 +24,34 @@ import java.sql.Timestamp;
import java.sql.Types;
import java.util.Arrays;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.mock.MockConnection;
import com.alibaba.druid.mock.MockPreparedStatement;
import com.alibaba.druid.pool.DruidConnectionHolder;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.pool.DruidPooledPreparedStatement;
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
import com.alibaba.druid.pool.PreparedStatementHolder;
public class PoolablePreparedStatementTest extends TestCase {
protected MockPreparedStatement raw;
protected MockPreparedStatement raw;
protected DruidPooledPreparedStatement stmt;
protected void setUp() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
MockConnection mockConn = new MockConnection();
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn);
DruidPooledConnection conn = new DruidPooledConnection(connHolder);
raw = new MockPreparedStatement(null, null);
stmt = new DruidPooledPreparedStatement(null,
new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {
stmt = new DruidPooledPreparedStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null,
null, 0, 0,
0), raw)) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
@@ -1,45 +1,45 @@
/*
* 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.pool.basic;
import java.sql.SQLException;
import junit.framework.TestCase;
import com.alibaba.druid.mock.MockResultSet;
import com.alibaba.druid.pool.DruidPooledStatement;
public class PoolableStatementTest3 extends TestCase {
public void test_clearResultSetError() throws Exception {
final MockResultSet rs = new MockResultSet(null) {
public void close() throws SQLException {
throw new SQLException();
}
};
DruidPooledStatement stmt = new DruidPooledStatement(null, null) {
public void close() throws SQLException {
resultSetTrace.add(rs);
clearResultSet();
}
};
stmt.close();
}
}
/*
* 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.pool.basic;
import java.sql.SQLException;
import junit.framework.TestCase;
import com.alibaba.druid.mock.MockResultSet;
import com.alibaba.druid.pool.DruidPooledStatement;
public class PoolableStatementTest3 extends TestCase {
public void test_clearResultSetError() throws Exception {
final MockResultSet rs = new MockResultSet(null) {
public void close() throws SQLException {
throw new SQLException();
}
};
DruidPooledStatement stmt = new DruidPooledStatement(null, null) {
public void close() throws SQLException {
addResultSetTrace(rs);
clearResultSet();
}
};
stmt.close();
}
}
File diff suppressed because it is too large Load Diff
@@ -18,7 +18,7 @@ package com.alibaba.druid.bvt.proxy.filter;
import java.sql.Connection;
import java.sql.Statement;
import junit.framework.Assert;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.pool.DruidDataSource;
@@ -18,9 +18,10 @@ package com.alibaba.druid.bvt.proxy.filter;
import java.sql.Connection;
import java.sql.Statement;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
public class MergeStatFilterTest2 extends TestCase {
@@ -19,9 +19,10 @@ import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.Statement;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.util.IOUtils;
@@ -17,7 +17,6 @@ package com.alibaba.druid.bvt.proxy.filter;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Set;
import javax.management.openmbean.TabularData;
@@ -26,7 +25,6 @@ import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.stat.DruidDataSourceStatManager;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.druid.util.JdbcUtils;
@@ -17,7 +17,6 @@ package com.alibaba.druid.bvt.proxy.filter;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Set;
import javax.management.openmbean.TabularData;
@@ -26,7 +25,6 @@ import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.stat.DruidDataSourceStatManager;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.druid.util.JdbcUtils;
@@ -17,7 +17,6 @@ package com.alibaba.druid.bvt.proxy.filter;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Set;
import javax.management.openmbean.TabularData;
@@ -26,7 +25,6 @@ import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.stat.DruidDataSourceStatManager;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.druid.util.JdbcUtils;
@@ -0,0 +1,80 @@
/*
* 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.proxy.filter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.management.openmbean.TabularData;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.druid.util.JdbcUtils;
public class MergeStatFilterTest_tddl_3 extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
TabularData sqlList = JdbcStatManager.getInstance().getSqlList();
if (sqlList.size() > 0) {
for (Object item : JdbcStatManager.getInstance().getSqlList().values()) {
String text = JSONUtils.toJSONString(item);
System.out.println(text);
}
}
Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xx");
dataSource.setFilters("mergeStat");
dataSource.setDbType("mysql");
dataSource.setConnectionProperties("druid.useGloalDataSourceStat");
}
protected void tearDown() throws Exception {
JdbcUtils.close(dataSource);
Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
}
public void test_merge() throws Exception {
for (int i = 1000; i < 2000; ++i) {
String tableName = "t_" + i;
Connection conn = dataSource.getConnection();
String sql = "update " + tableName + " SET a = ? WHERE b = ?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "aaa");
stmt.setInt(1, 2);
stmt.execute();
stmt.close();
conn.close();
}
Assert.assertEquals(1, dataSource.getDataSourceStat().getSqlStatMap().size());
}
}
@@ -0,0 +1,81 @@
/*
* 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.proxy.filter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.management.openmbean.TabularData;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.druid.util.JdbcUtils;
public class MergeStatFilterTest_tddl_4 extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
TabularData sqlList = JdbcStatManager.getInstance().getSqlList();
if (sqlList.size() > 0) {
for (Object item : JdbcStatManager.getInstance().getSqlList().values()) {
String text = JSONUtils.toJSONString(item);
System.out.println(text);
}
}
Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xx");
dataSource.setFilters("mergeStat");
dataSource.setDbType("mysql");
dataSource.setConnectionProperties("druid.useGloalDataSourceStat");
dataSource.setPoolPreparedStatements(true);
}
protected void tearDown() throws Exception {
JdbcUtils.close(dataSource);
Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
}
public void test_merge() throws Exception {
for (int i = 1000; i < 2000; ++i) {
String tableName = "t_" + i;
Connection conn = dataSource.getConnection();
String sql = "update " + tableName + " SET a = ? WHERE b = ?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "aaa");
stmt.setInt(1, 2);
stmt.execute();
stmt.close();
conn.close();
}
Assert.assertEquals(1, dataSource.getDataSourceStat().getSqlStatMap().size());
}
}
@@ -1,11 +1,13 @@
package com.alibaba.druid.bvt.proxy.filter;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.filter.stat.StatFilter;
public class StatFilterTest3 extends TestCase {
@SuppressWarnings("deprecation")
public void test_dbType() throws Exception {
StatFilter filter = new StatFilter();