Changeset 17087 for gsdl/trunk/perllib/IncrementalDocument.pm
- Timestamp:
- 2008-08-29T13:10:39+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/IncrementalDocument.pm
r15894 r17087 35 35 { 36 36 my ($class, $collection, $oid) = @_; 37 37 38 #rint STDERR "IncrementalDocument::new($collection, $oid)\n"; 39 38 40 # Test the parameters 39 41 die ("Error! Can't create a document that doesn't belong to a collection!") unless $collection; 40 42 die ("Error! Can't create a document that doesn't have a unique id (OID)!") unless $oid; 43 41 44 # Store the variables 42 45 my $self = {}; 46 43 47 # The collection this document object has been loaded from. 44 48 $self->{'collection'} = $collection; 49 45 50 # An associative array of information retrieved from the GDBM database 46 51 # which maps a key string to a nested associative array listing values. 47 52 $self->{'data'} = {}; 53 48 54 # The unique identifier of the document loaded 49 55 $self->{'oid'} = $oid; 56 50 57 # Stores the order in which metadata keys where discovered/added. 51 58 $self->{'order'} = {}; 52 # Bless me father for I have sinned 59 53 60 bless $self, $class; 54 61 return $self; … … 61 68 { 62 69 my ($self, $key, $value, $internal) = @_; 70 63 71 # Validate the arguments 64 72 die ("Error! Can't add a metadata value to a document without a valid key!") unless $key =~ /[\w]+/; 65 73 die ("Error! Can't add a metadata key to a document without a valid value!") unless $value =~ /[\w\d]+/; 74 66 75 # Is this a new key that we haven't encountered before? If so ensure an 67 76 # array exists for its values, and record the order in which we encountered … … 75 84 $self->{'data'}->{$key} = {}; 76 85 } 86 77 87 # Set the value of the associative path to 1. 78 88 $self->{'data'}->{$key}->{$value} = 1; … … 84 94 # */ 85 95 sub getAllMetadata() 86 { 96 { 97 my ($self) = @_; 98 my @all_metadata; 99 87 100 print STDERR "IncrementalDocument.getAllMetadata()\n"; 88 my ($self) = @_;89 my @all_metadata;90 101 91 102 my $key_count = scalar(keys %{$self->{'order'}}); … … 137 148 #rint STDERR "IncrementalDocument::loadDocument()\n"; 138 149 # Load the raw text for the document object from GDBM 139 my $text = &GDBMUtils::gdbmGet($self->{'collection'}, $self->{'oid'}); 150 my $collection = $self->{'collection'}; 151 my $text = &GDBMUtils::gdbmCachedCollectionGet($collection, $self->{'oid'}); 140 152 # For each line in the raw text, extract the key (enclosed in angle 141 153 # brackets) and the value … … 170 182 # Get a textual version of this object 171 183 my $text = $self->toString(); 184 172 185 # Now store the object in the database using the GDBM utilities 173 &GDBMUtils::gdbmSet($self->{'collection'}, $self->{'oid'}, $text); 186 my $collection = $self->{'collection'}; 187 &GDBMUtils::gdbmCachedCollectionSet($collection, $self->{'oid'}, $text); 188 174 189 # There is a little bit of extra complexity when saving an incremental 175 190 # document in that we should ensure that a reverse lookup-from DocNum or … … 178 193 if($doc_num >= 0) 179 194 { 180 my $text = &GDBMUtils::gdbm Get($self->{'collection'}, $doc_num);195 my $text = &GDBMUtils::gdbmCachedCollectionGet($collection, $doc_num); 181 196 # If there is no reverse lookup, then add one now 182 197 if($text !~ /<section>/) 183 198 { 184 &GDBMUtils::gdbm Set($self->{'collection'}, $doc_num, "<section>" . $self->{'oid'});199 &GDBMUtils::gdbmCachedCollectionSet($collection, $doc_num, "<section>" . $self->{'oid'}); 185 200 } 186 201 }
Note:
See TracChangeset
for help on using the changeset viewer.