comparison base/database/datasets-functions.lisp @ 287:00d35eb70ef9

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