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

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

There is a newer version: 3.19.15
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
 *
 *  https://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
 * ASL 2.0 and offer limited warranties, support, maintenance, and commercial
 * database integrations.
 *
 * For more information, please visit: https://www.jooq.org/legal/licensing
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
package org.jooq.impl;

// ...
// ...
// ...
// ...
// ...
import static org.jooq.SQLDialect.CUBRID;
// ...
import static org.jooq.SQLDialect.DERBY;
// ...
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.H2;
// ...
import static org.jooq.SQLDialect.HSQLDB;
import static org.jooq.SQLDialect.IGNITE;
// ...
// ...
import static org.jooq.SQLDialect.MARIADB;
// ...
import static org.jooq.SQLDialect.MYSQL;
// ...
// ...
// ...
// ...
import static org.jooq.SQLDialect.SQLITE;
// ...
// ...
// ...
// ...
import static org.jooq.impl.Keywords.K_AS;
import static org.jooq.impl.Keywords.K_CAST;
import static org.jooq.impl.Keywords.K_ROW;
import static org.jooq.impl.Tools.unalias;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_LIST_ALREADY_INDENTED;

import java.util.Set;

import org.jooq.Context;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.QueryPart;
import org.jooq.Record;
// ...
import org.jooq.SQLDialect;
import org.jooq.Table;
// ...

/**
 * @author Lukas Eder
 */
final class TableAsField
extends
    AbstractRowAsField
implements
    QOM.TableAsField,
    ScopeMappableWrapper, Table>
{

    final Table table;

    TableAsField(Table table) {
        this(table, table.getQualifiedName());
    }

    TableAsField(final Table table, Name as) {
        super(as, new RecordDataType<>(
            ((AbstractTable) table).fieldsRow(),
            (Class) table.getRecordType(),
            table.getName()
        ));

        this.table = table;
    }

    @Override
    final Table fields0() {
        return table;
    }

    @SuppressWarnings("unchecked")
    @Override
    final Class getRecordType() {
        return (Class) table.getRecordType();
    }

    @Override
    final void acceptDefault(Context ctx) {
        if (RowAsField.NO_NATIVE_SUPPORT.contains(ctx.dialect()))
            ctx.data(DATA_LIST_ALREADY_INDENTED, true, c -> c.visit(new SelectFieldList<>(emulatedFields(ctx.configuration()).fields.fields)));




        // [#4727] [#13664] [#14100] In the first versions of jOOQ 3.17, there
        // used to be native implementations for this feature here, but they
        // produced a significant amount of problems, most importantly #14100,
        // where we relied on code generation column order to match production
        // metadata column order, something which we should never rely upon.
        // Hence, even in the presence of native support (e.g. PostgreSQL), we
        // are now emulating the feature.
        else
            ctx.visit(new RowAsField<>(table.fieldsRow(), getQualifiedName()));
    }

    @Override
    public Field as(Name alias) {
        return new TableAsField<>(table, alias);
    }

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

    @Override
    public final Field $aliased() {
        return new TableAsField<>(table);
    }

    @Override
    public final Name $alias() {
        return getQualifiedName();
    }

    @Override
    public final Table $table() {
        return table;
    }















    // -------------------------------------------------------------------------
    // XXX: ScopeMappable
    // -------------------------------------------------------------------------

    @Override
    public final TableAsField wrap(Table wrapped) {
        return new TableAsField<>(wrapped, getQualifiedName());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy