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

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

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

revision 1.1 by joko, Fri Nov 29 04:45:50 2002 UTC revision 1.7 by joko, Fri Dec 13 21:49:34 2002 UTC
# Line 6  Line 6 
6  ##  ##
7  ##    ----------------------------------------------------------------------------------------  ##    ----------------------------------------------------------------------------------------
8  ##    $Log$  ##    $Log$
9    ##    Revision 1.7  2002/12/13 21:49:34  joko
10    ##    + sub configure
11    ##    + sub checkOptions
12    ##
13    ##    Revision 1.6  2002/12/06 04:49:10  jonen
14    ##    + disabled output-puffer here
15    ##
16    ##    Revision 1.5  2002/12/05 08:06:05  joko
17    ##    + bugfix with determining empty fields (Null) with DBD::CSV
18    ##    + debugging
19    ##    + updated comments
20    ##
21    ##    Revision 1.4  2002/12/03 15:54:07  joko
22    ##    + {import}-flag is now {prepare}-flag
23    ##
24    ##    Revision 1.3  2002/12/01 22:26:59  joko
25    ##    + minor cosmetics for logging
26    ##
27    ##    Revision 1.2  2002/12/01 04:43:25  joko
28    ##    + mapping deatil entries may now be either an ARRAY or a HASH
29    ##    + erase flag is used now (for export-operations)
30    ##    + expressions to refer to values inside deep nested structures
31    ##    - removed old mappingV2-code
32    ##    + cosmetics
33    ##    + sub _erase_all
34    ##
35  ##    Revision 1.1  2002/11/29 04:45:50  joko  ##    Revision 1.1  2002/11/29 04:45:50  joko
36  ##    + initial check in  ##    + initial check in
37  ##  ##
# Line 20  use strict; Line 46  use strict;
46  use warnings;  use warnings;
47    
48  use Data::Dumper;  use Data::Dumper;
49    #use Hash::Merge qw( merge );
50    
51  use misc::HashExt;  use misc::HashExt;
52  use libp qw( md5_base64 );  use libp qw( md5_base64 );
53  use libdb qw( quotesql hash2Sql );  use libdb qw( quotesql hash2Sql );
54  use Data::Transform::OO qw( hash2object );  use Data::Transform::Deep qw( hash2object refexpr2perlref );
55  use Data::Compare::Struct qw( getDifference isEmpty );  use Data::Compare::Struct qw( getDifference isEmpty );
56    
57  # get logger instance  # get logger instance
58  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
59    
60    $| = 1;
61    
62  sub new {  sub new {
63    my $invocant = shift;    my $invocant = shift;
64    my $class = ref($invocant) || $invocant;    my $class = ref($invocant) || $invocant;
65    my $self = { @_ };    my $self = {};
66    $logger->debug( __PACKAGE__ . "->new(@_)" );    $logger->debug( __PACKAGE__ . "->new(@_)" );
67    bless $self, $class;    bless $self, $class;
68    $self->_init();    $self->configure(@_);
69    return $self;    return $self;
70  }  }
71    
72    
73    sub configure {
74      my $self = shift;
75      my @args = @_;
76      if (!isEmpty(\@args)) {
77        my %properties = @_;
78        # merge args to properties
79        map { $self->{$_} = $properties{$_}; } keys %properties;
80        $self->_init();
81      } else {
82        #print "no args!", "\n";
83      }
84      #print Dumper($self);
85    }
86    
87  sub _init {  sub _init {
88    my $self = shift;    my $self = shift;
89    
90      $self->{configured} = 1;
91        
92    # build new container if necessary    # build new container if necessary
93    $self->{container} = Data::Storage::Container->new() if !$self->{container};    $self->{container} = Data::Storage::Container->new() if !$self->{container};
# Line 61  sub _init { Line 106  sub _init {
106  }  }
107    
108    
109    sub prepareOptions {
110    
111      my $self = shift;
112      my $opts = shift;
113    
114    #print Dumper($opts);
115    
116      $opts->{mode} ||= '';
117      $opts->{erase} ||= 0;
118      #$opts->{import} ||= 0;
119      
120      $logger->info( __PACKAGE__ . "->prepareOptions( source_node $opts->{source_node} mode $opts->{mode} erase $opts->{erase} prepare $opts->{prepare} )");
121    
122      if (!$opts->{mapping} || !$opts->{mapping_module}) {
123        $logger->warning( __PACKAGE__ . "->prepareOptions: No mapping supplied - please check key 'mappings' in BizWorks/Config.pm");
124      }
125    
126      my $evstring = "use $opts->{mapping_module};";
127      eval($evstring);
128      if ($@) {
129        $logger->warning( __PACKAGE__ . "->prepareOptions: error while trying to access mapping - $@");
130        return;
131      }
132    
133      # resolve mapping metadata (returned from sub)
134      my $mapObject = $opts->{mapping_module}->new();
135      #print Dumper($map);
136      my $source_node_name = $opts->{source_node};
137      # check if mapping for certain node is contained in mapping object
138      if (!$mapObject->can($source_node_name)) {
139        $logger->warning( __PACKAGE__ . "->prepareOptions: Can't access mapping for node \"$source_node_name\" - please check $opts->{mapping_module}.");
140        return;
141      }
142      my $map = $mapObject->$source_node_name;
143    
144      # remove asymmetries from $map (patch keys)
145      $map->{source_node} = $map->{source}; delete $map->{source};
146      $map->{target_node} = $map->{target}; delete $map->{target};
147      $map->{mapping} = $map->{details}; delete $map->{details};
148      $map->{direction} = $map->{mode}; delete $map->{mode};
149    
150      # defaults (mostly for backward-compatibility)
151      $map->{source_node} ||= $source_node_name;
152      $map->{source_ident} ||= 'storage_method:id';
153      $map->{target_ident} ||= 'property:oid';
154      $map->{direction} ||= $opts->{mode};         # | PUSH | PULL | FULL
155      $map->{method} ||= 'checksum';                # | timestamp
156      $map->{source_exclude} ||= [qw( cs )];
157    
158      # merge map to opts
159      map { $opts->{$_} = $map->{$_}; } keys %$map;
160        
161    #print Dumper($opts);
162    
163      # TODO: move this to checkOptions...
164      
165      # check - do we have a target?
166      if (!$opts->{target_node}) {
167        $logger->warning( __PACKAGE__ . "->prepareOptions: No target given - please check metadata declaration.");
168        return;
169      }
170    
171    
172      #return $opts;
173      return 1;
174    
175    }
176    
177    
178    sub checkOptions {
179      my $self = shift;
180      my $opts = shift;
181      
182      my $result = 1;
183      
184      # check - do we have a target node?
185      if (!$opts->{target_node}) {
186        $logger->warning( __PACKAGE__ . "->checkOptions: Error while resolving resource metadata - no 'target node' could be determined.");
187        $result = 0;
188      }
189    
190      # check - do we have a mapping?
191      if (!$opts->{mapping} && !$opts->{mapping_module}) {
192        $logger->warning( __PACKAGE__ . "->checkOptions: Error while resolving resource metadata - no 'mapping' could be determined.");
193        $result = 0;
194      }
195      
196      return $result;
197      
198    }
199    
200    
201  # TODO: some feature to show off the progress of synchronization (cur/max * 100)  # TODO: some feature to show off the progress of synchronization (cur/max * 100)
202  sub syncNodes {  sub syncNodes {
203    
204    my $self = shift;    my $self = shift;
205    my $args = shift;    my $args = shift;
206    
207      if (!$self->{configured}) {
208        $logger->critical( __PACKAGE__ . "->syncNodes: Synchronization object is not configured/initialized correctly." );
209        return;
210      }
211    
212    # remember arguments through the whole processing    # remember arguments through the whole processing
213    $self->{args} = $args;    $self->{args} = $args;
214    
# Line 89  sub syncNodes { Line 231  sub syncNodes {
231    }    }
232    
233    # decompose identifiers for each partner    # decompose identifiers for each partner
234    # TODO: take this list from already established/given metadata    # TODO: refactor!!! take this list from already established/given metadata
235    foreach ('source', 'target') {    foreach ('source', 'target') {
236            
237      # get/set metadata for further processing      # get/set metadata for further processing
# Line 144  sub syncNodes { Line 286  sub syncNodes {
286      #print "iiiiisprov: ", Dumper($self->{meta}->{$_}->{storage}), "\n";      #print "iiiiisprov: ", Dumper($self->{meta}->{$_}->{storage}), "\n";
287    }    }
288    
289    #print Dumper($self->{meta});
290    
291    $logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbkey}/$self->{meta}->{source}->{node} $direction_arrow target=$self->{meta}->{target}->{dbkey}/$self->{meta}->{target}->{node}" );    $logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbkey}/$self->{meta}->{source}->{node} $direction_arrow target=$self->{meta}->{target}->{dbkey}/$self->{meta}->{target}->{node}" );
292    
293    # build mapping    # build mapping
294      # incoming: and Array of node map entries (Array or Hash) - e.g.
295      #   [ 'source:item_name' => 'target:class_val' ]
296      #   { source => 'event->startDateTime', target => 'begindate' }
297    foreach (@{$self->{args}->{mapping}}) {    foreach (@{$self->{args}->{mapping}}) {
298      my @key1 = split(':', $_->[0]);      if (ref $_ eq 'ARRAY') {
299      my @key2 = split(':', $_->[1]);        my @entry1 = split(':', $_->[0]);
300      push @{$self->{meta}->{$key1[0]}->{childnodes}}, $key1[1];        my @entry2 = split(':', $_->[1]);
301      push @{$self->{meta}->{$key2[0]}->{childnodes}}, $key2[1];        my $descent = [];
302          my $node = [];
303          $descent->[0] = $entry1[0];
304          $descent->[1] = $entry2[0];
305          $node->[0] = $entry1[1];
306          $node->[1] = $entry2[1];
307          push @{$self->{meta}->{$descent->[0]}->{childnodes}}, $node->[0];
308          push @{$self->{meta}->{$descent->[1]}->{childnodes}}, $node->[1];
309        } elsif (ref $_ eq 'HASH') {
310          foreach my $entry_key (keys %$_) {
311            my $entry_val = $_->{$entry_key};
312            push @{$self->{meta}->{$entry_key}->{childnodes}}, $entry_val;
313          }
314        }
315    
316    }    }
317    
318    #print Dumper($self->{meta});
319      
320    # check partners/nodes: does partner exist / is node available?    # check partners/nodes: does partner exist / is node available?
321    foreach my $partner (keys %{$self->{meta}}) {    foreach my $partner (keys %{$self->{meta}}) {
322      next if $self->{meta}->{$partner}->{storage}->{locator}->{type} eq 'DBI';    # for DBD::CSV - re-enable for others      next if $self->{meta}->{$partner}->{storage}->{locator}->{type} eq 'DBI';    # for DBD::CSV - re-enable for others
# Line 185  sub syncNodes { Line 348  sub syncNodes {
348    
349    # import flag means: prepare the source node to be syncable    # import flag means: prepare the source node to be syncable
350    # 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
351    if ($self->{args}->{import}) {    if ($self->{args}->{prepare}) {
352      $self->_prepareNode_MetaProperties('source');      $self->_prepareNode_MetaProperties('source');
353      $self->_prepareNode_DummyIdent('source');      $self->_prepareNode_DummyIdent('source');
354      #return;      #return;
355      #$self->_erase_all($opts->{source_node});      #$self->_erase_all($opts->{source_node});
356    }    }
357        
358      # erase flag means: erase the target
359      #if ($opts->{erase}) {
360      if ($self->{args}->{erase}) {
361        # TODO: move this method to the scope of the synchronization core and wrap it around different handlers
362        #print "ERASE", "\n";
363        $self->_erase_all('target');
364      }
365    
366    $self->_syncNodes();    $self->_syncNodes();
367    
368  }  }
# Line 216  sub _syncNodes { Line 387  sub _syncNodes {
387      $results ||= $self->_getNodeList('source', $filter);      $results ||= $self->_getNodeList('source', $filter);
388    }    }
389        
390    # get reference to node list from convenient method provided by corehandle    # get reference to node list from convenient method provided by CORE-HANDLE
391    #$results ||= $self->{source}->getListUnfiltered($self->{meta}->{source}->{node});    #$results ||= $self->{source}->getListUnfiltered($self->{meta}->{source}->{node});
392    #$results ||= $self->{meta}->{source}->{storage}->getListUnfiltered($self->{meta}->{source}->{node});    #$results ||= $self->{meta}->{source}->{storage}->getListUnfiltered($self->{meta}->{source}->{node});
393    $results ||= $self->_getNodeList('source');    $results ||= $self->_getNodeList('source');
# Line 294  sub _syncNodes { Line 465  sub _syncNodes {
465      my $identOK = $self->_resolveNodeIdent('source');      my $identOK = $self->_resolveNodeIdent('source');
466      #if (!$identOK && lc $self->{args}->{direction} ne 'import') {      #if (!$identOK && lc $self->{args}->{direction} ne 'import') {
467      if (!$identOK) {      if (!$identOK) {
468        $logger->critical( __PACKAGE__ . "->syncNodes: Can not synchronize: No ident found in source node, maybe try to \"import\" this node first." );        #print Dumper($self->{meta}->{source});
469          $logger->critical( __PACKAGE__ . "->syncNodes: No ident found in source node \"$self->{meta}->{source}->{node}\", try to \"prepare\" this node first?" );
470        return;        return;
471      }      }
472    
473  #print "statload", "\n";  #print "statload", "\n";
474  #print "ident: ", $self->{node}->{source}->{ident}, "\n";  #print "ident: ", $self->{node}->{source}->{ident}, "\n";
475    #print Dumper($self->{node});
476            
477      my $statOK = $self->_statloadNode('target', $self->{node}->{source}->{ident});      my $statOK = $self->_statloadNode('target', $self->{node}->{source}->{ident});
478    
479    #print Dumper($self->{node});
480            
481      # mark node as new either if there's no ident or if stat/load failed      # mark node as new either if there's no ident or if stat/load failed
482      if (!$statOK) {      if (!$statOK) {
# Line 388  sub _syncNodes { Line 563  sub _syncNodes {
563        $tc->{attempt_new}++;        $tc->{attempt_new}++;
564        $self->_doTransferToTarget('insert');        $self->_doTransferToTarget('insert');
565        # asymmetry: refetch node from target to re-calculate new ident and checksum (TODO: is IdentAuthority of relevance here?)        # asymmetry: refetch node from target to re-calculate new ident and checksum (TODO: is IdentAuthority of relevance here?)
566          #print Dumper($self->{node});
567        $self->_statloadNode('target', $self->{node}->{target}->{ident}, 1);        $self->_statloadNode('target', $self->{node}->{target}->{ident}, 1);
568        $self->_readChecksum('target');        $self->_readChecksum('target');
569    
# Line 413  sub _syncNodes { Line 589  sub _syncNodes {
589      # change ident in source (take from target), if transfer was ok and target is an IdentAuthority      # change ident in source (take from target), if transfer was ok and target is an IdentAuthority
590      # this is (for now) called a "retransmit" indicated by a "r"-character when verbosing      # this is (for now) called a "retransmit" indicated by a "r"-character when verbosing
591      if ($self->{node}->{status}->{ok} && $self->{meta}->{target}->{storage}->{isIdentAuthority}) {      if ($self->{node}->{status}->{ok} && $self->{meta}->{target}->{storage}->{isIdentAuthority}) {
592          print "r" if $self->{verbose};
593        #print Dumper($self->{meta});        #print Dumper($self->{meta});
594        #print Dumper($self->{node});        #print Dumper($self->{node});
595        #exit;        #exit;
596        $self->_doModifySource_IdentChecksum($self->{node}->{target}->{ident});        $self->_doModifySource_IdentChecksum($self->{node}->{target}->{ident});
       print "r" if $self->{verbose};  
597      }      }
598    
599      print ":" if $self->{verbose};      print ":" if $self->{verbose};
# Line 427  sub _syncNodes { Line 603  sub _syncNodes {
603    print "\n" if $self->{verbose};    print "\n" if $self->{verbose};
604        
605    # build user-message from some stats    # build user-message from some stats
606      my $msg = "stats: $tc";      my $msg = "statistics: $tc";
607            
608      if ($tc->{error_per_row}) {      if ($tc->{error_per_row}) {
609        $msg .= "\n";        $msg .= "\n";
610        $msg .= "errors:" . "\n";        $msg .= "errors from \"error_per_row\":" . "\n";
611        $msg .= Dumper($tc->{error_per_row});        $msg .= Dumper($tc->{error_per_row});
612      }      }
613            
# Line 455  sub _dumpCompact { Line 631  sub _dumpCompact {
631      my $item = {};      my $item = {};
632      foreach my $key (keys %$_) {      foreach my $key (keys %$_) {
633        my $val = $_->{$key};        my $val = $_->{$key};
634    
635    #print Dumper($val);
636    
637        if (ref $val eq 'Set::Object') {        if (ref $val eq 'Set::Object') {
638          #print "========================= SET", "\n";          #print "========================= SET", "\n";
639          #print Dumper($val);  #print Dumper($val);
640          #print Dumper($val->members());          #print Dumper($val->members());
641          #$val = $val->members();          #$val = $val->members();
642          #$vars->[$count]->{$key} = $val->members() if $val->can("members");          #$vars->[$count]->{$key} = $val->members() if $val->can("members");
643          #$item->{$key} = $val->members() if $val->can("members");          #$item->{$key} = $val->members() if $val->can("members");
644          $item->{$key} = $val->members();          $item->{$key} = $val->members();
645          #print Dumper($vars->[$count]->{$key});          #print Dumper($vars->[$count]->{$key});
646    
647        } else {        } else {
648          $item->{$key} = $val;          $item->{$key} = $val;
649        }        }
650    
651      }      }
652      push @data, $item;      push @data, $item;
653      $count++;      $count++;
654    }    }
655    
656  #print "Dump:", "\n";  #print "Dump:", Dumper(@data), "\n";
 #print Dumper(@data);  
657    
658    $Data::Dumper::Indent = 0;    $Data::Dumper::Indent = 0;
659    my $result = Dumper(@data);    my $result = Dumper(@data);
660    $Data::Dumper::Indent = 2;    $Data::Dumper::Indent = 2;
661    return $result;    return $result;
662      
663  }  }
664    
665    
# Line 572  sub _buildMap { Line 753  sub _buildMap {
753        for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) {        for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) {
754          #my $map_right = $self->{args}->{mapping}->{$key};          #my $map_right = $self->{args}->{mapping}->{$key};
755                    
756            $self->{node}->{source}->{propcache} = {};
757            $self->{node}->{target}->{propcache} = {};
758            
759          # get property name          # get property name
760          $self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx];          $self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx];
761          $self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx];          $self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx];
# Line 589  sub _buildMap { Line 773  sub _buildMap {
773            $self->{node}->{source}->{propcache}->{value} = $self->{node}->{source}->{payload}->{$self->{node}->{source}->{propcache}->{property}};            $self->{node}->{source}->{propcache}->{value} = $self->{node}->{source}->{payload}->{$self->{node}->{source}->{propcache}->{property}};
774          }          }
775          #$self->{node}->{map}->{$key} = $value;          #$self->{node}->{map}->{$key} = $value;
776            
777            # detect expression
778            # for transferring deeply nested structures described by expressions
779            #print "val: $self->{node}->{source}->{propcache}->{value}", "\n";
780            if ($self->{node}->{source}->{propcache}->{property} =~ s/^expr://) {
781              
782              # create an anonymous sub to act as callback target dispatcher
783                my $cb_dispatcher = sub {
784                  #print "===============  CALLBACK DISPATCHER", "\n";
785                  #print "ident: ", $self->{node}->{source}->{ident}, "\n";
786                  #return $self->{node}->{source}->{ident};
787                  
788                };
789              
790    
791    #print Dumper($self->{node});
792              
793              # build callback map for helper function
794              #my $cbmap = { $self->{meta}->{source}->{IdentProvider}->{arg} => $cb_dispatcher };
795              my $cbmap = {};
796              my $value = refexpr2perlref($self->{node}->{source}->{payload}, $self->{node}->{source}->{propcache}->{property}, $cbmap);
797              $self->{node}->{source}->{propcache}->{value} = $value;
798            }
799    
800          # encode values dependent on type of underlying storage here - expand cases...          # encode values dependent on type of underlying storage here - expand cases...
801          my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type};          my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type};
802          if ($storage_type eq 'DBI') {          if ($storage_type eq 'DBI') {
803            # ...for sql            # ...for sql
804            $self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value});            $self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value});
805          } elsif ($storage_type eq 'Tangram') {          }
806             elsif ($storage_type eq 'Tangram') {
807              # iso? utf8 already possible?
808            
809          } elsif ($storage_type eq 'LDAP') {          } elsif ($storage_type eq 'LDAP') {
810            # TODO: encode utf8 here?            # TODO: encode utf8 here?
811          }          }
# Line 606  sub _buildMap { Line 816  sub _buildMap {
816        }        }
817      }      }
818    
 #print "self->{entry}: ", Dumper($self->{node}), "\n"; exit;  
   
     # for transferring deeply nested structures described by expressions  
     # this currently does not work!  
     # TODO: re-enable this!  
     if ($self->{args}->{mappingV2}) {  
         
       # apply mapping from $self->{args}->{mappingV2} to $self->{node}->{map}  
       foreach my $mapStep (@{$self->{args}->{mappingV2}}) {  
           
         # prepare left/right keys/values  
         my $left_key = $mapStep->{left};  
         my $left_val = _resolveMapStepExpr( $self->{node}->{source}->{payload}, $mapStep->{left} );  
         my $right_key = $mapStep->{right};  
         my $right_val = ( $mapStep->{right} );  
         #print "map: $map_right", "\n";  
           
         if ($mapStep->{method}) {  
           if ($mapStep->{method} eq 'v:1') {  
             $left_val = $left_key;  
           }  
         }  
   
         #$self->{node}->{map}->{$key} = $value;  
         #if ( grep(!/$right_key/, @{$self->{args}->{exclude}}) ) {  
           $self->{node}->{map}->{$right_key} = $self->{R}->quoteSql($left_val);  
         #}  
       }  
     }  
819            
820    # TODO: $logger->dump( ... );    # TODO: $logger->dump( ... );
821    #$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) );    #$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) );
# Line 708  sub _modifyNode { Line 889  sub _modifyNode {
889      }      }
890    }    }
891        
892      
893      #print Dumper($self->{meta});
894    
895    # DBI speaks SQL    # DBI speaks SQL
896    if ($self->{meta}->{$descent}->{storage}->{locator}->{type} eq 'DBI') {    if ($self->{meta}->{$descent}->{storage}->{locator}->{type} eq 'DBI') {
# Line 721  sub _modifyNode { Line 904  sub _modifyNode {
904      #print $action, "\n";      #print $action, "\n";
905  #$action = "anc";  #$action = "anc";
906  #print "yai", "\n";  #print "yai", "\n";
907    
908    #print Dumper($map);
909    #delete $map->{cs};
910    
911      if (lc($action) eq 'insert') {      if (lc($action) eq 'insert') {
912        $sql_main = hash2Sql($self->{meta}->{$descent}->{node}, $map, 'SQL_INSERT');        $sql_main = hash2Sql($self->{meta}->{$descent}->{node}, $map, 'SQL_INSERT');
913      } elsif (lc $action eq 'update') {      } elsif (lc $action eq 'update') {
# Line 728  sub _modifyNode { Line 915  sub _modifyNode {
915        $sql_main = hash2Sql($self->{meta}->{$descent}->{node}, $map, 'SQL_UPDATE', $crit);        $sql_main = hash2Sql($self->{meta}->{$descent}->{node}, $map, 'SQL_UPDATE', $crit);
916      }      }
917    
918      #print "sql: ", $sql_main, "\n";  #$sql_main = "UPDATE currencies_csv SET oid='abcdef' WHERE text='Australian Dollar' AND key='AUD';";
919      #exit;  #$sql_main = "UPDATE currencies_csv SET oid='huhu2' WHERE ekey='AUD'";
920    
921    #print "sql: ", $sql_main, "\n";
922    #exit;
923    
924      # transfer data      # transfer data
925      my $sqlHandle = $self->{meta}->{$descent}->{storage}->sendCommand($sql_main);      my $sqlHandle = $self->{meta}->{$descent}->{storage}->sendCommand($sql_main);
926    
927    #exit;
928    
929      # handle errors      # handle errors
930      if ($sqlHandle->err) {      if ($sqlHandle->err) {
931        #if ($self->{args}->{debug}) { print "sql-error with statement: $sql_main", "\n"; }        #if ($self->{args}->{debug}) { print "sql-error with statement: $sql_main", "\n"; }
# Line 809  sub _modifyNode { Line 1001  sub _modifyNode {
1001        hash2object($object, $map);        hash2object($object, $map);
1002    
1003        # ... and re-update@orm.        # ... and re-update@orm.
1004    #print Dumper($object);
1005        $self->{meta}->{$descent}->{storage}->update($object);        $self->{meta}->{$descent}->{storage}->update($object);
1006    
1007        # asymmetry: get ident after insert        # asymmetry: get ident after insert
1008        # TODO:        # TODO:
1009        #   - just do this if it is an IdentAuthority        #   - just do this if it is an IdentAuthority
1010        #   - use IdentProvider metadata here        #   - use IdentProvider metadata here
1011        $self->{node}->{$descent}->{ident} = $self->{meta}->{$descent}->{storage}->id($object);  #print Dumper($self->{meta}->{$descent});
1012          my $oid = $self->{meta}->{$descent}->{storage}->id($object);
1013    #print "oid: $oid", "\n";
1014          $self->{node}->{$descent}->{ident} = $oid;
1015    
1016    
1017      } elsif (lc $action eq 'update') {      } elsif (lc $action eq 'update') {
# Line 912  sub _statloadNode { Line 1108  sub _statloadNode {
1108        #print "\n", "Attempt to fetch entry implicitely by ident failed: no ident given! This may result in an insert if no write-protection is in the way.", "\n";        #print "\n", "Attempt to fetch entry implicitely by ident failed: no ident given! This may result in an insert if no write-protection is in the way.", "\n";
1109        return;        return;
1110      }      }
1111        
1112        # patch for DBD::CSV
1113        if ($ident && $ident eq 'Null') {
1114          return;
1115        }
1116    
1117      my $result = $self->{meta}->{$descent}->{storage}->sendQuery({  #print "yai!", "\n";
1118    
1119        my $query = {
1120        node => $self->{meta}->{$descent}->{node},        node => $self->{meta}->{$descent}->{node},
1121        subnodes => [qw( cs )],        subnodes => [qw( cs )],
1122        criterias => [        criterias => [
# Line 921  sub _statloadNode { Line 1124  sub _statloadNode {
1124             op => 'eq',             op => 'eq',
1125             val => $ident },             val => $ident },
1126        ]        ]
1127      });      };
1128    
1129    #print Dumper($query);
1130    
1131        my $result = $self->{meta}->{$descent}->{storage}->sendQuery($query);
1132    
1133      my $entry = $result->getNextEntry();      my $entry = $result->getNextEntry();
1134    
1135    #print Dumper($entry);
1136    #print "pers: " . $self->{meta}->{$descent}->{storage}->is_persistent($entry), "\n";
1137    #my $state = $self->{meta}->{$descent}->{storage}->_fetch_object_state($entry, { name => 'TransactionHop' } );
1138    #print Dumper($state);
1139    
1140      my $status = $result->getStatus();      my $status = $result->getStatus();
1141    
1142    #print Dumper($status);
1143        
1144      # TODO: enhance error handling (store inside tc)      # TODO: enhance error handling (store inside tc)
1145      #if (!$row) {      #if (!$row) {
1146      #  print "\n", "row error", "\n";      #  print "\n", "row error", "\n";
1147      #  next;      #  next;
1148      #}      #}
1149      if (($status && $status->{err}) || !$entry) {  
1150        #$logger->critical( __PACKAGE__ . "->_loadNode (ident=\"$ident\") failed" );      # these checks run before actually loading payload- and meta-data to node-container
1151        return;      
1152      }        # 1st level - hard error
1153          if ($status && $status->{err}) {
1154            $logger->debug( __PACKAGE__ . "->_statloadNode (ident=\"$ident\") failed - hard error (that's ok): $status->{err}" );
1155            return;
1156          }
1157      
1158          # 2nd level - logical (empty/notfound) error
1159          if (($status && $status->{empty}) || !$entry) {
1160            $logger->debug( __PACKAGE__ . "->_statloadNode (ident=\"$ident\") failed - logical error (that's ok)" );
1161            #print "no entry (logical)", "\n";
1162            return;
1163          }
1164    
1165    #print Dumper($entry);
1166    
1167      # was:      # was:
1168      # $self->{node}->{$descent}->{ident} = $ident;        # $self->{node}->{$descent}->{ident} = $ident;  
1169      # is:      # is:
1170      # TODO: re-resolve ident from entry via metadata "IdentProvider"      # TODO: re-resolve ident from entry via metadata "IdentProvider" here - like elsewhere
1171      $self->{node}->{$descent}->{ident} = $ident;      $self->{node}->{$descent}->{ident} = $ident;
1172      $self->{node}->{$descent}->{payload} = $entry;      $self->{node}->{$descent}->{payload} = $entry;
1173    
1174    }    }
1175        
1176    return 1;    return 1;
# Line 964  sub _doModifySource_IdentChecksum { Line 1194  sub _doModifySource_IdentChecksum {
1194      $self->{meta}->{source}->{IdentProvider}->{arg} => $ident_new,      $self->{meta}->{source}->{IdentProvider}->{arg} => $ident_new,
1195      cs => $self->{node}->{target}->{checksum},      cs => $self->{node}->{target}->{checksum},
1196    };    };
1197    #print Dumper($map);  
1198    #print Dumper($self->{node});  #print Dumper($map);
1199    #exit;  #print Dumper($self->{node});
1200    #exit;
1201    
1202    $self->_modifyNode('source', 'update', $map);    $self->_modifyNode('source', 'update', $map);
1203  }  }
1204    
# Line 1048  sub _prepareNode_DummyIdent { Line 1280  sub _prepareNode_DummyIdent {
1280      }      }
1281      my $crit = join ' AND ', @crits;      my $crit = join ' AND ', @crits;
1282      print "p" if $self->{verbose};      print "p" if $self->{verbose};
1283    
1284    #print Dumper($map);
1285    #print Dumper($crit);
1286    
1287      $self->_modifyNode($descent, 'update', $map, $crit);      $self->_modifyNode($descent, 'update', $map, $crit);
1288      $i++;      $i++;
1289    }    }
# Line 1063  sub _prepareNode_DummyIdent { Line 1299  sub _prepareNode_DummyIdent {
1299  # TODO: handle this in an abstract way (wipe out use of 'source' and/or 'target' inside core)  # TODO: handle this in an abstract way (wipe out use of 'source' and/or 'target' inside core)
1300  sub _otherSide {  sub _otherSide {
1301    my $self = shift;    my $self = shift;
1302    my $side = shift;    my $descent = shift;
1303    return 'source' if $side eq 'target';    return 'source' if $descent eq 'target';
1304    return 'target' if $side eq 'source';    return 'target' if $descent eq 'source';
1305    return '';    return '';
1306  }  }
1307    
1308    sub _erase_all {
1309      my $self = shift;
1310      my $descent = shift;
1311      #my $node = shift;
1312      my $node = $self->{meta}->{$descent}->{node};
1313      $self->{meta}->{$descent}->{storage}->eraseAll($node);
1314    }
1315    
1316    
1317  =pod  =pod
1318    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.7

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