...
After retrieving a transaction resource using the RESTful HTTP API - Transactions, clients can send additional REST API calls within the scope of that transaction. After committing the transaction, the pending changes will be persisted in a single atomic operation. Validation, eventThe updates related to a given transaction are only visible within that transaction scope. Event-driven workflows , and other asynchronous operations are not triggered until the transaction is committed, which may provide a performance increase for some types of iterative tasks. Transactions can also be rolled back on-demand or based on a configurable timeout duration, leaving the repository in the state as if they the transaction had never occurred.
Example
Create a transaction:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
curl -vi -X POST "http://localhost:8080/rest/fcr:tx" |
Create a transaction. In the response, the Location header will contain a path to the created transaction URI:
Code Block | ||||
---|---|---|---|---|
| ||||
Status: 201 Created Headers: Location: http://localhost:8080/rest/fcr:tx:83e34464/fd4f48c4-144e7c47-43d946ee-af138907-b3464a1fb9b5af6411ae4215 Expires: SatThu, 1607 NovMay 20132020 0014:3218:5716 GMT |
The expires header indicates when the transaction will be automatically rolled back.
Warning |
---|
Transactions are automatically closed and rolled back after 3 minutes. Transactions can be refreshed by POSTing to /rest/{tx:id}/fcr:txthe transaction URI returned in the "Location" header of the initial creation request. |
The following API methods on repository resources can be called within the scope of a transaction: PUT, POST, GET, and DELETE .
In order to make a request within the transaction, include the Transaction URI in the "Atomic-ID" request headerAPI requests can be prefixed with the transaction identifier:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
curl -X POST "-H"Atomic-ID: http://localhost:8080/rest/tx:83e34464-144e-43d9-af13-b3464a1fb9b5fcr:tx/fd4f48c4-7c47-46ee-8907-af6411ae4215" -X POST "http://localhost:8080/rest/path/to/object/to/create" curl -X DELETE "-H"Atomic-ID: http://localhost:8080/rest/tx:83e34464-144e-43d9-af13-b3464a1fb9b5fcr:tx/fd4f48c4-7c47-46ee-8907-af6411ae4215" -X DELETE "http://localhost:8080/rest/path/to/resource/to/delete" |
You can send most API requests scoped by the transaction. API requests that are not prefixed by a path to the node do not occur within the scope of a transaction and cannot be used (e.g. fcr:nodetypes, fcr:namespaces, etc)To get the status of a transaction, perform a GET request on the Transaction URI:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
curl -Xi POSTGET "http://localhost:8080/rest/fcr:tx:83e34464/fd4f48c4-144e7c47-43d946ee-af13-b3464a1fb9b5/fcr:tx/fcr:commit8907-af6411ae4215" |
Until the transaction is committed, no other client will see the changes made within the scope of the transaction. After committing, the changes will be applied to the workspace repository, associated events will be emitted, and all clients will be able to see the change(s).Fedora's transactions do NOT support checkpointing. After committing a transaction, it is closed, and any further operations on that transaction will be rejected.
To commit a transaction, perform a PUT request on the "commit" endpoint on the Transaction URI:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
curl -X POSTPUT "http://localhost:8080/rest/tx:83e34464-144e-43d9-af13-b3464a1fb9b5fcr:tx/fd4f48c4-7c47-46ee-8907-af6411ae4215/commit" |
To rollback a transaction, perform a DELETE request on the Transaction URI:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
curl -X DELETE "http://localhost:8080/rest/fcr:tx/fcr:rollback"fd4f48c4-7c47-46ee-8907-af6411ae4215" |
Note: Rolling back a transaction will result in the The changes made within the scope of the transaction will to be erased, and the transaction closed and removed.
After committing or rolling back a transaction, it is closed, and any further operations on that transaction will be rejected.