Package org.pgcodekeeper.core.schema
Class PgPrivilege
java.lang.Object
org.pgcodekeeper.core.schema.PgPrivilege
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionPgPrivilege(String state, String permission, String name, String role, boolean isGrantOption, DatabaseType dbType) Creates a new privilege instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendDefaultPostgresPrivileges(PgStatement newObj, SQLScript script) Appends default PostgreSQL privileges for a database object.static voidappendPrivileges(Collection<PgPrivilege> privileges, SQLScript script) Appends multiple privileges to a SQL script.voidcomputeHash(Hasher hasher) Computes the hash of the implementing object using the provided hasher.booleanGenerates the SQL statement for this privilege.Generates the SQL statement to drop this privilege.getName()getRole()inthashCode()booleanisRevoke()Checks if this privilege represents a REVOKE operation.toString()
-
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 torole- the role receiving or losing the privilegeisGrantOption- whether this privilege includes GRANT OPTIONdbType- 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
Generates the SQL statement for this privilege.- Returns:
- the GRANT or REVOKE SQL statement
-
getDropSQL
Generates the SQL statement to drop this privilege.- Returns:
- the REVOKE SQL statement, or null if this is already a REVOKE
-
appendPrivileges
Appends multiple privileges to a SQL script.- Parameters:
privileges- the collection of privileges to appendscript- the script to append to
-
appendDefaultPostgresPrivileges
Appends default PostgreSQL privileges for a database object.- Parameters:
newObj- the database object to set default privileges forscript- the script to append privileges to
-
equals
-
hashCode
public int hashCode() -
computeHash
Description copied from interface:IHashableComputes the hash of the implementing object using the provided hasher. The implementation should call appropriateputmethods on the hasher for all fields that should contribute to the hash value.- Specified by:
computeHashin interfaceIHashable- Parameters:
hasher- the hasher instance to use for hash computation
-
toString
-
getPermission
-
getRole
-
getName
-