net.sf.hajdbc.util.BatchMap Maven / Gradle / Ivy
package net.sf.hajdbc.util;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
/**
* HashMap batch support.
* @author dib
* @param
* @param
*/
public class BatchMap {
final transient ReentrantLock lock = new ReentrantLock();
private final Map data = new HashMap<>();
public void commit(Map map){
lock.lock();
try {
data.clear();
data.putAll(map);
}finally {
lock.unlock();
}
}
public Map getData(){
Map map = new HashMap<>();
lock.lock();
try {
map.putAll(data);
}finally {
lock.unlock();
}
return map;
}
}