use of com.github.pagehelper.mapper.ProviderMethod in project Mybatis-PageHelper by pagehelper.
the class TestProviderInteceptor method testInterceptor.
@Test
public void testInterceptor() {
SqlSession sqlSession = MybatisInterceptorHelper.getSqlSession();
final UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
try {
PageHelper.startPage(1, 10).boundSqlInterceptor(new BoundSqlInterceptor() {
@Override
public BoundSql boundSql(Type type, BoundSql boundSql, CacheKey cacheKey, Chain chain) {
System.out.println("[" + Thread.currentThread().getName() + "] - before: " + boundSql.getSql());
BoundSql doBoundSql = chain.doBoundSql(type, boundSql, cacheKey);
System.out.println("[" + Thread.currentThread().getName() + "] - after: " + doBoundSql.getSql());
if (type == Type.ORIGINAL) {
Assert.assertTrue(doBoundSql.getSql().contains(TestBoundSqlInterceptor.COMMENT));
}
return doBoundSql;
}
});
final String str = "飞";
userMapper.selectSimple(str);
assertEquals(new ProviderMethod().selectSimple(str), SqlCache.get());
userMapper.selectSimple(str);
assertEquals(new ProviderMethod().selectSimple(str), SqlCache.get());
userMapper.selectSimple(str);
assertEquals(new ProviderMethod().selectSimple(str), SqlCache.get());
} finally {
SqlCache.remove();
sqlSession.close();
}
}
Aggregations