### Question:
CacheableUpdateOperator extends UpdateOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); Object r = execute(context, stat); if (driver.isUseMultipleKeys()) { Set<String> keys = driver.getCacheKeys(context); if (!keys.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Cache delete for multiple keys {}", keys); } driver.batchDeleteFromCache(keys, stat); } } else { String key = driver.getCacheKey(context); if (logger.isDebugEnabled()) { logger.debug("Cache delete for single key [{}]", key); } driver.deleteFromCache(key, stat); } return r; } CacheableUpdateOperator(ASTRootNode rootNode, MethodDescriptor md, CacheDriver cacheDriver, Config config); @Override Object execute(Object[] values, InvocationStat stat);  }### Answer:
@Test public void testUpdate() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Integer> rt = TypeToken.of(int.class); String srcSql = "update user set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public void delete(String key, Class<?> daoClass) { assertThat(key, equalTo("user_100")); } }, new MockCacheBy("id")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "update user set name=? where id=?"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(2)); assertThat(args[0], equalTo((Object) "ash")); assertThat(args[1], equalTo((Object) 100)); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{user}, stat); assertThat(stat.getCacheDeleteSuccessCount(), equalTo(1L)); }
@Test public void testUpdateWithIn() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<Integer> rt = TypeToken.of(int.class); String srcSql = "update user set name=ash where id in (:1)"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public void batchDelete(Set<String> keys, Class<?> daoClass) { Set<String> set = new HashSet<String>(); set.add("user_100"); set.add("user_200"); assertThat(keys, equalTo(set)); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "update user set name=ash where id in (?,?)"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(2)); assertThat(args[0], equalTo((Object) 100)); assertThat(args[1], equalTo((Object) 200)); return 1; } }); List<Integer> ids = Arrays.asList(100, 200); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{ids}, stat); assertThat(stat.getCacheBatchDeleteSuccessCount(), equalTo(1L)); }