mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
改进PreparedStatementCache
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@916 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -76,15 +76,7 @@ public class DataSourceTest3 extends TestCase {
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.setPoolPreparedStatements(false);
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
dataSource.setPoolPreparedStatements(false);
|
||||
}
|
||||
|
||||
public void test_error_2() throws Exception {
|
||||
|
||||
@@ -18,6 +18,8 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockCallableStatement;
|
||||
import com.alibaba.druid.pool.PoolableCallableStatement;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.PreparedStatementHolder;
|
||||
|
||||
public class PoolableCallableStatementTest extends TestCase {
|
||||
|
||||
@@ -26,7 +28,7 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
raw = new MockCallableStatement(null, null);
|
||||
stmt = new PoolableCallableStatement(null, raw, null, null) {
|
||||
stmt = new PoolableCallableStatement(null, new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
|
||||
|
||||
protected SQLException checkException(Throwable error) throws SQLException {
|
||||
if (error instanceof SQLException) {
|
||||
|
||||
@@ -14,6 +14,8 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement;
|
||||
import com.alibaba.druid.pool.PreparedStatementHolder;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
|
||||
public class PoolablePreparedStatementTest extends TestCase {
|
||||
|
||||
@@ -22,7 +24,7 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
raw = new MockPreparedStatement(null, null);
|
||||
stmt = new PoolablePreparedStatement(null, raw, null, null) {
|
||||
stmt = new PoolablePreparedStatement(null, new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
|
||||
|
||||
protected SQLException checkException(Throwable error) throws SQLException {
|
||||
if (error instanceof SQLException) {
|
||||
|
||||
@@ -5,8 +5,8 @@ import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.PreparedStatementHolder;
|
||||
import com.alibaba.druid.pool.PreparedStatementPool;
|
||||
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
|
||||
|
||||
@@ -96,8 +96,9 @@ public class PreparedStatementKeyTest extends TestCase {
|
||||
|
||||
public void test_contains() throws Exception {
|
||||
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
|
||||
PreparedStatementPool pool = new PreparedStatementPool();
|
||||
pool.put(new PoolablePreparedStatement(null, new MockPreparedStatement(null, null), k1, null));
|
||||
PreparedStatementPool pool = new PreparedStatementPool(10);
|
||||
MockPreparedStatement raw = new MockPreparedStatement(null, null);
|
||||
pool.put(new PreparedStatementHolder(k1, raw));
|
||||
Assert.assertTrue(pool.get(k1) != null);
|
||||
Assert.assertTrue(pool.get(k1) == null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user