Skip to content

Commit 2e9a712

Browse files
committed
Update Release notes and documentation for the SODA lock method
1 parent fc6f4d0 commit 2e9a712

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

doc/src/api_manual/sodacollection.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,39 @@ with the key “c” is matched.
451451
The ``limit()`` method cannot be used in conjunction with
452452
:meth:`~sodaOperation.count()`.
453453

454+
.. method:: sodaOperation.lock()
455+
456+
.. versionadded:: 6.2
457+
458+
.. code-block:: javascript
459+
460+
lock()
461+
462+
Locks the documents fetched from the collection.
463+
464+
Using ``lock()`` allows for pessimistic locking, that is, only the current
465+
user that performed the lock can modify the documents in the collection.
466+
Other users can only perform operations on these documents once they are
467+
unlocked. The functionality of this method is equivalent to the
468+
``SELECT FOR UPDATE`` clause.
469+
470+
The documents can be unlocked with an explicit call to
471+
:meth:`~connection.commit()` or :meth:`~connection.rollback()` on the
472+
connection. Ensure that the :attr:`oracledb.autoCommit` is
473+
set to *false* for the connection. Otherwise, the documents will be
474+
unlocked immediately after the operation is complete.
475+
476+
This method should only be used with read operations (other than
477+
:meth:`~sodaOperation.count()`), and should not be used in conjunction
478+
with non-terminal methods :meth:`~sodaOperation.skip()` and
479+
:meth:`~sodaOperation.limit()`.
480+
481+
If this method is specified in conjunction with a write operation, then
482+
this method is ignored.
483+
484+
This method is only supported in Oracle Client 21.3 and Oracle Client
485+
19.11 (or later).
486+
454487
.. method:: sodaOperation.skip()
455488

456489
.. versionadded:: 3.0

doc/src/release_notes.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ Thin Mode Changes
2121
Thick Mode Changes
2222
++++++++++++++++++
2323

24-
#) Fixed segfault while populating object Collection having BLOB property.
25-
`https://node-oracledb.slack.com/archives/CCM8AMSF7/p1694544451676639`--.
26-
27-
#) Added lock() method on sodaOperation object to disable modification on any
28-
SODA document. An explicit commit/rollback is required to unlock and
29-
modify any corresponding SODA document.
24+
#) Fixed bug where a segmentation fault (segfault) occurred while populating
25+
object Collection having BLOB property. See
26+
`node-oracledb public Slack channel <https://node-oracledb.slack.com/
27+
archives/CCM8AMSF7/p1694544451676639>`__.
28+
29+
#) Added :meth:`sodaOperation.lock()` method on
30+
:ref:`SodaOperation <sodaoperationclass>` object to disable modification
31+
on any SODA document. An explicit commit or rollback is required to unlock
32+
and modify any corresponding SODA document.
3033

3134
#) Fixed bug that throws an 'ORA-21525' error with dbObjects having one or
3235
more 'Number' attributes of precision less than or equal to 18 and scale

doc/src/user_guide/soda.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Note:
119119
- When :attr:`oracledb.autoCommit` is *true*,
120120
most SODA methods will issue a commit before successful return.
121121
- SODA provides optimistic locking, see :meth:`sodaOperation.version()`.
122+
- SODA provides pessimistic locking, see :meth:`sodaOperation.lock()`.
122123
- When mixing SODA and relational access, any commit or rollback on the
123124
connection will affect all work.
124125

@@ -397,6 +398,21 @@ Other examples of chained read and write operations include:
397398
398399
const n = collection.find().count();
399400
401+
- To lock the documents in a collection:
402+
403+
.. code-block:: javascript
404+
405+
collection.find().lock();
406+
407+
Using :meth:`~sodaOperation.lock()` allows pessimistic locking, so that the
408+
:meth:`~sodaCollection.find()` terminal method does not allow anyone else to
409+
modify the documents in the collection other than the current user.
410+
411+
After all the documents have been modified, explicitly call
412+
:meth:`~connection.commit()` in your application to unlock the documents.
413+
Also, an explicit call to :meth:`~connection.rollback()` will unlock the
414+
documents in the collection.
415+
400416
- When using :meth:`~sodaOperation.getCursor()` and
401417
:meth:`~sodaOperation.getDocuments()` to return a
402418
number of documents, performance of document retrieval can be tuned

0 commit comments

Comments
 (0)