DB 参考曞。 グロヌバルの実䟋3


パヌト1
パヌト2

蚘事のタむトルにある「Living」ずいう蚀葉は、これらの蚘事のメカニズム、コヌド、およびデヌタがワヌキングドラフトで䜿甚されおいるこずを意味したす。

デヌタベヌスを開発するための゜リュヌション構造、メカニズムのいく぀かに興味があるかもしれたせん。

この図は、ディレクトリのグロヌバルルヌルを説明するコヌドを瀺しおいたす。

C R UDメ゜ッドは、䜜業䞭に垞にこれらのルヌルを参照しお、実行する必芁があるアクションを正確に芋぀けたす。

以前、私たちは次のグロヌバルを持っおいるずいう事実に萜ち着きたした。

グロヌバルを衚瀺
^Dictionary("Vehicle","TransmissionType",1,0,"UpdateTime")="62086,66625" ^Dictionary("Vehicle","TransmissionType",1,0,"uid")=888 ^Dictionary("Vehicle","TransmissionType",2,0,"UpdateTime")="62086,66625" ^Dictionary("Vehicle","TransmissionType",2,0,"uid")=888 ^NameDictionaryElement(1,"partUri",0)="akp" ^NameDictionaryElement(1,"partUri",0,"UpdateTime")="62086,66625" ^NameDictionaryElement(1,"ru",0)="" ^NameDictionaryElement(1,"ru",0,"UpdateTime")="62086,66625" ^NameDictionaryElement(2,"partUri",0)="meh" ^NameDictionaryElement(2,"partUri",0,"UpdateTime")="62086,66625" ^NameDictionaryElement(2,"ru",0)="" ^NameDictionaryElement(2,"ru",0,"UpdateTime")="62086,66625" ^IndexDictionary("Vehicle","TransmissionType","name","partUri","akp",1)=1 ^IndexDictionary("Vehicle","TransmissionType","name","partUri","meh",2)=1 ^IndexDictionary("Vehicle","TransmissionType","name","ru","",1)=1 ^IndexDictionary("Vehicle","TransmissionType","name","ru","",2)=1 ^IndexDictionary("Vehicle","TransmissionType","uid",888,1)=1 ^IndexDictionary("Vehicle","TransmissionType","uid",888,2)=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""partUri"",""akp"",1)")=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""ru"","""",1)")=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""uid"",888,1)")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""partUri"",""meh"",2)")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""ru"","""",2)")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""uid"",888,2)")=1 


グロヌバルの䜜成Ctrl + C / V
 set ^Dictionary("Vehicle","TransmissionType",1,0,"UpdateTime")="62086,66625" set ^Dictionary("Vehicle","TransmissionType",1,0,"uid")=888 set ^Dictionary("Vehicle","TransmissionType",2,0,"UpdateTime")="62086,66625" set ^Dictionary("Vehicle","TransmissionType",2,0,"uid")=888 set ^NameDictionaryElement(1,"partUri",0)="akp" set ^NameDictionaryElement(1,"partUri",0,"UpdateTime")="62086,66625" set ^NameDictionaryElement(1,"ru",0)="" set ^NameDictionaryElement(1,"ru",0,"UpdateTime")="62086,66625" set ^NameDictionaryElement(2,"partUri",0)="meh" set ^NameDictionaryElement(2,"partUri",0,"UpdateTime")="62086,66625" set ^NameDictionaryElement(2,"ru",0)="" set ^NameDictionaryElement(2,"ru",0,"UpdateTime")="62086,66625" set ^IndexDictionary("Vehicle","TransmissionType","name","partUri","akp",1)=1 set ^IndexDictionary("Vehicle","TransmissionType","name","partUri","meh",2)=1 set ^IndexDictionary("Vehicle","TransmissionType","name","ru","",1)=1 set ^IndexDictionary("Vehicle","TransmissionType","name","ru","",2)=1 set ^IndexDictionary("Vehicle","TransmissionType","uid",888,1)=1 set ^IndexDictionary("Vehicle","TransmissionType","uid",888,2)=1 set ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""partUri"",""akp"",1)")=1 set ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""ru"","""",1)")=1 set ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""uid"",888,1)")=1 set ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""partUri"",""meh"",2)")=1 set ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""ru"","""",2)")=1 set ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""uid"",888,2)")=1 




グロヌバルディレクトリルヌル


すべおのオントロゞヌずディレクトリのタむプの説明は、このグロヌバルに保存されたす。 特定のプロパティ、特性、さたざたなタむプのむンデックスが瀺されおいたす。 デヌタ怜蚌関数の呌び出しが登録されたす。 入れ子構造の階局が構築されたす。 埐々に話をし、䟋を挙げお説明したす。 時間が経぀に぀れお、グロヌバルルヌルが倧きくなりたす。 プロゞェクトの存続䞭にも同じこずが起こりたす。新しいタむプのディレクトリが衚瀺されたす。 新しいプロパティが远加されたした。 サヌビスデヌタ凊理機胜は倉化しおいたす。 新しい機胜がプログラムされおいたす。 このグロヌバルの䞻な目的は、 参照デヌタの凊理のすべおの詳现を保存するこずです。

^ RuleDictionaryルヌルグロヌバルの構造を考えおみたしょう-むンデックスの意味は次のずおりです。
  1. オントロゞヌ
  2. ディレクトリのタむプ
  3. CRUDメ゜ッドの1぀の名前
  4. 実行されおいるアクションのタむプの衚瀺
  5. アクションのシヌケンス

3番目から始たるルヌルのグロヌバルむンデックスは、他の堎合には䜕か他のものを意味する可胜性があるずいう事実に泚意を促したす䟋ずしおこれに出くわした堎合、詳现に説明したす。

オントロゞヌのすべおのルヌルを出力したすSimpleOntology、コマンドを実行したす
zwrite ^ RuleDictionary "SimpleOntology"
「MONTOLOGY」は名前空間の名前であるこずを思い出しおください。

 MONTOLOGY>zwrite ^RuleDictionary("SimpleOntology") ^RuleDictionary("SimpleOntology","SimpleType","create","check",10)="do clearPunctuationAndControlCharAllLang()" ^RuleDictionary("SimpleOntology","SimpleType","create","check",20)="do checkUniqueNameElementAllLang()" ^RuleDictionary("SimpleOntology","SimpleType","update","check",10)="do clearPunctuationAndControlCharAllLang()" ^RuleDictionary("SimpleOntology","SimpleType","update","check",20)="do checkUniqueNameElementAllLang()" MONTOLOGY> 

グロヌバルの䜜成Ctrl + C / V
 set ^RuleDictionary("SimpleOntology","SimpleType","create","check",10)="do clearPunctuationAndControlCharAllLang()" set ^RuleDictionary("SimpleOntology","SimpleType","create","check",20)="do checkUniqueNameElementAllLang()" set ^RuleDictionary("SimpleOntology","SimpleType","update","check",10)="do clearPunctuationAndControlCharAllLang()" set ^RuleDictionary("SimpleOntology","SimpleType","update","check",20)="do checkUniqueNameElementAllLang()" 


私たちが掚論したこずを詳しく芋おみたしょう。 ご芧のずおり、 SimpleOntologyオントロゞヌには、1぀のタむプのSimpleType参照がありたす。 このディレクトリには远加のパラメヌタヌはありたせんデフォルトのプロパティを陀く。 createメ゜ッドには、2぀の前凊理機胜ずデヌタ怜蚌機胜が定矩されおいたす 。 曎新メ゜ッドにも同じ機胜が定矩されおいたす。 それらはグロヌバル倀に保存されたす。 アクションのシヌケンス10、20は、必ずしも敎数である必芁はありたせん。 実行の順序は小さいものから倧きいものぞず進みたす。 SimpleOntologyおよびSimpleTypeのルヌルは、デフォルトですべおの単玔なディレクトリに䜿甚され、暙準のプロパティのみが存圚したす名前、曎新日、およびナヌザヌuid 。

䜜成する


これがどのように機胜するかを理解するには、 createメ゜ッドを怜蚎しおください 。 簡単にするために、ロック、トランザクション凊理、およびさたざたなタむプの゚ラヌを枛らしたす。 その埌、これに戻りたす。

 #; -------------------------------------------------------------------------------------------------- #;   . #;         . #; -------------------------------------------------------------------------------------------------- create() #;     kill map("out") #;     t #;         create new t #;      set t("err")=$$check("create") #; ,    if t("err")<0 { quit t("err") } #;   "UpdateTime" do setProperty(t("ontology"),t("type"),"UpdateTime",$horolog,t("id"),"false") #;   "uid" do setProperty(t("ontology"),t("type"),"uid",t("uid"),t("id"),"true") set t("lang")="" for { #;    (     ) set t("lang")=$order(t("nameList",t("lang"))) #;   ,     quit:t("lang")="" #;      set t("name")=$get(t("nameList",t("lang"))) #;      do setName(t("ontology"),t("type"),t("lang"),t("name"),t("id")) } #;          do saveOntoAndTypeID #;         do saveElementPath #;         set map("out","id")=t("id") #;     kill map("in") #;     quit t("id") #; -------------------------------------------------------------------------------------------------- 

createメ゜ッドにパラメヌタヌが明瀺的に枡されないこずがわかりたす。 メ゜ッドが呌び出される前に定矩する必芁があるロヌカル倉数mapに曞き蟌たれるこずを前提ずしおいたす。 map倉数では、 map "in"ずmap "out"の 2぀のメむンブランチを䜿甚したす。 ロヌカル倉数は、ディスクに保存されず、最倧サむズに制限があるずいう点でのみグロヌバル倉数ず異なりたす。 それ以倖の堎合、グロヌバルず同じむンデックスが付けられたす。 関数にパラメヌタヌずしお枡すこずができたす $ order 、 $ qsubscript 、 $ qlength 、 $ nameなど。 倚くの倉数を生成せず、スコヌプを監芖しないためには、単䞀の倉数new tを宣蚀するだけで十分です。 倉数tは、 createメ゜ッド内のどこからでも、たた、そこから呌び出される他のすべおのプログラムずルヌチン内でも䜿甚できたす。 マップ倉数に぀いおも同じこずが蚀えたす。 create䞭に呌び出された関数内でnew tが怜出された堎合、この関数はcreateメ゜ッド内で宣蚀された倉数tにアクセスできたせん。 スコヌプ内倉数スタックのどこかにある倉数tで動䜜したす。 おそらく、私が説明したCachéの倉数の範囲の原理は十分に明確ではありたせん。コメントで質問しおください。

確認する

次に、 t「err」に、関数$$ check「create」の結果を曞き蟌みたす 。 すべおのチェックが成功した堎合、関数は0を返したす 。それ以倖の堎合、結果は負になりたす。 $$ check関数がどのように機胜し、そこから呌び出されるメ゜ッドを芋おみたしょう。 これらの蚘事では、 メ゜ッド、関数、サブルヌチン-単語は同矩語であるこずに泚意しおください。 サヌビスワヌドprivate-メ゜ッドは、 Dictionaryプログラム内でのみ呌び出すこずができるこずを意味したす。

 #; -------------------------------------------------------------------------------------------------- #;  . #;    ^RuleDictionary    . #; -------------------------------------------------------------------------------------------------- check(action)private #;     check new check #;        action set check=$case(action,"create":$$checkCreate(),"update":$$checkUpdate(),"delete":$$checkDelete(),:-1) #;   quit:check<0 check #;  "uid"      set t("uid")=$get(map("in","uid"),888) #; ,      "check",        if $data(^RuleDictionary(t("ontology"),t("type"),action,"check")) { #;  t("map")        set t("map")=$name(^RuleDictionary(t("ontology"),t("type"),action,"check")) } else { #;  t("map")              set t("map")=$name(^RuleDictionary("SimpleOntology","SimpleType",action,"check")) } set check("i")="" for { #;     set check("i")=$order(@t("map")@(check("i"))) #;   ,     quit:check("i")="" #;     xecute $get(@t("map")@(check("i"))) #;   ,     quit:check<0 } #;    quit check #; -------------------------------------------------------------------------------------------------- #;      . #;  id, ontology, type,   . #; -------------------------------------------------------------------------------------------------- checkCreate()private #;       st("ontology")=$get(map("in","ontology"),"") #;       quit:t("ontology")="" -1 #;        set t("type")=$get(map("in","type"),"") #;  ,      quit:t("type")="" -1 #;     set t("check")=$$checkNames() #;  ,     quit:t("check")<0 t("check") #;       set t("id")=$increment(^Dictionary("MaxID")) #;      ^Dictionary set t("path")=$name(^Dictionary(t("ontology"),t("type"),t("id"))) #;     quit 0 #; -------------------------------------------------------------------------------------------------- checkUpdate() quit 0 #; -------------------------------------------------------------------------------------------------- checkDelete() quit 0 #; -------------------------------------------------------------------------------------------------- #;     . #; -------------------------------------------------------------------------------------------------- checkNames()private #;          merge t("nameList")=map("in","nameList") #;   t("check")  #;         set t("check")=-1 set t("lang")="" for { #;    set t("lang")=$order(t("nameList",t("lang"))) #;   ,     quit:t("lang")="" #;      set t("name")=$get(t("nameList",t("lang")),"") #;    if t("name")="" { #;   t("check")  set t("check")=-1 #;    quit } else { #;  t("check")   ,     set t("check")=0 } } #;     quit t("check") #; -------------------------------------------------------------------------------------------------- 

checkメ゜ッドの最初に、珟圚のアクションに必芁なチェック機胜を実行したす。 私たちの堎合、これはcheckCreate関数です。 checkUpdateおよびcheckDelete関数のスタブはコヌド内にも存圚するこずに泚意しおください-これは、 Dictionaryプログラムを自分でコピヌしおコンパむルする堎合に必芁です。

checkCreateルヌチンは、オントロゞヌパラメヌタヌの存圚ず入力マップ内のディレクトリタむプをチェックしたす。 内郚checkNames -各蚀語の名前の存圚がチェックされ、少なくずも1぀の蚀語が存圚するための前提条件がありたすシステムでは、名前なしでディレクトリ芁玠を䜜成するこずはできたせん。 同じ方法で、䜜成されたディレクトリ芁玠の識別子は、安党な関数$ incrementによっお生成されたす 。 ディレクトリ芁玠の珟圚の最倧識別子オントロゞヌずタむプの堎合は^ Dictionary "MaxID"に保存されたす。
すべおの識別子は、異なるディレクトリやオントロゞヌ内でも䞀意です
checkCreateメ゜ッドの最埌で、 t "パス"倉数に、䜜成されたディレクトリ芁玠が栌玍されるグロヌバルブランチ^ Dictionaryの正芏名を曞き蟌みたす。

checkNamesメ゜ッドの甚語merge t "nameList"= map "in"、 "nameList"に泚意しおください。
mergeコマンドは、ロヌカルたたはグロヌバルずしお定矩されおいるかどうかにかかわらず、むンデックス付き倉数のサブツリヌ党䜓を盞互にコピヌしたす。
本から取られた定矩 Wolfgang Kirsten。 マむケル・アむリンゞャヌ。 マティアス・クネ。 ベルンハルト・ルヌリグ。 ポストリレヌショナルDBMSCaché5.オブゞェクト指向のアプリケヌション開発。 第二版。 モスクワ 出版瀟BINOM 。 2005. A.マスロフ、K。アリストフによる翻蚳。 116ペヌゞ

したがっお、 checkCreateメ゜ッドを実行するず、次の重芁なデヌタがロヌカル倉数tに含たれたす。

check関数を実行し続けたす。 checkCreateが実行された埌、ナヌザヌuid  888-デフォルトを取埗したす。 次に、倉数t "map"に、ディレクトリやアクションなどのオントロゞヌに必芁な怜蚌関数を含むグロヌバルルヌルのブランチの正芏名を曞き蟌みたす。 珟圚、オントロゞヌずデフォルトタむプのルヌルのみが^ RuleDictionary globalで定矩されおいるため、 ^ RuleDictionaryブランチの暙準ビュヌ "SimpleOntology"、 "SimpleType"、 "create"、 "check"はt "map"に蚘述されたす。 

行を詳现に分析しおみたしょう。
 set check("i")=$order(@t("map")@(check("i"))) 

@は間接挔算子であるこずを思い出させおください。 初期倀はcheck "i" = ""です。 したがっお、ルヌプの開始時には、この行は次の行ず同等です。
 set check("i")=$order(^RuleDictionary("SimpleOntology","SimpleType","create","check","")) 

぀たり、 チェック「i」は10になりたす。 間接挔算子の構文で疑問が生じる堎合は、コメントで質問したす。

次に芋おみたしょう
 xecute $get(@t("map")@(check("i"))) 

xecuteコマンドは 、文字列を単䞀行のサブルヌチンずしお実行したす。
ペヌゞ115、 同じ本。

぀たり、ルヌプの最初に^ RuleDictionary "SimpleOntology"、 "SimpleType"、 "create"、 "check"、10で蚘述されおいるこずを行いたす 。 そしおこれ
 do clearPunctuationAndControlCharAllLang() 

このサブルヌチンを実行するず、指定されたすべおの蚀語の名前から句読点ず補助文字がスロヌされたす。

ルヌプの次の反埩では、倀^ RuleDictionary "SimpleOntology"、 "SimpleType"、 "create"、 "check"、20を実行したす。 そしおこれ
 do checkUniqueNameElementAllLang() 

このルヌチンは、指定されたすべおの蚀語の名前の䞀意性を怜蚌したす。 少なくずも1぀の名前が䞀意でない堎合、 checkメ゜ッドで定矩されたチェック倉数に゚ラヌが曞き蟌たれたす。

サブルヌチンコヌド
 #; -------------------------------------------------------------------------------------------------- clearPunctuationAndControlCharAllLang() set t("lang")="" for { #;     set t("lang")=$order(t("nameList",t("lang"))) quit:t("lang")="" #;           set t("nameList",t("lang"))=$$clearPunctuationAndControlChar($get(t("nameList",t("lang")),"")) } quit #; -------------------------------------------------------------------------------------------------- checkUniqueNameElementAllLang() set t("lang")="" for { #;     set t("lang")=$order(t("nameList",t("lang"))) quit:t("lang")="" #;    set t("name")=$get(t("nameList",t("lang")),"") #;   check     (0 -  ) set check=$$checkUniqueNameElement() #;     -    quit:check<0 } quit #; -------------------------------------------------------------------------------------------------- #;         . #; -------------------------------------------------------------------------------------------------- clearPunctuationAndControlChar(str) new t #;  t("str")     set t("str")="" #;      for t("i")=1:1:$length(str) { #;    set t("ch")=$extract(str,t("i")) if '((t("ch")?1P)||(t("ch")?1C)) { #;       set t("str")=t("str")_t("ch") } } #;    quit t("str") #; -------------------------------------------------------------------------------------------------- #; -------------------------------------------------------------------------------------------------- #;      ,   ,   . #;  ,   . #; -------------------------------------------------------------------------------------------------- checkUniqueNameElement() #;    set t("q")=0 set t("uniqueId")="" for { #; ,         #;   , ,   (  ) set t("uniqueId")=$order(^IndexDictionary(t("ontology"),t("type"),"name",t("lang"),$zconvert(t("name"),"l"),t("uniqueId"))) #;     quit:t("uniqueId")="" #; ,      #;     update if (t("uniqueId")'=t("id")) { #;  ,       set t("q")=-1 quit } } #;   quit t("q") #; -------------------------------------------------------------------------------------------------- 


ルヌチンは新しい関数を䜿甚したす $ zconvert 、 $ length 、 $ extract ; テンプレヌトチェック挔算子ず同様に、蚘号「」 。 文字列内の句読点ずサヌビス文字の存圚の確認は、組み蟌みのKashev関数を䜿甚しお別の方法で実行できたすが、私のプロゞェクトでは文字ごずの分析の方法を䜿甚しおいたす。

したがっお、 createメ゜ッドは次の行を正垞に完了したした set t "err"= $$ check "create" 、およびt倉数には重芁なサヌビス情報が含たれおいたす。

setProperty

次に、 setProperty関数を䜿甚しお、 「UpdateTime」および「uid」プロパティを蚭定したす。

 #; -------------------------------------------------------------------------------------------------- #;  ,     . #;         . #; -------------------------------------------------------------------------------------------------- setProperty(ontology,type,property,value,id,index="true")private #;      ()    set ^Dictionary(ontology,type,id,0,property)=value #;    if index="true" { #;   set ^IndexDictionary(ontology,type,property,value,id)=1 #;      set ^RefsDictionary(id,$name(^|"MONTOLOGY"|IndexDictionary(ontology,type,property,value,id)))=1 } quit 0 #; -------------------------------------------------------------------------------------------------- 

$ horologは、Caché圢匏の珟圚の日付ず時刻です。 「UpdateTime」プロパティにはむンデックスが付けられおいないこずに泚意しおください極端なパラメヌタヌはindex =“ false”です 。 同じ方法で、グロヌバル^ RefsDictionaryが最初に衚瀺されたす。 むンデックスの構造は単玔です
  1. アむテムID
  2. 正芏むンデックスのグロヌバルブランチ名

぀たり、必芁な堎合たずえば、芁玠を削陀するずき-この芁玠の蚀及を含むすべおの異なるむンデックスセットをすばやく取埗したす。

setName

次に、 setName関数を䜿甚しお名前の倀を蚭定したす。

 #; -------------------------------------------------------------------------------------------------- #;   ,     . #;  (  )   . #; -------------------------------------------------------------------------------------------------- setName(ontology,type,lang,value,id)private #;         set ^NameDictionaryElement(id,lang,0)=value #;   / set ^NameDictionaryElement(id,lang,0,"UpdateTime")=$horolog #;     set ^IndexDictionary(ontology,type,"name",lang,$zconvert(value,"l"),id)=1 #;    set ^RefsDictionary(id,$name(^|"MONTOLOGY"|IndexDictionary(ontology,type,"name",lang,$zconvert(value,"l"),id)))=1 quit 0 #; -------------------------------------------------------------------------------------------------- 

その埌、 saveOntoAndTypeID関数を呌び出したす。 この関数は、オントロゞヌず芁玠タむプをグロヌバルブランチ^ IndexDictionary "ID"、t "id"に曞き蟌みたす。 これは将来の堎合に必芁であり、ディレクトリの芁玠によっお、どのタむプずオントロゞヌが属しおいるかを知る必芁がありたす。 次に、同じブランチのsaveElementPath関数は、ディレクトリアむテムぞのパスを蚘録したす。

 #; -------------------------------------------------------------------------------------------------- saveOntoAndTypeID set ^IndexDictionary("ID",t("id"),"ontology")=t("ontology") set ^RefsDictionary(t("id"),$name(^|"MONTOLOGY"|IndexDictionary("ID",t("id"),"ontology")))=1 set ^IndexDictionary("ID",t("id"),"type")=t("type") set ^RefsDictionary(t("id"),$name(^|"MONTOLOGY"|IndexDictionary("ID",t("id"),"type")))=1 quit #; -------------------------------------------------------------------------------------------------- saveElementPath set ^IndexDictionary("ID",t("id"),"path")=t("path") set ^RefsDictionary(t("id"),$name(^|"MONTOLOGY"|IndexDictionary("ID",t("id"),"path")))=1 quit #; -------------------------------------------------------------------------------------------------- 

グロヌバル^ RefsDictionaryのすべおの゚ントリには、明瀺的なネヌムスペヌス名が含たれおいるこずに泚意しおください| "MONTOLOGY" | 。将来、別のネヌムスペヌスからこのグロヌバルを䜿甚する堎合、垞に正しいフルパスを䜿甚できたす。もちろん、Dictionaryプログラム自䜓の䞭でも、フルパスを蚘述する必芁がありたす他の名前空間からメ゜ッドを呌び出す堎合。私のプロゞェクトでは、これはマクロを介しお実装されおいたすが、簡単にするために、ここでは簡単なコヌドを提䟛したした。

すべおの蟞曞コヌド
 #; -------------------------------------------------------------------------------------------------- #;   #; -------------------------------------------------------------------------------------------------- Dictionary #; -------------------------------------------------------------------------------------------------- #;   . #; -------------------------------------------------------------------------------------------------- retrieve(id,lang="ru",version=0) quit $get(^NameDictionaryElement(id,lang,version),"") #; -------------------------------------------------------------------------------------------------- #;      . #; -------------------------------------------------------------------------------------------------- retrieveListByIndex(ontology,type,index,value,str="",lang="ru") #;     ,       set str=$zconvert(str,"L") set id="" for { #;  ()    set id=$order(^IndexDictionary(ontology,type,index,value,id)) #;  ,        quit:id="" #;   set name=$$retrieve(id,lang) #;      str if $extract($zconvert(name,"L"),1,$length(str))=str { #;  (  ) write id_" "_name,! } } quit #; -------------------------------------------------------------------------------------------------- #;   . #;         . #; -------------------------------------------------------------------------------------------------- create() #;     kill map("out") #;     t #;         create new t #;      set t("err")=$$check("create") #; ,    if t("err")<0 { quit t("err") } #;   "UpdateTime" do setProperty(t("ontology"),t("type"),"UpdateTime",$horolog,t("id"),"false") #;   "uid" do setProperty(t("ontology"),t("type"),"uid",t("uid"),t("id"),"true") set t("lang")="" for { #;    (     ) set t("lang")=$order(t("nameList",t("lang"))) #;   ,     quit:t("lang")="" #;      set t("name")=$get(t("nameList",t("lang"))) #;      do setName(t("ontology"),t("type"),t("lang"),t("name"),t("id")) } #;          do saveOntoAndTypeID #;         do saveElementPath #;         set map("out","id")=t("id") #;     kill map("in") #;     quit t("id") #; -------------------------------------------------------------------------------------------------- #;  . #;    ^RuleDictionary    . #; -------------------------------------------------------------------------------------------------- check(action)private #;     check new check #;        action set check=$case(action,"create":$$checkCreate(),"update":$$checkUpdate(),"delete":$$checkDelete(),:-1) #;   quit:check<0 check #;  "uid"      set t("uid")=$get(map("in","uid"),888) #; ,      "check",        if $data(^RuleDictionary(t("ontology"),t("type"),action,"check")) { #;  t("map")        set t("map")=$name(^RuleDictionary(t("ontology"),t("type"),action,"check")) } else { #;  t("map")              set t("map")=$name(^RuleDictionary("SimpleOntology","SimpleType",action,"check")) } set check("i")="" for { #;     set check("i")=$order(@t("map")@(check("i"))) #;   ,     quit:check("i")="" #;     xecute $get(@t("map")@(check("i"))) #;   ,     quit:check<0 } #;    quit check #; -------------------------------------------------------------------------------------------------- #;      . #;  id, ontology, type,   . #; -------------------------------------------------------------------------------------------------- checkCreate()private #;       st("ontology")=$get(map("in","ontology"),"") #;       quit:t("ontology")="" -1 #;        set t("type")=$get(map("in","type"),"") #;  ,      quit:t("type")="" -1 #;     set t("check")=$$checkNames() #;  ,     quit:t("check")<0 t("check") #;       set t("id")=$increment(^Dictionary("MaxID")) #;      ^Dictionary set t("path")=$name(^Dictionary(t("ontology"),t("type"),t("id"))) #;     quit 0 #; -------------------------------------------------------------------------------------------------- checkUpdate() quit 0 #; -------------------------------------------------------------------------------------------------- checkDelete() quit 0 #; -------------------------------------------------------------------------------------------------- #;     . #; -------------------------------------------------------------------------------------------------- checkNames()private #;          merge t("nameList")=map("in","nameList") #;   t("check")  #;         set t("check")=-1 set t("lang")="" for { #;    set t("lang")=$order(t("nameList",t("lang"))) #;   ,     quit:t("lang")="" #;      set t("name")=$get(t("nameList",t("lang")),"") #;    if t("name")="" { #;   t("check")  set t("check")=-1 #;    quit } else { #;  t("check")   ,     set t("check")=0 } } #;     quit t("check") #; -------------------------------------------------------------------------------------------------- clearPunctuationAndControlCharAllLang() set t("lang")="" for { #;     set t("lang")=$order(t("nameList",t("lang"))) quit:t("lang")="" #;           set t("nameList",t("lang"))=$$clearPunctuationAndControlChar($get(t("nameList",t("lang")),"")) } quit #; -------------------------------------------------------------------------------------------------- checkUniqueNameElementAllLang() set t("lang")="" for { #;     set t("lang")=$order(t("nameList",t("lang"))) quit:t("lang")="" #;    set t("name")=$get(t("nameList",t("lang")),"") #;   check     (0 -  ) set check=$$checkUniqueNameElement() #;     -    quit:check<0 } quit #; -------------------------------------------------------------------------------------------------- #;         . #; -------------------------------------------------------------------------------------------------- clearPunctuationAndControlChar(str) new t #;  t("str")     set t("str")="" #;      for t("i")=1:1:$length(str) { #;    set t("ch")=$extract(str,t("i")) if '((t("ch")?1P)||(t("ch")?1C)) { #;       set t("str")=t("str")_t("ch") } } #;    quit t("str") #; -------------------------------------------------------------------------------------------------- #; -------------------------------------------------------------------------------------------------- #;      ,   ,   . #;  ,   . #; -------------------------------------------------------------------------------------------------- checkUniqueNameElement() #;    set t("q")=0 set t("uniqueId")="" for { #; ,         #;   , ,   (  ) set t("uniqueId")=$order(^IndexDictionary(t("ontology"),t("type"),"name",t("lang"),$zconvert(t("name"),"l"),t("uniqueId"))) #;     quit:t("uniqueId")="" #; ,      #;     update if (t("uniqueId")'=t("id")) { #;  ,       set t("q")=-1 quit } } #;   quit t("q") #; -------------------------------------------------------------------------------------------------- #;  ,     . #;         . #; -------------------------------------------------------------------------------------------------- setProperty(ontology,type,property,value,id,index="true")private #;      ()    set ^Dictionary(ontology,type,id,0,property)=value #;    if index="true" { #;   set ^IndexDictionary(ontology,type,property,value,id)=1 #;      set ^RefsDictionary(id,$name(^|"MONTOLOGY"|IndexDictionary(ontology,type,property,value,id)))=1 } quit 0 #; -------------------------------------------------------------------------------------------------- #;   ,     . #;  (  )   . #; -------------------------------------------------------------------------------------------------- setName(ontology,type,lang,value,id)private #;         set ^NameDictionaryElement(id,lang,0)=value #;   / set ^NameDictionaryElement(id,lang,0,"UpdateTime")=$horolog #;     set ^IndexDictionary(ontology,type,"name",lang,$zconvert(value,"l"),id)=1 #;    set ^RefsDictionary(id,$name(^|"MONTOLOGY"|IndexDictionary(ontology,type,"name",lang,$zconvert(value,"l"),id)))=1 quit 0 #; -------------------------------------------------------------------------------------------------- saveOntoAndTypeID set ^IndexDictionary("ID",t("id"),"ontology")=t("ontology") set ^RefsDictionary(t("id"),$name(^|"MONTOLOGY"|IndexDictionary("ID",t("id"),"ontology")))=1 set ^IndexDictionary("ID",t("id"),"type")=t("type") set ^RefsDictionary(t("id"),$name(^|"MONTOLOGY"|IndexDictionary("ID",t("id"),"type")))=1 quit #; -------------------------------------------------------------------------------------------------- saveElementPath set ^IndexDictionary("ID",t("id"),"path")=t("path") set ^RefsDictionary(t("id"),$name(^|"MONTOLOGY"|IndexDictionary("ID",t("id"),"path")))=1 quit #; -------------------------------------------------------------------------------------------------- 


^ RuleDictionaryルヌルglobalを陀くすべおのグロヌバルを削陀したす。
 MONTOLOGY>kill ^Dictionary,^IndexDictionary,^NameDictionaryElement,^RefsDictionary MONTOLOGY> 

そしお、ディレクトリの最初の2぀の芁玠を䜜成したす。
 MONTOLOGY>kill map MONTOLOGY>set map("in","ontology")="Vehicle",map("in","type")="TransmissionType" MONTOLOGY>set map("in","nameList","ru")=" ,",map("in","nameList","partUri")="akp" MONTOLOGY>write $$create^Dictionary() 1 MONTOLOGY>kill map MONTOLOGY>set map("in","ontology")="Vehicle",map("in","type")="TransmissionType" MONTOLOGY>set map("in","nameList","ru")="",map("in","nameList","partUri")="meh" MONTOLOGY>write $$create^Dictionary() 2 MONTOLOGY> 

すべおのグロヌバルを印刷したす。
 MONTOLOGY>zwrite ^Dictionary,^IndexDictionary,^NameDictionaryElement,^RefsDictionary ^Dictionary("MaxID")=2 ^Dictionary("Vehicle","TransmissionType",1,0,"UpdateTime")="62948,47015" ^Dictionary("Vehicle","TransmissionType",1,0,"uid")=888 ^Dictionary("Vehicle","TransmissionType",2,0,"UpdateTime")="62948,47022" ^Dictionary("Vehicle","TransmissionType",2,0,"uid")=888 ^IndexDictionary("ID",1,"ontology")="Vehicle" ^IndexDictionary("ID",1,"path")="^Dictionary(""Vehicle"",""TransmissionType"",1)" ^IndexDictionary("ID",1,"type")="TransmissionType" ^IndexDictionary("ID",2,"ontology")="Vehicle" ^IndexDictionary("ID",2,"path")="^Dictionary(""Vehicle"",""TransmissionType"",2)" ^IndexDictionary("ID",2,"type")="TransmissionType" ^IndexDictionary("Vehicle","TransmissionType","name","partUri","akp",1)=1 ^IndexDictionary("Vehicle","TransmissionType","name","partUri","meh",2)=1 ^IndexDictionary("Vehicle","TransmissionType","name","ru","",1)=1 ^IndexDictionary("Vehicle","TransmissionType","name","ru","",2)=1 ^IndexDictionary("Vehicle","TransmissionType","uid",888,1)=1 ^IndexDictionary("Vehicle","TransmissionType","uid",888,2)=1 ^NameDictionaryElement(1,"partUri",0)="akp" ^NameDictionaryElement(1,"partUri",0,"UpdateTime")="62948,47015" ^NameDictionaryElement(1,"ru",0)="" ^NameDictionaryElement(1,"ru",0,"UpdateTime")="62948,47015" ^NameDictionaryElement(2,"partUri",0)="meh" ^NameDictionaryElement(2,"partUri",0,"UpdateTime")="62948,47022" ^NameDictionaryElement(2,"ru",0)="" ^NameDictionaryElement(2,"ru",0,"UpdateTime")="62948,47022" ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""ID"",1,""ontology"")")=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""ID"",1,""path"")")=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""ID"",1,""type"")")=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""partUri"",""akp"",1)")=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""ru"","""",1)")=1 ^RefsDictionary(1,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""uid"",888,1)")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""ID"",2,""ontology"")")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""ID"",2,""path"")")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""ID"",2,""type"")")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""partUri"",""meh"",2)")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""name"",""ru"","""",2)")=1 ^RefsDictionary(2,"^|""MONTOLOGY""|IndexDictionary(""Vehicle"",""TransmissionType"",""uid"",888,2)")=1 

ご芧のずおり、これらのグロヌバルは蚘事の冒頭に瀺したものずは異なりたす。倀は「UpdateTime」のみです-今日これらのアクションを実行したした-したがっお、日付は最新です。新しいブランチ^ IndexDictionary "ID"も登堎し、グロヌバル^ RefsDictionaryでそれぞのバックリンクがありたす。では^蟞兞«MAXID»参照サブシステムで私たちのアむデンティティヌの最倧の芁玠を保ちたした。蟞曞

プログラムのコヌドは䜜業䞭のプロゞェクトで䜿甚されおいたすが、明確化ず単玔化のために、いく぀かの構成を芋逃し、コマンドの完党な名前を䜿甚したした。おそらくどこかで゚ラヌが忍び寄った-もし誰かがそれを芋぀けたら-コメントに曞いおください。

次の蚘事では、ネスト構造に぀いお説明したす。もっずコンパクトにしようず思いたす。

ご枅聎ありがずうございたした。

私は質問、コメント、提案を喜んでいたす。

Source: https://habr.com/ru/post/J178563/


All Articles