/[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.10 by joko, Sun Jan 19 02:31:51 2003 UTC revision 1.17 by joko, Tue May 13 07:58:49 2003 UTC
# Line 1  Line 1 
1  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
2  ##    $Id$  ##    $Id$
3  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
4  ##    $Log$  ##    $Log$
5    ##    Revision 1.17  2003/05/13 07:58:49  joko
6    ##    fix: die if methodname is empty
7    ##    fixes to log-string
8    ##
9    ##    Revision 1.16  2003/04/18 16:07:53  joko
10    ##    just use logger if instantiation successed
11    ##
12    ##    Revision 1.15  2003/02/20 20:19:13  joko
13    ##    tried to get auto-disconnect working again - failed with that
14    ##
15    ##    Revision 1.14  2003/02/09 05:12:28  joko
16    ##    + quoting of strings used in sql-queries!
17    ##
18    ##    Revision 1.13  2003/01/30 22:27:05  joko
19    ##    + added new abstract methods
20    ##
21    ##    Revision 1.12  2003/01/30 21:46:32  joko
22    ##    + fixed behaviour of AUTOLOAD-method
23    ##
24    ##    Revision 1.11  2003/01/20 16:43:18  joko
25    ##    + better argument-property merging
26    ##    + debugging-output !!!
27    ##    + abstract-dummy 'sub createChildNode'
28    ##
29  ##    Revision 1.10  2003/01/19 02:31:51  joko  ##    Revision 1.10  2003/01/19 02:31:51  joko
30  ##    + fix to 'sub AUTOLOAD'  ##    + fix to 'sub AUTOLOAD'
31  ##  ##
# Line 33  Line 57 
57  ##  ##
58  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko
59  ##    + new  ##    + new
60  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
61    
62    
63  package Data::Storage::Handler::Abstract;  package Data::Storage::Handler::Abstract;
# Line 43  use warnings; Line 67  use warnings;
67    
68  use base qw( DesignPattern::Object );  use base qw( DesignPattern::Object );
69    
70    
71  use Data::Dumper;  use Data::Dumper;
72  use Tie::SecureHash;  use Tie::SecureHash;
73  #use Data::Storage::Handler;  #use Data::Storage::Handler;
74    use Hash::Merge qw( merge );
75    
76    #use Log::Dispatch::Config;
77    #Log::Dispatch::Config->configure();
78    
79  # get logger instance  # get logger instance
80  my $logger = Log::Dispatch::Config->instance;  my $logger;
81    eval('$logger = Log::Dispatch::Config->instance;');
82    
83  #our $lock_info;  #our $lock_info;
84    
# Line 57  sub new { Line 87  sub new {
87    my $class = ref($invocant) || $invocant;    my $class = ref($invocant) || $invocant;
88        
89    # logging info about the actual handler called    # logging info about the actual handler called
90      $logger->debug( "$invocant->new( @_ )" );      $logger->debug( "$invocant->new( @_ )" ) if $logger;
91      #$logger->debug( __PACKAGE__ . "->" . "new()" );      #$logger->debug( __PACKAGE__ . "->" . "new()" );
92    
93    # V1 - arguments become properties automagically / normal perl mode blessing    # V1 - arguments become properties automagically / normal perl mode blessing
# Line 95  sub new { Line 125  sub new {
125  #=cut  #=cut
126    
127    # 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
128        
129      # mungle arguments from array into hash - perl does the job  ;)      # mungle arguments from array into hash - perl does the job  ;)
130      my %args = @_;      #my %args = @_;
131          #my %args = ();
132    
133    #print Dumper(@_);
134    
135      # merge attributes one-by-one      # merge attributes one-by-one
136      # TODO: deep_copy? / merge_deep?      # TODO: deep_copy? / merge_deep?
137      foreach (keys %args) {      while (my $elemName = shift @_) {
138        #print "key: $_", "\n";        #print "elemName: $elemName", "\n";
139        $self->{$_} = $args{$_};        if (my $elemValue = shift @_) {
140            #print Dumper($elemValue);
141            #print "elemName=$elemName, elemValue=$elemValue", "\n";
142            $self->{$elemName} = $elemValue;
143          }
144          #$self->{$_} = $args{$_};
145          #$self->{$_} = $args{$_};
146      }      }
147        
148    # 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 193  sub AUTOLOAD { Line 232  sub AUTOLOAD {
232      $handlertype ||= '';      $handlertype ||= '';
233    
234      my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";      my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";
235  print $err_msg_core, "\n";  
236      if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {  #print $err_msg_core, "\n";
237    
238        #if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {
239        $logger->error( $err_msg_core );        $logger->error( $err_msg_core );
240      }      #}
241    
242      return;      return;
243        
244    }    }
245  #=cut  #=cut
246    
247      if (!$methodname) {
248        die("Methodname is not defined!");
249        return;
250      }
251    
252  #print "$methodname - 3", "\n";  #print "$methodname - 3", "\n";
253    
254    # try to dispatch method-call to Storage::Handler::*    # try to dispatch method-call to Storage::Handler::*
# Line 229  print $err_msg_core, "\n"; Line 277  print $err_msg_core, "\n";
277      #$lock_AUTOLOAD = 1 if ($methodname eq 'insert');      #$lock_AUTOLOAD = 1 if ($methodname eq 'insert');
278      if (!$self->{lock_info}->{log_lock}) {      if (!$self->{lock_info}->{log_lock}) {
279        #print "method: $methodname", "\n";        #print "method: $methodname", "\n";
280        $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->" . $methodname . "(@_)" );        my $type = $self->{metainfo}->{type};
281          $type ||= '';
282          # FIXME!
283          #$logger->debug( __PACKAGE__ . "[$type]" . "->" . $methodname . "(@_)" );
284          $logger->debug( __PACKAGE__ . "[$type]" . "->" . $methodname );
285      } else {      } else {
286        # AUTOLOAD - sub is locked to prevent deep recursions if (e.g.) db-inserts cause log-actions to same db itself        # AUTOLOAD - sub is locked to prevent deep recursions if (e.g.) db-inserts cause log-actions to same db itself
287      }      }
# Line 250  print $err_msg_core, "\n"; Line 302  print $err_msg_core, "\n";
302    
303  sub DESTROY {  sub DESTROY {
304    my $self = shift;    my $self = shift;
305    #if ($self->{COREHANDLE}) {  
306    if ($self->exists('_COREHANDLE')) {  return;
307    
308      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );
309    
310      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};
311      print "meth: ", $disconnectMethod, "\n";
312      
313      #$disconnectMethod && $self->{_COREHANDLE} && ( $self->{_COREHANDLE}->$disconnectMethod() );
314      $self->{_COREHANDLE}->$disconnectMethod();
315      #$self->$disconnectMethod();
316    
317      #my $core1 = $self->getCOREHANDLE() if $self->can('getCOREHANDLE');
318      #$core1->$disconnectMethod();
319    
320    return;
321    
322      print "DESTROY-1", "\n";
323      #if ($self->{__COREHANDLE}) {
324      #if ($self->exists('_COREHANDLE')) {
325    
326      # get corehandle instance from underlying handler
327      my $core;
328      $core = $self->getCOREHANDLE() if $self->can('getCOREHANDLE');
329    
330      #if ($self->{STORAGEHANDLE}) {
331      if ($core) {
332        print "DESTROY-2", "\n";
333      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );      $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" );
334    
335      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};      my $disconnectMethod = $self->{metainfo}->{disconnectMethod};
# Line 278  sub _typeCheck2 { Line 356  sub _typeCheck2 {
356    sub existsChildNode {    sub existsChildNode {
357      my $self = shift;      my $self = shift;
358      my $nodename = shift;      my $nodename = shift;
359      #$nodename = 'TransactionRoutingTable';  
360      $logger->debug( __PACKAGE__ . "->existsChildNode( nodename $nodename )" );      # TODO: don't use $self->{meta}->{childnodes} directly in here
361        # get it returned from $self->getChildNodes()!!!
362    
363        $logger->debug( __PACKAGE__ . "->existsChildNode( nodename=$nodename )" );
364      $self->getChildNodes() unless $self->{meta}->{childnodes};      $self->getChildNodes() unless $self->{meta}->{childnodes};
365      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!  
366        # quote this, it might contain meta characters which don't work in a regex
367          $nodename = quotemeta($nodename);
368    
369        # trace
370          #print Dumper($self->{meta});
371          #print "nodename: $nodename", "\n";
372        
373        # FIXME: use "/i" only on win32-systems!
374        my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});
375        
376      return $result;      return $result;
377    }    }
378    
# Line 316  sub _typeCheck2 { Line 407  sub _typeCheck2 {
407      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
408    }    }
409    
410      sub createChildNode {
411        my $self = shift;
412        $self->_abstract_function('createChildNode');
413      }
414    
415    sub existsChildNode_tmp {    sub existsChildNode_tmp {
416      my $self = shift;      my $self = shift;
417      $self->_abstract_function('existsChildNode');      $self->_abstract_function('existsChildNode');
# Line 397  sub _typeCheck2 { Line 493  sub _typeCheck2 {
493      return;      return;
494    }    }
495    
496      sub getDbName {
497        my $self = shift;
498        $self->_abstract_function('getDbName');
499        return;
500      }
501    
502      sub testAvailability {
503        my $self = shift;
504        $self->_abstract_function('testAvailability');
505        return;
506      }
507    
508      sub isConnected {
509        my $self = shift;
510        $self->_abstract_function('isConnected');
511        return;
512      }
513    
514      sub testDsn {
515        my $self = shift;
516        $self->_abstract_function('testDsn');
517        return;
518      }
519    
520  1;  1;

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.17

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