Fix typo in transactional contains()

This commit is contained in:
dsyer
2010-04-03 10:10:34 +00:00
parent f7d377908d
commit 39eafb8b78
2 changed files with 21 additions and 5 deletions

View File

@@ -164,11 +164,15 @@ public class TransactionAwareProxyFactory<T> {
}
Object result = invocation.getMethod().invoke(cache, invocation.getArguments());
String methodName = invocation.getMethod().getName();
if (appendOnly && result==null && (methodName.equals("get") || methodName.equals("contains"))) {
// In appendOnly mode the result of a get might not be in the cache...
return invocation.proceed();
if (appendOnly) {
String methodName = invocation.getMethod().getName();
if ((result == null && methodName.equals("get"))
|| (Boolean.FALSE.equals(result) && methodName.startsWith("contains"))) {
// In appendOnly mode the result of a get might not be
// in the cache...
return invocation.proceed();
}
}
return result;

View File

@@ -17,6 +17,7 @@
package org.springframework.batch.support.transaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.ArrayList;
import java.util.HashMap;
@@ -84,6 +85,17 @@ public class ConcurrentTransactionAwareProxyTests {
testMap(map);
}
@Test
public void testTransactionalContains() throws Exception {
final Map<Long, Map<String, String>> map = TransactionAwareProxyFactory.createAppendOnlyTransactionalMap();
boolean result = (Boolean) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
return map.containsKey("foo");
}
});
assertFalse(result);
}
private void testSet(final Set<String> set) throws Exception {
CompletionService<List<String>> completionService = new ExecutorCompletionService<List<String>>(Executors