Show More
@@ -1,63 +1,63 b'' | |||||
1 |
|
1 | |||
2 | (in-package mito-transactions.dev) |
|
2 | (in-package mito-transactions.dev) | |
3 |
|
3 | |||
4 | ;;; Locking (for MT version) |
|
4 | ;;; Locking (for MT version) | |
5 |
|
5 | |||
6 | #+:mito-transactions-mt |
|
6 | #+:mito-transactions-mt | |
7 | (defvar *lock* (bt:make-recursive-lock)) |
|
7 | (defvar *lock* (bt:make-recursive-lock)) | |
8 |
|
8 | |||
9 | (defmacro maybe-lock (&body body) |
|
9 | (defmacro maybe-lock (&body body) | |
10 | #+:mito-transactions-mt |
|
10 | #+:mito-transactions-mt | |
11 | `(bt:with-recursive-lock-held (*lock*) |
|
11 | `(bt:with-recursive-lock-held (*lock*) | |
12 | ,@body) |
|
12 | ,@body) | |
13 | #-:mito-transactions-mt |
|
13 | #-:mito-transactions-mt | |
14 | `(progn |
|
14 | `(progn | |
15 | ,@body)) |
|
15 | ,@body)) | |
16 |
|
16 | |||
17 | ;;; Metaclass |
|
17 | ;;; Metaclass | |
18 |
|
18 | |||
19 | (defclass cached-dao-class (mito:dao-table-class) |
|
19 | (defclass cached-dao-class (mito:dao-table-class) | |
20 | ((cache :initform (trivial-garbage:make-weak-hash-table :weakness :value :test 'equal)))) |
|
20 | ((cache :initform (trivial-garbage:make-weak-hash-table :weakness :value :test 'equal)))) | |
21 |
|
21 | |||
22 | (defclass transaction-dao-class (cached-dao-class) |
|
22 | (defclass transaction-dao-class (cached-dao-class) | |
23 | ((transaction-slots :reader transaction-slots))) |
|
23 | ((transaction-slots :reader transaction-slots))) | |
24 |
|
24 | |||
25 | (ensure-superclass-for-metaclass cached-dao-class cached-dao) |
|
25 | (ensure-superclass-for-metaclass cached-dao-class cached-dao) | |
26 | (ensure-superclass-for-metaclass transaction-dao-class transaction-dao) |
|
26 | (ensure-superclass-for-metaclass transaction-dao-class transaction-dao) | |
27 |
|
27 | |||
28 | (defmethod shared-initialize :after ((class transaction-dao-class) slot-names &key &allow-other-keys) |
|
28 | (defmethod shared-initialize :after ((class transaction-dao-class) slot-names &key &allow-other-keys) | |
29 | (setf (slot-value class 'transaction-slots) |
|
29 | (setf (slot-value class 'transaction-slots) | |
30 | (mapcar #'c2mop:slot-definition-name |
|
30 | (mapcar #'c2mop:slot-definition-name | |
31 | (remove-if #'mito.class.column:ghost-slot-p |
|
31 | (remove-if #'mito.class.column:ghost-slot-p | |
32 | (all-direct-slots class 'transaction-dao-direct-slot))))) |
|
32 | (all-direct-slots class 'transaction-dao-direct-slot))))) | |
33 |
|
33 | |||
34 | ;;; Class |
|
34 | ;;; Class | |
35 |
|
35 | |||
36 | (defvar *ignore-transaction* nil "Bind to T to ignore transaction slot writer in a dynamic scope") |
|
36 | (defvar *ignore-transaction* nil "Bind to T to ignore transaction slot writer in a dynamic scope") | |
37 |
|
37 | |||
38 | (defmacro deftable (name direct-superclasses direct-slots &rest options) |
|
38 | (defmacro deftable (name direct-superclasses direct-slots &rest options) | |
39 | (unless (and (getf options :auto-pk) |
|
39 | (unless (and (cdr (or (assoc :auto-pk options) (cons t t))) | |
40 |
( |
|
40 | (cdr (or (assoc :record-timestamps options) (cons t t)))) | |
41 | (error "Cached DAO require both :AUTO-PK and :RECORD-TIMESTAMPS")) |
|
41 | (error "Cached DAO require both :AUTO-PK and :RECORD-TIMESTAMPS")) | |
42 | `(defclass ,name ,direct-superclasses |
|
42 | `(defclass ,name ,direct-superclasses | |
43 | ,direct-slots |
|
43 | ,direct-slots | |
44 | (:metaclass transaction-dao-class) |
|
44 | (:metaclass transaction-dao-class) | |
45 | ,@(unless (find :conc-name options :key #'car) |
|
45 | ,@(unless (find :conc-name options :key #'car) | |
46 | `((:conc-name ,(intern (format nil "~@:(~A-~)" name) (symbol-package name))))) |
|
46 | `((:conc-name ,(intern (format nil "~@:(~A-~)" name) (symbol-package name))))) | |
47 | ,@options)) |
|
47 | ,@options)) | |
48 |
|
48 | |||
49 | (defclass cached-dao (mito:dao-class) |
|
49 | (defclass cached-dao (mito:dao-class) | |
50 | ()) |
|
50 | ()) | |
51 |
|
51 | |||
52 | (defclass transaction-dao (cached-dao) |
|
52 | (defclass transaction-dao (cached-dao) | |
53 | ((value-backup :accessor value-backup |
|
53 | ((value-backup :accessor value-backup | |
54 | :initform nil |
|
54 | :initform nil | |
55 | :documentation "Previous slot values. Used to rollback transactions"))) |
|
55 | :documentation "Previous slot values. Used to rollback transactions"))) | |
56 |
|
56 | |||
57 | ;;; Slots |
|
57 | ;;; Slots | |
58 |
|
58 | |||
59 | (defclass transaction-dao-direct-slot (mito.dao.column:dao-table-column-class) |
|
59 | (defclass transaction-dao-direct-slot (mito.dao.column:dao-table-column-class) | |
60 | ()) |
|
60 | ()) | |
61 |
|
61 | |||
62 | (defmethod c2mop:direct-slot-definition-class ((class transaction-dao-class) &key &allow-other-keys) |
|
62 | (defmethod c2mop:direct-slot-definition-class ((class transaction-dao-class) &key &allow-other-keys) | |
63 | 'transaction-dao-direct-slot) |
|
63 | 'transaction-dao-direct-slot) |
General Comments 0
You need to be logged in to leave comments.
Login now