Relatude Help

15 Transactions

A transaction groups writes so they succeed or fail together. Transaction has the same write methods as NodeStore, with the same OrFail, IfExists and Force… variants. Nothing is written until you call Execute:

var t = db.CreateTransaction();
t.Insert(venue);
t.Insert(ev);
t.AddRelation<IVenue>(venue, v => v.Events, ev);
t.SetRelation<IEvent>(ev, e => e.Host, organizer);
t.Update(organizer);

TransactionResult result = t.Execute();

If one action fails, Execute throws and nothing is written. result.ResultingOperations says what each action did, in order: CreateNode, UpdateNode, None for an update that changed nothing, and so on. After Execute the transaction is empty and can be filled again.

  • Locks — Every transaction is atomic on its own. A lock is for longer work, such as an editing session, where nobody else may write a node in the meantime. Writes to a locked node are retried and then rejected, unless the…
  • Transaction plugins — A transaction plugin runs your code in every transaction that writes nodes of a type T, or of a type that inherits from it. Use it for rules that must hold however a node is written: checks, derived values, audit trails.