@@ -50,12 +50,12 @@ public function acquireLock(
50
50
PostgresAdvisoryLockScopeEnum::Transaction,
51
51
PostgresAdvisoryLockTypeEnum::NonBlocking,
52
52
PostgresLockModeEnum::Share,
53
- ] => 'SELECT PG_TRY_ADVISORY_XACT_LOCK_SHARE (:class_id, :object_id); ' ,
53
+ ] => 'SELECT PG_TRY_ADVISORY_XACT_LOCK_SHARED (:class_id, :object_id); ' ,
54
54
[
55
55
PostgresAdvisoryLockScopeEnum::Transaction,
56
56
PostgresAdvisoryLockTypeEnum::Blocking,
57
57
PostgresLockModeEnum::Share,
58
- ] => 'SELECT PG_ADVISORY_XACT_LOCK_SHARE (:class_id, :object_id); ' ,
58
+ ] => 'SELECT PG_ADVISORY_XACT_LOCK_SHARED (:class_id, :object_id); ' ,
59
59
[
60
60
PostgresAdvisoryLockScopeEnum::Session,
61
61
PostgresAdvisoryLockTypeEnum::NonBlocking,
@@ -70,12 +70,12 @@ public function acquireLock(
70
70
PostgresAdvisoryLockScopeEnum::Session,
71
71
PostgresAdvisoryLockTypeEnum::NonBlocking,
72
72
PostgresLockModeEnum::Share,
73
- ] => 'SELECT PG_TRY_ADVISORY_LOCK_SHARE (:class_id, :object_id); ' ,
73
+ ] => 'SELECT PG_TRY_ADVISORY_LOCK_SHARED (:class_id, :object_id); ' ,
74
74
[
75
75
PostgresAdvisoryLockScopeEnum::Session,
76
76
PostgresAdvisoryLockTypeEnum::Blocking,
77
77
PostgresLockModeEnum::Share,
78
- ] => 'SELECT PG_ADVISORY_LOCK_SHARE (:class_id, :object_id); ' ,
78
+ ] => 'SELECT PG_ADVISORY_LOCK_SHARED (:class_id, :object_id); ' ,
79
79
};
80
80
$ sql .= " -- $ postgresLockId ->humanReadableValue " ;
81
81
@@ -97,16 +97,19 @@ public function releaseLock(
97
97
PDO $ dbConnection ,
98
98
PostgresLockId $ postgresLockId ,
99
99
PostgresAdvisoryLockScopeEnum $ scope = PostgresAdvisoryLockScopeEnum::Session,
100
+ PostgresLockModeEnum $ mode = PostgresLockModeEnum::Exclusive,
100
101
): bool {
101
102
if ($ scope === PostgresAdvisoryLockScopeEnum::Transaction) {
102
103
throw new \InvalidArgumentException ('Transaction-level advisory lock cannot be released ' );
103
104
}
104
105
105
- $ statement = $ dbConnection ->prepare (
106
- <<<SQL
107
- SELECT PG_ADVISORY_UNLOCK(:class_id, :object_id); -- $ postgresLockId ->humanReadableValue
108
- SQL ,
109
- );
106
+ $ sql = match ($ mode ) {
107
+ PostgresLockModeEnum::Exclusive => 'SELECT PG_ADVISORY_UNLOCK(:class_id, :object_id); ' ,
108
+ PostgresLockModeEnum::Share => 'SELECT PG_ADVISORY_UNLOCK_SHARED(:class_id, :object_id); ' ,
109
+ };
110
+ $ sql .= " -- $ postgresLockId ->humanReadableValue " ;
111
+
112
+ $ statement = $ dbConnection ->prepare ($ sql );
110
113
$ statement ->execute (
111
114
[
112
115
'class_id ' => $ postgresLockId ->classId ,
0 commit comments