com.clickhouse.data.mapper.IterableRecordWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clickhouse-data Show documentation
Show all versions of clickhouse-data Show documentation
Data processing utilities for ClickHouse
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);
}
}