mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed
This commit is contained in:
@@ -998,6 +998,10 @@ public class DruidPooledPreparedStatement extends DruidPooledStatement implement
|
||||
return (T) stmt;
|
||||
}
|
||||
|
||||
if (iface == PreparedStatementHolder.class) {
|
||||
return (T) this.holder;
|
||||
}
|
||||
|
||||
return super.unwrap(iface);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public class PreparedStatementPool {
|
||||
return null;
|
||||
}
|
||||
|
||||
holder.incrementHitCount();
|
||||
dataSource.incrementCachedPreparedStatementHitCount();
|
||||
if (holder.isEnterOracleImplicitCache()) {
|
||||
OracleUtils.exitImplicitCacheToActive(holder.getStatement());
|
||||
|
||||
@@ -10,6 +10,7 @@ import oracle.jdbc.OracleConnection;
|
||||
import oracle.jdbc.internal.OraclePreparedStatement;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.PreparedStatementHolder;
|
||||
import com.alibaba.druid.test.util.OracleMockDriver;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
@@ -34,20 +35,25 @@ public class TestOraclePrefetch extends TestCase {
|
||||
|
||||
String sql = "SELECT 1";
|
||||
|
||||
OracleConnection oracleConn;
|
||||
OraclePreparedStatement oracleStmt;
|
||||
PreparedStatementHolder stmtHolder;
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
{
|
||||
OracleConnection oracleConn = conn.unwrap(OracleConnection.class);
|
||||
oracleConn = conn.unwrap(OracleConnection.class);
|
||||
Assert.assertEquals(50, oracleConn.getDefaultRowPrefetch());
|
||||
}
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
|
||||
{
|
||||
OraclePreparedStatement oracleStmt = stmt.unwrap(OraclePreparedStatement.class);
|
||||
Assert.assertEquals(50, oracleStmt.getRowPrefetch());
|
||||
}
|
||||
oracleStmt = stmt.unwrap(OraclePreparedStatement.class);
|
||||
Assert.assertEquals(50, oracleStmt.getRowPrefetch());
|
||||
|
||||
stmtHolder = stmt.unwrap(PreparedStatementHolder.class);
|
||||
Assert.assertNotNull(stmtHolder);
|
||||
Assert.assertEquals(0, stmtHolder.getHitCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
@@ -61,22 +67,29 @@ public class TestOraclePrefetch extends TestCase {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
{
|
||||
OracleConnection oracleConn = conn.unwrap(OracleConnection.class);
|
||||
Assert.assertEquals(50, oracleConn.getDefaultRowPrefetch());
|
||||
OracleConnection oracleConn2 = conn.unwrap(OracleConnection.class);
|
||||
Assert.assertEquals(50, oracleConn2.getDefaultRowPrefetch());
|
||||
Assert.assertSame(oracleConn, oracleConn2);
|
||||
}
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
|
||||
{
|
||||
PreparedStatementHolder stmtHolder2 = stmt.unwrap(PreparedStatementHolder.class);
|
||||
Assert.assertSame(stmtHolder2, stmtHolder);
|
||||
Assert.assertEquals(1, stmtHolder.getHitCount());
|
||||
}
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
|
||||
rs.close();
|
||||
stmt.close();
|
||||
{
|
||||
OraclePreparedStatement oracleStmt = stmt.unwrap(OraclePreparedStatement.class);
|
||||
OraclePreparedStatement oracleStmt2 = stmt.unwrap(OraclePreparedStatement.class);
|
||||
Assert.assertSame(oracleStmt, oracleStmt2);
|
||||
Assert.assertEquals(2, oracleStmt.getRowPrefetch());
|
||||
}
|
||||
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user