1 |
joko |
1.1 |
## $Id: API.pm,v 1.1 2003/01/19 01:23:04 joko Exp $ |
2 |
|
|
## |
3 |
|
|
## Copyright (c) 2002 Andreas Motl <andreas.motl@ilo.de> |
4 |
|
|
## |
5 |
|
|
## See COPYRIGHT section in pod text below for usage and distribution rights. |
6 |
|
|
## |
7 |
|
|
## ---------------------------------------------------------------------------------------- |
8 |
|
|
## $Log: API.pm,v $ |
9 |
|
|
## Revision 1.1 2003/01/19 01:23:04 joko |
10 |
|
|
## + new from Data/Transfer/Sync.pm |
11 |
|
|
## |
12 |
|
|
## ---------------------------------------------------------------------------------------- |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
package Data::Transfer::Sync::StorageInterface; |
16 |
|
|
|
17 |
|
|
use strict; |
18 |
|
|
use warnings; |
19 |
|
|
|
20 |
|
|
use mixin::with qw( Data::Transfer::Sync ); |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
24 |
|
|
|
25 |
|
|
# get logger instance |
26 |
|
|
my $logger = Log::Dispatch::Config->instance; |
27 |
|
|
|
28 |
|
|
use Data::Dumper; |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
# this is a shortcut method |
32 |
|
|
# ... let's try to avoid _any_ redundant code in here (ok... - at the cost of method lookups...) |
33 |
|
|
sub _getNodeList { |
34 |
|
|
my $self = shift; |
35 |
|
|
my $descent = shift; |
36 |
|
|
my $filter = shift; |
37 |
|
|
#$results ||= $self->{source}->getListUnfiltered($self->{meta}->{source}->{node}); |
38 |
|
|
#$results ||= $self->{meta}->{source}->{storage}->getListUnfiltered($self->{meta}->{source}->{node}); |
39 |
|
|
my $list = $self->{meta}->{$descent}->{storage}->getListFiltered($self->{meta}->{$descent}->{nodeName}, $filter); |
40 |
|
|
#print Dumper($list); |
41 |
|
|
return $list; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
sub _resolveNodeIdent { |
45 |
|
|
my $self = shift; |
46 |
|
|
my $descent = shift; |
47 |
|
|
|
48 |
|
|
#print Dumper($self->{node}->{$descent}); |
49 |
|
|
|
50 |
|
|
# get to the payload |
51 |
|
|
#my $item = $specifier->{item}; |
52 |
|
|
my $payload = $self->{node}->{$descent}->{payload}; |
53 |
|
|
|
54 |
|
|
# resolve method to get to the id of the given item |
55 |
|
|
# we use global metadata and the given descent for this task |
56 |
|
|
#my $ident = $self->{$descent}->id($item); |
57 |
|
|
#my $ident = $self->{meta}->{$descent}->{storage}->id($item); |
58 |
|
|
|
59 |
|
|
my $ident; |
60 |
|
|
my $provider_method = $self->{meta}->{$descent}->{IdentProvider}->{method}; |
61 |
|
|
my $provider_arg = $self->{meta}->{$descent}->{IdentProvider}->{arg}; |
62 |
|
|
|
63 |
|
|
#print "provider_method: $provider_method", "\n"; |
64 |
|
|
#print "provider_arg: $provider_arg", "\n"; |
65 |
|
|
|
66 |
|
|
# resolve to ident |
67 |
|
|
if (lc $provider_method eq 'property') { |
68 |
|
|
$ident = $payload->{$provider_arg}; |
69 |
|
|
|
70 |
|
|
} elsif (lc $provider_method eq 'storage_method') { |
71 |
|
|
#$ident = $self->{meta}->{$descent}->{storage}->id($item); |
72 |
|
|
$ident = $self->{meta}->{$descent}->{storage}->$provider_arg($payload); |
73 |
|
|
|
74 |
|
|
} elsif (lc $provider_method eq 'code') { |
75 |
|
|
$ident = 'ac'; |
76 |
|
|
|
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
$self->{node}->{$descent}->{ident} = $ident; |
80 |
|
|
|
81 |
|
|
return 1 if $ident; |
82 |
|
|
|
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
# TODO: |
86 |
|
|
# this should be split up into... |
87 |
|
|
# - a "_statNode" (should just touch the node to check for existance) |
88 |
|
|
# - a "_loadNode" (should load node completely) |
89 |
|
|
# - maybe additionally a "loadNodeProperty" (may specify properties to load) |
90 |
|
|
# - introduce $self->{nodecache} for this purpose |
91 |
|
|
# TODO: |
92 |
|
|
# should we: |
93 |
|
|
# - not pass ident in here but resolve it via "$descent"? |
94 |
|
|
# - refactor this and stuff it with additional debug/error message |
95 |
|
|
# - this = the way the implicit load mechanism works |
96 |
|
|
sub _statloadNode { |
97 |
|
|
|
98 |
|
|
my $self = shift; |
99 |
|
|
my $descent = shift; |
100 |
|
|
my $ident = shift; |
101 |
|
|
my $force = shift; |
102 |
|
|
|
103 |
|
|
# fetch entry to retrieve checksum from |
104 |
|
|
# was: |
105 |
|
|
if (!$self->{node}->{$descent} || $force) { |
106 |
|
|
# is: |
107 |
|
|
#if (!$self->{node}->{$descent}->{item} || $force) { |
108 |
|
|
|
109 |
|
|
if (!$ident) { |
110 |
|
|
#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"; |
111 |
|
|
return; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
# patch for DBD::CSV |
115 |
|
|
if ($ident && $ident eq 'Null') { |
116 |
|
|
return; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
#print "yai!", "\n"; |
120 |
|
|
|
121 |
|
|
my $query = { |
122 |
|
|
node => $self->{meta}->{$descent}->{nodeName}, |
123 |
|
|
subnodes => [qw( cs )], |
124 |
|
|
criterias => [ |
125 |
|
|
{ key => $self->{meta}->{$descent}->{IdentProvider}->{arg}, |
126 |
|
|
op => 'eq', |
127 |
|
|
val => $ident }, |
128 |
|
|
] |
129 |
|
|
}; |
130 |
|
|
|
131 |
|
|
print Dumper($query); |
132 |
|
|
|
133 |
|
|
my $result = $self->{meta}->{$descent}->{storage}->sendQuery($query); |
134 |
|
|
|
135 |
|
|
my $entry = $result->getNextEntry(); |
136 |
|
|
|
137 |
|
|
#print Dumper($entry); |
138 |
|
|
#print "pers: " . $self->{meta}->{$descent}->{storage}->is_persistent($entry), "\n"; |
139 |
|
|
#my $state = $self->{meta}->{$descent}->{storage}->_fetch_object_state($entry, { name => 'TransactionHop' } ); |
140 |
|
|
#print Dumper($state); |
141 |
|
|
|
142 |
|
|
my $status = $result->getStatus(); |
143 |
|
|
|
144 |
|
|
#print Dumper($status); |
145 |
|
|
|
146 |
|
|
# TODO: enhance error handling (store inside tc) |
147 |
|
|
#if (!$row) { |
148 |
|
|
# print "\n", "row error", "\n"; |
149 |
|
|
# next; |
150 |
|
|
#} |
151 |
|
|
|
152 |
|
|
# these checks run before actually loading payload- and meta-data to node-container |
153 |
|
|
|
154 |
|
|
# 1st level - hard error |
155 |
|
|
if ($status && $status->{err}) { |
156 |
|
|
$logger->debug( __PACKAGE__ . "->_statloadNode (ident=\"$ident\") failed - hard error (that's ok): $status->{err}" ); |
157 |
|
|
return; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
# 2nd level - logical (empty/notfound) error |
161 |
|
|
if (($status && $status->{empty}) || !$entry) { |
162 |
|
|
$logger->debug( __PACKAGE__ . "->_statloadNode (ident=\"$ident\") failed - logical error (that's ok)" ); |
163 |
|
|
#print "no entry (logical)", "\n"; |
164 |
|
|
return; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
#print Dumper($entry); |
168 |
|
|
|
169 |
|
|
# was: |
170 |
|
|
# $self->{node}->{$descent}->{ident} = $ident; |
171 |
|
|
# is: |
172 |
|
|
# TODO: re-resolve ident from entry via metadata "IdentProvider" here - like elsewhere |
173 |
|
|
$self->{node}->{$descent}->{ident} = $ident; |
174 |
|
|
$self->{node}->{$descent}->{payload} = $entry; |
175 |
|
|
|
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
return 1; |
179 |
|
|
|
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
|
183 |
|
|
1; |