All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.datastax.impl.setter.MapWithConverterSettableDataSetter Maven / Gradle / Ivy

There is a newer version: 8.2.3
Show newest version
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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy