/*
 * This file is generated by jOOQ.
 */
package ervu_secret.ervu_secret.db_beans.information_schema.tables;


import ervu_secret.ervu_secret.db_beans.information_schema.Domains;
import ervu_secret.ervu_secret.db_beans.information_schema.InformationSchema;
import ervu_secret.ervu_secret.db_beans.information_schema.tables.records.ViewTableUsageRecord;

import java.util.Collection;

import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.PlainSQL;
import org.jooq.QueryPart;
import org.jooq.SQL;
import org.jooq.Schema;
import org.jooq.Select;
import org.jooq.Stringly;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.impl.DSL;
import org.jooq.impl.TableImpl;


/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class ViewTableUsage extends TableImpl<ViewTableUsageRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of
     * <code>information_schema.view_table_usage</code>
     */
    public static final ViewTableUsage VIEW_TABLE_USAGE = new ViewTableUsage();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<ViewTableUsageRecord> getRecordType() {
        return ViewTableUsageRecord.class;
    }

    /**
     * The column <code>information_schema.view_table_usage.view_catalog</code>.
     */
    public final TableField<ViewTableUsageRecord, String> VIEW_CATALOG = createField(DSL.name("view_catalog"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column <code>information_schema.view_table_usage.view_schema</code>.
     */
    public final TableField<ViewTableUsageRecord, String> VIEW_SCHEMA = createField(DSL.name("view_schema"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column <code>information_schema.view_table_usage.view_name</code>.
     */
    public final TableField<ViewTableUsageRecord, String> VIEW_NAME = createField(DSL.name("view_name"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.view_table_usage.table_catalog</code>.
     */
    public final TableField<ViewTableUsageRecord, String> TABLE_CATALOG = createField(DSL.name("table_catalog"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column <code>information_schema.view_table_usage.table_schema</code>.
     */
    public final TableField<ViewTableUsageRecord, String> TABLE_SCHEMA = createField(DSL.name("table_schema"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column <code>information_schema.view_table_usage.table_name</code>.
     */
    public final TableField<ViewTableUsageRecord, String> TABLE_NAME = createField(DSL.name("table_name"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    private ViewTableUsage(Name alias, Table<ViewTableUsageRecord> aliased) {
        this(alias, aliased, (Field<?>[]) null, null);
    }

    private ViewTableUsage(Name alias, Table<ViewTableUsageRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "view_table_usage" as  SELECT DISTINCT (current_database())::information_schema.sql_identifier AS view_catalog,
          (nv.nspname)::information_schema.sql_identifier AS view_schema,
          (v.relname)::information_schema.sql_identifier AS view_name,
          (current_database())::information_schema.sql_identifier AS table_catalog,
          (nt.nspname)::information_schema.sql_identifier AS table_schema,
          (t.relname)::information_schema.sql_identifier AS table_name
         FROM pg_namespace nv,
          pg_class v,
          pg_depend dv,
          pg_depend dt,
          pg_class t,
          pg_namespace nt
        WHERE ((nv.oid = v.relnamespace) AND (v.relkind = 'v'::"char") AND (v.oid = dv.refobjid) AND (dv.refclassid = ('pg_class'::regclass)::oid) AND (dv.classid = ('pg_rewrite'::regclass)::oid) AND (dv.deptype = 'i'::"char") AND (dv.objid = dt.objid) AND (dv.refobjid <> dt.refobjid) AND (dt.classid = ('pg_rewrite'::regclass)::oid) AND (dt.refclassid = ('pg_class'::regclass)::oid) AND (dt.refobjid = t.oid) AND (t.relnamespace = nt.oid) AND (t.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])) AND pg_has_role(t.relowner, 'USAGE'::text));
        """), where);
    }

    /**
     * Create an aliased <code>information_schema.view_table_usage</code> table
     * reference
     */
    public ViewTableUsage(String alias) {
        this(DSL.name(alias), VIEW_TABLE_USAGE);
    }

    /**
     * Create an aliased <code>information_schema.view_table_usage</code> table
     * reference
     */
    public ViewTableUsage(Name alias) {
        this(alias, VIEW_TABLE_USAGE);
    }

    /**
     * Create a <code>information_schema.view_table_usage</code> table reference
     */
    public ViewTableUsage() {
        this(DSL.name("view_table_usage"), null);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : InformationSchema.INFORMATION_SCHEMA;
    }

    @Override
    public ViewTableUsage as(String alias) {
        return new ViewTableUsage(DSL.name(alias), this);
    }

    @Override
    public ViewTableUsage as(Name alias) {
        return new ViewTableUsage(alias, this);
    }

    @Override
    public ViewTableUsage as(Table<?> alias) {
        return new ViewTableUsage(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public ViewTableUsage rename(String name) {
        return new ViewTableUsage(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public ViewTableUsage rename(Name name) {
        return new ViewTableUsage(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public ViewTableUsage rename(Table<?> name) {
        return new ViewTableUsage(name.getQualifiedName(), null);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewTableUsage where(Condition condition) {
        return new ViewTableUsage(getQualifiedName(), aliased() ? this : null, null, condition);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewTableUsage where(Collection<? extends Condition> conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewTableUsage where(Condition... conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewTableUsage where(Field<Boolean> condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewTableUsage where(SQL condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewTableUsage where(@Stringly.SQL String condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewTableUsage where(@Stringly.SQL String condition, Object... binds) {
        return where(DSL.condition(condition, binds));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public ViewTableUsage where(@Stringly.SQL String condition, QueryPart... parts) {
        return where(DSL.condition(condition, parts));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewTableUsage whereExists(Select<?> select) {
        return where(DSL.exists(select));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public ViewTableUsage whereNotExists(Select<?> select) {
        return where(DSL.notExists(select));
    }
}
