j@216: (cl:in-package #:amuse-database-admin) j@216: j@216: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; j@216: ;;; Constructors j@216: j@216: (defun make-amuse-dataset-identifier (dataset-id) j@216: (make-instance 'amuse-dataset-identifier j@216: :dataset-id dataset-id)) j@216: j@216: (defun %make-amuse-dataset (dataset-identifier description j@216: composition-identifiers) j@216: (make-instance 'amuse-dataset j@216: :%data composition-identifiers j@216: :identifier dataset-identifier j@216: :description description)) j@216: j@216: j@216: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; j@216: ;;; Database functions j@216: j@216: (defun make-new-dataset (description &optional (database j@216: *amuse-database*)) j@216: "A dataset is a set of pieces used for a particualar analytical j@216: task. A dataset is not necessarily the same thing as a corpus or j@216: collection (are these things different?). Corpus indicates that a set j@216: of pieces have been curated in some way and in that sense `belong j@216: together'. A dataset is just simply a set of pieces gathered together j@216: to analyse, and the pieces can be from any corpus or backend." j@216: (let (dataset-id) j@216: #.(clsql:locally-enable-sql-reader-syntax) j@216: (clsql:insert-records :into "amuse_datasets" j@216: :attributes '([description]) j@216: :values (list description) j@216: :database database) j@216: #.(clsql:locally-disable-sql-reader-syntax) j@216: (setf dataset-id (clsql-mysql::mysql-insert-id j@216: (clsql-mysql::database-mysql-ptr j@216: database))) j@216: (make-amuse-dataset-identifier dataset-id))) j@216: j@216: (defun assign-composition-to-dataset (composition-identifier j@216: dataset-identifier j@216: &optional (database j@216: *amuse-database*)) j@216: (clsql:execute-command (format nil " j@216: INSERT INTO amuse_datasets_join j@216: SET dataset_id := ~S, j@216: implementation_id := (SELECT get_impl_id('~A')), j@216: composition_id := ~S;" j@216: (dataset-id dataset-identifier) j@216: (implementation-namestring j@216: composition-identifier) j@216: (composition-id j@216: composition-identifier))) j@216: :database database) j@216: j@216: (defun get-dataset (dataset-identifier &optional (database j@216: *amuse-database*)) j@216: (let ((dataset-header (clsql:query (format nil " j@216: SELECT description j@216: FROM amuse_datasets j@216: WHERE dataset_id = ~S" (dataset-id dataset-identifier)) j@216: :database database j@216: :flatp t j@216: :field-names nil)) j@216: (dataset-rows (clsql:query (format nil " j@216: SELECT implementation_name, composition_id j@216: FROM amuse_datasets_join j@216: LEFT JOIN amuse_implementations j@216: USING (implementation_id) j@216: WHERE dataset_id = ~S" j@216: (dataset-id j@216: dataset-identifier)) j@216: :flatp t j@216: :field-names nil j@216: :database database))) j@216: (%make-amuse-dataset dataset-identifier (car dataset-header) j@216: (%init-dataset-rows dataset-rows)))) j@216: j@216: (defun %init-dataset-rows (dataset-rows) j@216: (loop for row in dataset-rows j@216: collect (make-composition-identifier (find-package j@216: (first row)) (second row)) j@216: into composition-identifiers j@216: finally (return composition-identifiers)))