@Test public void testQueryMultiKey() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<List<User>> rt = new TypeToken<List<User>>() { }; String srcSql = "select * from user where id in (:1)"; final Set<String> keys = new HashSet<String>(); final Set<String> setKeys = new HashSet<String>(); keys.add("user_1"); keys.add("user_2"); keys.add("user_3"); AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public Map<String, Object> getBulk(Set<String> keys, Type type, Class<?> daoClass) { assertThat(keys, Matchers.equalTo(keys)); Map<String, Object> map = new HashMap<String, Object>(); map.put("user_2", new User()); return map; } @Override public void set(String key, Object value, int expires, Class<?> daoClass) { setKeys.add(key); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> List<T> queryForList(DataSource ds, BoundSql boundSql, ListSupplier listSupplier, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select * from user where id in (?,?)"; assertThat(sql, Matchers.equalTo(descSql)); assertThat(args.length, Matchers.equalTo(2)); assertThat(args[0], Matchers.equalTo((Object) 1)); assertThat(args[1], Matchers.equalTo((Object) 3)); List<T> users = new ArrayList<T>(); users.add((T) new User(1, "1")); users.add((T) new User(3, "3")); return users; } }); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{Arrays.asList(1, 2, 3)}, stat); assertThat(stat.getHitCount(), Matchers.equalTo(1L)); assertThat(stat.getMissCount(), Matchers.equalTo(2L)); keys.remove("user_2"); assertThat(keys, Matchers.equalTo(setKeys)); }
@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);  }