/[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.4 by joko, Sun Dec 1 04:45:38 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.4  2002/12/01 04:45:38  joko
7    #  + sub eraseAll
8    #  + sub createDb
9    #
10    #  Revision 1.3  2002/11/29 04:58:20  joko
11    #  + Storage::Result now uses the same dispatching mechanism like Storage::Handler
12    #
13    #  Revision 1.2  2002/10/17 00:08:07  joko
14    #  + bugfixes regarding "deep recursion" stuff
15    #
16  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko
17  #  + new  #  + new
18  #  #
# Line 26  sub new { Line 36  sub new {
36    my $class = ref($invocant) || $invocant;    my $class = ref($invocant) || $invocant;
37        
38    # logging info about the actual handler called    # logging info about the actual handler called
     $logger->debug( __PACKAGE__ . "->" . "new()" );  
39      $logger->debug( "$invocant->new( @_ )" );      $logger->debug( "$invocant->new( @_ )" );
40        #$logger->debug( __PACKAGE__ . "->" . "new()" );
41    
42      # arguments become properties
43      my $self = { @_ };
44      # create object from blessed hash-reference
45      bless $self, $class;
46    
47    # handle meta data    # handle meta data
48      my $metainfo = _getMetaInfo($class);      #my $metainfo = $self->getMetaInfo($class);
49        my $metainfo = $self->getMetaInfo();
50      if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; }      if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; }
51      # type?      # type?
52      $invocant =~ s/Data::Storage::Handler:://;      $invocant =~ s/Data::Storage::Handler:://;
53      $metainfo->{type} = $invocant;      $metainfo->{type} = $invocant;
54    
   # create object from blessed hash-reference  
55      # direct accessible (non-protected) properties         ( was: my $self = { }; )      # direct accessible (non-protected) properties         ( was: my $self = { }; )
56      my $self = { metainfo => $metainfo, @_ };      $self->{metainfo} = $metainfo;
     bless $self, $class;  
57    
58    return $self;    return $self;
59  }  }
# Line 56  sub AUTOLOAD { Line 70  sub AUTOLOAD {
70      # - 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)",
71      #             so e.g. a "$storage->insert" would trigger another "$storage->insert" itself      #             so e.g. a "$storage->insert" would trigger another "$storage->insert" itself
72      #             which leads to a infinite recursion loop (deep recursion)      #             which leads to a infinite recursion loop (deep recursion)
73      # - solution: locks! (by Hack or via Perl "local"s)      # - solution: locks! (by Hack or (maybe) via Perl "local"s)
74    
75    my $self = shift;    my $self = shift;
76    
# Line 77  sub AUTOLOAD { Line 91  sub AUTOLOAD {
91        
92    # test for COREHANDLE    # test for COREHANDLE
93    if (!$self->{COREHANDLE}) {    if (!$self->{COREHANDLE}) {
94      $logger->error( __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"" );      #print "no COREHANDLE", "\n";
95        if (!$self->{lock_info}->{log_lock}) {
96          $logger->error( __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"" );
97        }
98      return;      return;
99    }    }
100    
# Line 100  sub AUTOLOAD { Line 117  sub AUTOLOAD {
117      }      }
118      #$lock_AUTOLOAD = 0;      #$lock_AUTOLOAD = 0;
119      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );      #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" );
120        
121        # method calls doing it until here will get dispatched to the proper handler
122      return $self->{COREHANDLE}->$methodname(@_);      return $self->{COREHANDLE}->$methodname(@_);
123    }    }
124    
# Line 135  sub _typeCheck { Line 154  sub _typeCheck {
154    eval("use Data::Storage::$type;");    eval("use Data::Storage::$type;");
155  }  }
156    
 sub _getMetaInfo {  
   my $packagename = shift;  
   #return $self->$metainfo;  
   
   my $ns = '$' . $packagename . "::metainfo";  
   $logger->debug( __PACKAGE__ . "->" . "_getMetaInfo()" . "   " . "[$ns]" );  
   return eval($ns);  
 }  
   
157    
158  # ====================================================  # ====================================================
159  #   PUBLIC METHODS  #   PUBLIC METHODS
160  # ====================================================  # ====================================================
161    
162    # 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 {  
       
163      my $self = shift;      my $self = shift;
164      $self->_abstract_function('connect');      my $nodename = shift;
165      return;      #$nodename = 'TransactionRoutingTable';
166            $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" );
167      $logger->debug( "\"connect\" has to be implemented by handler!" );      $self->getChildNodes() unless $self->{meta}->{childnodes};
168      return;      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!
169        return $result;
170      }
171    
172      sub connect_tmp {
173            
174  #    my $self = shift;  #    my $self = shift;
175  #    my $connectionString = shift;  #    my $connectionString = shift;
# Line 168  sub _getMetaInfo { Line 178  sub _getMetaInfo {
178    
179    }    }
180        
181    
182    # ====================================================
183    #   CONCRETE METHOD DUMMIES (croaking via "$logger" by calling "_abstract_function")
184    # ====================================================
185    
186      # TODO:
187      #   - abstract "abstract methods" to list/hash to be used in AUTOLOAD
188      #      e.g.: my @ABSTRACT_METHODS = (qw( connect sendCommand getChildNodes ));
189      #      use Class::XYZ (Construct)
190      #   - build them via anonymous subs
191      #   - introduce them via symbols
192    
193    sub sendCommand {    sub sendCommand {
194      my $self = shift;      my $self = shift;
195      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
# Line 183  sub _getMetaInfo { Line 205  sub _getMetaInfo {
205      $self->_abstract_function('configureCOREHANDLE');      $self->_abstract_function('configureCOREHANDLE');
206    }    }
207    
 1;  
208      sub getMetaInfo {
209        my $self = shift;
210        $self->_abstract_function('getMetaInfo');
211        return;
212      }
213    
214      sub getListUnfiltered {
215        my $self = shift;
216        $self->_abstract_function('getListUnfiltered');
217        return;
218      }
219    
220      sub getListFiltered {
221        my $self = shift;
222        $self->_abstract_function('getListFiltered');
223        return;
224      }
225    
226      sub sendQuery {
227        my $self = shift;
228        $self->_abstract_function('sendQuery');
229        return;
230      }
231    
232      sub connect {
233        my $self = shift;
234        $self->_abstract_function('connect');
235        return;
236      }
237    
238      sub testIntegrity {
239        my $self = shift;
240        $self->_abstract_function('testIntegrity');
241        return;
242      }
243    
244      sub quoteSql {
245        my $self = shift;
246        $self->_abstract_function('quoteSql');
247        return;
248      }
249    
250      sub eraseAll {
251        my $self = shift;
252        $self->_abstract_function('eraseAll');
253        return;
254      }
255    
256      sub createDb {
257        my $self = shift;
258        $self->_abstract_function('createDb');
259        return;
260      }
261    
262    1;

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

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