/[cvs]/nfo/perl/libs/Data/Storage/Handler/Tangram.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage/Handler/Tangram.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by joko, Sun Dec 1 04:46:19 2002 UTC revision 1.12 by joko, Wed Dec 4 11:34:49 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.12  2002/12/04 11:34:49  joko
7    #  - $schema_tangram doesn't have to be in class?
8    #
9    #  Revision 1.11  2002/12/04 08:54:08  jonen
10    #  + untested bugfix: undef($object) after transform to hash at getObjectAsHash
11    #
12    #  Revision 1.10  2002/12/03 15:53:23  joko
13    #  + small bugfix regarding object hierarchy
14    #
15    #  Revision 1.9  2002/12/03 05:29:40  joko
16    #  + sub getObject
17    #  + sub getObjectAsHash
18    #
19    #  Revision 1.8  2002/12/01 22:25:51  joko
20    #  + now utilizing metadata from storage locator when connecting to DBI in "raw"-mode
21    #
22  #  Revision 1.7  2002/12/01 04:46:19  joko  #  Revision 1.7  2002/12/01 04:46:19  joko
23  #  + sub eraseAll  #  + sub eraseAll
24  #  #
# Line 53  use Data::Dumper; Line 69  use Data::Dumper;
69  use libp qw( getNewPerlObjectByPkgName );  use libp qw( getNewPerlObjectByPkgName );
70  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
71  use Data::Compare::Struct qw( isEmpty );  use Data::Compare::Struct qw( isEmpty );
72    use Data::Transform::Deep qw( var_deref );
73    use Data::Transform::Encode qw( var2utf8 );
74    
75    
76  # get logger instance  # get logger instance
77  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
78    
79    
80    # this holds the complete instantiated schema from tangram
81    my $schema_tangram;
82    
83  sub getMetaInfo {  sub getMetaInfo {
84    my $self = shift;    my $self = shift;
85    $logger->debug( __PACKAGE__ . "->getMetaInfo()"  );    $logger->debug( __PACKAGE__ . "->getMetaInfo()"  );
# Line 69  sub getMetaInfo { Line 91  sub getMetaInfo {
91  sub _initSchema {  sub _initSchema {
92    my $self = shift;    my $self = shift;
93    $logger->debug( __PACKAGE__ . "->_initSchema()" );    $logger->debug( __PACKAGE__ . "->_initSchema()" );
94    #if (!$self->{schema_tangram}) {    #if (!$schema_tangram) {
95      my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );      my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );
96      $self->{schema_tangram} = $obj->getSchema();      $schema_tangram = $obj->getSchema();
97    #}    #}
98    if (!$self->{schema_tangram}) {    if (!$schema_tangram) {
99      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
100      return 0;      return 0;
101    }    }
# Line 102  sub connect { Line 124  sub connect {
124    
125      # create the main tangram storage object      # create the main tangram storage object
126      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );
127      $self->{COREHANDLE} = Tangram::Relational->connect( $self->{schema_tangram}, $dsn );      $self->{COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn );
128        
129      # some attempts for configuring the wrapped underlying dbi.....      # some attempts for configuring the wrapped underlying dbi.....
130      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();
# Line 138  sub getChildNodes { Line 160  sub getChildNodes {
160  #print Dumper($self);  #print Dumper($self);
161    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
162        
163    $storage->disconnect();    # TODO: REVIEW
164      #$storage->disconnect();
165        
166    $self->{meta}->{childnodes} = \@nodes;    $self->{meta}->{childnodes} = \@nodes;
167        
# Line 242  sub deploySchema { Line 265  sub deploySchema {
265    my $args = shift;    my $args = shift;
266        
267    my $dsn = $self->{locator}->{dbi}->{dsn};    my $dsn = $self->{locator}->{dbi}->{dsn};
   #my $dsn = $self->{dbi}->{dsn};  
268    
269    $logger->debug( __PACKAGE__ . "->deploySchema( dsn $dsn )" );    $logger->debug( __PACKAGE__ . "->deploySchema( dsn $dsn )" );
270    
271    my $ok;    my $ok;
272    # TODO: is this DBI->connect okay here like it is? regarding errors.....???    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
   if ( my $dbh = DBI->connect($dsn, '', '', {  
                                                       PrintError => 0,  
                                                     } ) ) {  
   
273      return unless $self->_initSchema();      return unless $self->_initSchema();
274            $ok = Tangram::Relational->deploy($schema_tangram, $dbh );
     $ok = Tangram::Relational->deploy($self->{schema_tangram}, $dbh );  
275      $dbh->disconnect();      $dbh->disconnect();
276    }    }
277    return $ok;    return $ok;
# Line 264  sub retreatSchema { Line 281  sub retreatSchema {
281    
282    my $self = shift;    my $self = shift;
283    my $dsn = $self->{locator}->{dbi}->{dsn};    my $dsn = $self->{locator}->{dbi}->{dsn};
   #my $dsn = $self->{dbi}->{dsn};  
284    
285    $logger->debug( __PACKAGE__ . "->retreatSchema( dsn $dsn )" );    $logger->debug( __PACKAGE__ . "->retreatSchema( dsn $dsn )" );
286    
287    my $ok;    my $ok;
288    if ( my $dbh = DBI->connect($dsn, '', '', {    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
                                                       #PrintError => 0,  
                                                       #RaiseError => 0,  
                                                     } ) ) {  
289    
290      return unless $self->_initSchema();      return unless $self->_initSchema();
291            
292      #use Data::Dumper; print Dumper($self);      #use Data::Dumper; print Dumper($self);
293      $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");      $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");
294            
295      $ok = Tangram::Relational->retreat($self->{schema_tangram}, $dbh );      $ok = Tangram::Relational->retreat($schema_tangram, $dbh );
296      $ok = 2;    # answer is "maybe" for now since Tangram::Relational->retreat doesn't seem to return a valid status  
297                      # idea: test this by checking for count of tables in database -      # answer "$ok=2" means "maybe" for now - we have to patch this to a constant here because...
298                      #          problem with this: there may be some left not having been included to the schema      # - ... Tangram::Relational->retreat doesn't seem to return a valid status
299        # - possible improvement:
300        #   - test this by checking for count of tables in database
301        #   - problem with this: there may be some left not having been included to the schema
302        #   - maybe better: use "->getChildNodes"?
303        $ok = 2;
304    
305      $dbh->disconnect();      $dbh->disconnect();
306    
307    }    }
308    return $ok;    return $ok;
309  }  }
# Line 445  sub sendQuery { Line 465  sub sendQuery {
465  sub eraseAll {  sub eraseAll {
466    my $self = shift;    my $self = shift;
467    my $classname = shift;    my $classname = shift;
468    my $remote = $self->{storage}->remote($classname);    my $remote = $self->{COREHANDLE}->remote($classname);
469    my @objs = $self->{storage}->select($remote);    my @objs = $self->{COREHANDLE}->select($remote);
470    $self->{COREHANDLE}->erase(@objs);    $self->{COREHANDLE}->erase(@objs);
471  }  }
472    
473    sub createDb {
474      my $self = shift;
475      my $storage = $self->_getSubLayerHandle();
476      return $storage->createDb();
477    }
478    
479    sub getObject {
480      my $self = shift;
481      my $oid = shift;
482      # TODO: review this
483      #if (!$self->{COREHANDLE}) { return; }
484      return $self->{COREHANDLE}->load($oid);
485    }
486    
487    sub getObjectAsHash {
488      my $self = shift;
489      my $oid = shift;
490      my $options = shift;
491      my $obj = $self->getObject($oid);
492      my $deref = var_deref($obj);
493      var2utf8($deref) if ($options->{utf8});
494      undef($obj) if($options->{destroy});
495      return $deref;
496    }
497    
498    sub getSchema {
499      return $schema_tangram;
500    }
501    
502  1;  1;

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

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