--- nfo/perl/libs/Data/Storage.pm 2002/10/27 18:35:07 1.4 +++ nfo/perl/libs/Data/Storage.pm 2002/11/17 06:07:18 1.7 @@ -1,4 +1,4 @@ -# $Id: Storage.pm,v 1.4 2002/10/27 18:35:07 joko Exp $ +# $Id: Storage.pm,v 1.7 2002/11/17 06:07:18 joko Exp $ # # Copyright (c) 2002 Andreas Motl # @@ -7,6 +7,17 @@ ################################# # # $Log: Storage.pm,v $ +# Revision 1.7 2002/11/17 06:07:18 joko +# + creating the handler is easier than proposed first - for now :-) +# + sub testAvailability +# +# Revision 1.6 2002/11/09 01:04:58 joko +# + updated pod +# +# Revision 1.5 2002/10/29 19:24:18 joko +# - reduced logging +# + added some pod +# # Revision 1.4 2002/10/27 18:35:07 joko # + added pod # @@ -33,6 +44,7 @@ $Data::Storage::VERSION = 0.01; } + =head1 NAME Data::Storage - Interface for accessing various Storage implementations for Perl in an independent way @@ -61,9 +73,18 @@ =head2 NOTE This module heavily relies on DBI and Tangram, but adds a lot of additional bugs and quirks. -Please look at their documentation and this code for additional information. +Please look at their documentation and/or this code for additional information. +=head1 REQUIREMENTS + +For full functionality: + DBI from CPAN + Tangram from CPAN + Class::Tangram from CPAN + MySQL::Diff from http://adamspiers.org/computing/mysqldiff/ + ... and all their dependencies + =cut # The POD text continues at the end of the file. @@ -75,6 +96,10 @@ use warnings; use Data::Storage::Locator; +use Data::Dumper; + +# TODO: actually implement level (integrate with Log::Dispatch) +my $TRACELEVEL = 0; # get logger instance my $logger = Log::Dispatch::Config->instance; @@ -83,13 +108,14 @@ my $invocant = shift; my $class = ref($invocant) || $invocant; #my @args = normalizeArgs(@_); - + my $arg_locator = shift; my $arg_options = shift; - + #my $self = { STORAGEHANDLE => undef, @_ }; my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; - $logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); + #$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); + $logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" ); return bless $self, $class; } @@ -111,20 +137,25 @@ my $method = $AUTOLOAD; $method =~ s/^.*:://; - # advanced logging of AUTOLOAD calls - my $logstring = ""; - $logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method; - #print "count: ", $#_, "\n"; - #$logstring .= Dumper(@_) if ($#_ != -1); - my $tabcount = int( (80 - length($logstring)) / 10 ); - $logstring .= "\t" x $tabcount . "(AUTOLOAD)"; - # TODO: only ok if logstring doesn't contain - # e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" - # but that would be way too specific as long as we don't have an abstract handler for this ;) - $logger->debug( $logstring ); - + # advanced logging of AUTOLOAD calls ... + # ... nice but do it only when TRACING (TODO) is enabled + if ($TRACELEVEL) { + my $logstring = ""; + $logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method; + #print "count: ", $#_, "\n"; + #$logstring .= Dumper(@_) if ($#_ != -1); + my $tabcount = int( (80 - length($logstring)) / 10 ); + $logstring .= "\t" x $tabcount . "(AUTOLOAD)"; + # TODO: only ok if logstring doesn't contain + # e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" + # but that would be way too specific as long as we don't have an abstract handler for this ;) + $logger->debug( $logstring ); + #print join('; ', @_); + } + # filtering AUTOLOAD calls if ($self->_filter_AUTOLOAD($method)) { + #print "_accessStorage\n"; $self->_accessStorage(); $self->{STORAGEHANDLE}->$method(@_); } @@ -155,7 +186,9 @@ sub _accessStorage { my $self = shift; # TODO: to some tracelevel! - $logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->_accessStorage()" ); + if ($TRACELEVEL) { + $logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->_accessStorage()" ); + } if (!$self->{STORAGEHANDLE}) { $self->_createStorageHandle(); } @@ -163,33 +196,27 @@ sub _createStorageHandle { my $self = shift; - my $type = $self->{locator}->{type}; $logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); my $pkg = "Data::Storage::Handler::" . $type . ""; - # propagate args to handler - # needs some more thoughts! (not only "dbi" to Tangram, when (in future) db is not more the common case) - if ($type eq 'DBI') { - use Data::Storage::Handler::DBI; - #my @args = %{$self->{locator}->{dbi}}; - my @args = %{$self->{locator}}; - # 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(); + # try to load perl module at runtime + my $evalstr = "use $pkg;"; + eval($evalstr); + if ($@) { + $logger->error( __PACKAGE__ . "[$type]" . "->_createStorageHandle(): $@" ); + return; } + # build up some additional arguments to pass on + #my @args = %{$self->{locator}}; + my @args = (); + + # create new storage handle object, propagate arguments to handler + # pass locator by reference to be able to store status information in it + $self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args ); + } sub addLogDispatchHandler { @@ -248,10 +275,17 @@ $dbh->disconnect(); return 1; } else { - $logger->error( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); + $logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); } } +sub testAvailability { + my $self = shift; + my $status = $self->testDsn(); + $self->{locator}->{status}->{available} = $status; + return $status; +} + sub createDb { my $self = shift; my $dsn = $self->{locator}->{dbi}->{dsn}; @@ -329,9 +363,8 @@ =head1 ACKNOWLEDGEMENTS -Larry Wall and the C for Perl, -Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object, -Sam Vilain for Class::Tangram. +Larry Wall for Perl, 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. =head1 SUPPORT / WARRANTY @@ -373,29 +406,61 @@ R retrieve -> no, not subject of this aspect since it is about deployment only U update -> yes, just by user-interaction; maybe automatically if it can be determined that data wouldn't be lost D delete -> yes, just by user-interaction - It's all about not to be able to loose data simply while this is in alpha stage. + + It's all about not to be able to loose data simply while this is in pre-alpha stage. + And loosing data by being able to modify and redeploy schemas easily is definitely quite easy. + + As we can see, creations of Classes and new Class variables is handled + automatically and this is believed to be the most common case under normal circumstances. =head2 Introduce some features: - Get this stuff together with UML (Unified Modeling Language) and/or standards from ODMG. - Make it possible to load/save schemas in XMI (XML Metadata Interchange), - which seems to be most commonly used today, perhaps handle objects with OIFML. - Integrate/bundle this with a web-/html-based UML modeling tool or - some other interesting stuff like the "Co-operative UML Editor" from Uni Darmstadt. (web-/java-based) - Enable Round Trip Engineering. Keep code and diagrams in sync. Don't annoy/bother the programmer. + - Get this stuff together with UML (Unified Modeling Language) and/or standards from ODMG. + - Make it possible to load/save schemas in XMI (XML Metadata Interchange), + which seems to be most commonly used today, perhaps handle objects with OIFML. + Integrate/bundle this with a web-/html-based UML modeling tool or + some other interesting stuff like the "Co-operative UML Editor" from Uni Darmstadt. (web-/java-based) + - Enable Round Trip Engineering. Keep code and diagrams in sync. Don't annoy/bother the programmers. + - Add some more handlers: + - look at DBD::CSV, Text::CSV, XML::CSV, XML::Excel + - Add some more locations/locators: + - PerlDAV: http://www.webdav.org/perldav/ + - Move to t3, use InCASE =head3 Links: + Specs: UML 1.3 Spec: http://cgi.omg.org/cgi-bin/doc?ad/99-06-08.pdf XMI 1.1 Spec: http://cgi.omg.org/cgi-bin/doc?ad/99-10-02.pdf XMI 2.0 Spec: http://cgi.omg.org/docs/ad/01-06-12.pdf ODMG: http://odmg.org/ OIFML: http://odmg.org/library/readingroom/oifml.pdf - Co-operative UML Editor: http://www.darmstadt.gmd.de/concert/activities/internal/umledit.html - further readings: + CASE Tools: + Rational Rose (commercial): http://www.rational.com/products/rose/ + Together (commercial): http://www.oi.com/products/controlcenter/index.jsp + InCASE - Tangram-based Universal Object Editor + Sybase PowerDesigner: http://www.sybase.com/powerdesigner + + UML Editors: + Fujaba (free, university): http://www.fujaba.de/ + ArgoUML (free): http://argouml.tigris.org/ + Poseidon (commercial): http://www.gentleware.com/products/poseidonDE.php3 + Co-operative UML Editor (research): http://www.darmstadt.gmd.de/concert/activities/internal/umledit.html + Metamill (commercial): http://www.metamill.com/ + Violet (university, research, education): http://www.horstmann.com/violet/ + PyUt (free): http://pyut.sourceforge.net/ + (Dia (free): http://www.lysator.liu.se/~alla/dia/) + UMLet (free, university): http://www.swt.tuwien.ac.at/umlet/index.html + Voodoo (free): http://voodoo.sourceforge.net/ + Umbrello UML Modeller: http://uml.sourceforge.net/ + + UML Tools: + http://www.objectsbydesign.com/tools/umltools_byPrice.html + + Further readings: http://www.google.com/search?q=web+based+uml+editor&hl=en&lr=&ie=UTF-8&oe=UTF-8&start=10&sa=N http://www.fernuni-hagen.de/DVT/Aktuelles/01FHHeidelberg.pdf http://www.enhyper.com/src/documentation/ @@ -403,5 +468,3 @@ http://citeseer.nj.nec.com/vilain00diagrammatic.html http://archive.devx.com/uml/articles/Smith01/Smith01-3.asp - maybe useful for / to be integrated with: - ArapXML: http://xml.coverpages.org/ni2001-09-24-b.html