use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class DruidJdbcExtractorTest method test_spring_filter.
public void test_spring_filter() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
try {
DruidNativeJdbcExtractor extractor = new DruidNativeJdbcExtractor();
dataSource.setUrl("jdbc:mock:xx1");
dataSource.setFilters("stat");
Connection conn = dataSource.getConnection();
Assert.assertEquals(true, extractor.getNativeConnection(conn) instanceof MockConnection);
Statement stmt = conn.createStatement();
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(stmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(stmt) instanceof MockStatement);
stmt.close();
PreparedStatement preStmt = conn.prepareStatement("select 1");
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(preStmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(preStmt) instanceof MockPreparedStatement);
Assert.assertEquals(true, extractor.getNativePreparedStatement(preStmt) instanceof MockPreparedStatement);
preStmt.close();
PreparedStatement callStmt = conn.prepareCall("select 1");
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(callStmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(callStmt) instanceof MockCallableStatement);
Assert.assertEquals(true, extractor.getNativePreparedStatement(callStmt) instanceof MockCallableStatement);
callStmt.close();
conn.close();
} finally {
dataSource.close();
}
}
use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class Bug_for_happyday517 method test_for_happyday517_2.
public void test_for_happyday517_2() throws Exception {
Connection conn = dataSource.getConnection();
String sql = "select 1";
Statement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
MockPreparedStatement mockStmt = stmt.unwrap(MockPreparedStatement.class);
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
stmt.close();
conn.close();
}
use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class EncodingConvertFilterTest method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setFilters("encoding");
dataSource.setDriver(new MockDriver() {
public ResultSet createResultSet(MockPreparedStatement stmt) {
return new MyResultSet(stmt);
}
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
return new MyResultSet(stmt);
}
});
dataSource.getConnectProperties().put("clientEncoding", CLIENT_ENCODING);
dataSource.getConnectProperties().put("serverEncoding", SERVER_ENCODING);
dataSource.init();
}
use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class EncodingConvertFilterTest2 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setFilters("encoding");
dataSource.setDriver(new MockDriver() {
public ResultSet createResultSet(MockPreparedStatement stmt) {
return new MyResultSet(stmt);
}
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
return new MyResultSet(stmt);
}
});
dataSource.getConnectProperties().put("clientEncoding", CLIENT_ENCODING);
dataSource.getConnectProperties().put("serverEncoding", SERVER_ENCODING);
dataSource.init();
}
use of com.alibaba.druid.mock.MockPreparedStatement in project druid by alibaba.
the class PoolablePreparedStatementTest method setUp.
protected void setUp() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
MockConnection mockConn = new MockConnection();
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
DruidPooledConnection conn = new DruidPooledConnection(connHolder);
raw = new MockPreparedStatement(null, null);
stmt = new DruidPooledPreparedStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
return (SQLException) error;
}
return new SQLException(error);
}
};
}
Aggregations