org.sfm.datastax.impl.setter.MapWithConverterSettableDataSetter Maven / Gradle / Ivy
package org.sfm.datastax.impl.setter;
import com.datastax.driver.core.SettableByIndexData;
import org.sfm.reflect.Setter;
import org.sfm.utils.conv.Converter;
import java.util.HashMap;
import java.util.Map;
public class MapWithConverterSettableDataSetter implements Setter, Map> {
private final int index;
private final Converter keyConverter;
private final Converter valueConverter;
public MapWithConverterSettableDataSetter(int index, Converter keyConverter, Converter valueConverter) {
this.index = index;
this.keyConverter = keyConverter;
this.valueConverter = valueConverter;
}
@Override
public void set(SettableByIndexData> target, Map value) throws Exception {
if (value == null) {
target.setToNull(index);
} else {
Map map = new HashMap();
for(Map.Entry e : value.entrySet()) {
map.put(keyConverter.convert(e.getKey()),
valueConverter.convert(e.getValue()));
}
target.setMap(index, map);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy