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

com.kenshoo.pl.entity.internal.SimpleEntityFieldDbAdapter Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
package com.kenshoo.pl.entity.internal;

import com.kenshoo.jooq.DataTable;
import com.kenshoo.pl.entity.EntityFieldDbAdapter;
import com.kenshoo.pl.entity.ValueConverter;
import org.jooq.Record;
import org.jooq.TableField;

import java.util.Iterator;
import java.util.stream.Stream;

public class SimpleEntityFieldDbAdapter implements EntityFieldDbAdapter {

    private final DataTable table;
    private final TableField tableField;
    private final ValueConverter valueConverter;

    public SimpleEntityFieldDbAdapter(TableField tableField, ValueConverter valueConverter) {
        this.table = (DataTable) tableField.getTable();
        this.tableField = tableField;
        this.valueConverter = valueConverter;
    }

    @Override
    public DataTable getTable() {
        return table;
    }

    @Override
    public Stream> getTableFields() {
        return Stream.of(tableField);
    }

    @Override
    public Stream getDbValues(T value) {
        return Stream.of(valueConverter.convertTo(value));
    }

    @Override
    public T getFromRecord(Iterator valuesIterator) {
        //noinspection unchecked
        return valueConverter.convertFrom((DBT) valuesIterator.next());
    }
}