/[cvs]/nfo/perl/libs/Data/Transfer/Sync/API.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Transfer/Sync/API.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by joko, Sun Feb 9 05:03:02 2003 UTC revision 1.8 by joko, Thu Mar 27 15:31:15 2003 UTC
# Line 6  Line 6 
6  ##  ##
7  ##    ----------------------------------------------------------------------------------------  ##    ----------------------------------------------------------------------------------------
8  ##    $Log$  ##    $Log$
9    ##    Revision 1.8  2003/03/27 15:31:15  joko
10    ##    fixes to modules regarding new namespace(s) below Data::Mungle::*
11    ##
12    ##    Revision 1.7  2003/02/21 08:00:24  joko
13    ##    debugging
14    ##
15    ##    Revision 1.6  2003/02/14 12:58:47  joko
16    ##    + re-enabled the erase-mechanism
17    ##
18    ##    Revision 1.5  2003/02/11 05:26:04  joko
19    ##    + sub _tellWhatIWillDo
20    ##    + re-enabled "branch to execution path for special targets" mechanism
21    ##
22  ##    Revision 1.4  2003/02/09 05:03:02  joko  ##    Revision 1.4  2003/02/09 05:03:02  joko
23  ##    + minor fix regarding namespace of api versioning extension module  ##    + minor fix regarding namespace of api versioning extension module
24  ##  ##
# Line 38  use mixin::with qw( Data::Transfer::Sync Line 51  use mixin::with qw( Data::Transfer::Sync
51  use Data::Dumper;  use Data::Dumper;
52  use Hash::Merge qw( merge );  use Hash::Merge qw( merge );
53    
54  use Data::Compare::Struct qw( isEmpty );  use Data::Mungle::Compare::Struct qw( isEmpty );
55    
56  # get logger instance  # get logger instance
57  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 66  sub _loadVersionExtensions { Line 79  sub _loadVersionExtensions {
79  sub configure {  sub configure {
80    my $self = shift;    my $self = shift;
81    
 #print "YAI\n";  
 #print Dumper(@_);  
 #exit;  
   
82    $logger->debug( __PACKAGE__ . "->configure");    $logger->debug( __PACKAGE__ . "->configure");
83    
84    my @args = @_;    my @args = @_;
85    
 #print Dumper(@args);  
   
86    if (!isEmpty(\@args)) {    if (!isEmpty(\@args)) {
87      my %properties = @_;      my %properties = @_;
88      # merge args to properties      # merge args to properties
# Line 150  sub syncNodes { Line 157  sub syncNodes {
157    my $self = shift;    my $self = shift;
158    my $args = shift;    my $args = shift;
159    
160      #$logger->notice( "==========================   " . __PACKAGE__ . "->syncNodes   ==============");
161    $logger->debug( __PACKAGE__ . "->syncNodes: starting" );    $logger->debug( __PACKAGE__ . "->syncNodes: starting" );
162    
163  #print Dumper($self);  #print Dumper($self);
# Line 158  sub syncNodes { Line 166  sub syncNodes {
166  #print Dumper($self->{options});  #print Dumper($self->{options});
167    $self->_prepareOptions();    $self->_prepareOptions();
168    
169  #print Dumper($self->{options});    # trace
170        #print Dumper($self->{options});
171        #exit;
172    
173    if (!$self->checkOptions()) {    if (!$self->checkOptions()) {
174      $logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed.");      $logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed.");
# Line 170  sub syncNodes { Line 180  sub syncNodes {
180      return;      return;
181    }    }
182    
183      #print Dumper($args);
184    
185    # remember arguments through the whole processing    # remember arguments through the whole processing
186    $self->{args} = $args;    $self->{args} = $args;
187    
# Line 179  sub syncNodes { Line 191  sub syncNodes {
191    # hash to sum up results    # hash to sum up results
192    # TODO: re-implement! (sync-statistics???)    # TODO: re-implement! (sync-statistics???)
193    
194      #print Dumper($self->{options}->{process});
195    
196    # detect synchronization method to determine which optical symbol (directed arrow) to use    # detect synchronization method to determine which optical symbol (directed arrow) to use
197    my $mode = $self->{args}->{mode};   # V1    my $mode = $self->{args}->{mode};   # V1
198    $mode ||= $self->{options}->{process}->{mode};    # V2    $mode ||= $self->{options}->{process}->{mode};    # V2
# Line 199  sub syncNodes { Line 213  sub syncNodes {
213      $self->options2metadata();      $self->options2metadata();
214      $self->options2metadata_accessor();      $self->options2metadata_accessor();
215    
216      # branch to execution path for special targets
217      # detect for option 'handler' which could be a CODEref
218        if ($self->{options}->{handler} && ref $self->{options}->{handler} eq 'CODE') {
219          $logger->info( __PACKAGE__ . "->syncNodes: Running (special handler code - no generic sync!) on '$self->{options}->{target}->{dbKey}' with MODE $self->{options}->{process}->{mode}, NODE $self->{options}->{target}->{address}");
220          #print Dumper($self);
221          #exit;
222          # don't do this any more - it wasn't very nice somehow ...
223          #$self->{options}->{handler}->($self->{app}, $self->{options});
224          # .... now: better let the parent application scope handle this via callback
225            # not any more required for this: $self->{app} inside here (which isn't the app we mean here)
226            # required for this: getting the options out of here: establish some getter method! ($self->getOptions(...))
227            # so....
228            #$self->{__bridge}->{parent_ref}->
229          
230          # ahh okay, DesignPattern::Bridge moves closer to some Class::Inner!???
231            # so...
232            # similar like above - but it isn't very nice anyway ...  (no privateness, but: who cares?)
233            #print Dumper($self->{__bridge});
234            # just take the global application instance and
235            # throw it into the context of the mapping module - this is heavy!  ;-) (but again, who cares...)
236            # TODO: handle this more abstract *sometime*
237            #$self->{options}->{handler}->($self->{__bridge}->{parent}->{app}, $self->{options});
238            $self->{options}->{handler}->($self->{__bridge}->{parent}->{process}, $self->{options});
239          
240          return;
241        }
242    
243      # TODO: execution path branch V2!!!
244        # option1: wrap this via callback to parent scope (like current impl. mechanism)
245        # option2: branch directly from here (this needs refactoring of the sub handler)
246    
247    # tracing    # tracing
248      #print Dumper($self);      #print Dumper($self);
249      #exit;      #exit;
250    
251    $logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow target=$self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]" );    # V1:
252      $logger->debug( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow target=$self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]" );
253      
254      # V2:
255      my $what = "$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow $self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]";
256      #my $header = ("~.." x 7) . "  " . $what . "  " . ("~.." x 4);
257      #my $header = ("= " x 7) . "  " . $what . "  " . ("= " x 4);
258      #my $header = ("~=-_-=" x 3) . "  " . $what . "  " . ("~=-_-=" x 4);
259      my $header = ("_-=~=-" x 4) . "  " . $what . "  " . ("_-=~=-" x 4);
260      $logger->notice($header);
261    
262    
263    return if !$self->buildFieldmapping();    return if !$self->buildFieldmapping();
264    return if !$self->_touchNodeSet();    return if !$self->_touchNodeSet();
265    return if !$self->_prepare_sync();    return if !$self->_prepare_sync();
266      $self->_tellWhatIWillDo();
267    
268    # tracing    # tracing
269      #print Dumper($self);      #print Dumper($self);
# Line 223  sub syncNodes { Line 279  sub syncNodes {
279  }  }
280    
281    
282    my $c_string_default = '';
283    sub c_string {
284      my $value = shift;
285      $value ||= "[$c_string_default]";
286      return $value;
287    }
288    
289    sub _tellWhatIWillDo {
290      my $self = shift;
291    
292    
293    #return;
294      
295      # trace
296        #print Dumper($self->{meta});
297        #exit;
298      
299      $c_string_default = 'n/a';
300      my $source = c_string($self->{opt}->{'source'});
301      my $source_node = c_string($self->{opt}->{'source-node'});
302      my $source_type = c_string($self->{opt}->{'source-type'});
303      my $target = c_string($self->{opt}->{'target'});
304      my $target_node = c_string($self->{opt}->{'target-node'});
305      my $target_type = c_string($self->{opt}->{'target-type'});
306      
307      my $mapping_module = c_string($self->{opt}->{'mapping-module'});
308      my $mode = uc c_string($self->{opt}->{'mode'});
309    
310      #my $ql = "$mode INTO $source NODE $source_node TYPE $source_type SELECT NODE $target_node TYPE $target_type FROM $target USING MODULE $mapping_module;";
311      #$logger->notice( __PACKAGE__ . ": $ql" );
312      my $ql = <<EOT;
313    
314      FETCH DATA
315        FROM STORAGE $self->{meta}->{source}->{dbKey}
316        AT NODE $self->{meta}->{source}->{accessorName}.$self->{meta}->{source}->{nodeName}
317        USING IDENTIFIER $self->{meta}->{source}->{IdentProvider}->{method}.$self->{meta}->{source}->{IdentProvider}->{arg}
318      CONVERT DATA
319        CAST FROM $self->{meta}->{source}->{nodeType} TO $self->{meta}->{target}->{nodeType}
320        MAP ATTRIBUTES FROM @{$self->{meta}->{source}->{childnodes}} TO @{$self->{meta}->{target}->{childnodes}}
321      STORE DATA
322        TO STORAGE $self->{meta}->{target}->{dbKey}
323        AT NODE $self->{meta}->{target}->{accessorName}.$self->{meta}->{target}->{nodeName}
324        USING IDENTIFIER $self->{meta}->{target}->{IdentProvider}->{method}.$self->{meta}->{target}->{IdentProvider}->{arg}
325    EOT
326      
327      
328      chomp($ql);
329      $logger->info($ql);
330      
331      #exit;
332      return;
333      
334      my $actioning = ucfirst $self->{opt}->{'action'} . 'ing';
335      
336      # FIXME: this is weird!
337      my $long = <<EOT;
338    
339        - $actioning data of type $target_type and
340          filtered by $target_node from the storage named $target
341          to the storage named $source - filtered by $source_node.
342        - Will attempt to convert the data to $source_type.
343    EOT
344      chomp($long);
345      $logger->notice( __PACKAGE__ . ": $long" );
346      
347    }
348    
349    
350  sub _prepareOptions {  sub _prepareOptions {
351    
352    my $self = shift;    my $self = shift;
# Line 311  sub _prepareOptions { Line 435  sub _prepareOptions {
435    # merging - V2    # merging - V2
436    
437      # merge local map with local opts      # merge local map with local opts
438        
439          # delete undef'd items in $map
440        
441        # enable cloning        # enable cloning
442        # FIXME: do we really need cloning here? trade safety/encapsulation for speed?        # FIXME: do we really need cloning here? trade safety/encapsulation for speed?
443        Hash::Merge::set_clone_behavior(1);        Hash::Merge::set_clone_behavior(1);
444        Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );        Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );
445          #Hash::Merge::set_behavior( 'STORAGE_PRECEDENT' );
446          #Hash::Merge::set_behavior( 'RETAINMENT_PRECEDENT' );
447          # TODO: add an option to Hash::Merge not to overwrite set items with undefined/empty/not assigned ones
448        my $locals_merged = merge( $opts, $map );        my $locals_merged = merge( $opts, $map );
449    
450      # trace      # trace
# Line 400  sub _prepare_sync { Line 530  sub _prepare_sync {
530      # TODO: introduce different mechanism to make more then two partners (descents) possible      # TODO: introduce different mechanism to make more then two partners (descents) possible
531      ($self->{meta}->{source}, $self->{meta}->{target}) =      ($self->{meta}->{source}, $self->{meta}->{target}) =
532          ($self->{meta}->{target}, $self->{meta}->{source});          ($self->{meta}->{target}, $self->{meta}->{source});
533        #($self->{options}->{source}, $self->{options}->{target}) =
534        #    ($self->{options}->{target}, $self->{options}->{source});
535        
536    } elsif (lc $self->{options}->{process}->{mode} eq 'full') {    } elsif (lc $self->{options}->{process}->{mode} eq 'full') {
537      # TODO:      # TODO:
# Line 413  sub _prepare_sync { Line 545  sub _prepare_sync {
545    
546    # import flag means: prepare the source node to be syncable    # import flag means: prepare the source node to be syncable
547    # this is useful if there are e.g. no "ident" or "checksum" columns yet inside a DBI like (row-based) storage    # this is useful if there are e.g. no "ident" or "checksum" columns yet inside a DBI like (row-based) storage
548    if ($self->{args}->{prepare}) {    if ($self->{options}->{process}->{prepare}) {
549      $self->_prepareNode_MetaProperties('source');      $self->_prepareNode_MetaProperties('source');
550      $self->_prepareNode_DummyIdent('source');      $self->_prepareNode_DummyIdent('source');
551      #return;      #return;
# Line 422  sub _prepare_sync { Line 554  sub _prepare_sync {
554        
555    # erase flag means: erase the target    # erase flag means: erase the target
556    #if ($opts->{erase}) {    #if ($opts->{erase}) {
557    if ($self->{args}->{erase}) {    if ($self->{options}->{process}->{erase}) {
558      # TODO: move this method to the scope of the synchronization core and wrap it around different handlers      # TODO: move this method to the scope of the synchronization core and wrap it around different handlers
559      #print "ERASE", "\n";      #print "ERASE", "\n";
560      $self->_erase_all('target');      $self->_erase_all('target');

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.8

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed