Merge remote-tracking branch 'origin/master'

This commit is contained in:
wenshao
2013-05-29 18:03:20 +08:00
11 changed files with 96 additions and 34 deletions
@@ -17,5 +17,7 @@ package com.alibaba.druid;
public interface Constants {
public final static String DRUID_STAT_SQL_MAX_SIZE = "druid.stat.sql.MaxSize";
public final static String DRUID_STAT_SQL_MAX_SIZE = "druid.stat.sql.MaxSize";
public final static String DRUID_TIME_BETWEEN_LOG_STATS_MILLIS = "druid.timeBetweenLogStatsMillis";
}
@@ -191,13 +191,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
}
{
String property = properties.getProperty("druid.timeBetweenLogStatsMillis");
String property = properties.getProperty(Constants.DRUID_TIME_BETWEEN_LOG_STATS_MILLIS);
if (property != null && property.length() > 0) {
try {
long value = Long.parseLong(property);
this.setTimeBetweenLogStatsMillis(value);
} catch (NumberFormatException e) {
LOG.error("illegal property 'timeBetweenLogStatsMillis'", e);
LOG.error("illegal property '" + Constants.DRUID_TIME_BETWEEN_LOG_STATS_MILLIS + "'", e);
}
}
}
@@ -419,21 +419,21 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (inited && LOG.isInfoEnabled()) {
LOG.info("connectProperties changed : " + this.connectProperties + " -> " + properties);
}
configFromPropety(properties);
for (Filter filter : this.filters) {
filter.configFromProperties(properties);
}
if (exceptionSorter != null) {
exceptionSorter.configFromProperties(properties);
}
if (validConnectionChecker != null) {
validConnectionChecker.configFromProperties(properties);
}
if (statLogger != null) {
statLogger.configFromProperties(properties);
}
@@ -1,3 +1,18 @@
/*
* 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.pool;
import java.util.Properties;
@@ -17,8 +17,10 @@ package com.alibaba.druid.pool;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.stat.JdbcSqlStatValue;
import com.alibaba.druid.support.json.JSONUtils;
public class DruidDataSourceStatValue {
@@ -78,6 +80,27 @@ public class DruidDataSourceStatValue {
protected long sqlSkipCount;
protected List<JdbcSqlStatValue> sqlList;
@SuppressWarnings("unchecked")
public void fromJSON(String json) {
// protected String dbType;
// protected String driverClassName;
// protected String url;
// protected String userName;
// protected List<String> filterClassNames;
// protected boolean removeAbandoned;
//
Map<String, Object> map = (Map<String, Object>) JSONUtils.parse(json);
fromJSON(map);
}
public void fromJSON(Map<String, Object> map) {
this.name = (String) map.get("name");
this.dbType = (String) map.get("dbType");
this.driverClassName = (String) map.get("driverClassName");
this.url = (String) map.get("url");
this.userName = (String) map.get("userName");
}
public Date getPoolingPeakTime() {
if (poolingPeakTime <= 0) {
@@ -482,5 +505,6 @@ public class DruidDataSourceStatValue {
public void setPoolingPeakTime(long poolingPeakTime) {
this.poolingPeakTime = poolingPeakTime;
}
}
@@ -1,3 +1,18 @@
/*
* 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.pool;
import java.sql.Connection;
@@ -36,6 +36,9 @@ public class SQLCastExpr extends SQLExprImpl {
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
@@ -120,11 +120,11 @@ public final class DruidStatService implements DruidStatServiceMBean {
if (url.startsWith("/sql.json")) {
return returnJSONResult(RESULT_CODE_SUCCESS, getSqlStatDataList(parameters));
}
if (url.startsWith("/wall.json")) {
return returnJSONResult(RESULT_CODE_SUCCESS, getWallStatMap(parameters));
return returnJSONResult(RESULT_CODE_SUCCESS, getWallStatMap(parameters));
}
if (url.startsWith("/wall-") && url.indexOf(".json") > 0) {
Integer dataSourceId = StringUtils.subStringToInteger(url, "wall-", ".json");
Object result = statManagerFacade.getWallStatMap(dataSourceId);
@@ -266,7 +266,7 @@ public final class DruidStatService implements DruidStatServiceMBean {
List<Map<String, Object>> sortedArray = comparatorOrderBy(array, parameters);
return sortedArray;
}
@SuppressWarnings("unchecked")
public Map<String, Object> getWallStatMap(Map<String, String> parameters) {
Integer dataSourceId = null;
@@ -275,14 +275,21 @@ public final class DruidStatService implements DruidStatServiceMBean {
if (dataSourceIdParam != null && dataSourceIdParam.length() > 0) {
dataSourceId = Integer.parseInt(dataSourceIdParam);
}
Map<String, Object> result = statManagerFacade.getWallStatMap(dataSourceId);
List<Map<String, Object>> sortedArray = comparatorOrderBy((List<Map<String, Object>>)result.get("tables"), parameters);
result.put("tables", sortedArray);
sortedArray = comparatorOrderBy((List<Map<String, Object>>)result.get("functions"), parameters);
result.put("functions", sortedArray);
if (result != null) {
List<Map<String, Object>> tables = (List<Map<String, Object>>) result.get("tables");
if (tables != null) {
List<Map<String, Object>> sortedArray = comparatorOrderBy(tables, parameters);
result.put("tables", sortedArray);
sortedArray = comparatorOrderBy((List<Map<String, Object>>) result.get("functions"), parameters);
result.put("functions", sortedArray);
}
} else {
result = Collections.emptyMap();
}
return result;
}
@@ -57,6 +57,7 @@ import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLInsertInto;
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
import com.alibaba.druid.sql.ast.statement.SQLRollbackStatement;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
@@ -1008,7 +1009,7 @@ public class WallVisitorUtils {
}
}
if (isWhereOrHaving(x)) {
if (!(x.getParent() instanceof ValuesClause)) {
addViolation(visitor, ErrorCode.FUNCTION_DENY, "deny function : " + methodName, x);
}
}
@@ -1,8 +0,0 @@
package com.alibaba.druid.bvt.pool.vendor;
import junit.framework.TestCase;
public class MySqlValidConnectionCheckerTest extends TestCase {
}
@@ -204,8 +204,9 @@ public class DruidStatServiceTest extends TestCase {
String result = DruidStatService.getInstance().service("/activeConnectionStackTrace.json");
Map<String, Object> resultMap = (Map<String, Object>) JSONUtils.parse(result);
List<String> contentList = (List<String>) resultMap.get("Content");
Object first = contentList.get(0);
assertThat(contentList.get(0), is(not(nullValue())));
assertThat(first, is(not(nullValue())));
// close connection at last.
stmt.close();
conn.close();
@@ -23,9 +23,12 @@ import static org.junit.Assert.assertThat;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -38,13 +41,12 @@ import com.alibaba.druid.util.JdbcUtils;
/**
* Multiple data source test case.
*/
public class DruidStatServiceTest2 {
public class DruidStatServiceTest2 extends TestCase {
private DruidDataSource dataSource;
private DruidDataSource dataSource2;
// every test, two data source initialized.
@Before
public void setUp() throws Exception {
// DruidStatService is singleton, reset all for other testcase.
DruidStatService.getInstance().service("/reset-all.json");
@@ -62,13 +64,11 @@ public class DruidStatServiceTest2 {
dataSource2.init();
}
@After
public void tearDown() throws Exception {
JdbcUtils.close(dataSource);
JdbcUtils.close(dataSource2);
}
@Test
public void test_statService_getSqlList() throws Exception {
String sql = "select 1";
@@ -106,7 +106,6 @@ public class DruidStatServiceTest2 {
}
}
@Test
public void test_statService_getSqlById() throws Exception {
String sql = "select 1";
@@ -155,7 +154,6 @@ public class DruidStatServiceTest2 {
assertThat(resultMap.get("Content"), is(nullValue()));
}
@Test
public void test_statService_getDataSourceList() throws Exception {
String result = DruidStatService.getInstance().service("/datasource.json");
Map<String, Object> resultMap = (Map<String, Object>) JSONUtils.parse(result);
@@ -167,5 +165,9 @@ public class DruidStatServiceTest2 {
assertThat((Integer) dataSourceStat.get("PoolingCount"), equalTo(0));
assertThat((Integer) dataSourceStat.get("ActiveCount"), equalTo(0));
}
public void test_getWallStatMap() throws Exception {
DruidStatService.getInstance().getWallStatMap(Collections.<String, String>emptyMap());
}
}