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

org.babyfish.jimmer.sql.ast.table.AssociationTable Maven / Gradle / Ivy

The newest version!
package org.babyfish.jimmer.sql.ast.table;

import org.babyfish.jimmer.meta.ImmutableType;
import org.babyfish.jimmer.sql.ImmutableProps;
import org.babyfish.jimmer.sql.JoinType;
import org.babyfish.jimmer.sql.association.Association;
import org.babyfish.jimmer.sql.association.meta.AssociationType;
import org.babyfish.jimmer.sql.ast.Expression;
import org.babyfish.jimmer.sql.ast.impl.table.AssociationTableProxyImpl;

import java.util.function.Function;

public interface AssociationTable<
        SE,
        ST extends Table,
        TE,
        TT extends Table
> extends TableEx> {

    @SuppressWarnings("unchecked")
    default ST source() {
        return (ST)join("source");
    }

    default  Expression sourceId() {
        return getAssociatedId("source");
    }

    @SuppressWarnings("unchecked")
    default ST source(ImmutableType treatedAs) {
        return (ST)join("source", JoinType.INNER, treatedAs);
    }

    default  Expression targetId() {
        return getAssociatedId("target");
    }

    @SuppressWarnings("unchecked")
    default TT target() {
        return (TT)join("target");
    }

    @SuppressWarnings("unchecked")
    default ST target(ImmutableType treatedAs) {
        return (ST)join("target", JoinType.INNER, treatedAs);
    }

    static <
            SE,
            ST extends Table,
            TE,
            TT extends Table
    > AssociationTable of(Class sourceTableType, Function targetTableGetter) {
        return AssociationTableProxyImpl.table(
                AssociationType.of(
                        ImmutableProps.join(sourceTableType, targetTableGetter)
                )
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy