/[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.2 by joko, Thu Oct 17 00:08:07 2002 UTC revision 1.6 by joko, Tue Dec 3 15:52:24 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.6  2002/12/03 15:52:24  joko
7    #  + fix/feature: if dispatching to deep core method fails (is not declared), try method at Data::Storage - level
8    #
9    #  Revision 1.5  2002/12/01 22:19:33  joko
10    #  + just disconnect if COREHANDLE exists
11    #
12    #  Revision 1.4  2002/12/01 04:45:38  joko
13    #  + sub eraseAll
14    #  + sub createDb
15    #
16    #  Revision 1.3  2002/11/29 04:58:20  joko
17    #  + Storage::Result now uses the same dispatching mechanism like Storage::Handler
18    #
19  #  Revision 1.2  2002/10/17 00:08:07  joko  #  Revision 1.2  2002/10/17 00:08:07  joko
20  #  + bugfixes regarding "deep recursion" stuff  #  + bugfixes regarding "deep recursion" stuff
21  #  #
# Line 32  sub new { Line 45  sub new {
45      $logger->debug( "$invocant->new( @_ )" );      $logger->debug( "$invocant->new( @_ )" );
46      #$logger->debug( __PACKAGE__ . "->" . "new()" );      #$logger->debug( __PACKAGE__ . "->" . "new()" );
47    
48      # arguments become properties
49      my $self = { @_ };
50      # create object from blessed hash-reference
51      bless $self, $class;
52    
53    # handle meta data    # handle meta data
54      my $metainfo = _getMetaInfo($class);      #my $metainfo = $self->getMetaInfo($class);
55        my $metainfo = $self->getMetaInfo();
56      if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; }      if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; }
57      # type?      # type?
58      $invocant =~ s/Data::Storage::Handler:://;      $invocant =~ s/Data::Storage::Handler:://;
59      $metainfo->{type} = $invocant;      $metainfo->{type} = $invocant;
60    
   # create object from blessed hash-reference  
61      # direct accessible (non-protected) properties         ( was: my $self = { }; )      # direct accessible (non-protected) properties         ( was: my $self = { }; )
62      my $self = { metainfo => $metainfo, @_ };      $self->{metainfo} = $metainfo;
     bless $self, $class;  
63    
64    return $self;    return $self;
65  }  }
# Line 106  sub AUTOLOAD { Line 123  sub AUTOLOAD {
123      }      }
124      #$lock_AUTOLOAD = 0;      #$lock_AUTOLOAD = 0;
125      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );
126        
127        # method calls doing it until here will get dispatched to the proper handler
128      return $self->{COREHANDLE}->$methodname(@_);      return $self->{COREHANDLE}->$methodname(@_);
129      
130      } elsif ($self->can($methodname)) {
131        return $self->$methodname(@_);
132    }    }
133    
134  }  }
# Line 120  sub DESTROY { Line 142  sub DESTROY {
142    
143      # call "disconnect" or alike on COREHANDLE      # call "disconnect" or alike on COREHANDLE
144      # was: $self->{COREHANDLE}->disconnect();      # was: $self->{COREHANDLE}->disconnect();
145      $disconnectMethod && ( $self->{COREHANDLE}->$disconnectMethod() );      $disconnectMethod && $self->{COREHANDLE} && ( $self->{COREHANDLE}->$disconnectMethod() );
146    
147      undef $self->{COREHANDLE};      undef $self->{COREHANDLE};
148    }    }
# Line 141  sub _typeCheck { Line 163  sub _typeCheck {
163    eval("use Data::Storage::$type;");    eval("use Data::Storage::$type;");
164  }  }
165    
 sub _getMetaInfo {  
   my $packagename = shift;  
   #return $self->$metainfo;  
   
   my $ns = '$' . $packagename . "::metainfo";  
   $logger->debug( __PACKAGE__ . "->" . "_getMetaInfo()" . "   " . "[$ns]" );  
   return eval($ns);  
 }  
   
166    
167  # ====================================================  # ====================================================
168  #   PUBLIC METHODS  #   PUBLIC METHODS
169  # ====================================================  # ====================================================
170    
171    # 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 {  
       
172      my $self = shift;      my $self = shift;
173      $self->_abstract_function('connect');      my $nodename = shift;
174      return;      #$nodename = 'TransactionRoutingTable';
175            $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" );
176      $logger->debug( "\"connect\" has to be implemented by handler!" );      $self->getChildNodes() unless $self->{meta}->{childnodes};
177      return;      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!
178        return $result;
179      }
180    
181      sub connect_tmp {
182            
183  #    my $self = shift;  #    my $self = shift;
184  #    my $connectionString = shift;  #    my $connectionString = shift;
# Line 174  sub _getMetaInfo { Line 187  sub _getMetaInfo {
187    
188    }    }
189        
190    
191    # ====================================================
192    #   CONCRETE METHOD DUMMIES (croaking via "$logger" by calling "_abstract_function")
193    # ====================================================
194    
195      # TODO:
196      #   - abstract "abstract methods" to list/hash to be used in AUTOLOAD
197      #      e.g.: my @ABSTRACT_METHODS = (qw( connect sendCommand getChildNodes ));
198      #      use Class::XYZ (Construct)
199      #   - build them via anonymous subs
200      #   - introduce them via symbols
201    
202    sub sendCommand {    sub sendCommand {
203      my $self = shift;      my $self = shift;
204      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
# Line 189  sub _getMetaInfo { Line 214  sub _getMetaInfo {
214      $self->_abstract_function('configureCOREHANDLE');      $self->_abstract_function('configureCOREHANDLE');
215    }    }
216    
 1;  
217      sub getMetaInfo {
218        my $self = shift;
219        $self->_abstract_function('getMetaInfo');
220        return;
221      }
222    
223      sub getListUnfiltered {
224        my $self = shift;
225        $self->_abstract_function('getListUnfiltered');
226        return;
227      }
228    
229      sub getListFiltered {
230        my $self = shift;
231        $self->_abstract_function('getListFiltered');
232        return;
233      }
234    
235      sub sendQuery {
236        my $self = shift;
237        $self->_abstract_function('sendQuery');
238        return;
239      }
240    
241      sub connect {
242        my $self = shift;
243        $self->_abstract_function('connect');
244        return;
245      }
246    
247      sub testIntegrity {
248        my $self = shift;
249        $self->_abstract_function('testIntegrity');
250        return;
251      }
252    
253      sub quoteSql {
254        my $self = shift;
255        $self->_abstract_function('quoteSql');
256        return;
257      }
258    
259      sub eraseAll {
260        my $self = shift;
261        $self->_abstract_function('eraseAll');
262        return;
263      }
264    
265      sub createDb {
266        my $self = shift;
267        $self->_abstract_function('createDb');
268        return;
269      }
270    
271    1;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

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