improved jndi datasource support.

This commit is contained in:
wenshao
2017-08-18 14:50:18 +08:00
parent 3b0b090989
commit e5bd1a24ad
2 changed files with 49 additions and 0 deletions
@@ -1788,6 +1788,16 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
@Override
public Connection getConnection(String username, String password) throws SQLException {
if (this.username == null
&& this.password == null
&& username != null
&& password != null) {
this.username = username;
this.password = password;
return getConnection();
}
if (!StringUtils.equals(username, this.username)) {
throw new UnsupportedOperationException("Not supported by DruidDataSource");
}
@@ -0,0 +1,39 @@
package com.alibaba.druid.bvt.pool;
import com.alibaba.druid.pool.DruidDataSource;
import junit.framework.TestCase;
import org.junit.Assert;
import java.sql.Connection;
/**
* 这个场景测试defaultAutoCommit
*
* @author wenshao [szujobs@hotmail.com]
*/
public class DruidDataSourceTest_getConnection_2 extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_conn_ok() throws Exception {
{
Connection conn = dataSource.getConnection("usr1", "pwd1");
conn.close();
}
{
Connection conn = dataSource.getConnection("usr1", "pwd1");
conn.close();
}
}
}