home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / prep_db_fn.tcl < prev    next >
Text File  |  1996-06-05  |  10KB  |  310 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 1993-1995 by Cadre Technologies Inc.
  4. #
  5. # This software is furnished under a license and may be used only in
  6. # accordance with the terms of such license and with the inclusion of
  7. # the above copyright notice. This software or any other copies thereof
  8. # may not be provided or otherwise made available to any other person.
  9. # No title to and ownership of the software is hereby transferred.
  10. #
  11. # The information in this software is subject to change without notice
  12. # and should not be construed as a commitment by Cadre Technologies Inc.
  13. #
  14. #---------------------------------------------------------------------------
  15. #
  16. #       File            : @(#)prep_db_fn.tcl    2.1
  17. #       Author          : edri
  18. #       Original date   : 11-10-94
  19. #       Description     : Prepare functions for "check", database dependent
  20. #
  21. #---------------------------------------------------------------------------
  22. #
  23.  
  24. #
  25. # Prepare functions for db objects; should be in TDB dependent dir
  26. #
  27. proc db_class_prepare {class model forwhat} {
  28.     if {$forwhat == "check"} {
  29.         prepare_db_class $class $model
  30.     }
  31. }
  32.  
  33. proc db_class::prepare {class model forwhat} {
  34.     class::prepare $class $model $forwhat
  35.     db_class_prepare $class $model $forwhat
  36. }
  37.  
  38. proc db_link_class::prepare {class model forwhat} {
  39.     link_class::prepare $class $model $forwhat
  40.     db_class_prepare $class $model $forwhat
  41. }
  42.  
  43. #
  44. # db_data_attrib
  45. #
  46.  
  47. proc db_data_attrib::prepare {attrib class model forwhat} {
  48.     set name [cap [$attrib getName]]
  49.     set type [[$attrib ooplType] getName]
  50.     set column [$attrib column]
  51.  
  52.     set op [$class addOperation get$name $type]
  53.     copy_access_mode $attrib $op 1 r
  54.  
  55.     if {[$column getColumnType] == "field"} {
  56.     set op [$class addOperation set$name ""]
  57.     $op addParameter new$name $type
  58.         copy_access_mode $attrib $op 1 w
  59.     }
  60.  
  61.     if [$column isNullable] {
  62.     set op [$class addOperation "[uncap $name]IsNull" int]
  63.     copy_access_mode $attrib $op 1 r
  64.  
  65.     set op [$class addOperation nullify$name ""]
  66.     copy_access_mode $attrib $op 1 w
  67.     }
  68. }
  69.  
  70. #
  71. # db_assoc_attrib prepare functions
  72. #
  73.  
  74. proc db_assoc_attrib::prepare {attrib class model forwhat} {
  75.     prepare_for_assoc $attrib $class $model $forwhat
  76. }
  77.  
  78. proc db_assoc_attrib::one_get_prepare {attrib class model forwhat} {
  79.     set type [[$attrib ooplType] getName]
  80.     set name [cap [$attrib getName]]
  81.  
  82.     set op [$class addOperation get$name $type]
  83.     copy_access_mode $attrib $op 0 r
  84. }
  85.  
  86. proc db_assoc_attrib::one_set_prepare {attrib class model forwhat} {
  87.     set type [[$attrib ooplType] getName]
  88.     set name [cap [$attrib getName]]
  89.  
  90.     set op [$class addOperation set$name int]
  91.     $op addParameter new$name $type
  92.     copy_access_mode $attrib $op 0 w
  93. }
  94.  
  95. proc db_assoc_attrib::one_remove_prepare {attrib class model forwhat} {
  96.     if [$attrib isMandatory] {
  97.         return
  98.     }
  99.     if {[set opp [$attrib opposite]] != "" &&
  100.     [$opp get_obj_type] == "db_qual_assoc_attrib"} {
  101.         return
  102.     }
  103.     set name [cap [$attrib getName]]
  104.  
  105.     set op [$class addOperation remove$name int]
  106.     copy_access_mode $attrib $op 0 w
  107. }
  108.  
  109. proc db_assoc_attrib::many_get_prepare {attrib class model forwhat} {
  110.     set type [[$attrib ooplType] getName]
  111.     set name [$attrib getName]
  112.     set settype [set_type_name [$attrib ooplType]]
  113.     set setname [cap [set_name $name]]
  114.  
  115.     catch {$model addClass $settype}
  116.     set op [$class addOperation get$setname int]
  117.     $op addParameter $setname $settype
  118.  
  119.     copy_access_mode $attrib $op 0 r
  120. }
  121.  
  122. proc db_assoc_attrib::many_set_prepare {attrib class model forwhat} {
  123.     if {[set opp [$attrib opposite]] != "" &&
  124.     [$opp get_obj_type] == "db_qual_assoc_attrib"} {
  125.         # Can't supply the key for a qualified assoc
  126.         return
  127.     }
  128.     set type [[$attrib ooplType] getName]
  129.     set name [cap [$attrib getName]]
  130.  
  131.     set op [$class addOperation add$name int]
  132.     $op addParameter new$name $type
  133.     copy_access_mode $attrib $op 0 w
  134. }
  135.  
  136. proc db_assoc_attrib::many_remove_prepare {attrib class model forwhat} {
  137.     if {[set opp [$attrib opposite]] != "" &&
  138.     [$opp get_obj_type] == "db_qual_assoc_attrib"} {
  139.         return
  140.     }
  141.     set type [[$attrib ooplType] getName]
  142.     set name [cap [$attrib getName]]
  143.  
  144.     set op [$class addOperation remove$name int]
  145.     $op addParameter old$name $type
  146.     copy_access_mode $attrib $op 0 w
  147. }
  148.  
  149. #
  150. # db_qual_assoc_attrib prepare functions
  151. #
  152.  
  153. proc db_qual_assoc_attrib::prepare {attrib class model forwhat} {
  154.     prepare_for_assoc $attrib $class $model $forwhat
  155. }
  156.  
  157. proc db_qual_assoc_attrib::any_set_prepare {attrib class model forwhat prefix} {
  158.     set type [[$attrib ooplType] getName]
  159.     set name [cap [$attrib getName]]
  160.     set keyname [[$attrib qualifier] getName]
  161.     set keytype [[[$attrib qualifier] ooplType] getName]
  162.  
  163.     set op [$class addOperation $prefix$name int]
  164.     $op addParameter $keyname $keytype
  165.     $op addParameter new$name $type
  166.     copy_access_mode $attrib $op 0 w
  167. }
  168.  
  169. proc db_qual_assoc_attrib::one_get_prepare {attrib class model forwhat} {
  170.     set type [[$attrib ooplType] getName]
  171.     set name [$attrib getName]
  172.     set keyname [[$attrib qualifier] getName]
  173.     set keytype [[[$attrib qualifier] ooplType] getName]
  174.  
  175.     set op [$class addOperation "get[cap $name]" $type]
  176.     $op addParameter $keyname $keytype
  177.     copy_access_mode $attrib $op 0 r
  178. }
  179.  
  180. proc db_qual_assoc_attrib::one_set_prepare {attrib class model forwhat} {
  181.     db_qual_assoc_attrib::any_set_prepare $attrib $class $model $forwhat "set"
  182. }
  183.  
  184. proc db_qual_assoc_attrib::one_remove_prepare {attrib class model forwhat} {
  185.     set name [cap [$attrib getName]]
  186.     set keyname [[$attrib qualifier] getName]
  187.     set keytype [[[$attrib qualifier] ooplType] getName]
  188.  
  189.     set op [$class addOperation remove$name int]
  190.     $op addParameter $keyname $keytype
  191.     copy_access_mode $attrib $op 0 w
  192. }
  193.  
  194. proc db_qual_assoc_attrib::many_get_prepare {attrib class model forwhat} {
  195.     set name [$attrib getName]
  196.     set settype [set_type_name [$attrib ooplType]]
  197.     set setname [cap [set_name $name]]
  198.     set keyname [[$attrib qualifier] getName]
  199.     set keytype [[[$attrib qualifier] ooplType] getName]
  200.  
  201.     catch {$model addClass $settype}
  202.     set op [$class addOperation get$setname int]
  203.     $op addParameter $setname $settype
  204.     $op addParameter $keyname $keytype
  205.     copy_access_mode $attrib $op 0 r
  206. }
  207.  
  208. proc db_qual_assoc_attrib::many_set_prepare {attrib class model forwhat} {
  209.     db_qual_assoc_attrib::any_set_prepare $attrib $class $model $forwhat "add"
  210. }
  211.  
  212. proc db_qual_assoc_attrib::many_remove_prepare {attrib class model forwhat} {
  213.     set type [[$attrib ooplType] getName]
  214.     set name [cap [$attrib getName]]
  215.     set keyname [[$attrib qualifier] getName]
  216.     set keytype [[[$attrib qualifier] ooplType] getName]
  217.  
  218.     set op [$class addOperation remove$name int]
  219.     $op addParameter $keyname $keytype
  220.     $op addParameter toRemove $type
  221.     copy_access_mode $attrib $op 0 w
  222. }
  223.  
  224. #
  225. # db_link_attrib prepare functions
  226. #
  227.  
  228. proc db_link_attrib::prepare {attrib class model forwhat} {
  229.     prepare_for_link $attrib $class $model $forwhat
  230. }
  231.  
  232. proc db_link_attrib::one_get_prepare {attrib class model forwhat} {
  233.     set type [[$attrib ooplType] getName]
  234.     set name [cap "${type}Of[cap [$attrib getName]]"]
  235.  
  236.     set op [$class addOperation get$name $type]
  237.     copy_access_mode $attrib $op 0 r
  238. }
  239.  
  240. proc db_link_attrib::many_get_prepare {attrib class model forwhat} {
  241.     set type [[$attrib ooplType] getName]
  242.     set name [$attrib getName]
  243.     set settype [set_type_name [$attrib ooplType]]
  244.     set setname [cap [set_name $name]]
  245.     set func_name get[cap [set_name "${type}Of[cap $name]"]]
  246.  
  247.     catch {$model addClass $settype}
  248.     set op [$class addOperation $func_name int]
  249.     $op addParameter $setname $settype
  250.     copy_access_mode $attrib $op 0 r
  251. }
  252.  
  253. #
  254. # db_qual_link_attrib prepare functions
  255. #
  256.  
  257. proc db_qual_link_attrib::prepare {attrib class model forwhat} {
  258.     prepare_for_link $attrib $class $model $forwhat
  259. }
  260.  
  261. proc db_qual_link_attrib::one_get_prepare {attrib class model forwhat} {
  262.     set type [[$attrib ooplType] getName]
  263.     set name [$attrib getName]
  264.     set keyname [[$attrib qualifier] getName]
  265.     set keytype [[[$attrib qualifier] ooplType] getName]
  266.     set func_name get[cap "${type}Of[cap $name]"]
  267.  
  268.     set op [$class addOperation $func_name $type]
  269.     $op addParameter $keyname $keytype
  270.     copy_access_mode $attrib $op 0 r
  271. }
  272.  
  273. proc db_qual_link_attrib::many_get_prepare {attrib class model forwhat} {
  274.     set type [[$attrib ooplType] getName]
  275.     set name [$attrib getName]
  276.     set settype [set_type_name [$attrib ooplType]]
  277.     set setname [cap [set_name $name]]
  278.     set keyname [[$attrib qualifier] getName]
  279.     set keytype [[[$attrib qualifier] ooplType] getName]
  280.     set func_name get[cap [set_name "${type}Of[cap $name]"]]
  281.  
  282.     catch {$model addClass $settype}
  283.     set op [$class addOperation $func_name int]
  284.     $op addParameter $setname $settype
  285.     $op addParameter $keyname $keytype
  286.     copy_access_mode $attrib $op 0 r
  287. }
  288.  
  289. #
  290. # db_rv_link_attrib prepare functions
  291. #
  292.  
  293. proc db_rv_link_attrib::prepare {attrib class model forwhat} {
  294.     prepare_for_link $attrib $class $model $forwhat
  295. }
  296.  
  297. proc db_rv_link_attrib::one_get_prepare {attrib class model forwhat} {
  298.     set type [[$attrib ooplType] getName]
  299.     set name [cap [$attrib getName]]
  300.  
  301.     set op [$class addOperation get$name $type]
  302.     copy_access_mode $attrib $op 0 r
  303. }
  304.  
  305. proc db_rv_link_attrib::many_get_prepare {attrib class model forwhat} {
  306.     # should not occur...
  307.     puts "ERROR: reverse link attribute '[$attrib getName]' with multiplicity \
  308.             'many' in class '[$class getName]'"
  309. }
  310.