Changeset 21661

Show
Ignore:
Timestamp:
27.01.2010 14:15:47 (9 years ago)
Author:
mdewsnip
Message:

Changed ClassifyTreeNode? so it gets the infodbtype from the model, instead of assuming GDBM. Part of making the code less GDBM-specific.

Location:
main/trunk/greenstone2/perllib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/ClassifyTreeModel.pm

    r21646 r21661  
    104104  } 
    105105# /** getCollection() **/ 
     106 
     107sub getInfoDBType() 
     108{ 
     109  my $self = shift(@_); 
     110  return $self->{'infodbtype'}; 
     111} 
    106112 
    107113# /** Retrieve a node from this tree based upon its CLID (OID). 
  • main/trunk/greenstone2/perllib/ClassifyTreeNode.pm

    r21563 r21661  
    2828 
    2929    my $collection = $model->getCollection(); 
     30    $self->{'infodbtype'} = $model->getInfoDBType(); 
    3031 
    3132    my $index_text_directory_path = &util::filename_cat($ENV{'GSDLHOME'}, "collect", $collection, "index", "text"); 
    32     $self->{'infodb_file_path'} = &dbutil::get_infodb_file_path("gdbm", $collection, $index_text_directory_path); 
     33    $self->{'infodb_file_path'} = &dbutil::get_infodb_file_path($self->{'infodbtype'}, $collection, $index_text_directory_path); 
    3334 
    3435    # Check if this node already exists in the database, and if not insert it 
    3536    # now 
    36     my $text = &dbutil::read_infodb_entry("gdbm", $self->{'infodb_file_path'}, $clid); 
     37    my $text = &dbutil::read_infodb_entry($self->{'infodbtype'}, $self->{'infodb_file_path'}, $clid); 
    3738    if($text !~ /\w+/ && $force_new) 
    3839      { 
    39     my $infodb_file_handle = &dbutil::open_infodb_write_handle("gdbm", $self->{'infodb_file_path'}, "append"); 
    40     &dbutil::write_infodb_entry("gdbm", $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash("<doctype>classify\n<hastxt>0\n<childtype>VList\n<Title>\n<numleafdocs>0\n<contains>\n")); 
    41     &dbutil::close_infodb_write_handle("gdbm", $infodb_file_handle); 
     40    my $infodb_file_handle = &dbutil::open_infodb_write_handle($self->{'infodbtype'}, $self->{'infodb_file_path'}, "append"); 
     41    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash("<doctype>classify\n<hastxt>0\n<childtype>VList\n<Title>\n<numleafdocs>0\n<contains>\n")); 
     42    &dbutil::close_infodb_write_handle($self->{'infodbtype'}, $infodb_file_handle); 
    4243      } 
    4344    # Bless me father for I have sinned 
     
    122123 
    123124    # Create a new document with the correct CLID 
    124     my $infodb_file_handle = &dbutil::open_infodb_write_handle("gdbm", $self->{'infodb_file_path'}, "append"); 
    125     &dbutil::write_infodb_entry("gdbm", $infodb_file_handle, $new_clid, &dbutil::convert_infodb_string_to_hash($text)); 
     125    my $infodb_file_handle = &dbutil::open_infodb_write_handle($self->{'infodbtype'}, $self->{'infodb_file_path'}, "append"); 
     126    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_file_handle, $new_clid, &dbutil::convert_infodb_string_to_hash($text)); 
    126127    # Remove the old document 
    127     &dbutil::delete_infodb_entry("gdbm", $infodb_file_handle, $self->{'clid'}); 
    128     &dbutil::close_infodb_write_handle("gdbm", $infodb_file_handle); 
     128    &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_file_handle, $self->{'clid'}); 
     129    &dbutil::close_infodb_write_handle($self->{'infodbtype'}, $infodb_file_handle); 
    129130 
    130131    # Finally, change the clid stored in this document 
     
    240241 
    241242    # Now determine if this node exists. 
    242     if (&dbutil::read_infodb_entry("gdbm", $self->{'infodb_file_path'}, $next_clid) =~ /\w+/) 
     243    if (&dbutil::read_infodb_entry($self->{'infodbtype'}, $self->{'infodb_file_path'}, $next_clid) =~ /\w+/) 
    243244      { 
    244245        # And if so, create it. 
     
    491492      } 
    492493    # Now remove the node from the database 
    493     my $infodb_file_handle = &dbutil::open_infodb_write_handle("gdbm", $self->{'infodb_file_path'}, "append"); 
    494     &dbutil::delete_infodb_entry("gdbm", $infodb_file_handle, $self->{'clid'}); 
    495     &dbutil::close_infodb_write_handle("gdbm", $infodb_file_handle); 
     494    my $infodb_file_handle = &dbutil::open_infodb_write_handle($self->{'infodbtype'}, $self->{'infodb_file_path'}, "append"); 
     495    &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_file_handle, $self->{'clid'}); 
     496    &dbutil::close_infodb_write_handle($self->{'infodbtype'}, $infodb_file_handle); 
    496497 
    497498    # Return the leaf count (so we can adjust the numleafdocs at the root node 
     
    630631 
    631632    # Load the text of this node 
    632     my $text = &dbutil::read_infodb_entry("gdbm", $self->{'infodb_file_path'}, $clid); 
     633    my $text = &dbutil::read_infodb_entry($self->{'infodbtype'}, $self->{'infodb_file_path'}, $clid); 
    633634 
    634635    # Replace the contains 
     
    637638    #rint STDERR "After:  $text\n"; 
    638639    # Store the changed text 
    639     my $infodb_file_handle = &dbutil::open_infodb_write_handle("gdbm", $self->{'infodb_file_path'}, "append"); 
    640     &dbutil::write_infodb_entry("gdbm", $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash($text)); 
    641     &dbutil::close_infodb_write_handle("gdbm", $infodb_file_handle); 
     640    my $infodb_file_handle = &dbutil::open_infodb_write_handle($self->{'infodbtype'}, $self->{'infodb_file_path'}, "append"); 
     641    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash($text)); 
     642    &dbutil::close_infodb_write_handle($self->{'infodbtype'}, $infodb_file_handle); 
    642643  } 
    643644# /** setContains() **/ 
     
    658659 
    659660    # Load the text of this node 
    660     my $text = &dbutil::read_infodb_entry("gdbm", $self->{'infodb_file_path'}, $clid); 
     661    my $text = &dbutil::read_infodb_entry($self->{'infodbtype'}, $self->{'infodb_file_path'}, $clid); 
    661662    # Replace the numleafdocs 
    662663    $text =~ s/<numleafdocs>\d*?\n+/<numleafdocs>$numleafdocs\n/; 
    663664    # Store the changed text 
    664     my $infodb_file_handle = &dbutil::open_infodb_write_handle("gdbm", $self->{'infodb_file_path'}, "append"); 
    665     &dbutil::write_infodb_entry("gdbm", $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash($text)); 
    666     &dbutil::close_infodb_write_handle("gdbm", $infodb_file_handle); 
     665    my $infodb_file_handle = &dbutil::open_infodb_write_handle($self->{'infodbtype'}, $self->{'infodb_file_path'}, "append"); 
     666    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash($text)); 
     667    &dbutil::close_infodb_write_handle($self->{'infodbtype'}, $infodb_file_handle); 
    667668  } 
    668669# /** setNumLeafDocs() **/ 
     
    685686 
    686687    # Load the text of this node 
    687     my $text = &dbutil::read_infodb_entry("gdbm", $self->{'infodb_file_path'}, $clid); 
     688    my $text = &dbutil::read_infodb_entry($self->{'infodbtype'}, $self->{'infodb_file_path'}, $clid); 
    688689    # Replace the title 
    689690    $text =~ s/<Title>.*?\n+/<Title>$title\n/; 
    690691    # Store the changed text 
    691     my $infodb_file_handle = &dbutil::open_infodb_write_handle("gdbm", $self->{'infodb_file_path'}, "append"); 
    692     &dbutil::write_infodb_entry("gdbm", $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash($text)); 
    693     &dbutil::close_infodb_write_handle("gdbm", $infodb_file_handle); 
     692    my $infodb_file_handle = &dbutil::open_infodb_write_handle($self->{'infodbtype'}, $self->{'infodb_file_path'}, "append"); 
     693    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_file_handle, $clid, &dbutil::convert_infodb_string_to_hash($text)); 
     694    &dbutil::close_infodb_write_handle($self->{'infodbtype'}, $infodb_file_handle); 
    694695  } 
    695696# /** setValue() **/ 
     
    708709    my $clid = $self->{'clid'}; 
    709710 
    710     my $text = &dbutil::read_infodb_entry("gdbm", $self->{'infodb_file_path'}, $clid); 
     711    my $text = &dbutil::read_infodb_entry($self->{'infodbtype'}, $self->{'infodb_file_path'}, $clid); 
    711712    return $text; 
    712713  }