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

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

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

import java.util.Iterator;
import java.util.List;

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

public final class IterableRecordWrapper implements Iterator {
    private final ClickHouseDataConfig config;
    private final List columns;
    private final Iterator records;
    private final Class objClass;
    private final T template;

    private ClickHouseRecordMapper mapper;

    public IterableRecordWrapper(ClickHouseDataConfig config, List columns,
            Iterator records, Class objClass, T template) {
        if (columns == null || records == null || objClass == null) {
            throw new IllegalArgumentException("Non-null column list, records and object class are required");
        }
        this.config = config;
        this.columns = columns;
        this.records = records;
        this.objClass = objClass;
        this.template = template;
    }

    @Override
    public boolean hasNext() {
        return records.hasNext();
    }

    @Override
    public T next() {
        if (mapper == null) {
            mapper = ClickHouseRecordMapper.of(config, columns, objClass);
        }
        return mapper.mapTo(records.next(), objClass, template);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy