/[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.1 by cvsjoko, Thu Oct 10 03:44:07 2002 UTC revision 1.3 by joko, Fri Nov 29 04:58:20 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.3  2002/11/29 04:58:20  joko
7    #  + Storage::Result now uses the same dispatching mechanism like Storage::Handler
8    #
9    #  Revision 1.2  2002/10/17 00:08:07  joko
10    #  + bugfixes regarding "deep recursion" stuff
11    #
12  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko
13  #  + new  #  + new
14  #  #
# Line 26  sub new { Line 32  sub new {
32    my $class = ref($invocant) || $invocant;    my $class = ref($invocant) || $invocant;
33        
34    # logging info about the actual handler called    # logging info about the actual handler called
     $logger->debug( __PACKAGE__ . "->" . "new()" );  
35      $logger->debug( "$invocant->new( @_ )" );      $logger->debug( "$invocant->new( @_ )" );
36        #$logger->debug( __PACKAGE__ . "->" . "new()" );
37    
38      # arguments become properties
39      my $self = { @_ };
40      # create object from blessed hash-reference
41      bless $self, $class;
42    
43    # handle meta data    # handle meta data
44      my $metainfo = _getMetaInfo($class);      #my $metainfo = $self->getMetaInfo($class);
45        my $metainfo = $self->getMetaInfo();
46      if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; }      if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; }
47      # type?      # type?
48      $invocant =~ s/Data::Storage::Handler:://;      $invocant =~ s/Data::Storage::Handler:://;
49      $metainfo->{type} = $invocant;      $metainfo->{type} = $invocant;
50    
   # create object from blessed hash-reference  
51      # direct accessible (non-protected) properties         ( was: my $self = { }; )      # direct accessible (non-protected) properties         ( was: my $self = { }; )
52      my $self = { metainfo => $metainfo, @_ };      $self->{metainfo} = $metainfo;
     bless $self, $class;  
53    
54    return $self;    return $self;
55  }  }
# Line 56  sub AUTOLOAD { Line 66  sub AUTOLOAD {
66      # - why:  debug-messages are on a very low level including every data-operation to "Data::Storage(::Handler::X)",      # - why:  debug-messages are on a very low level including every data-operation to "Data::Storage(::Handler::X)",
67      #             so e.g. a "$storage->insert" would trigger another "$storage->insert" itself      #             so e.g. a "$storage->insert" would trigger another "$storage->insert" itself
68      #             which leads to a infinite recursion loop (deep recursion)      #             which leads to a infinite recursion loop (deep recursion)
69      # - solution: locks! (by Hack or via Perl "local"s)      # - solution: locks! (by Hack or (maybe) via Perl "local"s)
70    
71    my $self = shift;    my $self = shift;
72    
# Line 77  sub AUTOLOAD { Line 87  sub AUTOLOAD {
87        
88    # test for COREHANDLE    # test for COREHANDLE
89    if (!$self->{COREHANDLE}) {    if (!$self->{COREHANDLE}) {
90      $logger->error( __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"" );      #print "no COREHANDLE", "\n";
91        if (!$self->{lock_info}->{log_lock}) {
92          $logger->error( __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"" );
93        }
94      return;      return;
95    }    }
96    
# Line 100  sub AUTOLOAD { Line 113  sub AUTOLOAD {
113      }      }
114      #$lock_AUTOLOAD = 0;      #$lock_AUTOLOAD = 0;
115      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );
116        
117        # method calls doing it until here will get dispatched to the proper handler
118      return $self->{COREHANDLE}->$methodname(@_);      return $self->{COREHANDLE}->$methodname(@_);
119    }    }
120    
# Line 135  sub _typeCheck { Line 150  sub _typeCheck {
150    eval("use Data::Storage::$type;");    eval("use Data::Storage::$type;");
151  }  }
152    
 sub _getMetaInfo {  
   my $packagename = shift;  
   #return $self->$metainfo;  
   
   my $ns = '$' . $packagename . "::metainfo";  
   $logger->debug( __PACKAGE__ . "->" . "_getMetaInfo()" . "   " . "[$ns]" );  
   return eval($ns);  
 }  
   
153    
154  # ====================================================  # ====================================================
155  #   PUBLIC METHODS  #   PUBLIC METHODS
156  # ====================================================  # ====================================================
157    
158    # TODO: abstract "abstract methods" to list/hash to be used in AUTOLOAD    sub existsChildNode {
   # e.g.: my @ABSTRACT_METHODS = (qw( connect sendCommand getChildNodes ));  
   
   sub connect {  
       
159      my $self = shift;      my $self = shift;
160      $self->_abstract_function('connect');      my $nodename = shift;
161      return;      #$nodename = 'TransactionRoutingTable';
162            $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" );
163      $logger->debug( "\"connect\" has to be implemented by handler!" );      $self->getChildNodes() unless $self->{meta}->{childnodes};
164      return;      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!
165        return $result;
166      }
167    
168      sub connect_tmp {
169            
170  #    my $self = shift;  #    my $self = shift;
171  #    my $connectionString = shift;  #    my $connectionString = shift;
# Line 168  sub _getMetaInfo { Line 174  sub _getMetaInfo {
174    
175    }    }
176        
177    
178    # ====================================================
179    #   CONCRETE METHOD DUMMIES (croaking via "$logger" by calling "_abstract_function")
180    # ====================================================
181    
182      # TODO:
183      #   - abstract "abstract methods" to list/hash to be used in AUTOLOAD
184      #      e.g.: my @ABSTRACT_METHODS = (qw( connect sendCommand getChildNodes ));
185      #   - build them via anonymous subs
186      #   - introduce them via symbols
187    
188    sub sendCommand {    sub sendCommand {
189      my $self = shift;      my $self = shift;
190      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
# Line 183  sub _getMetaInfo { Line 200  sub _getMetaInfo {
200      $self->_abstract_function('configureCOREHANDLE');      $self->_abstract_function('configureCOREHANDLE');
201    }    }
202    
 1;  
203      sub getMetaInfo {
204        my $self = shift;
205        $self->_abstract_function('getMetaInfo');
206        return;
207      }
208    
209      sub getListUnfiltered {
210        my $self = shift;
211        $self->_abstract_function('getListUnfiltered');
212        return;
213      }
214    
215      sub getListFiltered {
216        my $self = shift;
217        $self->_abstract_function('getListFiltered');
218        return;
219      }
220    
221      sub sendQuery {
222        my $self = shift;
223        $self->_abstract_function('sendQuery');
224        return;
225      }
226    
227      sub connect {
228        my $self = shift;
229        $self->_abstract_function('connect');
230        return;
231      }
232    
233      sub testIntegrity {
234        my $self = shift;
235        $self->_abstract_function('testIntegrity');
236        return;
237      }
238    
239      sub quoteSql {
240        my $self = shift;
241        $self->_abstract_function('quoteSql');
242        return;
243      }
244    
245    1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

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