6 |
## |
## |
7 |
## ---------------------------------------------------------------------------------------- |
## ---------------------------------------------------------------------------------------- |
8 |
## $Log$ |
## $Log$ |
9 |
|
## Revision 1.7 2003/02/21 08:00:24 joko |
10 |
|
## debugging |
11 |
|
## |
12 |
|
## Revision 1.6 2003/02/14 12:58:47 joko |
13 |
|
## + re-enabled the erase-mechanism |
14 |
|
## |
15 |
|
## Revision 1.5 2003/02/11 05:26:04 joko |
16 |
|
## + sub _tellWhatIWillDo |
17 |
|
## + re-enabled "branch to execution path for special targets" mechanism |
18 |
|
## |
19 |
|
## Revision 1.4 2003/02/09 05:03:02 joko |
20 |
|
## + minor fix regarding namespace of api versioning extension module |
21 |
|
## |
22 |
## Revision 1.3 2003/02/09 04:59:27 joko |
## Revision 1.3 2003/02/09 04:59:27 joko |
23 |
## + api versioning mechanism |
## + api versioning mechanism |
24 |
## + major structure changes |
## + major structure changes |
68 |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
69 |
#print Dumper($self); |
#print Dumper($self); |
70 |
#exit; |
#exit; |
71 |
my $module = "Version::$syncVersion"; |
my $module = "API::$syncVersion"; |
72 |
$self->load($module); |
$self->load($module); |
73 |
} |
} |
74 |
|
|
76 |
sub configure { |
sub configure { |
77 |
my $self = shift; |
my $self = shift; |
78 |
|
|
|
#print "YAI\n"; |
|
|
#print Dumper(@_); |
|
|
#exit; |
|
|
|
|
79 |
$logger->debug( __PACKAGE__ . "->configure"); |
$logger->debug( __PACKAGE__ . "->configure"); |
80 |
|
|
81 |
my @args = @_; |
my @args = @_; |
82 |
|
|
|
#print Dumper(@args); |
|
|
|
|
83 |
if (!isEmpty(\@args)) { |
if (!isEmpty(\@args)) { |
84 |
my %properties = @_; |
my %properties = @_; |
85 |
# merge args to properties |
# merge args to properties |
154 |
my $self = shift; |
my $self = shift; |
155 |
my $args = shift; |
my $args = shift; |
156 |
|
|
157 |
|
#$logger->notice( "========================== " . __PACKAGE__ . "->syncNodes =============="); |
158 |
$logger->debug( __PACKAGE__ . "->syncNodes: starting" ); |
$logger->debug( __PACKAGE__ . "->syncNodes: starting" ); |
159 |
|
|
160 |
#print Dumper($self); |
#print Dumper($self); |
163 |
#print Dumper($self->{options}); |
#print Dumper($self->{options}); |
164 |
$self->_prepareOptions(); |
$self->_prepareOptions(); |
165 |
|
|
166 |
#print Dumper($self->{options}); |
# trace |
167 |
|
#print Dumper($self->{options}); |
168 |
|
#exit; |
169 |
|
|
170 |
if (!$self->checkOptions()) { |
if (!$self->checkOptions()) { |
171 |
$logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed."); |
$logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed."); |
177 |
return; |
return; |
178 |
} |
} |
179 |
|
|
180 |
|
#print Dumper($args); |
181 |
|
|
182 |
# remember arguments through the whole processing |
# remember arguments through the whole processing |
183 |
$self->{args} = $args; |
$self->{args} = $args; |
184 |
|
|
188 |
# hash to sum up results |
# hash to sum up results |
189 |
# TODO: re-implement! (sync-statistics???) |
# TODO: re-implement! (sync-statistics???) |
190 |
|
|
191 |
|
#print Dumper($self->{options}->{process}); |
192 |
|
|
193 |
# detect synchronization method to determine which optical symbol (directed arrow) to use |
# detect synchronization method to determine which optical symbol (directed arrow) to use |
194 |
my $mode = $self->{args}->{mode}; # V1 |
my $mode = $self->{args}->{mode}; # V1 |
195 |
$mode ||= $self->{options}->{process}->{mode}; # V2 |
$mode ||= $self->{options}->{process}->{mode}; # V2 |
210 |
$self->options2metadata(); |
$self->options2metadata(); |
211 |
$self->options2metadata_accessor(); |
$self->options2metadata_accessor(); |
212 |
|
|
213 |
|
# branch to execution path for special targets |
214 |
|
# detect for option 'handler' which could be a CODEref |
215 |
|
if ($self->{options}->{handler} && ref $self->{options}->{handler} eq 'CODE') { |
216 |
|
$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}"); |
217 |
|
#print Dumper($self); |
218 |
|
#exit; |
219 |
|
# don't do this any more - it wasn't very nice somehow ... |
220 |
|
#$self->{options}->{handler}->($self->{app}, $self->{options}); |
221 |
|
# .... now: better let the parent application scope handle this via callback |
222 |
|
# not any more required for this: $self->{app} inside here (which isn't the app we mean here) |
223 |
|
# required for this: getting the options out of here: establish some getter method! ($self->getOptions(...)) |
224 |
|
# so.... |
225 |
|
#$self->{__bridge}->{parent_ref}-> |
226 |
|
|
227 |
|
# ahh okay, DesignPattern::Bridge moves closer to some Class::Inner!??? |
228 |
|
# so... |
229 |
|
# similar like above - but it isn't very nice anyway ... (no privateness, but: who cares?) |
230 |
|
#print Dumper($self->{__bridge}); |
231 |
|
# just take the global application instance and |
232 |
|
# throw it into the context of the mapping module - this is heavy! ;-) (but again, who cares...) |
233 |
|
# TODO: handle this more abstract *sometime* |
234 |
|
#$self->{options}->{handler}->($self->{__bridge}->{parent}->{app}, $self->{options}); |
235 |
|
$self->{options}->{handler}->($self->{__bridge}->{parent}->{process}, $self->{options}); |
236 |
|
|
237 |
|
return; |
238 |
|
} |
239 |
|
|
240 |
|
# TODO: execution path branch V2!!! |
241 |
|
# option1: wrap this via callback to parent scope (like current impl. mechanism) |
242 |
|
# option2: branch directly from here (this needs refactoring of the sub handler) |
243 |
|
|
244 |
# tracing |
# tracing |
245 |
#print Dumper($self); |
#print Dumper($self); |
246 |
#exit; |
#exit; |
247 |
|
|
248 |
$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: |
249 |
|
$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}]" ); |
250 |
|
|
251 |
|
# V2: |
252 |
|
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}]"; |
253 |
|
#my $header = ("~.." x 7) . " " . $what . " " . ("~.." x 4); |
254 |
|
#my $header = ("= " x 7) . " " . $what . " " . ("= " x 4); |
255 |
|
#my $header = ("~=-_-=" x 3) . " " . $what . " " . ("~=-_-=" x 4); |
256 |
|
my $header = ("_-=~=-" x 4) . " " . $what . " " . ("_-=~=-" x 4); |
257 |
|
$logger->notice($header); |
258 |
|
|
259 |
|
|
260 |
return if !$self->buildFieldmapping(); |
return if !$self->buildFieldmapping(); |
261 |
return if !$self->_touchNodeSet(); |
return if !$self->_touchNodeSet(); |
262 |
return if !$self->_prepare_sync(); |
return if !$self->_prepare_sync(); |
263 |
|
$self->_tellWhatIWillDo(); |
264 |
|
|
265 |
# tracing |
# tracing |
266 |
#print Dumper($self); |
#print Dumper($self); |
276 |
} |
} |
277 |
|
|
278 |
|
|
279 |
|
my $c_string_default = ''; |
280 |
|
sub c_string { |
281 |
|
my $value = shift; |
282 |
|
$value ||= "[$c_string_default]"; |
283 |
|
return $value; |
284 |
|
} |
285 |
|
|
286 |
|
sub _tellWhatIWillDo { |
287 |
|
my $self = shift; |
288 |
|
|
289 |
|
|
290 |
|
#return; |
291 |
|
|
292 |
|
# trace |
293 |
|
#print Dumper($self->{meta}); |
294 |
|
#exit; |
295 |
|
|
296 |
|
$c_string_default = 'n/a'; |
297 |
|
my $source = c_string($self->{opt}->{'source'}); |
298 |
|
my $source_node = c_string($self->{opt}->{'source-node'}); |
299 |
|
my $source_type = c_string($self->{opt}->{'source-type'}); |
300 |
|
my $target = c_string($self->{opt}->{'target'}); |
301 |
|
my $target_node = c_string($self->{opt}->{'target-node'}); |
302 |
|
my $target_type = c_string($self->{opt}->{'target-type'}); |
303 |
|
|
304 |
|
my $mapping_module = c_string($self->{opt}->{'mapping-module'}); |
305 |
|
my $mode = uc c_string($self->{opt}->{'mode'}); |
306 |
|
|
307 |
|
#my $ql = "$mode INTO $source NODE $source_node TYPE $source_type SELECT NODE $target_node TYPE $target_type FROM $target USING MODULE $mapping_module;"; |
308 |
|
#$logger->notice( __PACKAGE__ . ": $ql" ); |
309 |
|
my $ql = <<EOT; |
310 |
|
|
311 |
|
FETCH DATA |
312 |
|
FROM STORAGE $self->{meta}->{source}->{dbKey} |
313 |
|
AT NODE $self->{meta}->{source}->{accessorName}.$self->{meta}->{source}->{nodeName} |
314 |
|
USING IDENTIFIER $self->{meta}->{source}->{IdentProvider}->{method}.$self->{meta}->{source}->{IdentProvider}->{arg} |
315 |
|
CONVERT DATA |
316 |
|
CAST FROM $self->{meta}->{source}->{nodeType} TO $self->{meta}->{target}->{nodeType} |
317 |
|
MAP ATTRIBUTES FROM @{$self->{meta}->{source}->{childnodes}} TO @{$self->{meta}->{target}->{childnodes}} |
318 |
|
STORE DATA |
319 |
|
TO STORAGE $self->{meta}->{target}->{dbKey} |
320 |
|
AT NODE $self->{meta}->{target}->{accessorName}.$self->{meta}->{target}->{nodeName} |
321 |
|
USING IDENTIFIER $self->{meta}->{target}->{IdentProvider}->{method}.$self->{meta}->{target}->{IdentProvider}->{arg} |
322 |
|
EOT |
323 |
|
|
324 |
|
|
325 |
|
chomp($ql); |
326 |
|
$logger->info($ql); |
327 |
|
|
328 |
|
#exit; |
329 |
|
return; |
330 |
|
|
331 |
|
my $actioning = ucfirst $self->{opt}->{'action'} . 'ing'; |
332 |
|
|
333 |
|
# FIXME: this is weird! |
334 |
|
my $long = <<EOT; |
335 |
|
|
336 |
|
- $actioning data of type $target_type and |
337 |
|
filtered by $target_node from the storage named $target |
338 |
|
to the storage named $source - filtered by $source_node. |
339 |
|
- Will attempt to convert the data to $source_type. |
340 |
|
EOT |
341 |
|
chomp($long); |
342 |
|
$logger->notice( __PACKAGE__ . ": $long" ); |
343 |
|
|
344 |
|
} |
345 |
|
|
346 |
|
|
347 |
sub _prepareOptions { |
sub _prepareOptions { |
348 |
|
|
349 |
my $self = shift; |
my $self = shift; |
432 |
# merging - V2 |
# merging - V2 |
433 |
|
|
434 |
# merge local map with local opts |
# merge local map with local opts |
435 |
|
|
436 |
|
# delete undef'd items in $map |
437 |
|
|
438 |
# enable cloning |
# enable cloning |
439 |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
440 |
Hash::Merge::set_clone_behavior(1); |
Hash::Merge::set_clone_behavior(1); |
441 |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
442 |
|
#Hash::Merge::set_behavior( 'STORAGE_PRECEDENT' ); |
443 |
|
#Hash::Merge::set_behavior( 'RETAINMENT_PRECEDENT' ); |
444 |
|
# TODO: add an option to Hash::Merge not to overwrite set items with undefined/empty/not assigned ones |
445 |
my $locals_merged = merge( $opts, $map ); |
my $locals_merged = merge( $opts, $map ); |
446 |
|
|
447 |
# trace |
# trace |
527 |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
528 |
($self->{meta}->{source}, $self->{meta}->{target}) = |
($self->{meta}->{source}, $self->{meta}->{target}) = |
529 |
($self->{meta}->{target}, $self->{meta}->{source}); |
($self->{meta}->{target}, $self->{meta}->{source}); |
530 |
|
#($self->{options}->{source}, $self->{options}->{target}) = |
531 |
|
# ($self->{options}->{target}, $self->{options}->{source}); |
532 |
|
|
533 |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
534 |
# TODO: |
# TODO: |
542 |
|
|
543 |
# import flag means: prepare the source node to be syncable |
# import flag means: prepare the source node to be syncable |
544 |
# 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 |
545 |
if ($self->{args}->{prepare}) { |
if ($self->{options}->{process}->{prepare}) { |
546 |
$self->_prepareNode_MetaProperties('source'); |
$self->_prepareNode_MetaProperties('source'); |
547 |
$self->_prepareNode_DummyIdent('source'); |
$self->_prepareNode_DummyIdent('source'); |
548 |
#return; |
#return; |
551 |
|
|
552 |
# erase flag means: erase the target |
# erase flag means: erase the target |
553 |
#if ($opts->{erase}) { |
#if ($opts->{erase}) { |
554 |
if ($self->{args}->{erase}) { |
if ($self->{options}->{process}->{erase}) { |
555 |
# 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 |
556 |
#print "ERASE", "\n"; |
#print "ERASE", "\n"; |
557 |
$self->_erase_all('target'); |
$self->_erase_all('target'); |