--- nfo/perl/libs/Data/Storage/Schema/Abstract.pm 2002/10/17 00:07:14 1.1 +++ nfo/perl/libs/Data/Storage/Schema/Abstract.pm 2002/11/17 07:21:47 1.6 @@ -1,8 +1,24 @@ ############################################### # -# $Id: Abstract.pm,v 1.1 2002/10/17 00:07:14 joko Exp $ +# $Id: Abstract.pm,v 1.6 2002/11/17 07:21:47 jonen Exp $ # # $Log: Abstract.pm,v $ +# Revision 1.6 2002/11/17 07:21:47 jonen +# + using Class::Tangram::import_schema() again for proper usage of its helper functions +# +# Revision 1.5 2002/11/17 07:12:06 joko +# + extended ::getProperties with argument "want_transactions" +# +# Revision 1.4 2002/11/15 13:21:39 joko +# + added capability to propagate global schema options from schema module to tangram schema +# +# Revision 1.3 2002/11/09 01:27:23 joko +# + dependency of Class::Tangram now is 1.13 at minimum +# +# Revision 1.2 2002/10/25 11:45:10 joko +# + enhanced robustness +# + more logging for debug-levels +# # Revision 1.1 2002/10/17 00:07:14 joko # + new # @@ -36,7 +52,9 @@ my $class = ref($invocant) || $invocant; my @args = (); @_ && (@args = @_); - #$logger->debug( __PACKAGE__ . "->new(@args)" ); + + $logger->debug( __PACKAGE__ . "->new" ); + #my $self = { @_ }; # merge all entries from all hashes in args-array to single array (key, val, key, val) @@ -44,10 +62,14 @@ map { push(@args_all, %{$_}); } @args; # make hash from array my %args = @args_all; + + #$logger->debug( __PACKAGE__ . "->new( @args_all )" ); my $self = { %args }; bless $self, $class; + #use Data::Dumper; print Dumper($self); + # remember as which Class we are instantiated $self->{invocant} = $invocant; @@ -63,9 +85,9 @@ my $ctversion = $Class::Tangram::VERSION; #print "ctversion: ", $ctversion, "\n"; #if ($ctversion ne 1.04) { - if ($ctversion ne 1.12) { + if ($ctversion lt 1.13) { print "Version of \"Class::Tangram\": ", $ctversion, "\n"; - print "absolutely required version: ", "1.12", "\n"; + print "minimum required version : ", "1.13", "\n"; #print "quitting!!! (please install older version (1.04) of \"Class::Tangram\"", "\n"; exit; } @@ -76,6 +98,13 @@ my $filename = shift; my $exclude_pattern = shift; $logger->debug( __PACKAGE__ . "->_parsePackageFile( ... )" ); + if (!$filename) { + $logger->error( __PACKAGE__ . "->_parsePackageFile: you must specify a filename" ); + return; + } + if (! -e $filename) { + $logger->error( __PACKAGE__ . "->_parsePackageFile: could not find $filename" ); + } my @packages = (); open(FH, '<' . $filename); while () { @@ -109,7 +138,10 @@ # parse complete package to build list of classes if ($#{$classlist} == -1) { $logger->debug( "_doinit() Initializing all Classes from " . $self->{invocant} ); - my $perl_packagename = $self->{invocant}; + if (!$self->{invocant}->can('getFilename')) { + $logger->error( __PACKAGE__ . "->_doinit: Package $self->{invocant} doesn't contain method 'getFilename'" ); + return; + } my $perl_packagefile = eval('return ' . $self->{invocant} . '::getFilename();'); my $packages = $self->_parsePackageNamesFromFile($perl_packagefile, $self->{invocant}); # TODO: @@ -117,37 +149,65 @@ $classlist = $packages; } + my $schema_properties = {}; + if ($self->{invocant}->can('getProperties')) { + # TODO: rework this! call by ref and/or do oo + #$schema_properties = eval('return ' . $self->{invocant} . '::getProperties();'); + $schema_properties = eval('return ' . $self->{invocant} . '::getProperties($self->{want_transactions});'); + } + # build argument to be passed to "Tangram::Schema->new(...)" my @classes; map { - $logger->debug( __PACKAGE__ . "->_doinit() Initializing Class $_" ); + $logger->debug( __PACKAGE__ . "->_doinit: Initializing Class $_" ); + Class::Tangram::import_schema($_); # classname push @classes, $_; # schema my $schema; my $evalstr = '$schema = $' . $_ . '::schema;'; my $res = eval($evalstr); - use Data::Dumper; push @classes, $schema; } @{$classlist}; + # build up the schema as a hash + my $schema = { + classes => \@classes, + }; + + # merge schema properties + foreach (keys %$schema_properties) { + $schema->{$_} = $schema_properties->{$_}; + } + # create a new Tangram schema object - # these classes must occour in the same order used at a previous setup - $self->{schema} = Tangram::Schema->new({ classes => \@classes }); + # a) these classes must occour in the same order used at a previous setup or + # b) better use class ids! + $self->{schema} = Tangram::Schema->new($schema); return 1; +=pod # ====================================== - # template + # schema template $self->{schema} = Tangram::Schema->new({ + classes => [ - # misc - 'SystemEvent' => $SystemEvent::schema, - + 'Person' => $Person::schema, ], + + make_object => sub { ... }, + set_id => sub { ... } + get_id => sub { ... } + normalize => sub { ... }, + + control => '...' + + sql => { ... }, + }); # ====================================== - +=cut } @@ -162,8 +222,10 @@ sub getSchema { my $self = shift; if (!$self->{schema}) { - print "schema is not yet initialized!", "\n"; - exit; + #print "schema is not yet initialized!", "\n"; + #exit; + $logger->error( __PACKAGE__ . "->getSchema: Schema is not yet initialized!" ); + return; } return $self->{schema}; }