Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
firstline1
titleCreating a new transaction resource
linenumberstrue
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
titleCreate transaction response
collapsetrue
Status: 201 Created
 
Headers:
Expires: Wed, 20 May 2020 23:26:46 GMT
Location: http://localhost:8080/rest/fcr:tx:83e34464/fd4f48c4-144e7c47-43d946ee-af138907-b3464a1fb9b5
Expires: Sat, 16 Nov 2013 00:32:57 GMTaf6411ae4215

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.
See Application Configuration for setting a different session duration.

The following API methods on repository resources can be called within the scope of a transaction: PUT, POST, PATCH, 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
firstline2
titleModifying resources in the transaction
linenumberstrue
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
firstline42
titleCommitting Getting status of a transaction
linenumberstrue
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 To commit a transaction, it is closed, and any further operations on that transaction will be rejected.perform a PUT request on the Transaction URI:

Code Block
firstline54
titleRolling back Committing a transaction
linenumberstrue
curl -X POSTPUT "http://localhost:8080/rest/tx:83e34464-144e-43d9-af13-b3464a1fb9b5fcr:tx/fd4f48c4-7c47-46ee-8907-af6411ae4215"

To rollback a transaction, perform a DELETE request on the Transaction URI:

Code Block
firstline5
titleRolling back a transaction
linenumberstrue
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.