Class PgPrivilege

java.lang.Object
org.pgcodekeeper.core.schema.PgPrivilege
All Implemented Interfaces:
IHashable

public final class PgPrivilege extends Object implements IHashable
Represents a database privilege (GRANT/REVOKE) for a database object. Handles privilege operations including creation, dropping, and SQL generation for different database types.
  • Constructor Details

    • PgPrivilege

      public PgPrivilege(String state, String permission, String name, String role, boolean isGrantOption, DatabaseType dbType)
      Creates a new privilege instance.
      Parameters:
      state - the privilege state (GRANT or REVOKE)
      permission - the permission type (e.g., SELECT, INSERT, ALL)
      name - the object name the privilege applies to
      role - the role receiving or losing the privilege
      isGrantOption - whether this privilege includes GRANT OPTION
      dbType - the database type this privilege applies to
  • Method Details

    • isRevoke

      public boolean isRevoke()
      Checks if this privilege represents a REVOKE operation.
      Returns:
      true if this is a REVOKE privilege, false if GRANT
    • getCreationSQL

      public String getCreationSQL()
      Generates the SQL statement for this privilege.
      Returns:
      the GRANT or REVOKE SQL statement
    • getDropSQL

      public String getDropSQL()
      Generates the SQL statement to drop this privilege.
      Returns:
      the REVOKE SQL statement, or null if this is already a REVOKE
    • appendPrivileges

      public static void appendPrivileges(Collection<PgPrivilege> privileges, SQLScript script)
      Appends multiple privileges to a SQL script.
      Parameters:
      privileges - the collection of privileges to append
      script - the script to append to
    • appendDefaultPostgresPrivileges

      public static void appendDefaultPostgresPrivileges(PgStatement newObj, SQLScript script)
      Appends default PostgreSQL privileges for a database object.
      Parameters:
      newObj - the database object to set default privileges for
      script - the script to append privileges to
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • computeHash

      public void computeHash(Hasher hasher)
      Description copied from interface: IHashable
      Computes the hash of the implementing object using the provided hasher. The implementation should call appropriate put methods on the hasher for all fields that should contribute to the hash value.
      Specified by:
      computeHash in interface IHashable
      Parameters:
      hasher - the hasher instance to use for hash computation
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPermission

      public String getPermission()
    • getRole

      public String getRole()
    • getName

      public String getName()