$lock
Locks and unlocks an entity using the pessimistic mechanism.
Sintaxis
To lock an entity for other sessions and 4D processes:
/?$lock=true
To unlock the entity for other sessions and 4D processes:
/?$lock=false
The lockKindText
property is "Locked by session".
Descripción
The locks triggered by the REST API are put at the session level.
A locked entity is seen as locked (i.e. lock / unlock / update / delete actions are not possible) by:
- otras sesiones REST
- 4D processes (client/server, remote datastore, standalone) running on the REST server.
An entity locked by the REST API can only be unlocked:
- by its locker, i.e. a
/?$lock=false
in the REST session that sets/?$lock=true
- or if the session's inactivity timeout is reached (the session is closed).
Respuesta
A ?$lock
request returns a JSON object with "result"=true
if the lock operation was successful and "result"=false
if it failed.
The returned "__STATUS" object has the following properties:
| Propiedad | | Tipo | Descripción | | ------------ | | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | | | | Disponible sólo en caso de éxito: | | success | | booleano | true if the lock action is successful (or if the entity is already locked in the current session), false otherwise (not returned in this case). | | | | | Disponible sólo en caso de error: | | status | | number | Código de error, ver abajo | | statusText | | texto | Descripción del error, ver abajo | | lockKind | | number | Código de bloqueo | | lockKindText | | texto | "Locked by session" if locked by a REST session, "Locked by record" if locked by a 4D process |
The following values can be returned in the status and statusText properties of the __STATUS object in case of error:
status | statusText | Comentario |
---|---|---|
2 | "Stamp has changed" | El valor del sello interno de la entidad no coincide con el de la entidad almacenada en los datos (bloqueo optimista). |
3 | "Already locked" | La entidad está bloqueada por un bloqueo pesimista. |
4 | "Other error" | Un error grave es un error de base de datos de bajo nivel (por ejemplo, una llave duplicada), un error de hardware, etc. |
5 | "Entity does not exist anymore" | La entidad ya no existe en los datos. |
Ejemplo
Bloqueamos una entidad en un primer navegador:
GET /rest/Customers(1)/?$lock=true
Respuesta:
{
"result": true,
"__STATUS": {
"success": true
}
}
En un segundo navegador (otra sesión), enviamos la misma petición.
Respuesta:
{
"result":false,
"__STATUS":{
"status":3,
"statusText":"Already Locked",
"lockKind":7,
"lockKindText":"Locked By Session",
}
}