/[cvs]/nfo/perl/libs/Data/Storage.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by joko, Tue Oct 29 19:24:18 2002 UTC revision 1.7 by joko, Sun Nov 17 06:07:18 2002 UTC
# Line 7  Line 7 
7  #################################  #################################
8  #  #
9  #  $Log$  #  $Log$
10    #  Revision 1.7  2002/11/17 06:07:18  joko
11    #  + creating the handler is easier than proposed first - for now :-)
12    #  + sub testAvailability
13    #
14    #  Revision 1.6  2002/11/09 01:04:58  joko
15    #  + updated pod
16    #
17  #  Revision 1.5  2002/10/29 19:24:18  joko  #  Revision 1.5  2002/10/29 19:24:18  joko
18  #  - reduced logging  #  - reduced logging
19  #  + added some pod  #  + added some pod
# Line 66  Data::Storage - Interface for accessing Line 73  Data::Storage - Interface for accessing
73  =head2 NOTE  =head2 NOTE
74    
75  This module heavily relies on DBI and Tangram, but adds a lot of additional bugs and quirks.  This module heavily relies on DBI and Tangram, but adds a lot of additional bugs and quirks.
76  Please look at their documentation and this code for additional information.  Please look at their documentation and/or this code for additional information.
77    
78    
79    =head1 REQUIREMENTS
80    
81    For full functionality:
82      DBI              from CPAN
83      Tangram          from CPAN
84      Class::Tangram   from CPAN
85      MySQL::Diff      from http://adamspiers.org/computing/mysqldiff/
86      ... and all their dependencies
87    
88  =cut  =cut
89    
# Line 80  use strict; Line 96  use strict;
96  use warnings;  use warnings;
97    
98  use Data::Storage::Locator;  use Data::Storage::Locator;
99    use Data::Dumper;
100    
101    # TODO: actually implement level (integrate with Log::Dispatch)
102  my $TRACELEVEL = 0;  my $TRACELEVEL = 0;
103    
104  # get logger instance  # get logger instance
# Line 90  sub new { Line 108  sub new {
108    my $invocant = shift;    my $invocant = shift;
109    my $class = ref($invocant) || $invocant;    my $class = ref($invocant) || $invocant;
110    #my @args = normalizeArgs(@_);    #my @args = normalizeArgs(@_);
111      
112    my $arg_locator = shift;    my $arg_locator = shift;
113    my $arg_options = shift;    my $arg_options = shift;
114      
115    #my $self = { STORAGEHANDLE => undef, @_ };    #my $self = { STORAGEHANDLE => undef, @_ };
116    my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options };    my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options };
117    $logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" );    #$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" );
118      $logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" );
119    return bless $self, $class;    return bless $self, $class;
120  }  }
121    
# Line 131  sub AUTOLOAD { Line 150  sub AUTOLOAD {
150        #            e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c))          (AUTOLOAD)"        #            e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c))          (AUTOLOAD)"
151        # but that would be way too specific as long as we don't have an abstract handler for this  ;)        # but that would be way too specific as long as we don't have an abstract handler for this  ;)
152        $logger->debug( $logstring );        $logger->debug( $logstring );
153          #print join('; ', @_);
154      }      }
155            
156    # filtering AUTOLOAD calls    # filtering AUTOLOAD calls
157    if ($self->_filter_AUTOLOAD($method)) {    if ($self->_filter_AUTOLOAD($method)) {
158        #print "_accessStorage\n";
159      $self->_accessStorage();      $self->_accessStorage();
160      $self->{STORAGEHANDLE}->$method(@_);      $self->{STORAGEHANDLE}->$method(@_);
161    }    }
# Line 175  sub _accessStorage { Line 196  sub _accessStorage {
196    
197  sub _createStorageHandle {  sub _createStorageHandle {
198    my $self = shift;    my $self = shift;
   
199    my $type = $self->{locator}->{type};    my $type = $self->{locator}->{type};
200    $logger->debug( __PACKAGE__ .  "[$type]" . "->_createStorageHandle()" );    $logger->debug( __PACKAGE__ .  "[$type]" . "->_createStorageHandle()" );
201    
202    my $pkg = "Data::Storage::Handler::" . $type . "";    my $pkg = "Data::Storage::Handler::" . $type . "";
203        
204    # propagate args to handler    # try to load perl module at runtime
205    # needs some more thoughts! (not only "dbi" to Tangram, when (in future) db is not more the common case)    my $evalstr = "use $pkg;";
206    if ($type eq 'DBI') {    eval($evalstr);
207      use Data::Storage::Handler::DBI;    if ($@) {
208      #my @args = %{$self->{locator}->{dbi}};      $logger->error( __PACKAGE__ .  "[$type]" . "->_createStorageHandle(): $@" );
209      my @args = %{$self->{locator}};      return;
     # create new storage handle  
     $self->{STORAGEHANDLE} = $pkg->new( @args );  
   }  
   if ($type eq 'Tangram') {  
     use Data::Storage::Handler::Tangram;  
     #$self->{STORAGEHANDLE} = $pkg->new( dsn => $self->{locator}->{dbi}->{dsn} );  
     #my @args = %{$self->{locator}->{dbi}};  
     my @args = %{$self->{locator}};  
     # create new storage handle  
     $self->{STORAGEHANDLE} = $pkg->new( @args );  
   
     #$self->{STORAGEHANDLE_UNDERLYING} = $self->{STORAGEHANDLE}->getUnderlyingStorage();  
     #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE();  
210    }    }
211        
212      # build up some additional arguments to pass on
213      #my @args = %{$self->{locator}};
214      my @args = ();
215    
216      # create new storage handle object, propagate arguments to handler
217      # pass locator by reference to be able to store status information in it
218      $self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args );
219    
220  }  }
221    
222  sub addLogDispatchHandler {  sub addLogDispatchHandler {
# Line 260  sub testDsn { Line 275  sub testDsn {
275      $dbh->disconnect();      $dbh->disconnect();
276      return 1;      return 1;
277    } else {    } else {
278      $logger->error( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr );      $logger->warning( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr );
279    }    }
280  }  }
281    
282    sub testAvailability {
283      my $self = shift;
284      my $status = $self->testDsn();
285      $self->{locator}->{status}->{available} = $status;
286      return $status;
287    }
288    
289  sub createDb {  sub createDb {
290    my $self = shift;    my $self = shift;
291    my $dsn = $self->{locator}->{dbi}->{dsn};    my $dsn = $self->{locator}->{dbi}->{dsn};
# Line 341  License or the Artistic License, as spec Line 363  License or the Artistic License, as spec
363    
364  =head1 ACKNOWLEDGEMENTS  =head1 ACKNOWLEDGEMENTS
365    
366  Larry Wall and the C<perl5-porters> for Perl,  Larry Wall for Perl, Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object,
367  Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object,  Sam Vilain for Class::Tangram, Adam Spiers for MySQL::Diff and all contributors.
 Sam Vilain for Class::Tangram.  
368    
369    
370  =head1 SUPPORT / WARRANTY  =head1 SUPPORT / WARRANTY
# Line 434  Data::Storage is free software. IT COMES Line 455  Data::Storage is free software. IT COMES
455      (Dia (free): http://www.lysator.liu.se/~alla/dia/)      (Dia (free): http://www.lysator.liu.se/~alla/dia/)
456      UMLet (free, university): http://www.swt.tuwien.ac.at/umlet/index.html      UMLet (free, university): http://www.swt.tuwien.ac.at/umlet/index.html
457      Voodoo (free): http://voodoo.sourceforge.net/      Voodoo (free): http://voodoo.sourceforge.net/
458        Umbrello UML Modeller: http://uml.sourceforge.net/
459    
460    UML Tools:    UML Tools:
461      http://www.objectsbydesign.com/tools/umltools_byPrice.html      http://www.objectsbydesign.com/tools/umltools_byPrice.html

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.7

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