--- nfo/perl/libs/Data/Storage/Handler/Tangram.pm 2002/10/10 03:44:07 1.1 +++ nfo/perl/libs/Data/Storage/Handler/Tangram.pm 2002/10/17 00:10:05 1.2 @@ -1,8 +1,14 @@ ################################# # -# $Id: Tangram.pm,v 1.1 2002/10/10 03:44:07 cvsjoko Exp $ +# $Id: Tangram.pm,v 1.2 2002/10/17 00:10:05 joko Exp $ # # $Log: Tangram.pm,v $ +# Revision 1.2 2002/10/17 00:10:05 joko +# + removed dependency from tsobj.pm, schema is now independent +# + sub getNewPerlObjectByPkgName +# + sub deploySchema +# + sub retreatSchema +# # Revision 1.1 2002/10/10 03:44:07 cvsjoko # + new # @@ -27,6 +33,14 @@ 'disconnectMethod' => 'disconnect', }; +sub getNewPerlObjectByPkgName { + my $pkgname = shift; + my $args = shift; + my $evstring = "use $pkgname;"; + eval($evstring); + return $pkgname->new($args); +} + sub connect { my $self = shift; @@ -34,7 +48,7 @@ my $dsn = shift; $dsn ||= $self->{dbi}->{dsn}; - $logger->debug( __PACKAGE__ . "->connect($dsn)" ); + $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); #my $storage = Tangram::Relational->connect( $schema, $dsn ); #my $storage = Tangram::mysql->connect( $schema, $dsn ); @@ -45,12 +59,11 @@ # return; # } - - require 'OSA/tsobj.pm'; - tsobj::initSchema(); - #sleep 1; - my $schema = tsobj::getSchema(); - $self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); + my $obj = getNewPerlObjectByPkgName($self->{schema}, { EXPORT_OBJECTS => $self->{classnames} } ); + $self->{schema_tangram} = $obj->getSchema(); + + #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); + $self->{COREHANDLE} = Tangram::Relational->connect( $self->{schema_tangram}, $dsn ); #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage(); #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE(); @@ -93,8 +106,8 @@ # hack, make more generic! if (!$self->{STORAGE_SUBLAYER}) { - my $loc = new Data::Storage::Locator( type => "DBI", dbi => $self->{dbi}, COREHANDLE => $self->{COREHANDLE}->{db} ); - $self->{STORAGE_SUBLAYER} = new Data::Storage( $loc, { protected => 1 } ); + my $loc = Data::Storage::Locator->new( type => "DBI", dbi => $self->{dbi}, COREHANDLE => $self->{COREHANDLE}->{db} ); + $self->{STORAGE_SUBLAYER} = Data::Storage->new( $loc, { protected => 1 } ); #$self->{STORAGE_UNDER_THE_HOOD}->{STORAGEHANDLE}->_configureCOREHANDLE(); #$self->{STORAGE_UNDER_THE_HOOD}->_configureCOREHANDLE(); } @@ -144,4 +157,33 @@ } +sub deploySchema { + my $self = shift; + #my $dsn = $self->{locator}->{dbi}->{dsn}; + my $dsn = $self->{dbi}->{dsn}; + my $ok; + if ( my $dbh = DBI->connect($dsn, '', '', { + PrintError => 0, + } ) ) { + $ok = Tangram::Relational->deploy($self->{schema}, $dbh ); + $dbh->disconnect(); + } + return $ok; +} + +sub retreatSchema { + print "retreat\n"; + my $self = shift; + #my $dsn = $self->{locator}->{dbi}->{dsn}; + my $dsn = $self->{dbi}->{dsn}; + my $ok; + if ( my $dbh = DBI->connect($dsn, '', '', { + PrintError => 0, + } ) ) { + $ok = Tangram::Relational->retreat($self->{schema}, $dbh ); + $dbh->disconnect(); + } + return $ok; +} + 1;