[Bio] / Sprout / ERDBLoad.pm Repository:
ViewVC logotype

Diff of /Sprout/ERDBLoad.pm

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

revision 1.19, Fri Nov 3 00:34:10 2006 UTC revision 1.23, Wed Sep 3 20:56:20 2008 UTC
# Line 28  Line 28 
28    
29  =head3 new  =head3 new
30    
31  C<< my $erload = ERDBLoad->new($erdb, $relationName, $directory, $loadOnly, $ignore); >>      my $erload = ERDBLoad->new($erdb, $relationName, $directory, $loadOnly, $ignore);
32    
33  Begin loading an ERDB relation.  Begin loading an ERDB relation.
34    
# Line 82  Line 82 
82          Trace("Relation $relationName will be loaded from $fileName.") if T(2);          Trace("Relation $relationName will be loaded from $fileName.") if T(2);
83          $fileHandle = "";          $fileHandle = "";
84      } else {      } else {
85          # Determine the sort for this relation.          # Compute the file namefor this relation. We will build a file on
86          my $fileString = "| " . $erdb->SortNeeded($relationName) . " >$fileName";          # disk and then sort it into the real file when we're done.
87          Trace("Load file creation string is \"$fileString\".") if T(3);          my $fileString = ">$fileName.tmp";
88          # Open the output file and remember its handle.          # Open the output file and remember its handle.
89          $fileHandle = Open(undef, $fileString);          $fileHandle = Open(undef, $fileString);
90          Trace("Relation $relationName load file created with primary flag $primary.") if T(2);          Trace("Relation $relationName load file created with primary flag $primary.") if T(2);
# Line 108  Line 108 
108    
109  =head3 Ignore  =head3 Ignore
110    
111  C<< my $flag = $erload->Ignore; >>      my $flag = $erload->Ignore;
112    
113  Return TRUE if we are ignoring this table, else FALSE.  Return TRUE if we are ignoring this table, else FALSE.
114    
# Line 123  Line 123 
123    
124  =head3 Put  =head3 Put
125    
126  C<< my  = $erload->Put($field1, $field2, ..., $fieldN); >>      my  = $erload->Put($field1, $field2, ..., $fieldN);
127    
128  Write a line of data to the load file. This may also cause the load file to be closed  Write a line of data to the load file. This may also cause the load file to be closed
129  and data read into the table.  and data read into the table.
# Line 151  Line 151 
151          my $truncates = $self->{dbh}->VerifyFields($self->{relName}, \@rawFields);          my $truncates = $self->{dbh}->VerifyFields($self->{relName}, \@rawFields);
152          # Run through the list of field values, escaping them.          # Run through the list of field values, escaping them.
153          my @fields = map { Tracer::Escape($_) } @rawFields;          my @fields = map { Tracer::Escape($_) } @rawFields;
         # If this is a primary relation, append the new-record field.  
         if ($self->{primary}) {  
             push @fields, '0';  
         }  
154          # Form a data line from the fields.          # Form a data line from the fields.
155          my $line = join("\t", @fields) . "\n";          my $line = join("\t", @fields) . "\n";
156          # Write the new record to the load file.          # Write the new record to the load file.
# Line 174  Line 170 
170    
171  =head3 Add  =head3 Add
172    
173  C<< my  = $stats->Add($statName, $value); >>      my  = $stats->Add($statName, $value);
174    
175  Increment the specified statistic.  Increment the specified statistic.
176    
# Line 205  Line 201 
201    
202  =head3 Finish  =head3 Finish
203    
204  C<< my $stats = $erload->Finish(); >>      my $stats = $erload->Finish();
205    
206  Finish loading the table. This closes the load file.  Finish loading the table. This closes and sorts the load file.
207    
208  =over 4  =over 4
209    
# Line 226  Line 222 
222      if ($self->{fh}) {      if ($self->{fh}) {
223          # Close the load file.          # Close the load file.
224          close $self->{fh};          close $self->{fh};
225            # Get the ERDB object.
226            my $erdb = $self->{dbh};
227            # Get the output file name.
228            my $fileName = $self->{fileName};
229            # Get the sort command for this relation.
230            my $sortCommand = $erdb->SortNeeded($self->{relName});
231            # Open the temp file for input via sort.
232            my $ih = Open(undef, "$sortCommand <$fileName.tmp |");
233            # Open the real file for output.
234            my $oh = Open(undef, ">$fileName");
235            Trace("Sorting into $fileName with command: $sortCommand") if T(3);
236            # Set up a timer.
237            my $start = time();
238            # Sort from the temp file into the output file.
239            while (! eof $ih) {
240                print $oh (<$ih>);
241            }
242            # Record the time spent
243            $self->{stats}->Add(sortTime => (time() - $start));
244            # Delete the temp file.
245            unlink "$fileName.tmp";
246            # Tell the user we're done.
247            Trace("Load file $fileName created.") if T(3);
248    
249      }      }
250      # Return the statistics object.      # Return the statistics object.
251      return $self->{stats};      return $self->{stats};
# Line 233  Line 253 
253    
254  =head3 FinishAndLoad  =head3 FinishAndLoad
255    
256  C<< my $stats = $erload->FinishAndLoad(); >>      my $stats = $erload->FinishAndLoad();
257    
258  Finish the load and load the table, returning the statistics.  Finish the load and load the table, returning the statistics.
259    
# Line 254  Line 274 
274    
275  =head3 RelName  =head3 RelName
276    
277  C<< my $name = $erload->RelName; >>      my $name = $erload->RelName;
278    
279  Name of the relation being loaded by this object.  Name of the relation being loaded by this object.
280    
# Line 269  Line 289 
289    
290  =head3 LoadTable  =head3 LoadTable
291    
292  C<< my $stats = $erload->LoadTable(); >>      my $stats = $erload->LoadTable();
293    
294  Load the database table from the load file and return a statistics object.  Load the database table from the load file and return a statistics object.
295    
# Line 283  Line 303 
303      my $fileName = $self->{fileName};      my $fileName = $self->{fileName};
304      my $relName = $self->{relName};      my $relName = $self->{relName};
305      # Load the table. The third parameter indicates this is a drop and reload.      # Load the table. The third parameter indicates this is a drop and reload.
306      my $retVal = $erdb->LoadTable($fileName, $relName, 1);      my $retVal = $erdb->LoadTable($fileName, $relName, truncate => 1);
307      # Return the result.      # Return the result.
308      return $retVal;      return $retVal;
309  }  }

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.23

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3