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

org.jooq.impl.Nvl2 Maven / Gradle / Ivy

There is a newer version: 3.19.16
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Other licenses:
 * -----------------------------------------------------------------------------
 * Commercial licenses for this work are available. These replace the above
 * Apache-2.0 license and offer limited warranties, support, maintenance, and
 * commercial database integrations.
 *
 * For more information, please visit: http://www.jooq.org/licenses
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
package org.jooq.impl;

import static org.jooq.SQLDialect.MARIADB;
import static org.jooq.impl.DSL.function;
import static org.jooq.impl.DSL.iif;
import static org.jooq.impl.Names.N_NVL2;

import org.jooq.Context;
import org.jooq.Field;
import org.jooq.Function3;

/**
 * @author Lukas Eder
 */
final class Nvl2 extends AbstractField implements QOM.Nvl2 {

    private final Field arg1;
    private final Field arg2;
    private final Field arg3;

    Nvl2(Field arg1, Field arg2, Field arg3) {
        super(N_NVL2, !arg1.getDataType().nullable() ? arg2.getDataType() : Tools.allNotNull(arg2.getDataType(), arg2, arg3));

        this.arg1 = arg1;
        this.arg2 = arg2;
        this.arg3 = arg3;
    }

    @Override
    public final void accept(Context ctx) {
        switch (ctx.family()) {







            case MARIADB:





                acceptDefault(ctx);
                break;










            case CUBRID:
            case DERBY:
            case FIREBIRD:
            case MYSQL:
            case POSTGRES:
            case SQLITE:
            case YUGABYTEDB:
                acceptCase(ctx);
                break;

            default:
                acceptDefault(ctx);
                break;
        }
    }

    private void acceptCase(Context ctx) {
        ctx.visit(DSL.when(arg1.isNotNull(), arg2).otherwise(arg3));
    }

    private final void acceptDefault(Context ctx) {
        ctx.visit(function(N_NVL2, getDataType(), arg1, arg2, arg3));
    }

    // -------------------------------------------------------------------------
    // XXX: Query Object Model
    // -------------------------------------------------------------------------

    @Override
    public final Field $arg1() {
        return arg1;
    }

    @Override
    public final Field $arg2() {
        return arg2;
    }

    @Override
    public final Field $arg3() {
        return arg3;
    }

    @Override
    public final Function3, ? super Field, ? super Field, ? extends Field> $constructor() {
        return (a1, a2, a3) -> new Nvl2<>(a1, a2, a3);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy