org.simpleflatmapper.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.simpleflatmapper.datastax.impl.setter;
import com.datastax.driver.core.SettableByIndexData;
import org.simpleflatmapper.reflect.Setter;
import org.simpleflatmapper.converter.ContextualConverter;
import java.util.HashMap;
import java.util.Map;
public class MapWithConverterSettableDataSetter implements Setter, Map> {
private final int index;
private final ContextualConverter keyConverter;
private final ContextualConverter valueConverter;
public MapWithConverterSettableDataSetter(int index, ContextualConverter keyConverter, ContextualConverter 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(), null),
valueConverter.convert(e.getValue(), null));
}
target.setMap(index, map);
}
}
}