类 TransactionAwareProxyFactory<T>
- java.lang.Object
- org.springframework.batch.support.transaction.TransactionAwareProxyFactory<T>
public class TransactionAwareProxyFactory<T> extends java.lang.Object
Factory for transaction aware objects (like lists, sets, maps). If a transaction is active when a method is called on an instance created by the factory, it makes a copy of the target object and carries out all operations on the copy. Only when the transaction commits is the target re-initialised with the copy.
Works well with collections and maps for testing transactional behaviour without needing a database. The base implementation handles lists, sets and maps. Subclasses can implement
begin(Object)
andcommit(Object, Object)
to provide support for other resources.Generally not intended for multi-threaded use, but the
append only version
of collections gives isolation between threads operating on different keys in a map, provided they only append to the map. (Threads are limited to removing entries that were created in the same transaction.)- 作者:
- Dave Syer
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 protected T
begin(T target)
Make a copy of the target that can be used inside a transaction to isolate changes from the original.protected void
commit(T copy, T target)
Take the working copy state and commit it back to the original target.static <T> java.util.List<T>
createAppendOnlyTransactionalList()
static <K,V>
java.util.concurrent.ConcurrentMap<K,V>createAppendOnlyTransactionalMap()
static <T> java.util.Set<T>
createAppendOnlyTransactionalSet()
static <T> java.util.List<T>
createTransactionalList()
static <T> java.util.List<T>
createTransactionalList(java.util.List<T> list)
static <K,V>
java.util.Map<K,V>createTransactionalMap()
static <K,V>
java.util.Map<K,V>createTransactionalMap(java.util.Map<K,V> map)
static <T> java.util.Set<T>
createTransactionalSet()
static <T> java.util.Set<T>
createTransactionalSet(java.util.Set<T> set)
方法详细资料
begin
protected final T begin(T target)
Make a copy of the target that can be used inside a transaction to isolate changes from the original. Also called from the factory constructor to isolate the target from the original value passed in.- 参数:
target
- the target object (List, Set or Map)- 返回:
- an independent copy
commit
protected void commit(T copy, T target)
Take the working copy state and commit it back to the original target. The target then reflects all the changes applied to the copy during a transaction.- 参数:
copy
- the working copy.target
- the original target of the factory.
createTransactionalMap
public static <K,V> java.util.Map<K,V> createTransactionalMap()
createTransactionalMap
public static <K,V> java.util.Map<K,V> createTransactionalMap(java.util.Map<K,V> map)
createAppendOnlyTransactionalMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> createAppendOnlyTransactionalMap()
createAppendOnlyTransactionalSet
public static <T> java.util.Set<T> createAppendOnlyTransactionalSet()
createTransactionalSet
public static <T> java.util.Set<T> createTransactionalSet()
createTransactionalSet
public static <T> java.util.Set<T> createTransactionalSet(java.util.Set<T> set)
createAppendOnlyTransactionalList
public static <T> java.util.List<T> createAppendOnlyTransactionalList()
createTransactionalList
public static <T> java.util.List<T> createTransactionalList()
createTransactionalList
public static <T> java.util.List<T> createTransactionalList(java.util.List<T> list)