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

com.kenshoo.pl.entity.internal.VirtualEntityFieldDbAdapter 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 org.jooq.Record;
import org.jooq.TableField;

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

public class VirtualEntityFieldDbAdapter implements EntityFieldDbAdapter {

    private final EntityFieldDbAdapter adapter1;
    private final Function translationFunction;

    public VirtualEntityFieldDbAdapter(EntityFieldDbAdapter adapter1, Function translationFunction) {
        this.adapter1 = adapter1;
        this.translationFunction = translationFunction;
    }

    @Override
    public DataTable getTable() {
        return adapter1.getTable();
    }

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

    @Override
    public Stream getDbValues(T value) {
        throw new IllegalStateException("Virtual fields can not be written to the database");
    }

    @Override
    public Object getFirstDbValue(T value) {
        throw new IllegalStateException("Virtual fields can not be written to the database");
    }

    @Override
    public T getFromRecord(Iterator valuesIterator) {
        return translationFunction.apply(adapter1.getFromRecord(valuesIterator));
    }
}