mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support Connection.setSchema for mysql, fix #3865
This commit is contained in:
@@ -73,6 +73,7 @@ public final class DruidConnectionHolder {
|
||||
protected final Map<String, Object> variables;
|
||||
protected final Map<String, Object> globleVariables;
|
||||
final ReentrantLock lock = new ReentrantLock();
|
||||
protected String initSchema;
|
||||
|
||||
public DruidConnectionHolder(DruidAbstractDataSource dataSource, PhysicalConnectionInfo pyConnectInfo)
|
||||
throws SQLException{
|
||||
|
||||
@@ -1953,6 +1953,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (holder.initSchema != null) {
|
||||
holder.conn.setSchema(holder.initSchema);
|
||||
holder.initSchema = null;
|
||||
}
|
||||
|
||||
if (!enable) {
|
||||
discardConnection(holder);
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
|
||||
import com.alibaba.druid.proxy.jdbc.TransactionInfo;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
* @author wenshao [szujobs@hotmail.com]
|
||||
@@ -1190,6 +1191,16 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
|
||||
}
|
||||
|
||||
public void setSchema(String schema) throws SQLException {
|
||||
if (JdbcUtils.isMysqlDbType(holder.getDataSource().getDbType())) {
|
||||
if (holder.initSchema == null) {
|
||||
holder.initSchema = conn.getSchema();
|
||||
}
|
||||
conn.setSchema(schema);
|
||||
if (holder.statementPool != null) {
|
||||
holder.clearStatementCache();
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user