@Test public void testQuerySingleKeyMiss() throws Exception { TypeToken<Integer> pt = TypeToken.of(Integer.class); TypeToken<User> rt = TypeToken.of(User.class); String srcSql = "select * from user where id=:1"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public Object get(String key, Type type, Class<?> daoClass) { assertThat(key, Matchers.equalTo("user_1")); return null; } @Override public void set(String key, Object value, int expires, Class<?> daoClass) { assertThat(key, Matchers.equalTo("user_1")); assertThat(expires, Matchers.equalTo((int) TimeUnit.DAYS.toSeconds(1))); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> T queryForObject(DataSource ds, BoundSql boundSql, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select * from user where id=?"; assertThat(sql, Matchers.equalTo(descSql)); assertThat(args.length, Matchers.equalTo(1)); assertThat(args[0], Matchers.equalTo((Object) 1)); return (T) new User(); } }); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{1}, stat); assertThat(stat.getMissCount(), Matchers.equalTo(1L)); }
@Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return driver.isUseMultipleKeys() ? multipleKeysCache(context, rowMapper.getMappedClass(), driver.getOnlyCacheByClass(), stat) : singleKeyCache(context, stat); }
CacheableQueryOperator extends QueryOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return driver.isUseMultipleKeys() ? multipleKeysCache(context, rowMapper.getMappedClass(), driver.getOnlyCacheByClass(), stat) : singleKeyCache(context, stat); } }
CacheableQueryOperator extends QueryOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return driver.isUseMultipleKeys() ? multipleKeysCache(context, rowMapper.getMappedClass(), driver.getOnlyCacheByClass(), stat) : singleKeyCache(context, stat); } CacheableQueryOperator(ASTRootNode rootNode, MethodDescriptor md, CacheDriver cacheDriver, Config config); }
CacheableQueryOperator extends QueryOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return driver.isUseMultipleKeys() ? multipleKeysCache(context, rowMapper.getMappedClass(), driver.getOnlyCacheByClass(), stat) : singleKeyCache(context, stat); } CacheableQueryOperator(ASTRootNode rootNode, MethodDescriptor md, CacheDriver cacheDriver, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
CacheableQueryOperator extends QueryOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return driver.isUseMultipleKeys() ? multipleKeysCache(context, rowMapper.getMappedClass(), driver.getOnlyCacheByClass(), stat) : singleKeyCache(context, stat); } CacheableQueryOperator(ASTRootNode rootNode, MethodDescriptor md, CacheDriver cacheDriver, Config config); @Override Object execute(Object[] values, InvocationStat stat);  }