Coverage report: /development/source/library/org/datagraph/spocq-shard/src/store/transaction.lisp
| Kind | Covered | All | % |
| expression | 57 | 77 | 74.0 |
| branch | 4 | 6 | 66.7 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Base: 10; Package: org.datagraph.spocq.implementation; -*-
3
(in-package :org.datagraph.spocq.implementation)
5
(:documentation "This file defines abstract transaction definitions and operators
6
for the 'org.datagraph.spocq' RDF engine."
9
"Copyright 2016 [james anderson](mailto:james@datagraph.org) All Rights Reserved.")
14
(defun abort-transaction (&rest args)
15
"Invoke the abort-transaction restart with optional format specifications."
16
(apply #'invoke-restart 'abort-transaction args))
18
(defun commit-transaction (&rest args)
19
"Invoke the commit-transaction restart with optional format specifications."
20
(apply #'invoke-restart 'commit-transaction args))
23
(defgeneric call-with-open-repository (operator repository &rest args)
24
(:documentation "operate on an open repository for aomw internal subtask,
25
most likely relative to a running query.. if so, then authenticate,
26
otherwise permit unrestricted access.")
27
(:method ((operator t) (id t) &rest args)
28
(declare (dynamic-extent args))
29
(apply #'call-with-open-repository operator (repository id) args))
31
(:method ((operator t) (repository repository) &rest args &key
32
(id (make-internal-task-id))
34
(when (and *task* (not (eq *agent* (system-agent))))
35
(unless (access-authorized-p repository *agent*
36
(if read-only-p |acl|:|Read| |acl|:|Write|))
37
(spocq.e:task-authorization-error :task *task* :operation (task-operation *task*))))
38
(labels ((call-repository-with-bound-transaction (*transaction*)
39
#+(or) (print (cons :cwor.crwbt *transaction*))
40
(let ((*lexical->spocq-term-registry* (if *task* (task-lexical->spocq-term-registry *task*) (copy-registry *lexical->spocq-term-registry*)))
41
(*spocq->store-term-registry* (if *task* (task-spocq->store-term-registry *task*) (copy-registry *spocq->store-term-registry*)))
42
(*store->spocq-term-registry* (if *task* (task-store->spocq-term-registry *task*) (copy-registry *store->spocq-term-registry*))))
43
(unwind-protect (funcall operator repository)
44
(setq *transaction* nil)))))
45
(declare (dynamic-extent #'call-repository-with-bound-transaction))
46
(unwind-protect (progn (rdfcache:init-thread)
47
(apply #'call-with-revision-transaction #'call-repository-with-bound-transaction repository nil
50
:read-only-p read-only-p
52
(rdfcache:exit-thread)))))
54
(defgeneric call-with-open-transaction (operation transaction
56
api-key id revision-id
58
normal-disposition abnormal-disposition
61
(:documentation "Invoke the operation function in the dynamic extent of a new transaction.
62
GIven a transaction specification, as a combination of repository, repository revision,
63
a task uuid, and an authorization api-key, construct a new transaction and continue.
64
Given a transaction, invoke the function while observing the dispositions specified for
65
eventual success or failure outcome.
66
Upon exit, depending on success or failure close the transaction with normal (default :continue)
67
or abnormal (default :abort) disposition.")
69
(:method ((operation function) (repository-id string) &rest args)
70
(declare (dynamic-extent args))
71
(apply #'call-with-open-transaction operation (repository repository-id)
75
(defgeneric record-modified-resource (transaction term-id &key type)
76
(:method ((transaction t) (term-id t) &key type)
77
(declare (ignore type)) ;; do nothing
80
(defgeneric record-new-resource (transaction term-id &key type)
81
(:method ((transaction t) (term-id t) &key type)
82
(declare (ignore type)) ;; do nothing
85
(defgeneric transaction-open (transaction &key if-does-not-exist)
86
(:documentation "Given a transaction designator, depending on its current state either
87
establish a new store transaction or continue the current one,"))
89
(defgeneric transaction-close (transaction disposition)
90
(:method ((transaction t) (disposition (eql :begun)))
91
(transaction-close transaction :begin))
92
(:method ((transaction t) (disposition (eql :continue)))
93
;; no end time if continued -- this applies to read-only transactions
100
(defgeneric transaction-modified-p (transaction)
101
(:method ((no-transaction null))
104
(defgeneric transaction-open-p (transaction)
105
(:method ((no-transaction null))