mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
revert
This commit is contained in:
@@ -840,62 +840,25 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String user) {
|
||||
lock.lock();
|
||||
try {
|
||||
if (equals(this.username, user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inited) {
|
||||
this.modCount++;
|
||||
clear();
|
||||
}
|
||||
|
||||
this.username = user;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
public void setUsername(String username) {
|
||||
if (inited) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setUrlAndUserAndPassword(String url, String user, String password) {
|
||||
lock.lock();
|
||||
try {
|
||||
if (equals(this.jdbcUrl, url) && equals(this.username, user) && equals(this.password, password)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inited) {
|
||||
this.modCount++;
|
||||
clear();
|
||||
}
|
||||
|
||||
this.username = user;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
lock.lock();
|
||||
try {
|
||||
if (equals(this.password, password)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inited) {
|
||||
this.modCount++;
|
||||
clear();
|
||||
}
|
||||
|
||||
this.password = password;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
if (inited) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Properties getConnectProperties() {
|
||||
@@ -948,25 +911,13 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
}
|
||||
|
||||
public void setUrl(String jdbcUrl) {
|
||||
lock.lock();
|
||||
try {
|
||||
if (equals(this.jdbcUrl, jdbcUrl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inited) {
|
||||
this.modCount++;
|
||||
clear();
|
||||
}
|
||||
|
||||
this.jdbcUrl = jdbcUrl;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
if (inited) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
this.jdbcUrl = jdbcUrl;
|
||||
}
|
||||
|
||||
public abstract void clear();
|
||||
|
||||
public String getDriverClassName() {
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
@@ -1185,28 +1185,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
final List<ConnectionHolder> evictList = new ArrayList<ConnectionHolder>();
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
for (int i = 0; i < poolingCount; ++i) {
|
||||
ConnectionHolder connection = connections[i];
|
||||
evictList.add(connection);
|
||||
}
|
||||
|
||||
poolingCount = 0;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
for (ConnectionHolder item : evictList) {
|
||||
Connection connection = item.getConnection();
|
||||
JdbcUtils.close(connection);
|
||||
destroyCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public int getWaitThreadCount() {
|
||||
lock.lock();
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.alibaba.druid.bvt.pool.basic;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
@@ -56,32 +55,19 @@ public class DataSourceTest3 extends TestCase {
|
||||
JdbcStatManager.getInstance().setStatContext(null);
|
||||
}
|
||||
|
||||
public void test_setUser() throws Exception {
|
||||
Connection real;
|
||||
public void test_prepareStatement_error() throws Exception {
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
real = conn.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
|
||||
dataSource.setUsername(dataSource.getUsername());
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
dataSource.setUsername("xxx_u1");
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertNotSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.setUsername("xxx");
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,119 +159,19 @@ public class DataSourceTest3 extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void test_setPassword() throws Exception {
|
||||
Connection real;
|
||||
public void test_error_7() throws Exception {
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
real = conn.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
|
||||
dataSource.setPassword(dataSource.getPassword());
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
dataSource.setPassword("xxx_pass");
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertNotSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void test_setUrlAndUserAndPassword() throws Exception {
|
||||
Connection real;
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
real = conn.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
|
||||
dataSource.setUrlAndUserAndPassword(dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
dataSource.setUrlAndUserAndPassword(dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword() + "_");
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertNotSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void test_setUrlAndUserAndPassword_1() throws Exception {
|
||||
Connection real;
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
real = conn.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
|
||||
dataSource.setUrlAndUserAndPassword(dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
dataSource.setUrlAndUserAndPassword(dataSource.getUrl() + "_", dataSource.getUsername(), dataSource.getPassword() );
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertNotSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void test_setUrlAndUserAndPassword_2() throws Exception {
|
||||
Connection real;
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
real = conn.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
|
||||
dataSource.setUrlAndUserAndPassword(dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
dataSource.setUrlAndUserAndPassword(dataSource.getUrl(), dataSource.getUsername() + "_", dataSource.getPassword() );
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertNotSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.setPassword("xx");
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,32 +250,21 @@ public class DataSourceTest3 extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void test_setUrl() throws Exception {
|
||||
Connection real;
|
||||
public void test_error_11() throws Exception {
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
|
||||
conn.close();
|
||||
|
||||
dataSource.getUrl();
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
real = conn.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
|
||||
dataSource.setUrl(dataSource.getUrl());
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
}
|
||||
dataSource.setUrl("jdbc:mock:xxx_123");
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
Assert.assertNotSame(real, conn.getConnection());
|
||||
conn.close();
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.setUrl("x");
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user