--- nfo/perl/libs/Data/Storage/Schema/Abstract.pm 2002/11/15 13:21:39 1.4 +++ nfo/perl/libs/Data/Storage/Schema/Abstract.pm 2002/12/16 06:45:07 1.7 @@ -1,43 +1,53 @@ -############################################### -# -# $Id: Abstract.pm,v 1.4 2002/11/15 13:21:39 joko Exp $ -# -# $Log: Abstract.pm,v $ -# 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 -# -# -############################################### +## ------------------------------------------------------------------------ +## $Id: Abstract.pm,v 1.7 2002/12/16 06:45:07 joko Exp $ +## ------------------------------------------------------------------------ +## $Log: Abstract.pm,v $ +## Revision 1.7 2002/12/16 06:45:07 joko +## + injecting property 'guid' into each conrete class when initializing the schema +## +## 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 +## ------------------------------------------------------------------------ -# ==================================== + package Data::Storage::Schema::Abstract; - use strict; - use warnings; - - use Tangram; - use Class::Tangram; - - use Tangram::RawDate; - use Tangram::RawTime; - use Tangram::RawDateTime; +use strict; +use warnings; - use Tangram::FlatArray; - use Tangram::FlatHash; - use Tangram::PerlDump; - - # get logger instance - my $logger = Log::Dispatch::Config->instance; +use Tangram; +use Class::Tangram; + +use Tangram::RawDate; +use Tangram::RawTime; +use Tangram::RawDateTime; + +use Tangram::FlatArray; +use Tangram::FlatHash; +use Tangram::PerlDump; + + +use Data::Dumper; + +# get logger instance +my $logger = Log::Dispatch::Config->instance; + # ======== object constructor - %args to $self ======== @@ -47,6 +57,8 @@ my @args = (); @_ && (@args = @_); + $logger->debug( __PACKAGE__ . "->new" ); + #my $self = { @_ }; # merge all entries from all hashes in args-array to single array (key, val, key, val) @@ -55,11 +67,13 @@ # make hash from array my %args = @args_all; - $logger->debug( __PACKAGE__ . "->new( @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; @@ -141,13 +155,19 @@ my $schema_properties = {}; if ($self->{invocant}->can('getProperties')) { - $schema_properties = eval('return ' . $self->{invocant} . '::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 temporary index to look up class by classname + my $classindex = {}; + # build argument to be passed to "Tangram::Schema->new(...)" my @classes; map { $logger->debug( __PACKAGE__ . "->_doinit: Initializing Class $_" ); + Class::Tangram::import_schema($_); # classname push @classes, $_; # schema @@ -155,6 +175,7 @@ my $evalstr = '$schema = $' . $_ . '::schema;'; my $res = eval($evalstr); push @classes, $schema; + $classindex->{$_} = $schema; } @{$classlist}; # build up the schema as a hash @@ -166,6 +187,29 @@ foreach (keys %$schema_properties) { $schema->{$_} = $schema_properties->{$_}; } + +#print Dumper($schema); + + # patch guid into each concrete (non-abstract) object + # TODO: refactor this code into function: _injectProperty('guid') + foreach (@{$schema->{classes}}) { + my $ref = ref $_; + next if !$ref || $ref ne 'HASH'; + next if $_->{abstract}; + +#print Dumper($_); + + if (!$_->{fields}->{string}) { + $_->{fields}->{string}->{guid} = undef; + + } elsif (ref $_->{fields}->{string} eq 'ARRAY') { + push @{$_->{fields}->{string}}, 'guid'; + + } elsif (ref $_->{fields}->{string} eq 'HASH') { + $_->{fields}->{string}->{guid} = undef; + + } + } # create a new Tangram schema object # a) these classes must occour in the same order used at a previous setup or