@@ -28,14 +28,14 @@ final class PostgresAdvisoryLocker
2828 */
2929 public function acquireTransactionLevelLock (
3030 PDO $ dbConnection ,
31- PostgresLockKey $ postgresLockKey ,
31+ PostgresLockKey $ key ,
3232 PostgresLockWaitModeEnum $ waitMode = PostgresLockWaitModeEnum::NonBlocking,
3333 PostgresLockAccessModeEnum $ accessMode = PostgresLockAccessModeEnum::Exclusive,
3434 ): TransactionLevelLockHandle {
3535 return new TransactionLevelLockHandle (
3636 wasAcquired: $ this ->acquireLock (
3737 $ dbConnection ,
38- $ postgresLockKey ,
38+ $ key ,
3939 PostgresLockLevelEnum::Transaction,
4040 $ waitMode ,
4141 $ accessMode ,
@@ -63,18 +63,18 @@ public function acquireTransactionLevelLock(
6363 */
6464 public function acquireSessionLevelLock (
6565 PDO $ dbConnection ,
66- PostgresLockKey $ postgresLockKey ,
66+ PostgresLockKey $ key ,
6767 PostgresLockWaitModeEnum $ waitMode = PostgresLockWaitModeEnum::NonBlocking,
6868 PostgresLockAccessModeEnum $ accessMode = PostgresLockAccessModeEnum::Exclusive,
6969 ): SessionLevelLockHandle {
7070 return new SessionLevelLockHandle (
7171 $ dbConnection ,
7272 $ this ,
73- $ postgresLockKey ,
73+ $ key ,
7474 $ accessMode ,
7575 wasAcquired: $ this ->acquireLock (
7676 $ dbConnection ,
77- $ postgresLockKey ,
77+ $ key ,
7878 PostgresLockLevelEnum::Session,
7979 $ waitMode ,
8080 $ accessMode ,
@@ -94,10 +94,9 @@ public function acquireSessionLevelLock(
9494 * ⚠️ Transaction-level advisory locks are strongly preferred whenever possible,
9595 * as they are automatically released at the end of a transaction and are less error-prone.
9696 * Use session-level locks only when transactional context is not available.
97- * @see acquireTransactionLevelLock() for preferred locking strategy.
9897 *
9998 * @param PDO $dbConnection Active database connection.
100- * @param PostgresLockKey $postgresLockKey Lock key to be acquired.
99+ * @param PostgresLockKey $key Lock key to be acquired.
101100 * @param callable(SessionLevelLockHandle): TReturn $callback A callback that receives the lock handle.
102101 * @param PostgresLockWaitModeEnum $waitMode Whether to wait for the lock or fail immediately. Default is non-blocking.
103102 * @param PostgresLockAccessModeEnum $accessMode Whether to acquire a shared or exclusive lock. Default is exclusive.
@@ -106,17 +105,19 @@ public function acquireSessionLevelLock(
106105 * @template TReturn
107106 *
108107 * TODO: Cover with tests
108+ *@see acquireTransactionLevelLock() for preferred locking strategy.
109+ *
109110 */
110111 public function withinSessionLevelLock (
111112 PDO $ dbConnection ,
112- PostgresLockKey $ postgresLockKey ,
113+ PostgresLockKey $ key ,
113114 callable $ callback ,
114115 PostgresLockWaitModeEnum $ waitMode = PostgresLockWaitModeEnum::NonBlocking,
115116 PostgresLockAccessModeEnum $ accessMode = PostgresLockAccessModeEnum::Exclusive,
116117 ): mixed {
117118 $ lockHandle = $ this ->acquireSessionLevelLock (
118119 $ dbConnection ,
119- $ postgresLockKey ,
120+ $ key ,
120121 $ waitMode ,
121122 $ accessMode ,
122123 );
@@ -134,20 +135,20 @@ public function withinSessionLevelLock(
134135 */
135136 public function releaseSessionLevelLock (
136137 PDO $ dbConnection ,
137- PostgresLockKey $ postgresLockKey ,
138+ PostgresLockKey $ key ,
138139 PostgresLockAccessModeEnum $ accessMode = PostgresLockAccessModeEnum::Exclusive,
139140 ): bool {
140141 $ sql = match ($ accessMode ) {
141142 PostgresLockAccessModeEnum::Exclusive => 'SELECT PG_ADVISORY_UNLOCK(:class_id, :object_id); ' ,
142143 PostgresLockAccessModeEnum::Share => 'SELECT PG_ADVISORY_UNLOCK_SHARED(:class_id, :object_id); ' ,
143144 };
144- $ sql .= " -- $ postgresLockKey ->humanReadableValue " ;
145+ $ sql .= " -- $ key ->humanReadableValue " ;
145146
146147 $ statement = $ dbConnection ->prepare ($ sql );
147148 $ statement ->execute (
148149 [
149- 'class_id ' => $ postgresLockKey ->classId ,
150- 'object_id ' => $ postgresLockKey ->objectId ,
150+ 'class_id ' => $ key ->classId ,
151+ 'object_id ' => $ key ->objectId ,
151152 ],
152153 );
153154
@@ -170,14 +171,14 @@ public function releaseAllSessionLevelLocks(
170171
171172 private function acquireLock (
172173 PDO $ dbConnection ,
173- PostgresLockKey $ postgresLockKey ,
174+ PostgresLockKey $ key ,
174175 PostgresLockLevelEnum $ level ,
175176 PostgresLockWaitModeEnum $ waitMode = PostgresLockWaitModeEnum::NonBlocking,
176177 PostgresLockAccessModeEnum $ accessMode = PostgresLockAccessModeEnum::Exclusive,
177178 ): bool {
178179 if ($ level === PostgresLockLevelEnum::Transaction && $ dbConnection ->inTransaction () === false ) {
179180 throw new LogicException (
180- "Transaction-level advisory lock ` $ postgresLockKey ->humanReadableValue ` cannot be acquired outside of transaction " ,
181+ "Transaction-level advisory lock ` $ key ->humanReadableValue ` cannot be acquired outside of transaction " ,
181182 );
182183 }
183184
@@ -223,13 +224,13 @@ private function acquireLock(
223224 PostgresLockAccessModeEnum::Share,
224225 ] => 'SELECT PG_ADVISORY_LOCK_SHARED(:class_id, :object_id); ' ,
225226 };
226- $ sql .= " -- $ postgresLockKey ->humanReadableValue " ;
227+ $ sql .= " -- $ key ->humanReadableValue " ;
227228
228229 $ statement = $ dbConnection ->prepare ($ sql );
229230 $ statement ->execute (
230231 [
231- 'class_id ' => $ postgresLockKey ->classId ,
232- 'object_id ' => $ postgresLockKey ->objectId ,
232+ 'class_id ' => $ key ->classId ,
233+ 'object_id ' => $ key ->objectId ,
233234 ],
234235 );
235236
0 commit comments