j@287
|
1 (cl:in-package #:amuse-database-admin)
|
j@287
|
2
|
j@287
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
j@287
|
4 ;;; Constructors
|
j@287
|
5
|
j@287
|
6 (defun make-amuse-dataset-identifier (dataset-id)
|
j@287
|
7 (make-instance 'amuse-dataset-identifier
|
j@287
|
8 :dataset-id dataset-id))
|
j@287
|
9
|
j@287
|
10 (defun %make-amuse-dataset (dataset-identifier description
|
j@287
|
11 composition-identifiers)
|
j@287
|
12 (make-instance 'amuse-dataset
|
j@287
|
13 :%data composition-identifiers
|
j@287
|
14 :identifier dataset-identifier
|
j@287
|
15 :description description))
|
j@287
|
16
|
j@287
|
17
|
j@287
|
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
j@287
|
19 ;;; Database functions
|
j@287
|
20
|
j@287
|
21 (defun make-new-dataset (description &optional (database
|
j@287
|
22 *amuse-database*))
|
j@287
|
23 "A dataset is a set of pieces used for a particualar analytical
|
j@287
|
24 task. A dataset is not necessarily the same thing as a corpus or
|
j@287
|
25 collection (are these things different?). Corpus indicates that a set
|
j@287
|
26 of pieces have been curated in some way and in that sense `belong
|
j@287
|
27 together'. A dataset is just simply a set of pieces gathered together
|
j@287
|
28 to analyse, and the pieces can be from any corpus or backend."
|
j@287
|
29 (let (dataset-id)
|
j@287
|
30 #.(clsql:locally-enable-sql-reader-syntax)
|
j@287
|
31 (clsql:insert-records :into "amuse_datasets"
|
j@287
|
32 :attributes '([description])
|
j@287
|
33 :values (list description)
|
j@287
|
34 :database database)
|
j@287
|
35 #.(clsql:locally-disable-sql-reader-syntax)
|
j@287
|
36 (setf dataset-id (clsql-mysql::mysql-insert-id
|
j@287
|
37 (clsql-mysql::database-mysql-ptr
|
j@287
|
38 database)))
|
j@287
|
39 (make-amuse-dataset-identifier dataset-id)))
|
j@287
|
40
|
j@287
|
41 (defun assign-composition-to-dataset (composition-identifier
|
j@287
|
42 dataset-identifier
|
j@287
|
43 &optional (database
|
j@287
|
44 *amuse-database*))
|
j@287
|
45 (clsql:execute-command (format nil "
|
j@287
|
46 INSERT INTO amuse_datasets_join
|
j@287
|
47 SET dataset_id := ~S,
|
j@287
|
48 implementation_id := (SELECT get_impl_id('~A')),
|
j@287
|
49 composition_id := ~S;"
|
j@287
|
50 (dataset-id dataset-identifier)
|
j@287
|
51 (implementation-namestring
|
j@287
|
52 composition-identifier)
|
j@287
|
53 (composition-id
|
j@287
|
54 composition-identifier)))
|
j@287
|
55 :database database)
|
j@287
|
56
|
j@287
|
57 (defun get-dataset (dataset-identifier &optional (database
|
j@287
|
58 *amuse-database*))
|
j@287
|
59 (let ((dataset-header (clsql:query (format nil "
|
j@287
|
60 SELECT description
|
j@287
|
61 FROM amuse_datasets
|
j@287
|
62 WHERE dataset_id = ~S" (dataset-id dataset-identifier))
|
j@287
|
63 :database database
|
j@287
|
64 :flatp t
|
j@287
|
65 :field-names nil))
|
j@287
|
66 (dataset-rows (clsql:query (format nil "
|
j@287
|
67 SELECT implementation_name, composition_id
|
j@287
|
68 FROM amuse_datasets_join
|
j@287
|
69 LEFT JOIN amuse_implementations
|
j@287
|
70 USING (implementation_id)
|
j@287
|
71 WHERE dataset_id = ~S"
|
j@287
|
72 (dataset-id
|
j@287
|
73 dataset-identifier))
|
j@287
|
74 :flatp t
|
j@287
|
75 :field-names nil
|
j@287
|
76 :database database)))
|
j@287
|
77 (%make-amuse-dataset dataset-identifier (car dataset-header)
|
j@287
|
78 (%init-dataset-rows dataset-rows))))
|
j@287
|
79
|
j@287
|
80 (defun %init-dataset-rows (dataset-rows)
|
j@287
|
81 (loop for row in dataset-rows
|
j@287
|
82 collect (make-composition-identifier (find-package
|
j@287
|
83 (first row)) (second row))
|
j@287
|
84 into composition-identifiers
|
j@287
|
85 finally (return composition-identifiers)))
|