/ test /
/test/showcase.lisp
 1 ;; -*- mode: Lisp; Syntax: Common-Lisp; -*-
 2 ;;;
 3 ;;; Copyright (c) 2006 by the authors.
 4 ;;;
 5 ;;; See LICENCE for details.
 6 
 7 (in-package :cl-perec-test)
 8 
 9 (mapc #L(handler-case (drop-table !1)
10           (error (e) (declare (ignore e))))
11       '("_c1" "_c2" "_c3" "_c4"))
12 
13 (start-sql-recording)
14 
15 (defpclass c1 ()
16   ((s1 :type string :initform "no" :initarg :s1 :accessor s1-of)))
17 
18 (with-transaction
19   (make-instance 'c1 :s1 "hello"))
20 
21 (defpclass c2 (c1)
22   ((s2 :type (or null integer-16) :initarg :s2 :accessor s2-of)))
23 
24 (with-transaction
25   (s1-of (make-instance 'c2 :s1 "hello" :s2 12)))
26 
27 (with-transaction
28   (select (o)
29     (from (o c1))))
30 
31 (defpclass c3 ()
32   ((s3 :type c1 :initarg :s3 :accessor s3-of)))
33 
34 (let ((o
35        (with-transaction
36          (make-instance 'c3 :s3 (make-instance 'c2 :s2 nil)))))
37   (with-transaction
38     (revive-instance o)
39     (s2-of (s3-of o))))
40 
41 (defpclass c4 ()
42   ())
43 
44 (defassociation
45   ((:class c4 :slot c1s :type (set c1) :accessor c1s-of :initarg :c1s)
46    (:class c1 :slot c4 :type c4 :accessor c4-of :initarg :c4)))
47 
48 (with-transaction
49   (make-instance 'c1 :c4 (make-instance 'c4)))
50 
51 (with-transaction
52   (let ((c4 (select-first-matching-instance c4)))
53     (select ((c4-of c1) (s1-of c1))
54       (from (c1 c1))
55       (where (eq c4 (c4-of c1))))))