/*
 * 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.RoutinePrivilegesRecord;

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 RoutinePrivileges extends TableImpl<RoutinePrivilegesRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of
     * <code>information_schema.routine_privileges</code>
     */
    public static final RoutinePrivileges ROUTINE_PRIVILEGES = new RoutinePrivileges();

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

    /**
     * The column <code>information_schema.routine_privileges.grantor</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> GRANTOR = createField(DSL.name("grantor"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column <code>information_schema.routine_privileges.grantee</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> GRANTEE = createField(DSL.name("grantee"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.specific_catalog</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> SPECIFIC_CATALOG = createField(DSL.name("specific_catalog"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.specific_schema</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> SPECIFIC_SCHEMA = createField(DSL.name("specific_schema"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.specific_name</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> SPECIFIC_NAME = createField(DSL.name("specific_name"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.routine_catalog</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> ROUTINE_CATALOG = createField(DSL.name("routine_catalog"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.routine_schema</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> ROUTINE_SCHEMA = createField(DSL.name("routine_schema"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.routine_name</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> ROUTINE_NAME = createField(DSL.name("routine_name"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.privilege_type</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> PRIVILEGE_TYPE = createField(DSL.name("privilege_type"), Domains.CHARACTER_DATA.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.routine_privileges.is_grantable</code>.
     */
    public final TableField<RoutinePrivilegesRecord, String> IS_GRANTABLE = createField(DSL.name("is_grantable"), Domains.YES_OR_NO.getDataType(), this, "");

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

    private RoutinePrivileges(Name alias, Table<RoutinePrivilegesRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "routine_privileges" as  SELECT (u_grantor.rolname)::information_schema.sql_identifier AS grantor,
          (grantee.rolname)::information_schema.sql_identifier AS grantee,
          (current_database())::information_schema.sql_identifier AS specific_catalog,
          (n.nspname)::information_schema.sql_identifier AS specific_schema,
          (nameconcatoid(p.proname, p.oid))::information_schema.sql_identifier AS specific_name,
          (current_database())::information_schema.sql_identifier AS routine_catalog,
          (n.nspname)::information_schema.sql_identifier AS routine_schema,
          (p.proname)::information_schema.sql_identifier AS routine_name,
          ('EXECUTE'::character varying)::information_schema.character_data AS privilege_type,
          (
              CASE
                  WHEN (pg_has_role(grantee.oid, p.proowner, 'USAGE'::text) OR p.grantable) THEN 'YES'::text
                  ELSE 'NO'::text
              END)::information_schema.yes_or_no AS is_grantable
         FROM ( SELECT pg_proc.oid,
                  pg_proc.proname,
                  pg_proc.proowner,
                  pg_proc.pronamespace,
                  (aclexplode(COALESCE(pg_proc.proacl, acldefault('f'::"char", pg_proc.proowner)))).grantor AS grantor,
                  (aclexplode(COALESCE(pg_proc.proacl, acldefault('f'::"char", pg_proc.proowner)))).grantee AS grantee,
                  (aclexplode(COALESCE(pg_proc.proacl, acldefault('f'::"char", pg_proc.proowner)))).privilege_type AS privilege_type,
                  (aclexplode(COALESCE(pg_proc.proacl, acldefault('f'::"char", pg_proc.proowner)))).is_grantable AS is_grantable
                 FROM pg_proc) p(oid, proname, proowner, pronamespace, grantor, grantee, prtype, grantable),
          pg_namespace n,
          pg_authid u_grantor,
          ( SELECT pg_authid.oid,
                  pg_authid.rolname
                 FROM pg_authid
              UNION ALL
               SELECT (0)::oid AS oid,
                  'PUBLIC'::name) grantee(oid, rolname)
        WHERE ((p.pronamespace = n.oid) AND (grantee.oid = p.grantee) AND (u_grantor.oid = p.grantor) AND (p.prtype = 'EXECUTE'::text) AND (pg_has_role(u_grantor.oid, 'USAGE'::text) OR pg_has_role(grantee.oid, 'USAGE'::text) OR (grantee.rolname = 'PUBLIC'::name)));
        """), where);
    }

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

    /**
     * Create an aliased <code>information_schema.routine_privileges</code>
     * table reference
     */
    public RoutinePrivileges(Name alias) {
        this(alias, ROUTINE_PRIVILEGES);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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