Changeset 19126 for ext

Show
Ignore:
Timestamp:
12/10/07 03:52:30 (13 months ago)
Author:
Darren_Duncan
Message:

ext/Muldis-DB/ : split Machine role|class into itself and Process role|class

Location:
ext/Muldis-DB
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • ext/Muldis-DB/Changes

    r19122 r19126  
    2929    config keys, and so on, to use 'machine' rather than 'dbms'. 
    3030 
    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. 
    3238 
    33392007-10-20   Darren Duncan <perl@DarrenDuncan.net> 
  • ext/Muldis-DB/lib/Muldis/DB/Engine/Example.pm

    r19095 r19126  
    2828 
    2929    # 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; 
    3331 
    3432    # User-supplied config data for this Machine object. 
     
    4139    # For each of these, Hash keys are obj .WHERE/addrs, vals the objs. 
    4240    # These should be weak obj-refs, so objs disappear from here 
     41    has Hash $!assoc_processes; 
     42 
     43########################################################################### 
     44 
     45submethod 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 
     56submethod 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 
     64method fetch_exp_ast_lang of Array () { 
     65    return [$!exp_ast_lang.values]; 
     66} 
     67 
     68method store_exp_ast_lang (Array :$lang!) { 
     69    # TODO: input checks. 
     70    $!exp_ast_lang = [$lang.values]; 
     71    return; 
     72} 
     73 
     74########################################################################### 
     75 
     76method new_process of Muldis::DB::Engine::Example::Public::Process () { 
     77    return ::Muldis::DB::Engine::Example::Public::Process.new( 
     78        :machine(self) ); 
     79} 
     80 
     81method 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 
     92class 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 
    43105    has Hash $!assoc_vars; 
    44106    has Hash $!assoc_func_bindings; 
     
    51113########################################################################### 
    52114 
    53 submethod BUILD (Array :$exp_ast_lang!, Any :$machine_config!) { 
     115submethod BUILD (Muldis::DB::Engine::Example::Public::Machine :$machine!) { 
    54116 
    55117    # 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}; 
    58122 
    59123    $!assoc_vars          = {}; 
     
    74138########################################################################### 
    75139 
    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  
    88140method new_var of Muldis::DB::Engine::Example::Public::Var 
    89141        (Str :$decl_type!) { 
    90142    return ::Muldis::DB::Engine::Example::Public::Var.new( 
    91         :machine(self), :decl_type($decl_type) ); 
     143        :process(self), :decl_type($decl_type) ); 
    92144} 
    93145 
     
    99151        () { 
    100152    return ::Muldis::DB::Engine::Example::Public::FuncBinding.new( 
    101         :machine(self) ); 
     153        :process(self) ); 
    102154} 
    103155 
     
    109161        () { 
    110162    return ::Muldis::DB::Engine::Example::Public::ProcBinding.new( 
    111         :machine(self) ); 
     163        :process(self) ); 
    112164} 
    113165 
     
    122174 
    123175#    my $f = ::Muldis::DB::Engine::Example::Public::FuncBinding.new( 
    124 #        :machine(self) ); 
     176#        :process(self) ); 
    125177 
    126178    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') ); 
    128180 
    129181#    $f.bind_func( :func_name($func_name) ); 
     
    141193 
    142194#    my $p = ::Muldis::DB::Engine::Example::Public::ProcBinding.new( 
    143 #        :machine(self) ); 
     195#        :process(self) ); 
    144196 
    145197#    $p.bind_proc( :proc_name($proc_name) ); 
     
    184236########################################################################### 
    185237 
    186 } # class Muldis::DB::Engine::Example::Public::Machine 
     238} # class Muldis::DB::Engine::Example::Public::Process 
    187239 
    188240########################################################################### 
     
    192244    does Muldis::DB::Interface::Var; 
    193245 
    194     has Muldis::DB::Engine::Example::Public::Machine $!machine; 
     246    has Muldis::DB::Engine::Example::Public::Process $!process; 
    195247 
    196248    has Muldis::DB::Engine::Example::VM::Var $!var; 
     
    199251########################################################################### 
    200252 
    201 submethod BUILD (Muldis::DB::Engine::Example::Public::Machine :$machine!, 
     253submethod BUILD (Muldis::DB::Engine::Example::Public::Process :$process!, 
    202254        Str :$decl_type!) { 
    203255 
    204256    # TODO: input checks. 
    205257 
    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}; 
    209261 
    210262#    $!var = ::Muldis::DB::Engine::Example::VM::Var.new( 
     
    215267 
    216268submethod DESTROY () { 
    217 #    $!machine!assoc_vars.delete( self.WHERE ); 
     269#    $!process!assoc_vars.delete( self.WHERE ); 
    218270    return; 
    219271} 
     
    282334It also describes the same-number versions for Perl 6 of 
    283335Muldis::DB::Engine::Example::Public::Machine, 
     336Muldis::DB::Engine::Example::Public::Process, 
    284337Muldis::DB::Engine::Example::Public::Var, 
    285338Muldis::DB::Engine::Example::Public::FuncBinding, and 
  • ext/Muldis-DB/lib/Muldis/DB/Interface.pm

    r19095 r19126  
    7171    } 
    7272 
     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 
     86role Muldis::DB::Interface::Process { 
     87 
     88    method assoc_machine { 
     89        die q{not implemented by subclass } ~ self.WHAT; 
     90    } 
     91 
    7392    method new_var { 
    7493        die q{not implemented by subclass } ~ self.WHAT; 
     
    119138    } 
    120139 
    121 } # role Muldis::DB::Interface::Machine 
     140} # role Muldis::DB::Interface::Process 
    122141 
    123142########################################################################### 
     
    126145role Muldis::DB::Interface::Var { 
    127146 
    128     method assoc_machine { 
     147    method assoc_process { 
    129148        die q{not implemented by subclass } ~ self.WHAT; 
    130149    } 
     
    149168role Muldis::DB::Interface::FuncBinding { 
    150169 
    151     method assoc_machine { 
     170    method assoc_process { 
    152171        die q{not implemented by subclass } ~ self.WHAT; 
    153172    } 
     
    188207role Muldis::DB::Interface::ProcBinding { 
    189208 
    190     method assoc_machine { 
     209    method assoc_process { 
    191210        die q{not implemented by subclass } ~ self.WHAT; 
    192211    } 
     
    239258 
    240259It 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 
     260Muldis::DB::Interface::Machine ("Machine"), Muldis::DB::Interface::Process 
     261("Process"), Muldis::DB::Interface::Var ("Var"), 
     262Muldis::DB::Interface::FuncBinding ("FuncBinding"), and 
    243263Muldis::DB::Interface::ProcBinding ("ProcBinding"). 
    244264 
     
    256276        :machine_config({}), 
    257277    ); 
    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') ); 
    261282 
    262283    $r1.store_ast( :ast([ 'Relation', 'sys.Core.Relation.Relation', [ 
     
    286307    ] ]) ); 
    287308 
    288     my $r3 = $machine.call_func( 
     309    my $r3 = $process.call_func( 
    289310        :func_name('sys.Core.Relation.join'), 
    290311        :args({ 
     
    411432invocant's Engine knows how to or desires to handle. 
    412433 
     434=item C<new_process of Muldis::DB::Interface::Process ()> 
     435 
     436This method creates and returns a new C<Process> object that is associated 
     437with the invocant C<Machine>. 
     438 
     439=item C<assoc_processes of Array ()> 
     440 
     441This method returns, as elements of a new (unordered) Array, all the 
     442currently existing C<Process> objects that are associated with the invocant 
     443C<Machine>. 
     444 
     445=back 
     446 
     447=head2 The Muldis::DB::Interface::Process Role 
     448 
     449A C<Process> object represents a single Muldis DB in-DBMS process, which 
     450has its own autonomous transactional context, and for the most part, its 
     451own isolated environment.  It is associated with a specific C<Machine> 
     452object, the one whose C<new_process> method created it. 
     453 
     454=over 
     455 
     456=item C<assoc_machine of Muldis::DB::Interface::Machine ()> 
     457 
     458This method returns the C<Machine> object that the invocant C<Process> is 
     459associated with. 
     460 
    413461=item C<new_var of Muldis::DB::Interface::Var (Str :$decl_type!)> 
    414462 
    415463This 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 the 
     464the invocant C<Process>, and whose declared Muldis D type is named by the 
    417465C<$decl_type> argument, and whose default Muldis D value is the default 
    418466value of its declared type. 
     
    422470This method returns, as elements of a new (unordered) Array, all the 
    423471currently existing C<Var> objects that are associated with the invocant 
    424 C<Machine>. 
     472C<Process>. 
    425473 
    426474=item C<new_func_binding of Muldis::DB::Interface::FuncBinding ()> 
    427475 
    428476This method creates and returns a new C<FuncBinding> object that is 
    429 associated with the invocant C<Machine>. 
     477associated with the invocant C<Process>. 
    430478 
    431479=item C<assoc_func_bindings of Array ()> 
     
    433481This method returns, as elements of a new (unordered) Array, all the 
    434482currently existing C<FuncBinding> objects that are associated with the 
    435 invocant C<Machine>. 
     483invocant C<Process>. 
    436484 
    437485=item C<new_proc_binding of Muldis::DB::Interface::ProcBinding ()> 
    438486 
    439487This method creates and returns a new C<ProcBinding> object that is 
    440 associated with the invocant C<Machine>. 
     488associated with the invocant C<Process>. 
    441489 
    442490=item C<assoc_proc_bindings of Array ()> 
     
    444492This method returns, as elements of a new (unordered) Array, all the 
    445493currently existing C<ProcBinding> objects that are associated with the 
    446 invocant C<Machine>. 
     494invocant C<Process>. 
    447495 
    448496=item C<call_func of Muldis::DB::Interface::Var (Str :$func_name!, Hash 
     
    468516This method returns the current transaction nesting level of its invocant's 
    469517virtual machine.  If no explicit transactions were started, then the 
    470 nesting level is zero, in which case the Machine is conceptually 
     518nesting level is zero, in which case the Process is conceptually 
    471519auto-committing every successful Muldis D statement.  Each call of 
    472520C<start_trans> will increase the nesting level by one, and each 
     
    500548A C<Var> object is a Muldis D variable that is lexically scoped to the Perl 
    501549environment (like an ordinary Perl variable).  It is associated with a 
    502 specific C<Machine> object, the one whose C<new_var> method created it, but 
     550specific C<Process> object, the one whose C<new_var> method created it, but 
    503551it is considered anonymous and non-invokable within the virtual machine. 
    504552The only way for Muldis D code to work with these variables is if they 
     
    513561=over 
    514562 
    515 =item C<assoc_machine of Muldis::DB::Interface::Machine ()> 
    516  
    517 This method returns the C<Machine> object that the invocant C<Var> is 
     563=item C<assoc_process of Muldis::DB::Interface::Process ()> 
     564 
     565This method returns the C<Process> object that the invocant C<Var> is 
    518566associated with. 
    519567 
     
    540588 
    541589A 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, 
     590invoked by Perl code.  It is associated with a specific C<Process> object, 
    543591the one whose C<new_func_binding> method created it, and the function it 
    544592represents lives in and has a global-public scoped name in the 
     
    547595C<call> method is being executed, and a then-valid object can then become 
    548596invalid afterwards.  A C<FuncBinding> is conceptually used behind the 
    549 scenes to implement a C<Machine> object's C<call_func> method, but you can 
     597scenes to implement a C<Process> object's C<call_func> method, but you can 
    550598use it directly instead, for possibly better performance. 
    551599 
    552600=over 
    553601 
    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 
     604This method returns the C<Process> object that the invocant C<FuncBinding> 
    557605is associated with. 
    558606 
     
    607655 
    608656A 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> 
     657directly invoked by Perl code.  It is associated with a specific C<Process> 
    610658object, the one whose C<new_proc_binding> method created it, and the 
    611659procedure it represents lives in and has a global-public scoped name in the 
     
    614662C<call> method is being executed, and a then-valid object can then become 
    615663invalid afterwards.  A C<ProcBinding> is conceptually used behind the 
    616 scenes to implement a C<Machine> object's C<call_proc> method, but you can 
     664scenes to implement a C<Process> object's C<call_proc> method, but you can 
    617665use it directly instead, for possibly better performance. 
    618666 
    619667=over 
    620668 
    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 
     671This method returns the C<Process> object that the invocant C<ProcBinding> 
    624672is associated with. 
    625673 
  • ext/Muldis-DB/lib/Muldis/DB/Validator.pm

    r19095 r19126  
    1414sub main (Str :$engine_name!, Any :$machine_config!) { 
    1515 
    16     plan( 12 ); 
     16    plan( 13 ); 
    1717 
    1818    say "#### Muldis::DB::Validator starting test of $engine_name ####"; 
     
    2626    ); 
    2727    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 ); 
    3032 
    3133    say "#### Muldis::DB::Validator finished test of $engine_name ####"; 
     
    3739 
    3840sub _scenario_foods_suppliers_shipments_v1 
    39         (Muldis::DB::Interface::Machine $machine!) { 
     41        (Muldis::DB::Interface::Process $process!) { 
    4042 
    4143    # Declare our Perl-lexical variables to use for source data. 
    4244 
    43     my $src_suppliers = $machine.new_var( 
     45    my $src_suppliers = $process.new_var( 
    4446        :decl_type('sys.Core.Relation.Relation') ); 
    4547    does_ok( $src_suppliers, 'Muldis::DB::Interface::Var' ); 
    46     my $src_foods = $machine.new_var( 
     48    my $src_foods = $process.new_var( 
    4749        :decl_type('sys.Core.Relation.Relation') ); 
    4850    does_ok( $src_foods, 'Muldis::DB::Interface::Var' ); 
    49     my $src_shipments = $machine.new_var( 
     51    my $src_shipments = $process.new_var( 
    5052        :decl_type('sys.Core.Relation.Relation') ); 
    5153    does_ok( $src_shipments, 'Muldis::DB::Interface::Var' ); 
     
    141143    # data and see what suppliers there are for foods coloured 'orange'. 
    142144 
    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') ); 
    144146    does_ok( $desi_colour, 'Muldis::DB::Interface::Var' ); 
    145147    $desi_colour.store_ast( :ast([ 'NEText', 'orange' ]) ); 
    146148    pass( 'no death from loading desired colour into VM' ); 
    147149 
    148     my $matched_suppl = $machine.call_func( 
     150    my $matched_suppl = $process.call_func( 
    149151        :func_name('sys.Core.Relation.semijoin'), 
    150152        :args({ 
    151153            'source' => $src_suppliers, 
    152             'filter' => $machine.call_func( 
     154            'filter' => $process.call_func( 
    153155                :func_name('sys.Core.Relation.join'), 
    154156                :args({