Improve type safety of transactional collections by reducing visibility of private features
This commit is contained in:
@@ -8,7 +8,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Abstract {@link org.springframework.batch.item.ItemReader} for to extend when reading database records in a paging
|
||||
|
||||
@@ -50,7 +50,7 @@ public class TransactionAwareProxyFactory<T> {
|
||||
|
||||
private T target;
|
||||
|
||||
public TransactionAwareProxyFactory(T target) {
|
||||
private TransactionAwareProxyFactory(T target) {
|
||||
super();
|
||||
this.target = begin(target);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class TransactionAwareProxyFactory<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public T createInstance() {
|
||||
private T createInstance() {
|
||||
ProxyFactory factory = new ProxyFactory(target);
|
||||
factory.addAdvice(new MethodInterceptor() {
|
||||
|
||||
@@ -136,16 +136,31 @@ public class TransactionAwareProxyFactory<T> {
|
||||
return (Map<K,V>) new TransactionAwareProxyFactory(new HashMap<K,V>()).createInstance();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <K,V> Map<K,V> createTransactionalMap(Map<K,V> map) {
|
||||
return (Map<K,V>) new TransactionAwareProxyFactory(map).createInstance();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Set<T> createTransactionalSet() {
|
||||
return (Set<T>) new TransactionAwareProxyFactory(new HashSet<T>()).createInstance();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Set<T> createTransactionalSet(Set<T> set) {
|
||||
return (Set<T>) new TransactionAwareProxyFactory(set).createInstance();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> createTransactionalList() {
|
||||
return (List<T>) new TransactionAwareProxyFactory(new ArrayList<T>()).createInstance();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> createTransactionalList(List<T> list) {
|
||||
return (List<T>) new TransactionAwareProxyFactory(list).createInstance();
|
||||
}
|
||||
|
||||
private class TargetSynchronization extends TransactionSynchronizationAdapter {
|
||||
|
||||
T cache;
|
||||
|
||||
Reference in New Issue
Block a user