view base/datasets/datasets-db/methods.lisp @ 262:2284dbc7d51a

fix missing description value in mtp-compositions
author Jamie Forth <j.forth@gold.ac.uk>
date Sun, 10 Apr 2011 10:23:04 +0100
parents 6a3adca16910
children
line wrap: on
line source
(cl:in-package #:amuse-datasets)

(defmethod make-dataset ((identifier db-dataset-identifier)
			 composition-identifiers &optional
			 description)
  (make-instance 'db-dataset
		 :%data composition-identifiers
		 :identifier identifier
		 :description description))

(defmethod get-dataset ((dataset-identifier db-dataset-identifier))
  (let ((dataset-header (clsql:query (format nil "
SELECT description
FROM amuse_datasets
WHERE dataset_id = ~S" (dataset-id dataset-identifier))
				     :database
				     amuse-database-admin:*amuse-database*
				     :flatp t
				     :field-names nil))
	(dataset-rows (clsql:query (format nil "
SELECT implementation_name, composition_id
FROM amuse_datasets_join
LEFT JOIN amuse_implementations
USING (implementation_id)
WHERE dataset_id = ~S"
					   (dataset-id
					    dataset-identifier))
				   :flatp t
				   :field-names nil
				   :database
				   amuse-database-admin:*amuse-database*)))
    (make-dataset dataset-identifier
		  (%init-dataset-rows dataset-rows)
		  (car dataset-header))))

(defun %init-dataset-rows (dataset-rows)
  (loop for row in dataset-rows
     collect (make-composition-identifier
	      (find-package (first row)) (second row))
     into composition-identifiers
     finally (return composition-identifiers)))

(defmethod assign-composition-to-dataset (composition-identifier
					  (dataset-identifier
					   db-dataset-identifier))
  (clsql:execute-command (format nil "
INSERT INTO amuse_datasets_join
SET dataset_id := ~S,
implementation_id := (SELECT get_impl_id('~A')),
composition_id := ~S;"
					(dataset-id dataset-identifier)
					(amuse-database-admin:implementation-namestring
					 composition-identifier)
					(composition-id
					 composition-identifier)))
			 :database amuse-database-admin:*amuse-database*)