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

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

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

revision 1.6 by joko, Fri Mar 28 03:08:17 2003 UTC revision 1.7 by joko, Tue May 13 08:13:25 2003 UTC
# Line 1  Line 1 
1    ## -------------------------------------------------------------------------
2    ##
3  ##    $Id$  ##    $Id$
4  ##  ##
5  ##    Copyright (c) 2002  Andreas Motl <andreas.motl@ilo.de>  ##    Copyright (c) 2002  Andreas Motl <andreas.motl@ilo.de>
6  ##  ##
7  ##    See COPYRIGHT section in pod text below for usage and distribution rights.  ##    See COPYRIGHT section in associated pod text
8    ##    or below for usage and distribution rights.
9  ##  ##
10  ##    ----------------------------------------------------------------------------------------  ## -------------------------------------------------------------------------
11  ##    $Log$  ##    $Log$
12    ##    Revision 1.7  2003/05/13 08:13:25  joko
13    ##    moved "sub buildAttributeMap" to Map.pm
14    ##
15  ##    Revision 1.6  2003/03/28 03:08:17  joko  ##    Revision 1.6  2003/03/28 03:08:17  joko
16  ##    fix regarding namespace update  ##    fix regarding namespace update
17  ##  ##
# Line 40  use warnings; Line 46  use warnings;
46  use mixin::with qw( Data::Transfer::Sync );  use mixin::with qw( Data::Transfer::Sync );
47    
48    
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   main  
   
49  use Data::Dumper;  use Data::Dumper;
 use libdb qw( quotesql );  
 use Data::Mungle::Code::Ref qw( ref_slot );  
50    
51  # get logger instance  # get logger instance
52  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 212  sub options2metadata_accessor { Line 214  sub options2metadata_accessor {
214  }  }
215    
216    
   
 sub buildAttributeMap {  
   
  my $self = shift;  
   
   # field-structure for building sql  
   # mapping of sql-fieldnames to object-attributes  
     $self->{node}->{map} = {};  
   
     # manually set ...  
       # ... object-id  
       $self->{node}->{map}->{$self->{meta}->{target}->{IdentProvider}->{arg}} = $self->{node}->{source}->{ident};  
       # ... checksum  
       $self->{node}->{map}->{cs} = $self->{node}->{source}->{checksum};  
   
 #print "sqlmap: ", Dumper($self->{node}->{map}), "\n";  
   
 #print Dumper($self);  
 #exit;  
   
     # for transferring flat structures via simple (1:1) mapping  
     # TODO: diff per property / property value  
   
     #if ($self->{args}->{mapping}) {  
       # apply mapping from $self->{args}->{mapping} to $self->{node}->{map}  
       #foreach my $key (@{$self->{meta}->{source}->{childnodes}}) {  
       my @childnodes = @{$self->{meta}->{source}->{childnodes}};  
       for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) {  
         #my $map_right = $self->{args}->{mapping}->{$key};  
           
         $self->{node}->{source}->{propcache} = {};  
         $self->{node}->{target}->{propcache} = {};  
           
         # get property name  
         $self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx];  
         $self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx];  
         #print "map: $map_right", "\n";  
   
         # get property value  
         my $value;  
           
         # detect for callback - old style - (maybe the better???)  
         if (ref($self->{node}->{target}->{map}) eq 'CODE') {  
           #$value = &$map_right($objClone);  
         } else {  
           # plain (scalar?) value  
           #$value = $objClone->{$map_right};  
           $self->{node}->{source}->{propcache}->{value} = $self->{node}->{source}->{payload}->{$self->{node}->{source}->{propcache}->{property}};  
         }  
         #$self->{node}->{map}->{$key} = $value;  
           
         # detect expression  
         # for transferring deeply nested structures described by expressions  
         #print "val: $self->{node}->{source}->{propcache}->{value}", "\n";  
         if ($self->{node}->{source}->{propcache}->{property} =~ s/^expr://) {  
             
           # create an anonymous sub to act as callback target dispatcher  
             my $cb_dispatcher = sub {  
               #print "===============  CALLBACK DISPATCHER", "\n";  
               #print "ident: ", $self->{node}->{source}->{ident}, "\n";  
               #return $self->{node}->{source}->{ident};  
                 
             };  
             
   
 #print Dumper($self->{node});  
             
           # build callback map for helper function  
           #my $cbmap = { $self->{meta}->{source}->{IdentProvider}->{arg} => $cb_dispatcher };  
           my $cbmap = {};  
           my $value = ref_slot($self->{node}->{source}->{payload}, $self->{node}->{source}->{propcache}->{property}, $cbmap);  
           $self->{node}->{source}->{propcache}->{value} = $value;  
         }  
   
         # encode values dependent on type of underlying storage here - expand cases...  
         my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type};  
         if ($storage_type eq 'DBI') {  
           # ...for sql  
           # quotemeta?  
           $self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value});  
   
         } elsif ($storage_type eq 'Tangram') {  
           # iso? utf8 already possible?  
           
         } elsif ($storage_type eq 'LDAP') {  
           # TODO: encode utf8 here?  
   
         }  
   
         # store value to transfer map  
         $self->{node}->{map}->{$self->{node}->{target}->{propcache}->{property}} = $self->{node}->{source}->{propcache}->{value};  
   
       }  
     #}  
   
       
   # TODO: $logger->dump( ... );  
   #$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) );  
 #print "sqlmap: ", Dumper($self->{node}->{map}), "\n";  
 #print "entrystatus: ", Dumper($self->{node}), "\n";  
   
 }  
   
217  1;  1;
218    __END__

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

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