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 |
16 |
|
## fix regarding namespace update |
17 |
|
## |
18 |
## Revision 1.5 2003/02/21 08:34:58 joko |
## Revision 1.5 2003/02/21 08:34:58 joko |
19 |
## modified object hierarchy |
## modified object hierarchy |
20 |
## renamed method |
## renamed method |
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::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; |
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__ |