Changeset 193 for branches/new-datamodel/src/model
- Timestamp:
- 02/17/10 18:59:30 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/new-datamodel/src/model/datamodel.lisp ¶
r192 r193 12 12 (:nicknames :d) 13 13 (:export ;;classes 14 :RoleC 15 :OccurrenceC 16 :NameC 17 :VariantC 14 18 :PersistentIdC 15 19 :ItemIdentifierC … … 22 26 :uri 23 27 :identifieid-construct 24 :all-identified-constructs25 28 :item-identifiers 26 29 :reifier … … 38 41 :add-parent 39 42 :delete-parent 43 :variants 44 :add-variant 45 :delete-variant 46 :parent 47 :add-parent 48 :delete-parent 49 :player 50 :add-player 51 :delete-player 40 52 :mark-as-deleted 41 53 … … 45 57 (in-package :datamodel) 46 58 47 48 ;;TODO: implement delete-item-identifier 49 ;;TODO: implement delete-reifier 50 ;;TODO: implement all-reified-constructs (:with-deleted t) -> TopicC 51 ;; the method should return all reifed-constructs of the given topic 59 ;;TODO: use some exceptions --> more than one type, 60 ;; identifier, not-mergeable merges, ... 52 61 ;;TODO: implement make-construct -> symbol 53 62 ;; replace the latest make-construct-method … … 61 70 62 71 ;;; start hacks -> just some temporary hacks to avoid compiler-errors ;;;;;;;;;; 63 (defpclass NameC (TopicMapConstructC)64 ()65 (:documentation "A temporary emtpy class to avoid compiler-errors."))66 67 (defpclass OccurrenceC (TopicMapConstructC)68 ()69 (:documentation "A temporary emtpy class to avoid compiler-errors."))70 71 72 72 (defpclass TopicC (TopicMapConstructC) 73 73 () 74 74 (:documentation "A temporary emtpy class to avoid compiler-errors.")) 75 76 (defpclass AssociationC (TopicMapConstructC) 77 () 78 (:documentation "A temporary emtpy class to avoid compiler-errors.")) 79 75 80 76 81 (defgeneric merge-constructs(construc-1 construct-2 &key revision) … … 78 83 &key (revision *TM-REVISION*)) 79 84 (or construct-1 construct-2 revision))) 80 81 82 (defgeneric all-reified-constructs(topic &key with-deleted)83 (:method ((topic TopicC) &key (with-deleted t))84 (or topic with-deleted)))85 85 86 86 … … 302 302 303 303 ;;; Characterics ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 304 (defpclass OccurrenceC(CharacteristicC) 305 ((datatype :accessor datatype 306 :initarg :datatype 307 :initform nil 308 :documentation "The XML Schema datatype of the occurrencevalue 309 (optional, always IRI for resourceRef)."))) 310 311 312 (defpclass NameC(CharacteristicC) 313 ((variants :associate (VaraitnAssociationC name) 314 :documentation "Associates this obejct with varian-associations.")) 315 (:documentation "Scoped name of a topic.")) 316 317 318 (defgeneric variants (construct &key revision) 319 (:documentation "Returns all variants that correspond with the given revision 320 and that are associated with the passed construct.") 321 (:method ((construct NameC) &key (revision *TM-REVISION*)) 322 (let ((valid-associations 323 (filter-slot-value-by-revision construct 'variants 324 :start-revision revision))) 325 (map 'list #'characteristic valid-associations)))) 326 327 328 (defgeneric add-variant (construct variant &key revision) 329 (:documentation "Adds the given theme-topic to the passed 330 scopable-construct.") 331 (:method ((construct ScopableC) (variant VariantC) 332 &key (revision *TM-REVISION*)) 333 (let ((all-variants 334 (map 'list #'characteristic 335 (remove-if #'marked-as-deleted-p 336 (slot-p construct 'variants))))) 337 (if (find variant all-variants) 338 (let ((variant-assoc 339 (loop for variant-assoc in (slot-p construct 'variants) 340 when (eql (characteristic variant-assoc) variant) 341 return variant-assoc))) 342 (add-to-version-history variant-assoc :start-revision revision)) 343 (make-instance 'VariantAssociationC 344 :start-revision revision 345 :characteristic variant 346 :name construct))) 347 construct)) 348 349 350 (defgeneric delete-variant (construct variant &key revision) 351 (:documentation "Deletes the passed variant by marking it's association as 352 deleted in the passed revision.") 353 (:method ((construct NameC) (variant VariantC) 354 &key (revision (error "From delete-theme(): revision must be set"))) 355 (let ((assoc-to-delete (loop for variant-assoc in (slot-p construct 356 'variants) 357 when (eql (characteristic variant-assoc) variant) 358 return variant-assoc))) 359 (when assoc-to-delete 360 (mark-as-deleted assoc-to-delete :revision revision)) 361 construct))) 362 363 364 (defpclass VariantC(CharacteristicC) 365 ((datatype :accessor datatype 366 :initarg :datatype 367 :initform nil 368 :documentation "The XML Schema datatype of the occurrencevalue 369 (optional, always IRI for resourceRef)."))) 370 371 304 372 (defpclass CharacteristicC(ReifiableConstructC ScopableC TypableC) 305 373 ((parent :associate (CharacteriticAssociationC characteristic) … … 422 490 423 491 ;;; Versioned-Associations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 492 ;;; PlayerAssociationC 493 ;;; RoleAssociationC 424 494 ;;; VariantAssociationC 425 495 ;;; NameAssociationC … … 435 505 ;;; PointerAssociationC 436 506 ;;; VersionedAssociationC 507 (defpclass PlayerAssociationC(VersionedAssociationC) 508 ((player-topic :initarg :player-topic 509 :accessor player-topic 510 :associate TopicC 511 :initform (error "From PlayerAssociationC(): player-topic must be set") 512 :documentation "Associates this object with a topic that is 513 a player.") 514 (role :initarg :role 515 :accessor role 516 :associate RoleC 517 :initform (error "From PlayerAssociationC(): role must be set") 518 :documentation "Associates this object with the parent-association.")) 519 (:documentation "This class associates roles and their player in given 520 revisions.")) 521 522 523 (defmethod delete-construct :before ((construct PlayerAssociationC)) 524 "Deletes all elephant-associations." 525 (delete-1-n-association construct 'player-topic) 526 (delete-1-n-association construct 'role)) 527 528 529 (defpclass RoleAssociationC(VersionedAssociationC) 530 ((role :initarg :role 531 :accessor role 532 :associate RoleC 533 :initform (error "From RoleAssociationC(): role must be set") 534 :documentation "Associates this objetc with a role-object.") 535 (association :initarg :association 536 :accessor association 537 :associate AssociationC 538 :initform (error "From RoleAssociationC(): association must be set") 539 :documentation "Assocates thius object with an association-object.")) 540 (:documentation "Associates roles with assoications and adds some 541 version-infos between these realtions.")) 542 543 544 (defmethod delete-construct :before ((construct RoleAssociationC)) 545 "Deletes all elephant-associations and the entire role if it is not 546 associated with another AssociationC object." 547 (let ((role (role construct))) 548 (delete-1-n-association construct 'role) 549 (when (not (slot-p role 'parent)) 550 (delete-construct role)) 551 (delete-1-n-association construct 'association))) 552 553 437 554 (defpclass VariantAssociationC(CharateristicAssociationC) 438 555 ((name :initarg :name … … 441 558 :associate NameC 442 559 :documentation "Associates this object with a name.")) 443 (:index t)444 560 (:documentation "Associates variant objects with name obejcts. 445 561 Additionally version-infos are stored.")) … … 456 572 :associate TopicC 457 573 :documentation "Associates this object with a topic.")) 458 (:index t)459 574 (:documentation "Associates name objects with their parent topics. 460 575 Additionally version-infos are stored.")) … … 471 586 :associate TopicC 472 587 :documentation "Associates this object with a topic.")) 473 (:index t)474 588 (:documentation "Associates occurrence objects with their parent topics. 475 589 Additionally version-infos are stored.")) … … 515 629 construct that is typed by the 516 630 type-topic.")) 517 (:index t)518 631 (:documentation "This class associates topics that are used as type for 519 632 typable constructcs. Additionally there are stored some … … 541 654 construct that is scoped by the 542 655 scope-topic.")) 543 (:index t)544 656 (:documentation "This class associates topics that are used as scope with 545 657 scopable construtcs. Additionally there are stored some … … 566 678 :documentation "The reifier-topic that reifies the 567 679 reifiable-construct.")) 568 (:index t)569 680 (:documentation "A versioned-association that relates a reifiable-construct 570 681 with a topic.")) … … 588 699 :documentation "The actual topic which is associated 589 700 with the subject-locator.")) 590 (:index t)591 701 (:documentation "A pointer that associates subject-locators, versions 592 702 and topics.")) … … 604 714 :documentation "The actual topic which is associated 605 715 with the subject-identifier/psi.")) 606 (:index t)607 716 (:documentation "A pointer that associates subject-identifiers, versions 608 717 and topics.")) … … 620 729 :documentation "The actual topic which is associated 621 730 with the topic-identifier.")) 622 (:index t)623 731 (:documentation "A pointer that associates topic-identifiers, versions 624 732 and topics.")) … … 636 744 :documentation "The actual parent which is associated 637 745 with the item-identifier.")) 638 (:index t)639 746 (:documentation "A pointer that associates item-identifiers, versions 640 747 and reifiable-constructs.")) … … 662 769 (let ((id (slot-p construct 'identifier))) 663 770 (delete-1-n-association construct 'identifier) 664 (when (= (length ( all-identified-constructs id)) 0)771 (when (= (length (slot-p id 'identified-construct)) 0) 665 772 (delete-construct id)))) 666 773 … … 669 776 () 670 777 (:documentation "An abstract base class for all versioned associations.")) 778 779 780 ;;; RoleC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 781 (defpclass RoleC(ReifiableConstructC TypableC) 782 ((parent :associate (RoleAssociationC role) 783 :documentation "Associates this object with a role-association.") 784 (player :associate (PlayerAssociationC parent-role) 785 :documentation "Associates this object with a player-association."))) 786 787 788 (defmethod delete-construct :before ((construct RoleC)) 789 "Deletes all association-objects." 790 (dolist (assoc (slot-p construct 'parent)) 791 (delete-construct assoc)) 792 (dolist (assoc (slot-p construct 'player)) 793 (delete-construct assoc))) 794 795 796 (defgeneric parent (construct &key revision) 797 (:documentation "Returns the construct's parent corresponding to 798 the given revision.") 799 (:method ((construct RoleC) &key (revision *TM-REVISION*)) 800 (let ((valid-associations 801 (filter-slot-value-by-revision construct 'parent 802 :start-revision revision))) 803 (when valid-associations 804 (association (first valid-associations)))))) 805 806 807 (defmethod add-parent ((construct RoleC) (parent-construct AssociationC) 808 &key (revision *TM-REVISION*)) 809 (let ((already-set-parent 810 (map 'list #'association 811 (filter-slot-value-by-revision construct 'parent 812 :start-revision revision)))) 813 (cond ((and already-set-parent 814 (eql (first already-set-parent) parent-construct)) 815 (let ((parent-assoc 816 (loop for parent-assoc in (slot-p construct 'parent) 817 when (eql parent-construct (association parent-assoc)) 818 return parent-assoc))) 819 (add-to-version-history parent-assoc :start-revision revision))) 820 ((not already-set-parent) 821 (make-instance 'RoleAssociationC 822 :start-revision revision 823 :role construct 824 :association parent-construct)) 825 (t 826 (error "From add-parent(): ~a can't be a parent of ~a since it is already owned by the association ~a" 827 parent-construct construct already-set-parent))) 828 construct)) 829 830 831 (defmethod delete-parent ((construct RoleC) (parent-construct AssociationC) 832 &key (revision (error "From delete-parent(): revision must be set"))) 833 (let ((assoc-to-delete 834 (loop for parent-assoc in (slot-p construct 'parent) 835 when (eql (association parent-assoc) parent-construct) 836 return parent-assoc))) 837 (when assoc-to-delete 838 (mark-as-deleted assoc-to-delete :revision revision)) 839 construct)) 840 841 842 (defgeneric player (construct &key revision) 843 (:documentation "Returns the construct's player corresponding to 844 the given revision.") 845 (:method ((construct RoleC) &key (revision *TM-REVISION*)) 846 (let ((valid-associations 847 (filter-slot-value-by-revision construct 'player 848 :start-revision revision))) 849 (when valid-associations 850 (player-topic (first valid-associations)))))) 851 852 853 (defgeneric add-player (construct player-topic &key revision) 854 (:documentation "Adds a topic as a player to a role in the given revision.") 855 (:method ((construct RoleC) (player-topic TopicC) 856 &key (revision *TM-REVISION*)) 857 (let ((already-set-player 858 (map 'list #'player-topic 859 (filter-slot-value-by-revision construct 'player 860 :start-revision revision)))) 861 (cond ((and already-set-player 862 (eql (first already-set-player) player-topic)) 863 (let ((player-assoc 864 (loop for player-assoc in (slot-p construct 'player) 865 when (eql player-topic (player-topic player-assoc)) 866 return player-assoc))) 867 (add-to-version-history player-assoc :start-revision revision))) 868 ((not already-set-player) 869 (make-instance 'PlayerAssociationC 870 :start-revision revision 871 :role construct 872 :player-topic player-topic)) 873 (t 874 (error "From add-player(): ~a can't be a player of ~a since it has already the player ~a" 875 player-topic construct already-set-player))) 876 construct))) 877 878 879 (defgeneric delete-player (construct player-topic &key revision) 880 (:documentation "Deletes the passed topic as a player of the passed role 881 object by marking its association-object as deleted.") 882 (:method ((construct RoleC) (player-topic TopicC) 883 &key (revision (error "From delete-parent(): revision must be set"))) 884 (let ((assoc-to-delete 885 (loop for player-assoc in (slot-p construct 'player) 886 when (eql (player-topic player-assoc) player-topic) 887 return player-assoc))) 888 (when assoc-to-delete 889 (mark-as-deleted assoc-to-delete :revision revision)) 890 construct))) 671 891 672 892 … … 746 966 747 967 748 (defgeneric all-identified-constructs (construct &key with-deleted)749 (:documentation "Returns all constructs which are associated with this750 pointer.")751 (:method ((construct PointerC) &key (with-deleted t))752 (let ((all-values (slot-p construct 'identified-construct)))753 (let ((filtered-values754 (if with-deleted755 all-values756 (remove-if #'marked-as-deleted-p all-values))))757 (map 'list #'parent-construct filtered-values)))))758 759 760 968 ;;; ReifiableConstructC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 761 969 (defpclass ReifiableConstructC(TopicMapConstructC) … … 809 1017 (:method ((construct ReifiableConstructC) (item-identifier ItemIdentifierC) 810 1018 &key (revision *TM-REVISION*)) 811 (let ((all-constructs 812 (all-identified-constructs item-identifier 813 :with-deleted nil))) 814 (cond ((find construct all-constructs) 815 (let ((ii-assoc 816 (loop for ii-assoc in (slot-p construct 'item-identifiers) 817 when (eql (identifier ii-assoc) item-identifier) 818 return ii-assoc))) 819 (add-to-version-history ii-assoc :start-revision revision) 820 construct)) 821 (all-constructs 822 (merge-constructs (first all-constructs) construct)) 1019 (let ((all-ids 1020 (map 'list #'identifier 1021 (remove-if #'marked-as-deleted-p 1022 (slot-p construct 'item-identifiers))))) 1023 (cond ((find item-identifier all-ids) 1024 (let ((ii-assoc (loop for ii-assoc in (slot-p construct 1025 'item-identifiers) 1026 when (eql (identifier ii-assoc) item-identifier) 1027 return ii-assoc))) 1028 (add-to-version-history ii-assoc :start-revision revision))) 1029 (all-ids 1030 (merge-constructs (identified-construct (first all-ids) 1031 :revision revision) 1032 construct)) 823 1033 (t 824 1034 (make-construct 'ItemIdAssociationC … … 910 1120 911 1121 (defgeneric themes (construct &key revision) 912 (:documentation "Returns all topics that are not marked as deleted and are1122 (:documentation "Returns all topics that correspond with the given revision 913 1123 as a scope for the given topic.") 914 1124 (:method ((construct ScopableC) &key (revision *TM-REVISION*)) … … 924 1134 (:method ((construct ScopableC) (theme-topic TopicC) 925 1135 &key (revision *TM-REVISION*)) 926 (let ((all-themes (themes construct))) 1136 (let ((all-themes 1137 (map 'list #'theme-topic 1138 (remove-if #'marked-as-deleted-p (slot-p construct 'themes))))) 927 1139 (if (find theme-topic all-themes) 928 1140 (let ((theme-assoc
Note: See TracChangeset
for help on using the changeset viewer.