/[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.8 by joko, Fri Nov 29 04:48:23 2002 UTC revision 1.12 by joko, Thu Dec 12 02:50:15 2002 UTC
# Line 7  Line 7 
7  ############################################  ############################################
8  #  #
9  #  $Log$  #  $Log$
10    #  Revision 1.12  2002/12/12 02:50:15  joko
11    #  + this now (unfortunately) needs DBI for some helper functions
12    #  + TODO: these have to be refactored to another scope! (soon!)
13    #
14    #  Revision 1.11  2002/12/11 06:53:19  joko
15    #  + updated pod
16    #
17    #  Revision 1.10  2002/12/07 03:37:23  joko
18    #  + updated pod
19    #
20    #  Revision 1.9  2002/12/01 22:15:45  joko
21    #  - sub createDb: moved to handler
22    #
23  #  Revision 1.8  2002/11/29 04:48:23  joko  #  Revision 1.8  2002/11/29 04:48:23  joko
24  #  + updated pod  #  + updated pod
25  #  #
# Line 47  BEGIN { Line 60  BEGIN {
60    
61  =head1 NAME  =head1 NAME
62    
63  Data::Storage - Interface for accessing various Storage implementations for Perl in an independent way    Data::Storage - Interface for accessing various Storage implementations for Perl in an independent way
64    
65    
66  =head1 AIMS  =head1 AIMS
# Line 161  Data::Storage - Interface for accessing Line 174  Data::Storage - Interface for accessing
174    
175  =head2 NOTE  =head2 NOTE
176    
177  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.
178  Please look at their documentation and/or this code for additional information.    Please look at their documentation and/or this code for additional information.
179    
180    
181  =head1 REQUIREMENTS  =head1 REQUIREMENTS
# Line 190  use warnings; Line 203  use warnings;
203  use Data::Storage::Locator;  use Data::Storage::Locator;
204  use Data::Dumper;  use Data::Dumper;
205    
206    # TODO: wipe out!
207    use DBI;
208    
209  # TODO: actually implement level (integrate with Log::Dispatch)  # TODO: actually implement level (integrate with Log::Dispatch)
210  my $TRACELEVEL = 0;  my $TRACELEVEL = 0;
211    
# Line 355  sub getDbName { Line 371  sub getDbName {
371    return $database_name;    return $database_name;
372  }  }
373    
 sub testDsn {  
   my $self = shift;  
   my $dsn = $self->{locator}->{dbi}->{dsn};  
   my $result;  
   if ( my $dbh = DBI->connect($dsn, '', '', {  
                                                       PrintError => 0,  
                                                       } ) ) {  
     $dbh->disconnect();  
     return 1;  
   } else {  
     $logger->warning( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr );  
   }  
 }  
   
374  sub testAvailability {  sub testAvailability {
375    my $self = shift;    my $self = shift;
376    my $status = $self->testDsn();    my $status = $self->testDsn();
# Line 376  sub testAvailability { Line 378  sub testAvailability {
378    return $status;    return $status;
379  }  }
380    
381  sub createDb {  sub isConnected {
382    my $self = shift;    my $self = shift;
383    my $dsn = $self->{locator}->{dbi}->{dsn};    # TODO: REVIEW!
384      return 1 if $self->{STORAGEHANDLE};
385    $logger->debug( __PACKAGE__ .  "->createDb( dsn $dsn )" );  }
   
   $dsn =~ s/database=(.+?);//;  
   my $database_name = $1;  
386    
387    my $ok;  sub testDsn {
388        my $self = shift;
389      my $dsn = $self->{locator}->{dbi}->{dsn};
390      my $result;
391    if ( my $dbh = DBI->connect($dsn, '', '', {    if ( my $dbh = DBI->connect($dsn, '', '', {
392                                                        PrintError => 0,                                                        PrintError => 0,
393                                                        } ) ) {                                                        } ) ) {
394      if ($database_name) {      
395        if ($dbh->do("CREATE DATABASE $database_name;")) {      # TODO: REVIEW
         $ok = 1;  
       }  
     }  
396      $dbh->disconnect();      $dbh->disconnect();
397        
398        return 1;
399      } else {
400        $logger->warning( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr );
401    }    }
     
   return $ok;  
     
402  }  }
403    
404  sub dropDb {  sub dropDb {
# Line 421  sub dropDb { Line 420  sub dropDb {
420          $ok = 1;          $ok = 1;
421        }        }
422      }      }
423    
424      $dbh->disconnect();      $dbh->disconnect();
425    
426    }    }
427        
428    return $ok;    return $ok;
429  }  }
430    
 sub isConnected {  
   my $self = shift;  
   return 1 if $self->{STORAGEHANDLE};  
 }  
   
431  1;  1;
432  __END__  __END__
433    
434    
435  =head1 DESCRIPTION  =head1 DESCRIPTION
436    
437  Data::Storage is a module for accessing various "data structures" stored inside  =head2 Data::Storage
 various "data containers". It sits on top of DBI and/or Tangram.  
438    
439      Data::Storage is a module for accessing various "data structures / kinds of structured data" stored inside
440      various "data containers".
441      We tried to use the AdapterPattern (http://c2.com/cgi/wiki?AdapterPattern) to implement a wrapper-layer
442      around core CPAN modules (Tangram, DBI).
443    
444    =head2 Why?
445    
446      You will get a better code-structure (not bad for later maintenance) in growing Perl code projects,
447      especially when using multiple database connections at the same time.
448      You will be able to switch between different _kinds_ of implementations used for storing data.
449      Your code will use the very same API to access these storage layers.
450          ... implementation has to be changed for now
451      Maybe you will be able to switch "on-the-fly" without changing any bits in code in the future....
452          ... but that's not the focus
453    
454  =head1 AUTHORS / COPYRIGHT  =head2 What else?
455    
456  The Data::Storage module is Copyright (c) 2002 Andreas Motl.    Having this, we were able to do implement a generic data synchronization module more easy,
457  All rights reserved.    please look at Data::Transfer.
458    
459  You may distribute it under the terms of either the GNU General Public  
460  License or the Artistic License, as specified in the Perl README file.  =head1 AUTHORS / COPYRIGHT
461    
462      The Data::Storage module is Copyright (c) 2002 Andreas Motl.
463      All rights reserved.
464      You may distribute it under the terms of either the GNU General Public
465      License or the Artistic License, as specified in the Perl README file.
466    
467    
468  =head1 ACKNOWLEDGEMENTS  =head1 ACKNOWLEDGEMENTS
469    
470  Larry Wall for Perl, Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object,    Larry Wall for Perl, Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object,
471  Sam Vilain for Class::Tangram, Jochen Wiedmann and Jeff Zucker for DBD::CSV and related,    Sam Vilain for Class::Tangram, Jochen Wiedmann and Jeff Zucker for DBD::CSV & Co.,
472  Adam Spiers for MySQL::Diff and all contributors.    Adam Spiers for MySQL::Diff and all contributors.
473    
474    
475  =head1 SUPPORT / WARRANTY  =head1 SUPPORT / WARRANTY
476    
477  Data::Storage is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.    Data::Storage is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
478    
479    
480  =head1 TODO  =head1 TODO
# Line 531  Compare schema (structure diff) with dat Line 545  Compare schema (structure diff) with dat
545      -  .pst - files (Outlook Post Storage?)      -  .pst - files (Outlook Post Storage?)
546      -  XML (e.g. via XML::Simple?)      -  XML (e.g. via XML::Simple?)
547    - Move to t3, look at InCASE    - Move to t3, look at InCASE
548      - some kind of security layer for methods/objects
549        - acls (stored via tangram/ldap?) for functions, methods and objects (entity- & data!?)
550        - where are the hooks needed then?
551          - is Data::Storage & Co. okay, or do we have to touch the innards of DBI and/or Tangram?
552          - an attempt to start could be:
553             - 'sub getACLByObjectId($id, $context)'
554             - 'sub getACLByMethodname($id, $context)'
555             - 'sub getACLByName($id, $context)'
556                ( would require a kinda registry to look up these very names pointing to arbitrary locations (code, data, ...) )
557    
558    
559    
560  =head3 LINKS / REFERENCES  =head3 LINKS / REFERENCES

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

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