mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add exection sorter test
This commit is contained in:
@@ -41,8 +41,8 @@ public class MockStatement extends StatementBase implements MockStatementBase, S
|
||||
throw new SQLException();
|
||||
}
|
||||
|
||||
if (this.mockConnection != null && this.mockConnection.isClosed()) {
|
||||
throw new MockConnectionClosedException();
|
||||
if (this.mockConnection != null) {
|
||||
mockConnection.checkState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class DataSourceAdapter extends WrapperAdapter implements DataSource {
|
||||
|
||||
private int loginTimeout = 0;
|
||||
private PrintWriter logWriter = new PrintWriter(System.out);
|
||||
|
||||
public DataSourceAdapter(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getLogWriter() throws SQLException {
|
||||
return logWriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogWriter(PrintWriter out) throws SQLException {
|
||||
this.logWriter = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginTimeout(int seconds) throws SQLException {
|
||||
loginTimeout = seconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoginTimeout() throws SQLException {
|
||||
return loginTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,16 +21,8 @@ public class DataSourceClosedException extends SQLException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DataSourceClosedException(){
|
||||
super();
|
||||
}
|
||||
|
||||
public DataSourceClosedException(String reason){
|
||||
super(reason);
|
||||
}
|
||||
|
||||
public DataSourceClosedException(Throwable cause){
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -143,6 +143,16 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
String property = System.getProperty("druid.testWhileIdle");
|
||||
if ("true".equals(property)) {
|
||||
this.setTestWhileIdle(true);
|
||||
} else if ("false".equals(property)) {
|
||||
this.setTestWhileIdle(false);
|
||||
}
|
||||
}
|
||||
{
|
||||
String property = System.getProperty("druid.testOnBorrow");
|
||||
if ("true".equals(property)) {
|
||||
this.setTestOnBorrow(true);
|
||||
} else if ("false".equals(property)) {
|
||||
this.setTestOnBorrow(false);
|
||||
}
|
||||
}
|
||||
{
|
||||
@@ -159,6 +169,19 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.setUseGloalDataSourceStat(false);
|
||||
}
|
||||
}
|
||||
{
|
||||
String property = System.getProperty("druid.filters");
|
||||
|
||||
if (property == null || property.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.setFilters(property);
|
||||
} catch (SQLException e) {
|
||||
LOG.error("setFilters error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUseGloalDataSourceStat() {
|
||||
@@ -374,8 +397,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
this.id = DruidDriver.createDataSourceId();
|
||||
|
||||
loadFilterFromSystemProperty();
|
||||
|
||||
if (this.dbType == null || this.dbType.length() == 0) {
|
||||
this.dbType = JdbcUtils.getDbType(jdbcUrl, null);
|
||||
}
|
||||
@@ -523,15 +544,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
createConnectionThread.start();
|
||||
}
|
||||
|
||||
private void loadFilterFromSystemProperty() throws SQLException {
|
||||
String property = System.getProperty("druid.filters");
|
||||
|
||||
if (property == null || property.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setFilters(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* load filters from SPI ServiceLoader
|
||||
@@ -1284,15 +1296,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBusy() {
|
||||
lock.lock();
|
||||
try {
|
||||
return this.inited && this.activeCount == maxActive && this.poolingCount == 0;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public long getRemoveAbandonedCount() {
|
||||
return removeAbandonedCount;
|
||||
}
|
||||
|
||||
@@ -203,22 +203,6 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
|
||||
return disable;
|
||||
}
|
||||
|
||||
public void discard() {
|
||||
if (this.disable) {
|
||||
return;
|
||||
}
|
||||
|
||||
DruidConnectionHolder holder = this.holder;
|
||||
if (holder == null) {
|
||||
if (dupCloseLogEnable) {
|
||||
LOG.error("dup close");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
holder.getDataSource().discardConnection(holder.getConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
if (this.disable) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.sql.SQLException;
|
||||
public class GetConnectionTimeoutException extends SQLException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
public GetConnectionTimeoutException(){
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -30,17 +30,21 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLDDLS
|
||||
|
||||
private SQLName name;
|
||||
|
||||
private SQLName table;
|
||||
private SQLTableSource table;
|
||||
|
||||
private List<SQLSelectOrderByItem> items = new ArrayList<SQLSelectOrderByItem>();
|
||||
|
||||
private String type;
|
||||
|
||||
public SQLName getTable() {
|
||||
public SQLTableSource getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
public void setTable(SQLName table) {
|
||||
this.setTable(new SQLExprTableSource(table));
|
||||
}
|
||||
|
||||
public void setTable(SQLTableSource table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLDropIndexStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLExpr indexName;
|
||||
private SQLExpr tableName;
|
||||
private SQLExpr indexName;
|
||||
private SQLExprTableSource tableName;
|
||||
|
||||
public SQLExpr getIndexName() {
|
||||
return indexName;
|
||||
@@ -34,11 +34,15 @@ public class SQLDropIndexStatement extends SQLStatementImpl implements SQLDDLSta
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
public SQLExpr getTableName() {
|
||||
public SQLExprTableSource getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(SQLExpr tableName) {
|
||||
this.setTableName(new SQLExprTableSource(tableName));
|
||||
}
|
||||
|
||||
public void setTableName(SQLExprTableSource tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,9 +47,13 @@ import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCallStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement;
|
||||
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;
|
||||
@@ -1180,11 +1184,11 @@ public class WallVisitorUtils {
|
||||
if (name.startsWith("\"") && name.endsWith("\"")) {
|
||||
name = name.substring(1, name.length() - 1);
|
||||
}
|
||||
|
||||
|
||||
if (name.startsWith("'") && name.endsWith("'")) {
|
||||
name = name.substring(1, name.length() - 1);
|
||||
}
|
||||
|
||||
|
||||
if (name.startsWith("`") && name.endsWith("`")) {
|
||||
name = name.substring(1, name.length() - 1);
|
||||
}
|
||||
@@ -1293,7 +1297,9 @@ public class WallVisitorUtils {
|
||||
allow = config.isTruncateAllow();
|
||||
denyMessage = "truncate not allow";
|
||||
errorCode = ErrorCode.TRUNCATE_NOT_ALLOW;
|
||||
} else if (x instanceof SQLCreateTableStatement) {
|
||||
} else if (x instanceof SQLCreateTableStatement //
|
||||
|| x instanceof SQLCreateIndexStatement //
|
||||
|| x instanceof SQLCreateViewStatement) {
|
||||
allow = config.isCreateTableAllow();
|
||||
denyMessage = "create table not allow";
|
||||
errorCode = ErrorCode.CREATE_TABLE_NOT_ALLOW;
|
||||
@@ -1301,7 +1307,9 @@ public class WallVisitorUtils {
|
||||
allow = config.isAlterTableAllow();
|
||||
denyMessage = "alter table not allow";
|
||||
errorCode = ErrorCode.ALTER_TABLE_NOT_ALLOW;
|
||||
} else if (x instanceof SQLDropTableStatement) {
|
||||
} else if (x instanceof SQLDropTableStatement //
|
||||
|| x instanceof SQLDropIndexStatement //
|
||||
|| x instanceof SQLDropViewStatement) {
|
||||
allow = config.isDropTableAllow();
|
||||
denyMessage = "drop table not allow";
|
||||
errorCode = ErrorCode.DROP_TABLE_NOT_ALLOW;
|
||||
|
||||
Reference in New Issue
Block a user