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

com.kenshoo.pl.entity.internal.fetch.AliasedKey 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.fetch;

import com.kenshoo.jooq.TempTableResource;
import com.kenshoo.pl.data.ImpersonatorTable;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.UniqueKey;
import org.jooq.Record;
import org.jooq.TableField;
import org.jooq.lambda.Seq;

import java.util.List;
import java.util.stream.Collectors;

import static org.jooq.lambda.Seq.seq;

public class AliasedKey > {

    private static final String PREFIX = "key_field_";
    private final List> fields;

    public AliasedKey(UniqueKey key) {
        this.fields = Seq.of(key.getFields())
                .map(field -> {
                    TableField tableField = field.getDbAdapter().getFirstTableField();
                    return new Field(field, tableField.as(PREFIX + tableField.getName()));
                }).collect(Collectors.toList());
    }

    // foreign key
    public AliasedKey(UniqueKey key, TempTableResource otherTable) {
        this.fields = Seq.of(key.getFields())
                .map(field -> {
                    TableField tableField = otherTable.getTable().getField(field.getDbAdapter().getFirstTableField());
                    return new Field(field, tableField.as(PREFIX + tableField.getName()));
                }).collect(Collectors.toList());
    }

    public List> fields() {
        return this.fields;
    }

    public List> unAliasedFields() {
        return seq(this.fields).map(Field::unAliased).toList();
    }

    public List> aliasedFields() {
        return seq(this.fields).map(Field::aliased).toList();
    }

    public class Field> {
        private final EntityField original;
        private final org.jooq.Field aliased;

        public Field(EntityField original, org.jooq.Field aliased) {
            this.original = original;
            this.aliased = aliased;
        }

        public org.jooq.Field aliased(){
            return aliased;
        }

        public EntityField unAliased(){
            return original;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy