@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)); }
@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 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 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); }
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); }
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);  }