annotate base/database/datasets-functions.lisp @ 216:e1842efb1dd4

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