/[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.8 by joko, Fri Dec 13 21:48:35 2002 UTC revision 1.14 by joko, Sun Feb 9 05:12:28 2003 UTC
# Line 1  Line 1 
1  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
2  ##    $Id$  ##    $Id$
3  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
4  ##    $Log$  ##    $Log$
5    ##    Revision 1.14  2003/02/09 05:12:28  joko
6    ##    + quoting of strings used in sql-queries!
7    ##
8    ##    Revision 1.13  2003/01/30 22:27:05  joko
9    ##    + added new abstract methods
10    ##
11    ##    Revision 1.12  2003/01/30 21:46:32  joko
12    ##    + fixed behaviour of AUTOLOAD-method
13    ##
14    ##    Revision 1.11  2003/01/20 16:43:18  joko
15    ##    + better argument-property merging
16    ##    + debugging-output !!!
17    ##    + abstract-dummy 'sub createChildNode'
18    ##
19    ##    Revision 1.10  2003/01/19 02:31:51  joko
20    ##    + fix to 'sub AUTOLOAD'
21    ##
22    ##    Revision 1.9  2002/12/19 16:30:23  joko
23    ##    + added 'sub dropDb' and 'sub rebuildDb' as croakers for concrete implementations of methods in proper handlers
24    ##
25  ##    Revision 1.8  2002/12/13 21:48:35  joko  ##    Revision 1.8  2002/12/13 21:48:35  joko
26  ##    + sub _abstract_function  ##    + sub _abstract_function
27  ##  ##
# Line 27  Line 47 
47  ##  ##
48  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko
49  ##    + new  ##    + new
50  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
51    
52    
53  package Data::Storage::Handler::Abstract;  package Data::Storage::Handler::Abstract;
# Line 37  use warnings; Line 57  use warnings;
57    
58  use base qw( DesignPattern::Object );  use base qw( DesignPattern::Object );
59    
60    
61  use Data::Dumper;  use Data::Dumper;
62  use Tie::SecureHash;  use Tie::SecureHash;
63  #use Data::Storage::Handler;  #use Data::Storage::Handler;
64    use Data::Transform::Deep qw( merge );
65    
66    
67  # get logger instance  # get logger instance
68  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 62  sub new { Line 85  sub new {
85    bless $self, $class;    bless $self, $class;
86  =cut  =cut
87    
88    #=pod
89    # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash...    # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash...
90    my $self = Tie::SecureHash->new(    my $self = Tie::SecureHash->new(
91      $class,      $class,
# Line 86  sub new { Line 109  sub new {
109        #_protected => ,        #_protected => ,
110        #__private => ,        #__private => ,
111    );    );
112    #=cut
113    
114    # 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
115        
116      # mungle arguments from array into hash - perl does the job  ;)      # mungle arguments from array into hash - perl does the job  ;)
117      my %args = @_;      #my %args = @_;
118          #my %args = ();
119    
120    #print Dumper(@_);
121    
122      # merge attributes one-by-one      # merge attributes one-by-one
123      # TODO: deep_copy? / merge_deep?      # TODO: deep_copy? / merge_deep?
124      foreach (keys %args) {      while (my $elemName = shift @_) {
125        #print "key: $_", "\n";        #print "elemName: $elemName", "\n";
126        $self->{$_} = $args{$_};        if (my $elemValue = shift @_) {
127            #print Dumper($elemValue);
128            #print "elemName=$elemName, elemValue=$elemValue", "\n";
129            $self->{$elemName} = $elemValue;
130          }
131          #$self->{$_} = $args{$_};
132          #$self->{$_} = $args{$_};
133      }      }
134        
135    # 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 121  sub new { Line 153  sub new {
153  }  }
154    
155    
156    # TODO: use NEXT.pm inside this mechanism (to avoid repetitions...)
157  sub AUTOLOAD {  sub AUTOLOAD {
158    
159    # recursion problem to be avoided here!!!    # recursion problem to be avoided here!!!
# Line 157  sub AUTOLOAD { Line 190  sub AUTOLOAD {
190    #if (!$self->exists('COREHANDLE')) { return; }    #if (!$self->exists('COREHANDLE')) { return; }
191    
192    # handle locking (hack)    # handle locking (hack)
193    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}) {
194      $self->{lock_info}->{log_lock} = 1;      $self->{lock_info}->{log_lock} = 1;
195    } else {    } else {
196      $self->{lock_info}->{log_lock} = 0;      $self->{lock_info}->{log_lock} = 0;
# Line 178  sub AUTOLOAD { Line 211  sub AUTOLOAD {
211    #if (!$self->exists('_COREHANDLE')) {    #if (!$self->exists('_COREHANDLE')) {
212    #if (!$self->{_COREHANDLE}) {    #if (!$self->{_COREHANDLE}) {
213    if (!$core) {    if (!$core) {
214      my $err_msg_core = __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";  
215  print $err_msg_core, "\n";  #print Dumper($self);    
216      if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {  #exit;
217    
218        my $handlertype = $self->{metainfo}->{type};
219        $handlertype ||= '';
220    
221        my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";
222    
223    #print $err_msg_core, "\n";
224    
225        #if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {
226        $logger->error( $err_msg_core );        $logger->error( $err_msg_core );
227      }      #}
228    
229      return;      return;
230        
231    }    }
232  #=cut  #=cut
233    
# Line 224  print $err_msg_core, "\n"; Line 268  print $err_msg_core, "\n";
268            
269  #print "calling: $methodname", "\n";  #print "calling: $methodname", "\n";
270            
271      # 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
272      return $core->$methodname(@_);      return $core->$methodname(@_);
273        
274    } elsif ($self->can($methodname)) {    } elsif ($self->can($methodname)) {
275        # try to call specified method inside our or inherited module(s) scope(s)
276      return $self->$methodname(@_);      return $self->$methodname(@_);
277    }    }
278    
# Line 263  sub _typeCheck2 { Line 308  sub _typeCheck2 {
308    sub existsChildNode {    sub existsChildNode {
309      my $self = shift;      my $self = shift;
310      my $nodename = shift;      my $nodename = shift;
311      #$nodename = 'TransactionRoutingTable';  
312      $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" );      # TODO: don't use $self->{meta}->{childnodes} directly in here
313        # get it returned from $self->getChildNodes()!!!
314    
315        $logger->debug( __PACKAGE__ . "->existsChildNode( nodename=$nodename )" );
316      $self->getChildNodes() unless $self->{meta}->{childnodes};      $self->getChildNodes() unless $self->{meta}->{childnodes};
317      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!  
318        # quote this, it might contain meta characters which don't work in a regex
319          $nodename = quotemeta($nodename);
320    
321        # trace
322          #print Dumper($self->{meta});
323          #print "nodename: $nodename", "\n";
324        
325        # FIXME: use "/i" only on win32-systems!
326        my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});
327        
328      return $result;      return $result;
329    }    }
330    
# Line 301  sub _typeCheck2 { Line 359  sub _typeCheck2 {
359      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
360    }    }
361    
362      sub createChildNode {
363        my $self = shift;
364        $self->_abstract_function('createChildNode');
365      }
366    
367    sub existsChildNode_tmp {    sub existsChildNode_tmp {
368      my $self = shift;      my $self = shift;
369      $self->_abstract_function('existsChildNode');      $self->_abstract_function('existsChildNode');
# Line 370  sub _typeCheck2 { Line 433  sub _typeCheck2 {
433      return;      return;
434    }    }
435    
436      sub dropDb {
437        my $self = shift;
438        $self->_abstract_function('dropDb');
439        return;
440      }
441    
442      sub rebuildDb {
443        my $self = shift;
444        $self->_abstract_function('rebuildDb');
445        return;
446      }
447    
448      sub getDbName {
449        my $self = shift;
450        $self->_abstract_function('getDbName');
451        return;
452      }
453    
454      sub testAvailability {
455        my $self = shift;
456        $self->_abstract_function('testAvailability');
457        return;
458      }
459    
460      sub isConnected {
461        my $self = shift;
462        $self->_abstract_function('isConnected');
463        return;
464      }
465    
466      sub testDsn {
467        my $self = shift;
468        $self->_abstract_function('testDsn');
469        return;
470      }
471    
472  1;  1;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.14

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