- Timestamp:
- 12/10/07 03:52:30 (13 months ago)
- Location:
- ext/Muldis-DB
- Files:
-
- 4 modified
-
Changes (modified) (1 diff)
-
lib/Muldis/DB/Engine/Example.pm (modified) (13 diffs)
-
lib/Muldis/DB/Interface.pm (modified) (19 diffs)
-
lib/Muldis/DB/Validator.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ext/Muldis-DB/Changes
r19122 r19126 29 29 config keys, and so on, to use 'machine' rather than 'dbms'. 30 30 31 * TODO: split all ::Machine pkgs each into itself and ::Process. 31 * (Interface.pm, Example.pm, Validator.pm) Split the Machine 32 role|class into itself and the new Process role|class; a Machine now 33 has 0..N Process, and a Process now has 0..N 34 Var|FuncBinding|ProcBinding. The Machine constructor retained all of 35 its parameters, and the Process constructor has no configuration 36 parameters; nearly all of the Machine methods went to Process. As part 37 of the split, 2 methods were added to Machine, and 1 to Process. 32 38 33 39 2007-10-20 Darren Duncan <perl@DarrenDuncan.net> -
ext/Muldis-DB/lib/Muldis/DB/Engine/Example.pm
r19095 r19126 28 28 29 29 # Allow objects of these to update Machine' "assoc" list re themselves. 30 trusts Muldis::DB::Engine::Example::Public::Var; 31 trusts Muldis::DB::Engine::Example::Public::FuncBinding; 32 trusts Muldis::DB::Engine::Example::Public::ProcBinding; 30 trusts Muldis::DB::Engine::Example::Public::Process; 33 31 34 32 # User-supplied config data for this Machine object. … … 41 39 # For each of these, Hash keys are obj .WHERE/addrs, vals the objs. 42 40 # These should be weak obj-refs, so objs disappear from here 41 has Hash $!assoc_processes; 42 43 ########################################################################### 44 45 submethod BUILD (Array :$exp_ast_lang!, Any :$machine_config!) { 46 47 # TODO: input checks. 48 $!exp_ast_lang = [$exp_ast_lang.values]; 49 $!machine_config = $machine_config; 50 51 $!assoc_processes = {}; 52 53 return; 54 } 55 56 submethod DESTROY () { 57 # TODO: check for active trans and rollback ... or member VM does it. 58 # Likewise with closing open files or whatever. 59 return; 60 } 61 62 ########################################################################### 63 64 method fetch_exp_ast_lang of Array () { 65 return [$!exp_ast_lang.values]; 66 } 67 68 method store_exp_ast_lang (Array :$lang!) { 69 # TODO: input checks. 70 $!exp_ast_lang = [$lang.values]; 71 return; 72 } 73 74 ########################################################################### 75 76 method new_process of Muldis::DB::Engine::Example::Public::Process () { 77 return ::Muldis::DB::Engine::Example::Public::Process.new( 78 :machine(self) ); 79 } 80 81 method assoc_processes of Array () { 82 return [$!assoc_processes.values]; 83 } 84 85 ########################################################################### 86 87 } # class Muldis::DB::Engine::Example::Public::Machine 88 89 ########################################################################### 90 ########################################################################### 91 92 class Muldis::DB::Engine::Example::Public::Process { 93 does Muldis::DB::Interface::Process; 94 95 # Allow objects of these to update Process' "assoc" list re themselves. 96 trusts Muldis::DB::Engine::Example::Public::Var; 97 trusts Muldis::DB::Engine::Example::Public::FuncBinding; 98 trusts Muldis::DB::Engine::Example::Public::ProcBinding; 99 100 has Muldis::DB::Engine::Example::Public::Machine $!machine; 101 102 # Lists of user-held objects associated with parts of this Process. 103 # For each of these, Hash keys are obj .WHERE/addrs, vals the objs. 104 # These should be weak obj-refs, so objs disappear from here 43 105 has Hash $!assoc_vars; 44 106 has Hash $!assoc_func_bindings; … … 51 113 ########################################################################### 52 114 53 submethod BUILD ( Array :$exp_ast_lang!, Any :$machine_config!) {115 submethod BUILD (Muldis::DB::Engine::Example::Public::Machine :$machine!) { 54 116 55 117 # TODO: input checks. 56 $!exp_ast_lang = [$exp_ast_lang.values]; 57 $!machine_config = $machine_config; 118 119 $!machine = $machine; 120 # $machine!assoc_vars.{self.WHERE} = self; 121 # weaken $machine!assoc_vars.{self.WHERE}; 58 122 59 123 $!assoc_vars = {}; … … 74 138 ########################################################################### 75 139 76 method fetch_exp_ast_lang of Array () {77 return [$!exp_ast_lang.values];78 }79 80 method store_exp_ast_lang (Array :$lang!) {81 # TODO: input checks.82 $!exp_ast_lang = [$lang.values];83 return;84 }85 86 ###########################################################################87 88 140 method new_var of Muldis::DB::Engine::Example::Public::Var 89 141 (Str :$decl_type!) { 90 142 return ::Muldis::DB::Engine::Example::Public::Var.new( 91 : machine(self), :decl_type($decl_type) );143 :process(self), :decl_type($decl_type) ); 92 144 } 93 145 … … 99 151 () { 100 152 return ::Muldis::DB::Engine::Example::Public::FuncBinding.new( 101 : machine(self) );153 :process(self) ); 102 154 } 103 155 … … 109 161 () { 110 162 return ::Muldis::DB::Engine::Example::Public::ProcBinding.new( 111 : machine(self) );163 :process(self) ); 112 164 } 113 165 … … 122 174 123 175 # my $f = ::Muldis::DB::Engine::Example::Public::FuncBinding.new( 124 # : machine(self) );176 # :process(self) ); 125 177 126 178 my $result = ::Muldis::DB::Engine::Example::Public::Var.new( 127 : machine(self), :decl_type('sys.Core.Universal.Universal') );179 :process(self), :decl_type('sys.Core.Universal.Universal') ); 128 180 129 181 # $f.bind_func( :func_name($func_name) ); … … 141 193 142 194 # my $p = ::Muldis::DB::Engine::Example::Public::ProcBinding.new( 143 # : machine(self) );195 # :process(self) ); 144 196 145 197 # $p.bind_proc( :proc_name($proc_name) ); … … 184 236 ########################################################################### 185 237 186 } # class Muldis::DB::Engine::Example::Public:: Machine238 } # class Muldis::DB::Engine::Example::Public::Process 187 239 188 240 ########################################################################### … … 192 244 does Muldis::DB::Interface::Var; 193 245 194 has Muldis::DB::Engine::Example::Public:: Machine $!machine;246 has Muldis::DB::Engine::Example::Public::Process $!process; 195 247 196 248 has Muldis::DB::Engine::Example::VM::Var $!var; … … 199 251 ########################################################################### 200 252 201 submethod BUILD (Muldis::DB::Engine::Example::Public:: Machine :$machine!,253 submethod BUILD (Muldis::DB::Engine::Example::Public::Process :$process!, 202 254 Str :$decl_type!) { 203 255 204 256 # TODO: input checks. 205 257 206 $! machine = $machine;207 # $ machine!assoc_vars.{self.WHERE} = self;208 # weaken $ machine!assoc_vars.{self.WHERE};258 $!process = $process; 259 # $process!assoc_vars.{self.WHERE} = self; 260 # weaken $process!assoc_vars.{self.WHERE}; 209 261 210 262 # $!var = ::Muldis::DB::Engine::Example::VM::Var.new( … … 215 267 216 268 submethod DESTROY () { 217 # $! machine!assoc_vars.delete( self.WHERE );269 # $!process!assoc_vars.delete( self.WHERE ); 218 270 return; 219 271 } … … 282 334 It also describes the same-number versions for Perl 6 of 283 335 Muldis::DB::Engine::Example::Public::Machine, 336 Muldis::DB::Engine::Example::Public::Process, 284 337 Muldis::DB::Engine::Example::Public::Var, 285 338 Muldis::DB::Engine::Example::Public::FuncBinding, and -
ext/Muldis-DB/lib/Muldis/DB/Interface.pm
r19095 r19126 71 71 } 72 72 73 method new_process { 74 die q{not implemented by subclass } ~ self.WHAT; 75 } 76 77 method assoc_processes { 78 die q{not implemented by subclass } ~ self.WHAT; 79 } 80 81 } # role Muldis::DB::Interface::Machine 82 83 ########################################################################### 84 ########################################################################### 85 86 role Muldis::DB::Interface::Process { 87 88 method assoc_machine { 89 die q{not implemented by subclass } ~ self.WHAT; 90 } 91 73 92 method new_var { 74 93 die q{not implemented by subclass } ~ self.WHAT; … … 119 138 } 120 139 121 } # role Muldis::DB::Interface:: Machine140 } # role Muldis::DB::Interface::Process 122 141 123 142 ########################################################################### … … 126 145 role Muldis::DB::Interface::Var { 127 146 128 method assoc_ machine{147 method assoc_process { 129 148 die q{not implemented by subclass } ~ self.WHAT; 130 149 } … … 149 168 role Muldis::DB::Interface::FuncBinding { 150 169 151 method assoc_ machine{170 method assoc_process { 152 171 die q{not implemented by subclass } ~ self.WHAT; 153 172 } … … 188 207 role Muldis::DB::Interface::ProcBinding { 189 208 190 method assoc_ machine{209 method assoc_process { 191 210 die q{not implemented by subclass } ~ self.WHAT; 192 211 } … … 239 258 240 259 It also describes the same-number versions for Perl 6 of 241 Muldis::DB::Interface::Machine ("Machine"), Muldis::DB::Interface::Var 242 ("Var"), Muldis::DB::Interface::FuncBinding ("FuncBinding"), and 260 Muldis::DB::Interface::Machine ("Machine"), Muldis::DB::Interface::Process 261 ("Process"), Muldis::DB::Interface::Var ("Var"), 262 Muldis::DB::Interface::FuncBinding ("FuncBinding"), and 243 263 Muldis::DB::Interface::ProcBinding ("ProcBinding"). 244 264 … … 256 276 :machine_config({}), 257 277 ); 258 259 my $r1 = $machine.new_var( :decl_type('sys.Core.Relation.Relation') ); 260 my $r2 = $machine.new_var( :decl_type('sys.Core.Relation.Relation') ); 278 my $process = $machine.new_process(); 279 280 my $r1 = $process.new_var( :decl_type('sys.Core.Relation.Relation') ); 281 my $r2 = $process.new_var( :decl_type('sys.Core.Relation.Relation') ); 261 282 262 283 $r1.store_ast( :ast([ 'Relation', 'sys.Core.Relation.Relation', [ … … 286 307 ] ]) ); 287 308 288 my $r3 = $ machine.call_func(309 my $r3 = $process.call_func( 289 310 :func_name('sys.Core.Relation.join'), 290 311 :args({ … … 411 432 invocant's Engine knows how to or desires to handle. 412 433 434 =item C<new_process of Muldis::DB::Interface::Process ()> 435 436 This method creates and returns a new C<Process> object that is associated 437 with the invocant C<Machine>. 438 439 =item C<assoc_processes of Array ()> 440 441 This method returns, as elements of a new (unordered) Array, all the 442 currently existing C<Process> objects that are associated with the invocant 443 C<Machine>. 444 445 =back 446 447 =head2 The Muldis::DB::Interface::Process Role 448 449 A C<Process> object represents a single Muldis DB in-DBMS process, which 450 has its own autonomous transactional context, and for the most part, its 451 own isolated environment. It is associated with a specific C<Machine> 452 object, the one whose C<new_process> method created it. 453 454 =over 455 456 =item C<assoc_machine of Muldis::DB::Interface::Machine ()> 457 458 This method returns the C<Machine> object that the invocant C<Process> is 459 associated with. 460 413 461 =item C<new_var of Muldis::DB::Interface::Var (Str :$decl_type!)> 414 462 415 463 This method creates and returns a new C<Var> object that is associated with 416 the invocant C< Machine>, and whose declared Muldis D type is named by the464 the invocant C<Process>, and whose declared Muldis D type is named by the 417 465 C<$decl_type> argument, and whose default Muldis D value is the default 418 466 value of its declared type. … … 422 470 This method returns, as elements of a new (unordered) Array, all the 423 471 currently existing C<Var> objects that are associated with the invocant 424 C< Machine>.472 C<Process>. 425 473 426 474 =item C<new_func_binding of Muldis::DB::Interface::FuncBinding ()> 427 475 428 476 This method creates and returns a new C<FuncBinding> object that is 429 associated with the invocant C< Machine>.477 associated with the invocant C<Process>. 430 478 431 479 =item C<assoc_func_bindings of Array ()> … … 433 481 This method returns, as elements of a new (unordered) Array, all the 434 482 currently existing C<FuncBinding> objects that are associated with the 435 invocant C< Machine>.483 invocant C<Process>. 436 484 437 485 =item C<new_proc_binding of Muldis::DB::Interface::ProcBinding ()> 438 486 439 487 This method creates and returns a new C<ProcBinding> object that is 440 associated with the invocant C< Machine>.488 associated with the invocant C<Process>. 441 489 442 490 =item C<assoc_proc_bindings of Array ()> … … 444 492 This method returns, as elements of a new (unordered) Array, all the 445 493 currently existing C<ProcBinding> objects that are associated with the 446 invocant C< Machine>.494 invocant C<Process>. 447 495 448 496 =item C<call_func of Muldis::DB::Interface::Var (Str :$func_name!, Hash … … 468 516 This method returns the current transaction nesting level of its invocant's 469 517 virtual machine. If no explicit transactions were started, then the 470 nesting level is zero, in which case the Machineis conceptually518 nesting level is zero, in which case the Process is conceptually 471 519 auto-committing every successful Muldis D statement. Each call of 472 520 C<start_trans> will increase the nesting level by one, and each … … 500 548 A C<Var> object is a Muldis D variable that is lexically scoped to the Perl 501 549 environment (like an ordinary Perl variable). It is associated with a 502 specific C< Machine> object, the one whose C<new_var> method created it, but550 specific C<Process> object, the one whose C<new_var> method created it, but 503 551 it is considered anonymous and non-invokable within the virtual machine. 504 552 The only way for Muldis D code to work with these variables is if they … … 513 561 =over 514 562 515 =item C<assoc_ machine of Muldis::DB::Interface::Machine()>516 517 This method returns the C< Machine> object that the invocant C<Var> is563 =item C<assoc_process of Muldis::DB::Interface::Process ()> 564 565 This method returns the C<Process> object that the invocant C<Var> is 518 566 associated with. 519 567 … … 540 588 541 589 A C<FuncBinding> represents a single Muldis D function that may be directly 542 invoked by Perl code. It is associated with a specific C< Machine> object,590 invoked by Perl code. It is associated with a specific C<Process> object, 543 591 the one whose C<new_func_binding> method created it, and the function it 544 592 represents lives in and has a global-public scoped name in the … … 547 595 C<call> method is being executed, and a then-valid object can then become 548 596 invalid afterwards. A C<FuncBinding> is conceptually used behind the 549 scenes to implement a C< Machine> object's C<call_func> method, but you can597 scenes to implement a C<Process> object's C<call_func> method, but you can 550 598 use it directly instead, for possibly better performance. 551 599 552 600 =over 553 601 554 =item C<assoc_ machine of Muldis::DB::Interface::Machine()>555 556 This method returns the C< Machine> object that the invocant C<FuncBinding>602 =item C<assoc_process of Muldis::DB::Interface::Process ()> 603 604 This method returns the C<Process> object that the invocant C<FuncBinding> 557 605 is associated with. 558 606 … … 607 655 608 656 A C<ProcBinding> represents a single Muldis D procedure that may be 609 directly invoked by Perl code. It is associated with a specific C< Machine>657 directly invoked by Perl code. It is associated with a specific C<Process> 610 658 object, the one whose C<new_proc_binding> method created it, and the 611 659 procedure it represents lives in and has a global-public scoped name in the … … 614 662 C<call> method is being executed, and a then-valid object can then become 615 663 invalid afterwards. A C<ProcBinding> is conceptually used behind the 616 scenes to implement a C< Machine> object's C<call_proc> method, but you can664 scenes to implement a C<Process> object's C<call_proc> method, but you can 617 665 use it directly instead, for possibly better performance. 618 666 619 667 =over 620 668 621 =item C<assoc_ machine of Muldis::DB::Interface::Machine()>622 623 This method returns the C< Machine> object that the invocant C<ProcBinding>669 =item C<assoc_process of Muldis::DB::Interface::Process ()> 670 671 This method returns the C<Process> object that the invocant C<ProcBinding> 624 672 is associated with. 625 673 -
ext/Muldis-DB/lib/Muldis/DB/Validator.pm
r19095 r19126 14 14 sub main (Str :$engine_name!, Any :$machine_config!) { 15 15 16 plan( 1 2);16 plan( 13 ); 17 17 18 18 say "#### Muldis::DB::Validator starting test of $engine_name ####"; … … 26 26 ); 27 27 does_ok( $machine, 'Muldis::DB::Interface::Machine' ); 28 29 _scenario_foods_suppliers_shipments_v1( $machine ); 28 my Muldis::DB::Interface::Process $process = $machine.new_process(); 29 does_ok( $process, 'Muldis::DB::Interface::Process' ); 30 31 _scenario_foods_suppliers_shipments_v1( $process ); 30 32 31 33 say "#### Muldis::DB::Validator finished test of $engine_name ####"; … … 37 39 38 40 sub _scenario_foods_suppliers_shipments_v1 39 (Muldis::DB::Interface:: Machine $machine!) {41 (Muldis::DB::Interface::Process $process!) { 40 42 41 43 # Declare our Perl-lexical variables to use for source data. 42 44 43 my $src_suppliers = $ machine.new_var(45 my $src_suppliers = $process.new_var( 44 46 :decl_type('sys.Core.Relation.Relation') ); 45 47 does_ok( $src_suppliers, 'Muldis::DB::Interface::Var' ); 46 my $src_foods = $ machine.new_var(48 my $src_foods = $process.new_var( 47 49 :decl_type('sys.Core.Relation.Relation') ); 48 50 does_ok( $src_foods, 'Muldis::DB::Interface::Var' ); 49 my $src_shipments = $ machine.new_var(51 my $src_shipments = $process.new_var( 50 52 :decl_type('sys.Core.Relation.Relation') ); 51 53 does_ok( $src_shipments, 'Muldis::DB::Interface::Var' ); … … 141 143 # data and see what suppliers there are for foods coloured 'orange'. 142 144 143 my $desi_colour = $ machine.new_var( :decl_type('sys.Core.Text.Text') );145 my $desi_colour = $process.new_var( :decl_type('sys.Core.Text.Text') ); 144 146 does_ok( $desi_colour, 'Muldis::DB::Interface::Var' ); 145 147 $desi_colour.store_ast( :ast([ 'NEText', 'orange' ]) ); 146 148 pass( 'no death from loading desired colour into VM' ); 147 149 148 my $matched_suppl = $ machine.call_func(150 my $matched_suppl = $process.call_func( 149 151 :func_name('sys.Core.Relation.semijoin'), 150 152 :args({ 151 153 'source' => $src_suppliers, 152 'filter' => $ machine.call_func(154 'filter' => $process.call_func( 153 155 :func_name('sys.Core.Relation.join'), 154 156 :args({
