/[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.7 by joko, Thu Dec 5 07:57:48 2002 UTC revision 1.15 by joko, Thu Feb 20 20:19:13 2003 UTC
# Line 1  Line 1 
1  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
2  ##    $Id$  ##    $Id$
3  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
4  ##    $Log$  ##    $Log$
5    ##    Revision 1.15  2003/02/20 20:19:13  joko
6    ##    tried to get auto-disconnect working again - failed with that
7    ##
8    ##    Revision 1.14  2003/02/09 05:12:28  joko
9    ##    + quoting of strings used in sql-queries!
10    ##
11    ##    Revision 1.13  2003/01/30 22:27:05  joko
12    ##    + added new abstract methods
13    ##
14    ##    Revision 1.12  2003/01/30 21:46:32  joko
15    ##    + fixed behaviour of AUTOLOAD-method
16    ##
17    ##    Revision 1.11  2003/01/20 16:43:18  joko
18    ##    + better argument-property merging
19    ##    + debugging-output !!!
20    ##    + abstract-dummy 'sub createChildNode'
21    ##
22    ##    Revision 1.10  2003/01/19 02:31:51  joko
23    ##    + fix to 'sub AUTOLOAD'
24    ##
25    ##    Revision 1.9  2002/12/19 16:30:23  joko
26    ##    + added 'sub dropDb' and 'sub rebuildDb' as croakers for concrete implementations of methods in proper handlers
27    ##
28    ##    Revision 1.8  2002/12/13 21:48:35  joko
29    ##    + sub _abstract_function
30    ##
31  ##    Revision 1.7  2002/12/05 07:57:48  joko  ##    Revision 1.7  2002/12/05 07:57:48  joko
32  ##    + now using Tie::SecureHash as a base for the COREHANDLE  ##    + now using Tie::SecureHash as a base for the COREHANDLE
33  ##    + former public COREHANDLE becomes private _COREHANDLE now  ##    + former public COREHANDLE becomes private _COREHANDLE now
# Line 24  Line 50 
50  ##  ##
51  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko
52  ##    + new  ##    + new
53  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
54    
55    
56  package Data::Storage::Handler::Abstract;  package Data::Storage::Handler::Abstract;
# Line 32  package Data::Storage::Handler::Abstract Line 58  package Data::Storage::Handler::Abstract
58  use strict;  use strict;
59  use warnings;  use warnings;
60    
61    use base qw( DesignPattern::Object );
62    
63    
64  use Data::Dumper;  use Data::Dumper;
65  use Tie::SecureHash;  use Tie::SecureHash;
66  #use Data::Storage::Handler;  #use Data::Storage::Handler;
67    use Hash::Merge qw( merge );
68    
69    
70  # get logger instance  # get logger instance
71  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 57  sub new { Line 88  sub new {
88    bless $self, $class;    bless $self, $class;
89  =cut  =cut
90    
91    #=pod
92    # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash...    # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash...
93    my $self = Tie::SecureHash->new(    my $self = Tie::SecureHash->new(
94      $class,      $class,
# Line 81  sub new { Line 112  sub new {
112        #_protected => ,        #_protected => ,
113        #__private => ,        #__private => ,
114    );    );
115    #=cut
116    
117    # merge passed-in arguments to constructor as properties into already blessed secure object    # merge passed-in arguments to constructor as properties into already blessed secure object
118        
119      # mungle arguments from array into hash - perl does the job  ;)      # mungle arguments from array into hash - perl does the job  ;)
120      my %args = @_;      #my %args = @_;
121          #my %args = ();
122    
123    #print Dumper(@_);
124    
125      # merge attributes one-by-one      # merge attributes one-by-one
126      # TODO: deep_copy? / merge_deep?      # TODO: deep_copy? / merge_deep?
127      foreach (keys %args) {      while (my $elemName = shift @_) {
128        #print "key: $_", "\n";        #print "elemName: $elemName", "\n";
129        $self->{$_} = $args{$_};        if (my $elemValue = shift @_) {
130            #print Dumper($elemValue);
131            #print "elemName=$elemName, elemValue=$elemValue", "\n";
132            $self->{$elemName} = $elemValue;
133          }
134          #$self->{$_} = $args{$_};
135          #$self->{$_} = $args{$_};
136      }      }
137        
138    # V3 - rolling our own security (just for {COREHANDLE} - nothing else)  -  nope, Tie::SecureHash works wonderful    # V3 - rolling our own security (just for {COREHANDLE} - nothing else)  -  nope, Tie::SecureHash works wonderful
# Line 116  sub new { Line 156  sub new {
156  }  }
157    
158    
159    # TODO: use NEXT.pm inside this mechanism (to avoid repetitions...)
160  sub AUTOLOAD {  sub AUTOLOAD {
161    
162    # recursion problem to be avoided here!!!    # recursion problem to be avoided here!!!
# Line 152  sub AUTOLOAD { Line 193  sub AUTOLOAD {
193    #if (!$self->exists('COREHANDLE')) { return; }    #if (!$self->exists('COREHANDLE')) { return; }
194    
195    # handle locking (hack)    # handle locking (hack)
196    if ($self->exists('lock_info') && $self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) {    if ($self->can('exists') && $self->exists('lock_info') && $self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) {
197      $self->{lock_info}->{log_lock} = 1;      $self->{lock_info}->{log_lock} = 1;
198    } else {    } else {
199      $self->{lock_info}->{log_lock} = 0;      $self->{lock_info}->{log_lock} = 0;
# Line 173  sub AUTOLOAD { Line 214  sub AUTOLOAD {
214    #if (!$self->exists('_COREHANDLE')) {    #if (!$self->exists('_COREHANDLE')) {
215    #if (!$self->{_COREHANDLE}) {    #if (!$self->{_COREHANDLE}) {
216    if (!$core) {    if (!$core) {
217      my $err_msg_core = __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";  
218  print $err_msg_core, "\n";  #print Dumper($self);    
219      if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {  #exit;
220    
221        my $handlertype = $self->{metainfo}->{type};
222        $handlertype ||= '';
223    
224        my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";
225    
226    #print $err_msg_core, "\n";
227    
228        #if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {
229        $logger->error( $err_msg_core );        $logger->error( $err_msg_core );
230      }      #}
231    
232      return;      return;
233        
234    }    }
235  #=cut  #=cut
236    
# Line 219  print $err_msg_core, "\n"; Line 271  print $err_msg_core, "\n";
271            
272  #print "calling: $methodname", "\n";  #print "calling: $methodname", "\n";
273            
274      # method calls doing it until here will get dispatched to the proper handler      # method calls making it until here will get dispatched to the proper handler
275      return $core->$methodname(@_);      return $core->$methodname(@_);
276        
277    } elsif ($self->can($methodname)) {    } elsif ($self->can($methodname)) {
278        # try to call specified method inside our or inherited module(s) scope(s)
279      return $self->$methodname(@_);      return $self->$methodname(@_);
280    }    }
281    
# Line 230  print $err_msg_core, "\n"; Line 283  print $err_msg_core, "\n";
283    
284  sub DESTROY {  sub DESTROY {
285    my $self = shift;    my $self = shift;
286    #if ($self->{COREHANDLE}) {  
287    if ($self->exists('_COREHANDLE')) {  return;
288    
289      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );
290    
291      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};
292      print "meth: ", $disconnectMethod, "\n";
293      
294      #$disconnectMethod && $self->{_COREHANDLE} && ( $self->{_COREHANDLE}->$disconnectMethod() );
295      $self->{_COREHANDLE}->$disconnectMethod();
296      #$self->$disconnectMethod();
297    
298      #my $core1 = $self->getCOREHANDLE() if $self->can('getCOREHANDLE');
299      #$core1->$disconnectMethod();
300    
301    return;
302    
303      print "DESTROY-1", "\n";
304      #if ($self->{__COREHANDLE}) {
305      #if ($self->exists('_COREHANDLE')) {
306    
307      # get corehandle instance from underlying handler
308      my $core;
309      $core = $self->getCOREHANDLE() if $self->can('getCOREHANDLE');
310    
311      #if ($self->{STORAGEHANDLE}) {
312      if ($core) {
313        print "DESTROY-2", "\n";
314      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );
315    
316      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};
# Line 244  sub DESTROY { Line 323  sub DESTROY {
323    }    }
324  }  }
325    
   
 sub _abstract_function {  
   my $self = shift;  
   my $fName = shift;  
   my $class = ref($self);  
   # was:  
   # $logger->error( __PACKAGE__ . ": function \"$fName\" is an abstract method, please implement it in \"$class\"");  
   # is:  
   die( __PACKAGE__ . ": function \"$fName\" is an abstract method, please implement it in \"$class\"");  
   #exit;  
 }  
   
326  sub _typeCheck2 {  sub _typeCheck2 {
327    my $type = shift;    my $type = shift;
328    print "type: $type";    print "type: $type";
# Line 270  sub _typeCheck2 { Line 337  sub _typeCheck2 {
337    sub existsChildNode {    sub existsChildNode {
338      my $self = shift;      my $self = shift;
339      my $nodename = shift;      my $nodename = shift;
340      #$nodename = 'TransactionRoutingTable';  
341      $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" );      # TODO: don't use $self->{meta}->{childnodes} directly in here
342        # get it returned from $self->getChildNodes()!!!
343    
344        $logger->debug( __PACKAGE__ . "->existsChildNode( nodename=$nodename )" );
345      $self->getChildNodes() unless $self->{meta}->{childnodes};      $self->getChildNodes() unless $self->{meta}->{childnodes};
346      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!  
347        # quote this, it might contain meta characters which don't work in a regex
348          $nodename = quotemeta($nodename);
349    
350        # trace
351          #print Dumper($self->{meta});
352          #print "nodename: $nodename", "\n";
353        
354        # FIXME: use "/i" only on win32-systems!
355        my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});
356        
357      return $result;      return $result;
358    }    }
359    
# Line 308  sub _typeCheck2 { Line 388  sub _typeCheck2 {
388      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
389    }    }
390    
391      sub createChildNode {
392        my $self = shift;
393        $self->_abstract_function('createChildNode');
394      }
395    
396    sub existsChildNode_tmp {    sub existsChildNode_tmp {
397      my $self = shift;      my $self = shift;
398      $self->_abstract_function('existsChildNode');      $self->_abstract_function('existsChildNode');
# Line 377  sub _typeCheck2 { Line 462  sub _typeCheck2 {
462      return;      return;
463    }    }
464    
465      sub dropDb {
466        my $self = shift;
467        $self->_abstract_function('dropDb');
468        return;
469      }
470    
471      sub rebuildDb {
472        my $self = shift;
473        $self->_abstract_function('rebuildDb');
474        return;
475      }
476    
477      sub getDbName {
478        my $self = shift;
479        $self->_abstract_function('getDbName');
480        return;
481      }
482    
483      sub testAvailability {
484        my $self = shift;
485        $self->_abstract_function('testAvailability');
486        return;
487      }
488    
489      sub isConnected {
490        my $self = shift;
491        $self->_abstract_function('isConnected');
492        return;
493      }
494    
495      sub testDsn {
496        my $self = shift;
497        $self->_abstract_function('testDsn');
498        return;
499      }
500    
501  1;  1;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.15

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed