org.sfm.datastax.impl.setter.MapWithConverterSettableDataSetter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-datastax Show documentation
Show all versions of sfm-datastax Show documentation
Cassandra Datastax SFM supports.
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> {
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);
}
}
}