/[cvs]/nfo/perl/libs/Data/Storage/Handler/Abstract.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage/Handler/Abstract.pm

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

revision 1.6 by joko, Tue Dec 3 15:52:24 2002 UTC revision 1.7 by joko, Thu Dec 5 07:57:48 2002 UTC
# Line 1  Line 1 
1  #################################  ##    --------------------------------------------------------------------------------
2  #  ##    $Id$
3  #  $Id$  ##    --------------------------------------------------------------------------------
4  #  ##    $Log$
5  #  $Log$  ##    Revision 1.7  2002/12/05 07:57:48  joko
6  #  Revision 1.6  2002/12/03 15:52:24  joko  ##    + now using Tie::SecureHash as a base for the COREHANDLE
7  #  + fix/feature: if dispatching to deep core method fails (is not declared), try method at Data::Storage - level  ##    + former public COREHANDLE becomes private _COREHANDLE now
8  #  ##
9  #  Revision 1.5  2002/12/01 22:19:33  joko  ##    Revision 1.6  2002/12/03 15:52:24  joko
10  #  + just disconnect if COREHANDLE exists  ##    + fix/feature: if dispatching to deep core method fails (is not declared), try method at Data::Storage - level
11  #  ##
12  #  Revision 1.4  2002/12/01 04:45:38  joko  ##    Revision 1.5  2002/12/01 22:19:33  joko
13  #  + sub eraseAll  ##    + just disconnect if COREHANDLE exists
14  #  + sub createDb  ##
15  #  ##    Revision 1.4  2002/12/01 04:45:38  joko
16  #  Revision 1.3  2002/11/29 04:58:20  joko  ##    + sub eraseAll
17  #  + Storage::Result now uses the same dispatching mechanism like Storage::Handler  ##    + sub createDb
18  #  ##
19  #  Revision 1.2  2002/10/17 00:08:07  joko  ##    Revision 1.3  2002/11/29 04:58:20  joko
20  #  + bugfixes regarding "deep recursion" stuff  ##    + Storage::Result now uses the same dispatching mechanism like Storage::Handler
21  #  ##
22  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko  ##    Revision 1.2  2002/10/17 00:08:07  joko
23  #  + new  ##    + bugfixes regarding "deep recursion" stuff
24  #  ##
25  #  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko
26  #################################  ##    + new
27    ##    --------------------------------------------------------------------------------
28    
29    
30  package Data::Storage::Handler::Abstract;  package Data::Storage::Handler::Abstract;
31    
# Line 31  use strict; Line 33  use strict;
33  use warnings;  use warnings;
34    
35  use Data::Dumper;  use Data::Dumper;
36    use Tie::SecureHash;
37    #use Data::Storage::Handler;
38    
39  # get logger instance  # get logger instance
40  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 45  sub new { Line 49  sub new {
49      $logger->debug( "$invocant->new( @_ )" );      $logger->debug( "$invocant->new( @_ )" );
50      #$logger->debug( __PACKAGE__ . "->" . "new()" );      #$logger->debug( __PACKAGE__ . "->" . "new()" );
51    
52    # arguments become properties    # V1 - arguments become properties automagically / normal perl mode blessing
53    =pod
54      # autovivify passed-in arguments as future object attributes into to-be-blessed hash
55    my $self = { @_ };    my $self = { @_ };
56    # create object from blessed hash-reference    # create object from blessed hash-reference
57    bless $self, $class;    bless $self, $class;
58    =cut
59    
60    
61      # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash...
62      my $self = Tie::SecureHash->new(
63        $class,
64        # that's it:
65          'metainfo' => undef,
66          'lock_info' => undef,
67          '_COREHANDLE' => undef,
68          'meta' => undef,
69          'locator' => undef,
70          'dataStorageLayer' => undef,
71          'dbi' => undef,
72        # tries:
73          #'Data::Storage::Handler::Abstract::metainfo' => undef,
74          #'dataStorageLayer'
75          #'Data::Storage::Handler::Abstract::dataStorageLayer' => undef,
76          #'Data::Storage::Handler::Tangram::dataStorageLayer' => undef,
77          #'Data::Dumper::locator' => undef,
78          #$class . '::locator' => undef,
79          #'Data::Storage::Handler::Tangram::locator' => undef,
80          #'Data::Storage::Handler::DBI::locator' => undef,
81          #_protected => ,
82          #__private => ,
83      );
84    
85    
86      # merge passed-in arguments to constructor as properties into already blessed secure object
87        
88        # mungle arguments from array into hash - perl does the job  ;)
89        my %args = @_;
90      
91        # merge attributes one-by-one
92        # TODO: deep_copy? / merge_deep?
93        foreach (keys %args) {
94          #print "key: $_", "\n";
95          $self->{$_} = $args{$_};
96        }
97      
98      # V3 - rolling our own security (just for {COREHANDLE} - nothing else)  -  nope, Tie::SecureHash works wonderful
99      #my $self = { @_ };
100      #bless $self, $class;
101      
102      
103    
104    # handle meta data    # handle meta data
105      #my $metainfo = $self->getMetaInfo($class);      #my $metainfo = $self->getMetaInfo($class);
# Line 86  sub AUTOLOAD { Line 137  sub AUTOLOAD {
137    # find out methodname    # find out methodname
138    my $methodname = $AUTOLOAD;    my $methodname = $AUTOLOAD;
139    $methodname =~ s/^.*:://;    $methodname =~ s/^.*:://;
140      
141    #print "method: $methodname", "\n";
142      
143      # TODO: document this! handler-private methods listed here will not be triggered (internal use)
144      # in this case, "exists" is a method reserved for Tie::SecureHash,
145      # which encapsulates the perl data structure (HASH) under this object
146      # this is to prevent deep recursion's
147      return if lc $methodname eq 'exists';
148    
149    #print "$methodname - 1", "\n";
150    
151      # TODO: enhance logging/debugging
152      #if (!$self->exists('COREHANDLE')) { return; }
153    
154    # handle locking (hack)    # handle locking (hack)
155    if ($self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) {    if ($self->exists('lock_info') && $self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) {
156      $self->{lock_info}->{log_lock} = 1;      $self->{lock_info}->{log_lock} = 1;
157    } else {    } else {
158      $self->{lock_info}->{log_lock} = 0;      $self->{lock_info}->{log_lock} = 0;
159    }    }
160    $self->{lock_info}->{last_method} = $methodname;    $self->{lock_info}->{last_method} = $methodname;
161        
162    #print "$methodname - 2", "\n";
163    
164    #print Dumper($self);
165    #exit;
166    
167      # get corehandle instance from underlying handler
168      my $core = $self->getCOREHANDLE();
169    
170    # test for COREHANDLE    # test for COREHANDLE
171    if (!$self->{COREHANDLE}) {    #if (!$self->{_COREHANDLE}) {
172      #print "no COREHANDLE", "\n";  #=pod
173      if (!$self->{lock_info}->{log_lock}) {    #if (!$self->exists('_COREHANDLE')) {
174        $logger->error( __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"" );    #if (!$self->{_COREHANDLE}) {
175      if (!$core) {
176        my $err_msg_core = __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";
177    print $err_msg_core, "\n";
178        if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {
179          $logger->error( $err_msg_core );
180      }      }
181      return;      return;
182    }    }
183    #=cut
184    
185    #print "$methodname - 3", "\n";
186    
187    # try to dispatch method-call to Storage::Handler::*    # try to dispatch method-call to Storage::Handler::*
188    #if ($self->can($methodname)) {    #if ($self->can($methodname)) {
# Line 111  sub AUTOLOAD { Line 191  sub AUTOLOAD {
191      #if ($res) { return $res; }      #if ($res) { return $res; }
192    #}    #}
193    
194    #print "$methodname - 4", "\n";
195    
196    # try to dispatch method-call to COREHANDLE    # try to dispatch method-call to COREHANDLE
197    if ($self->{COREHANDLE}->can($methodname) || $self->{COREHANDLE}->can("AUTOLOAD")) {    # was:
198      #my $core = $self->{_COREHANDLE};
199      # is:
200      #my $core = $self->getCOREHANDLE();
201    
202    #print Dumper($core);
203    #exit;
204    
205      # was:
206      #if ($self->{_COREHANDLE}->can($methodname) || $self->{_COREHANDLE}->can("AUTOLOAD")) {
207      # is:
208      if ($core->can($methodname) || $core->can("AUTOLOAD")) {
209      #$logger->debug( __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );      #$logger->debug( __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );
210      #$lock_AUTOLOAD = 1 if ($methodname eq 'insert');      #$lock_AUTOLOAD = 1 if ($methodname eq 'insert');
211      if (!$self->{lock_info}->{log_lock}) {      if (!$self->{lock_info}->{log_lock}) {
# Line 124  sub AUTOLOAD { Line 217  sub AUTOLOAD {
217      #$lock_AUTOLOAD = 0;      #$lock_AUTOLOAD = 0;
218      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );
219            
220    #print "calling: $methodname", "\n";
221        
222      # method calls doing it until here will get dispatched to the proper handler      # method calls doing it until here will get dispatched to the proper handler
223      return $self->{COREHANDLE}->$methodname(@_);      return $core->$methodname(@_);
224        
225    } elsif ($self->can($methodname)) {    } elsif ($self->can($methodname)) {
226      return $self->$methodname(@_);      return $self->$methodname(@_);
# Line 135  sub AUTOLOAD { Line 230  sub AUTOLOAD {
230    
231  sub DESTROY {  sub DESTROY {
232    my $self = shift;    my $self = shift;
233    if ($self->{COREHANDLE}) {    #if ($self->{COREHANDLE}) {
234      if ($self->exists('_COREHANDLE')) {
235      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );
236    
237      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};
238    
239      # call "disconnect" or alike on COREHANDLE      # call "disconnect" or alike on COREHANDLE
240      # was: $self->{COREHANDLE}->disconnect();      # was: $self->{COREHANDLE}->disconnect();
241      $disconnectMethod && $self->{COREHANDLE} && ( $self->{COREHANDLE}->$disconnectMethod() );      $disconnectMethod && $self->{_COREHANDLE} && ( $self->{_COREHANDLE}->$disconnectMethod() );
242    
243      undef $self->{COREHANDLE};      undef $self->{_COREHANDLE};
244    }    }
245  }  }
246    
# Line 153  sub _abstract_function { Line 249  sub _abstract_function {
249    my $self = shift;    my $self = shift;
250    my $fName = shift;    my $fName = shift;
251    my $class = ref($self);    my $class = ref($self);
252    $logger->error( __PACKAGE__ . ": function \"$fName\" is an abstract method, please implement it in \"$class\"");    # was:
253      # $logger->error( __PACKAGE__ . ": function \"$fName\" is an abstract method, please implement it in \"$class\"");
254      # is:
255      die( __PACKAGE__ . ": function \"$fName\" is an abstract method, please implement it in \"$class\"");
256    #exit;    #exit;
257  }  }
258    
259  sub _typeCheck {  sub _typeCheck2 {
260    my $type = shift;    my $type = shift;
261    print "type: $type";    print "type: $type";
262    eval("use Data::Storage::$type;");    eval("use Data::Storage::$type;");
# Line 199  sub _typeCheck { Line 298  sub _typeCheck {
298    #   - build them via anonymous subs    #   - build them via anonymous subs
299    #   - introduce them via symbols    #   - introduce them via symbols
300    
301      sub getCOREHANDLE {
302        my $self = shift;
303        $self->_abstract_function('getCOREHANDLE');
304      }
305    
306    sub sendCommand {    sub sendCommand {
307      my $self = shift;      my $self = shift;
308      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
309    }    }
310    
311      sub existsChildNode_tmp {
312        my $self = shift;
313        $self->_abstract_function('existsChildNode');
314      }
315    
316    sub getChildNodes {    sub getChildNodes {
317      my $self = shift;      my $self = shift;
318      $self->_abstract_function('getChildNodes');      $self->_abstract_function('getChildNodes');

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