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

com.clickhouse.data.mapper.CompiledRecordMapper Maven / Gradle / Ivy

There is a newer version: 0.7.1-patch1
Show newest version
package com.clickhouse.data.mapper;

import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.List;

import com.clickhouse.data.ClickHouseColumn;
import com.clickhouse.data.ClickHouseDataConfig;
import com.clickhouse.data.ClickHouseRecord;
import com.clickhouse.data.ClickHouseRecordMapper;
import com.clickhouse.data.ClickHouseValue;

public class CompiledRecordMapper extends AbstractRecordMapper {
    private final Constructor constructor;
    private final PropertyInfo[] properties;

    private CompiledRecordMapper(Class objClass, Constructor constructor, List columns) {
        super(objClass);
        this.constructor = constructor;

        if (columns == null || columns.isEmpty()) {
            this.properties = new PropertyInfo[0];
        } else {
            this.properties = getProperties(objClass, columns);
        }
    }

    protected CompiledRecordMapper(Class objClass) {
        this(objClass, getDefaultConstructor(objClass), Collections.emptyList());
    }

    @Override
    public ClickHouseRecordMapper get(ClickHouseDataConfig config, List columns) {
        if (columns == null) {
            columns = Collections.emptyList();
        }
        // TODO use asm to generate mapper class
        // ClickHouseRecordMapper mapper = null;
        // if (config != null && config.isUseCompilation()) {
        // mapper = new CompiledRecordMapper(clazz, constructor, columns);
        // }

        return new DynamicRecordMapper(clazz, columns, constructor);
    }

    @SuppressWarnings("unchecked")
    @Override
    public  T mapTo(ClickHouseRecord r, Class objClass, T obj) {
        check(r, objClass);

        if (obj == null) {
            obj = (T) newInstance(constructor);
        }

        for (int i = 0, len = properties.length; i < len; i++) {
            PropertyInfo p = properties[i];
            ClickHouseValue v = r.getValue(p.index);
        }
        return obj;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy