1919import static it .aboutbits .postgresql .core .infrastructure .persistence .Tables .PG_CLASS ;
2020import static it .aboutbits .postgresql .core .infrastructure .persistence .Tables .PG_DATABASE ;
2121import static it .aboutbits .postgresql .core .infrastructure .persistence .Tables .PG_NAMESPACE ;
22+ import static it .aboutbits .postgresql .crd .grant .GrantObjectType .SEQUENCE ;
23+ import static it .aboutbits .postgresql .crd .grant .GrantObjectType .TABLE ;
2224import static org .jooq .impl .DSL .field ;
2325import static org .jooq .impl .DSL .noCondition ;
2426import static org .jooq .impl .DSL .query ;
@@ -82,7 +84,7 @@ public Map<String, Set<GrantPrivilege>> determineCurrentObjectPrivileges(
8284 )
8385 .fetchGroups (
8486 PG_DATABASE .DATNAME ,
85- GrantPrivilege .class
87+ r -> r . get ( ACLEXPLODE . PRIVILEGE_TYPE , GrantPrivilege .class )
8688 );
8789 /*
8890 * select
@@ -111,7 +113,7 @@ public Map<String, Set<GrantPrivilege>> determineCurrentObjectPrivileges(
111113 )
112114 .fetchGroups (
113115 PG_NAMESPACE .NSPNAME ,
114- GrantPrivilege .class
116+ r -> r . get ( PG_NAMESPACE . NSPNAME , GrantPrivilege .class )
115117 );
116118
117119 /*
@@ -154,7 +156,7 @@ public Map<String, Set<GrantPrivilege>> determineCurrentObjectPrivileges(
154156 )
155157 .fetchGroups (
156158 PG_CLASS .RELNAME ,
157- GrantPrivilege .class
159+ r -> r . get ( ACLEXPLODE . PRIVILEGE_TYPE , GrantPrivilege .class )
158160 );
159161 /*
160162 * select
@@ -192,7 +194,7 @@ public Map<String, Set<GrantPrivilege>> determineCurrentObjectPrivileges(
192194 )
193195 .fetchGroups (
194196 PG_CLASS .RELNAME ,
195- GrantPrivilege .class
197+ r -> r . get ( ACLEXPLODE . PRIVILEGE_TYPE , GrantPrivilege .class )
196198 );
197199 };
198200
@@ -232,7 +234,7 @@ public Map<String, Set<GrantPrivilege>> determineCurrentObjectPrivileges(
232234 (objects .isEmpty () ? 1 : objects .size ()) * spec .getPrivileges ().size ()
233235 );
234236
235- var allMode = objects .isEmpty ();
237+ var isAllMode = objects .isEmpty ();
236238
237239 switch (objectType ) {
238240 case DATABASE -> {
@@ -360,15 +362,15 @@ public Map<String, Set<GrantPrivilege>> determineCurrentObjectPrivileges(
360362 OID_DATA_TYPE ,
361363 val (schema )
362364 )),
363- allMode ? noCondition () : PG_CLASS .RELNAME .in (objects ),
365+ isAllMode ? noCondition () : PG_CLASS .RELNAME .in (objects ),
364366 // See https://www.postgresql.org/docs/current/catalog-pg-class.html#CATALOG-PG-CLASS
365367 PG_CLASS .RELKIND .eq (
366368 "S" // Sequence
367369 )
368370 )
369371 .fetchMap (PG_CLASS .RELNAME , isOwnerCondition );
370372
371- if (allMode ) {
373+ if (isAllMode ) {
372374 objectExistenceAndOwnershipMap .putAll (existingObjectsOwner );
373375 } else {
374376 for (var object : objects ) {
@@ -394,7 +396,7 @@ public void grant(
394396 DSLContext tx ,
395397 Grant resource ,
396398 String object ,
397- Set <GrantPrivilege > privilegesToRevoke
399+ Set <GrantPrivilege > privilegesToGrant
398400 ) {
399401 var spec = resource .getSpec ();
400402
@@ -407,7 +409,7 @@ public void grant(
407409 default -> quotedName (object );
408410 };
409411
410- var privileges = privilegesToRevoke .stream ()
412+ var privileges = privilegesToGrant .stream ()
411413 .map (GrantPrivilege ::privilege )
412414 .toList ();
413415
@@ -425,7 +427,7 @@ public void grant(
425427 public void grantOnAll (
426428 DSLContext tx ,
427429 Grant resource ,
428- Set <GrantPrivilege > privilegesToRevoke
430+ Set <GrantPrivilege > privilegesToGrant
429431 ) {
430432 var spec = resource .getSpec ();
431433
@@ -435,11 +437,11 @@ public void grantOnAll(
435437
436438 // grant <privileges> on all <objectType>s in schema <schema> to <role>;
437439 // is only supported by TABLE, SEQUENCE, FUNCTION, PROCEDURE and ROUTINE
438- if (objectType != GrantObjectType . TABLE && objectType != GrantObjectType . SEQUENCE ) {
440+ if (objectType != TABLE && objectType != SEQUENCE ) {
439441 return ;
440442 }
441443
442- var privileges = privilegesToRevoke .stream ()
444+ var privileges = privilegesToGrant .stream ()
443445 .map (GrantPrivilege ::privilege )
444446 .toList ();
445447
@@ -464,10 +466,9 @@ public void revoke(
464466
465467 var schema = spec .getSchema ();
466468 var role = role (spec .getRole ());
467- var objectTypeEnum = spec .getObjectType ();
468- var objectType = objectTypeEnum .objectType ();
469+ var objectType = spec .getObjectType ();
469470
470- var qualifiedObject = switch (objectTypeEnum ) {
471+ var qualifiedObject = switch (objectType ) {
471472 case TABLE , SEQUENCE -> quotedName (schema , object );
472473 default -> quotedName (object );
473474 };
@@ -479,7 +480,7 @@ public void revoke(
479480 var statement = query (
480481 "revoke {0} on {1} {2} from {3}" ,
481482 SQLUtil .concatenateQueryPartsWithComma (privileges ),
482- objectType ,
483+ objectType . objectType () ,
483484 qualifiedObject ,
484485 role
485486 );
0 commit comments