org.sfm.datastax.impl.setter.TupleValueSettableDataSetter Maven / Gradle / Ivy
package org.sfm.datastax.impl.setter;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.SettableByIndexData;
import com.datastax.driver.core.TupleType;
import com.datastax.driver.core.TupleValue;
import org.sfm.datastax.DatastaxColumnKey;
import org.sfm.datastax.SettableDataMapperBuilder;
import org.sfm.datastax.impl.SettableDataSetterFactory;
import org.sfm.map.Mapper;
import org.sfm.map.MapperConfig;
import org.sfm.map.column.FieldMapperColumnDefinition;
import org.sfm.map.mapper.ConstantTargetFieldMapperFactorImpl;
import org.sfm.reflect.ReflectionService;
import org.sfm.reflect.Setter;
import org.sfm.reflect.meta.ClassMeta;
import org.sfm.tuples.Tuple2;
import java.lang.reflect.Type;
import java.util.List;
public class TupleValueSettableDataSetter implements Setter {
private final int index;
public TupleValueSettableDataSetter(int index) {
this.index = index;
}
@Override
public void set(SettableByIndexData target, TupleValue value) throws Exception {
if (value == null) {
target.setToNull(index);
} else {
target.setTupleValue(index, value);
}
}
public static > Mapper newTupleMapper(Type target, TupleType tt,
MapperConfig> config,
ReflectionService reflectionService) {
SettableDataMapperBuilder builder = newFieldMapperBuilder(config, reflectionService, target);
List componentTypes = tt.getComponentTypes();
for(int i = 0; i < componentTypes.size(); i++) {
builder.addColumn(new DatastaxColumnKey("elt" + i, i, componentTypes.get(i)));
}
return builder.mapper();
}
public static SettableDataMapperBuilder newFieldMapperBuilder(MapperConfig> config,
ReflectionService reflectionService, Type target) {
ClassMeta classMeta = reflectionService.getClassMeta(target);
return new SettableDataMapperBuilder(classMeta, config, ConstantTargetFieldMapperFactorImpl.instance(new SettableDataSetterFactory(config, reflectionService)));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy