6 |
## |
## |
7 |
## ---------------------------------------------------------------------------------------- |
## ---------------------------------------------------------------------------------------- |
8 |
## $Log$ |
## $Log$ |
9 |
|
## Revision 1.6 2003/02/14 12:58:47 joko |
10 |
|
## + re-enabled the erase-mechanism |
11 |
|
## |
12 |
|
## Revision 1.5 2003/02/11 05:26:04 joko |
13 |
|
## + sub _tellWhatIWillDo |
14 |
|
## + re-enabled "branch to execution path for special targets" mechanism |
15 |
|
## |
16 |
|
## Revision 1.4 2003/02/09 05:03:02 joko |
17 |
|
## + minor fix regarding namespace of api versioning extension module |
18 |
|
## |
19 |
## Revision 1.3 2003/02/09 04:59:27 joko |
## Revision 1.3 2003/02/09 04:59:27 joko |
20 |
## + api versioning mechanism |
## + api versioning mechanism |
21 |
## + major structure changes |
## + major structure changes |
65 |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
66 |
#print Dumper($self); |
#print Dumper($self); |
67 |
#exit; |
#exit; |
68 |
my $module = "Version::$syncVersion"; |
my $module = "API::$syncVersion"; |
69 |
$self->load($module); |
$self->load($module); |
70 |
} |
} |
71 |
|
|
73 |
sub configure { |
sub configure { |
74 |
my $self = shift; |
my $self = shift; |
75 |
|
|
|
#print "YAI\n"; |
|
|
#print Dumper(@_); |
|
|
#exit; |
|
|
|
|
76 |
$logger->debug( __PACKAGE__ . "->configure"); |
$logger->debug( __PACKAGE__ . "->configure"); |
77 |
|
|
78 |
my @args = @_; |
my @args = @_; |
79 |
|
|
|
#print Dumper(@args); |
|
|
|
|
80 |
if (!isEmpty(\@args)) { |
if (!isEmpty(\@args)) { |
81 |
my %properties = @_; |
my %properties = @_; |
82 |
# merge args to properties |
# merge args to properties |
151 |
my $self = shift; |
my $self = shift; |
152 |
my $args = shift; |
my $args = shift; |
153 |
|
|
154 |
|
$logger->notice( "========================== " . __PACKAGE__ . "->syncNodes =============="); |
155 |
$logger->debug( __PACKAGE__ . "->syncNodes: starting" ); |
$logger->debug( __PACKAGE__ . "->syncNodes: starting" ); |
156 |
|
|
157 |
#print Dumper($self); |
#print Dumper($self); |
160 |
#print Dumper($self->{options}); |
#print Dumper($self->{options}); |
161 |
$self->_prepareOptions(); |
$self->_prepareOptions(); |
162 |
|
|
163 |
#print Dumper($self->{options}); |
# trace |
164 |
|
#print Dumper($self->{options}); |
165 |
|
#exit; |
166 |
|
|
167 |
if (!$self->checkOptions()) { |
if (!$self->checkOptions()) { |
168 |
$logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed."); |
$logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed."); |
174 |
return; |
return; |
175 |
} |
} |
176 |
|
|
177 |
|
#print Dumper($args); |
178 |
|
|
179 |
# remember arguments through the whole processing |
# remember arguments through the whole processing |
180 |
$self->{args} = $args; |
$self->{args} = $args; |
181 |
|
|
185 |
# hash to sum up results |
# hash to sum up results |
186 |
# TODO: re-implement! (sync-statistics???) |
# TODO: re-implement! (sync-statistics???) |
187 |
|
|
188 |
|
#print Dumper($self->{options}->{process}); |
189 |
|
|
190 |
# detect synchronization method to determine which optical symbol (directed arrow) to use |
# detect synchronization method to determine which optical symbol (directed arrow) to use |
191 |
my $mode = $self->{args}->{mode}; # V1 |
my $mode = $self->{args}->{mode}; # V1 |
192 |
$mode ||= $self->{options}->{process}->{mode}; # V2 |
$mode ||= $self->{options}->{process}->{mode}; # V2 |
207 |
$self->options2metadata(); |
$self->options2metadata(); |
208 |
$self->options2metadata_accessor(); |
$self->options2metadata_accessor(); |
209 |
|
|
210 |
|
# branch to execution path for special targets |
211 |
|
# detect for option 'handler' which could be a CODEref |
212 |
|
if ($self->{options}->{handler} && ref $self->{options}->{handler} eq 'CODE') { |
213 |
|
$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}"); |
214 |
|
#print Dumper($self); |
215 |
|
#exit; |
216 |
|
# don't do this any more - it wasn't very nice somehow ... |
217 |
|
#$self->{options}->{handler}->($self->{app}, $self->{options}); |
218 |
|
# .... now: better let the parent application scope handle this via callback |
219 |
|
# not any more required for this: $self->{app} inside here (which isn't the app we mean here) |
220 |
|
# required for this: getting the options out of here: establish some getter method! ($self->getOptions(...)) |
221 |
|
# so.... |
222 |
|
#$self->{__bridge}->{parent_ref}-> |
223 |
|
|
224 |
|
# ahh okay, DesignPattern::Bridge moves closer to some Class::Inner!??? |
225 |
|
# so... |
226 |
|
# similar like above - but it isn't very nice anyway ... (no privateness, but: who cares?) |
227 |
|
#print Dumper($self->{__bridge}); |
228 |
|
# just take the global application instance and |
229 |
|
# throw it into the context of the mapping module - this is heavy! ;-) (but again, who cares...) |
230 |
|
# TODO: handle this more abstract *sometime* |
231 |
|
#$self->{options}->{handler}->($self->{__bridge}->{parent}->{app}, $self->{options}); |
232 |
|
$self->{options}->{handler}->($self->{__bridge}->{parent}->{process}, $self->{options}); |
233 |
|
|
234 |
|
return; |
235 |
|
} |
236 |
|
|
237 |
|
# TODO: execution path branch V2!!! |
238 |
|
# option1: wrap this via callback to parent scope (like current impl. mechanism) |
239 |
|
# option2: branch directly from here (this needs refactoring of the sub handler) |
240 |
|
|
241 |
# tracing |
# tracing |
242 |
#print Dumper($self); |
#print Dumper($self); |
243 |
#exit; |
#exit; |
247 |
return if !$self->buildFieldmapping(); |
return if !$self->buildFieldmapping(); |
248 |
return if !$self->_touchNodeSet(); |
return if !$self->_touchNodeSet(); |
249 |
return if !$self->_prepare_sync(); |
return if !$self->_prepare_sync(); |
250 |
|
$self->_tellWhatIWillDo(); |
251 |
|
|
252 |
# tracing |
# tracing |
253 |
#print Dumper($self); |
#print Dumper($self); |
263 |
} |
} |
264 |
|
|
265 |
|
|
266 |
|
my $c_string_default = ''; |
267 |
|
sub c_string { |
268 |
|
my $value = shift; |
269 |
|
$value ||= "[$c_string_default]"; |
270 |
|
return $value; |
271 |
|
} |
272 |
|
|
273 |
|
sub _tellWhatIWillDo { |
274 |
|
my $self = shift; |
275 |
|
|
276 |
|
|
277 |
|
#return; |
278 |
|
|
279 |
|
# trace |
280 |
|
#print Dumper($self->{meta}); |
281 |
|
#exit; |
282 |
|
|
283 |
|
$c_string_default = 'n/a'; |
284 |
|
my $source = c_string($self->{opt}->{'source'}); |
285 |
|
my $source_node = c_string($self->{opt}->{'source-node'}); |
286 |
|
my $source_type = c_string($self->{opt}->{'source-type'}); |
287 |
|
my $target = c_string($self->{opt}->{'target'}); |
288 |
|
my $target_node = c_string($self->{opt}->{'target-node'}); |
289 |
|
my $target_type = c_string($self->{opt}->{'target-type'}); |
290 |
|
|
291 |
|
my $mapping_module = c_string($self->{opt}->{'mapping-module'}); |
292 |
|
my $mode = uc c_string($self->{opt}->{'mode'}); |
293 |
|
|
294 |
|
#my $ql = "$mode INTO $source NODE $source_node TYPE $source_type SELECT NODE $target_node TYPE $target_type FROM $target USING MODULE $mapping_module;"; |
295 |
|
#$logger->notice( __PACKAGE__ . ": $ql" ); |
296 |
|
my $ql = <<EOT; |
297 |
|
|
298 |
|
FETCH DATA |
299 |
|
FROM STORAGE $self->{meta}->{source}->{dbKey} |
300 |
|
AT NODE $self->{meta}->{source}->{accessorName}.$self->{meta}->{source}->{nodeName} |
301 |
|
USING IDENTIFIER $self->{meta}->{source}->{IdentProvider}->{method}.$self->{meta}->{source}->{IdentProvider}->{arg} |
302 |
|
CONVERT DATA |
303 |
|
CAST FROM $self->{meta}->{source}->{nodeType} TO $self->{meta}->{target}->{nodeType} |
304 |
|
MAP ATTRIBUTES FROM @{$self->{meta}->{source}->{childnodes}} TO @{$self->{meta}->{target}->{childnodes}} |
305 |
|
STORE DATA |
306 |
|
TO STORAGE $self->{meta}->{target}->{dbKey} |
307 |
|
AT NODE $self->{meta}->{target}->{accessorName}.$self->{meta}->{target}->{nodeName} |
308 |
|
USING IDENTIFIER $self->{meta}->{target}->{IdentProvider}->{method}.$self->{meta}->{target}->{IdentProvider}->{arg} |
309 |
|
EOT |
310 |
|
|
311 |
|
|
312 |
|
$logger->notice( $ql ); |
313 |
|
|
314 |
|
#exit; |
315 |
|
return; |
316 |
|
|
317 |
|
my $actioning = ucfirst $self->{opt}->{'action'} . 'ing'; |
318 |
|
|
319 |
|
# FIXME: this is weird! |
320 |
|
my $long = <<EOT; |
321 |
|
|
322 |
|
- $actioning data of type $target_type and |
323 |
|
filtered by $target_node from the storage named $target |
324 |
|
to the storage named $source - filtered by $source_node. |
325 |
|
- Will attempt to convert the data to $source_type. |
326 |
|
EOT |
327 |
|
chomp($long); |
328 |
|
$logger->notice( __PACKAGE__ . ": $long" ); |
329 |
|
|
330 |
|
} |
331 |
|
|
332 |
|
|
333 |
sub _prepareOptions { |
sub _prepareOptions { |
334 |
|
|
335 |
my $self = shift; |
my $self = shift; |
418 |
# merging - V2 |
# merging - V2 |
419 |
|
|
420 |
# merge local map with local opts |
# merge local map with local opts |
421 |
|
|
422 |
|
# delete undef'd items in $map |
423 |
|
|
424 |
# enable cloning |
# enable cloning |
425 |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
426 |
Hash::Merge::set_clone_behavior(1); |
Hash::Merge::set_clone_behavior(1); |
427 |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
428 |
|
#Hash::Merge::set_behavior( 'STORAGE_PRECEDENT' ); |
429 |
|
#Hash::Merge::set_behavior( 'RETAINMENT_PRECEDENT' ); |
430 |
|
# TODO: add an option to Hash::Merge not to overwrite set items with undefined/empty/not assigned ones |
431 |
my $locals_merged = merge( $opts, $map ); |
my $locals_merged = merge( $opts, $map ); |
432 |
|
|
433 |
# trace |
# trace |
513 |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
514 |
($self->{meta}->{source}, $self->{meta}->{target}) = |
($self->{meta}->{source}, $self->{meta}->{target}) = |
515 |
($self->{meta}->{target}, $self->{meta}->{source}); |
($self->{meta}->{target}, $self->{meta}->{source}); |
516 |
|
#($self->{options}->{source}, $self->{options}->{target}) = |
517 |
|
# ($self->{options}->{target}, $self->{options}->{source}); |
518 |
|
|
519 |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
520 |
# TODO: |
# TODO: |
528 |
|
|
529 |
# import flag means: prepare the source node to be syncable |
# import flag means: prepare the source node to be syncable |
530 |
# 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 |
531 |
if ($self->{args}->{prepare}) { |
if ($self->{options}->{process}->{prepare}) { |
532 |
$self->_prepareNode_MetaProperties('source'); |
$self->_prepareNode_MetaProperties('source'); |
533 |
$self->_prepareNode_DummyIdent('source'); |
$self->_prepareNode_DummyIdent('source'); |
534 |
#return; |
#return; |
537 |
|
|
538 |
# erase flag means: erase the target |
# erase flag means: erase the target |
539 |
#if ($opts->{erase}) { |
#if ($opts->{erase}) { |
540 |
if ($self->{args}->{erase}) { |
if ($self->{options}->{process}->{erase}) { |
541 |
# 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 |
542 |
#print "ERASE", "\n"; |
#print "ERASE", "\n"; |
543 |
$self->_erase_all('target'); |
$self->_erase_all('target'); |