use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class ConnectionTest4 method test_prepCall.
public void test_prepCall() throws Exception {
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
MockPreparedStatement raw = null;
{
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
raw = stmt.unwrap(MockPreparedStatement.class);
stmt.close();
}
{
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
stmt.close();
}
conn.close();
}
use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class ConnectionTest4 method test_prepareStatement_2.
public void test_prepareStatement_2() throws Exception {
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
MockPreparedStatement raw = null;
{
PreparedStatement stmt = conn.prepareStatement("SELECT 1", new int[0]);
raw = stmt.unwrap(MockPreparedStatement.class);
stmt.close();
}
{
PreparedStatement stmt = conn.prepareStatement("SELECT 1", new int[0]);
Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
stmt.close();
}
conn.close();
}
use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class PSCacheTest5 method test_0.
public void test_0() throws Exception {
MockPreparedStatement mockStmt = null;
{
Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement("select 1");
mockStmt = ps.unwrap(MockPreparedStatement.class);
ps.execute();
conn.close();
}
for (int i = 0; i < 1000; ++i) {
Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement("select 1");
Assert.assertSame(mockStmt, ps.unwrap(MockPreparedStatement.class));
ps.execute();
ps.close();
conn.close();
}
}
use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class TestPSCache method unwrap.
public static MockPreparedStatement unwrap(PreparedStatement stmt) throws Exception {
if (stmt instanceof NewProxyPreparedStatement) {
Field field = NewProxyPreparedStatement.class.getDeclaredField("inner");
field.setAccessible(true);
return (MockPreparedStatement) field.get(stmt);
}
MockPreparedStatement mockStmt = stmt.unwrap(MockPreparedStatement.class);
return mockStmt;
}
Aggregations