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

org.babyfish.jimmer.sql.ast.impl.SubQueryFunctionExpression Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.ast.impl;

import org.babyfish.jimmer.sql.ast.impl.render.AbstractSqlBuilder;
import org.babyfish.jimmer.sql.ast.query.TypedSubQuery;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public abstract class SubQueryFunctionExpression extends AbstractExpression {

    private TypedSubQuery subQuery;

    SubQueryFunctionExpression(TypedSubQuery subQuery) {
        this.subQuery = subQuery;
    }

    protected abstract String functionName();

    @SuppressWarnings("unchecked")
    @Override
    public Class getType() {
        return (Class) ((ExpressionImplementor) subQuery).getType();
    }

    @Override
    public int precedence() {
        return 0;
    }

    @Override
    public void accept(@NotNull AstVisitor visitor) {
        ((Ast) subQuery).accept(visitor);
    }

    @Override
    public void renderTo(@NotNull AbstractSqlBuilder builder) {
        builder.sql(functionName());
        renderChild((Ast) subQuery, builder);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SubQueryFunctionExpression that = (SubQueryFunctionExpression) o;
        return subQuery.equals(that.subQuery);
    }

    @Override
    protected boolean determineHasVirtualPredicate() {
        return hasVirtualPredicate(subQuery);
    }

    @Override
    protected Ast onResolveVirtualPredicate(AstContext ctx) {
        return (Ast) ctx.resolveVirtualPredicate(subQuery);
    }

    @Override
    public int hashCode() {
        return Objects.hash(subQuery);
    }

    public static class All extends SubQueryFunctionExpression {

        public All(TypedSubQuery subQuery) {
            super(subQuery);
        }

        @Override
        protected String functionName() {
            return "all";
        }
    }

    public static class Any extends SubQueryFunctionExpression {

        public Any(TypedSubQuery subQuery) {
            super(subQuery);
        }

        @Override
        protected String functionName() {
            return "any";
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy