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

Diff of /Sprout/ERDB.pm

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

revision 1.19, Fri Sep 9 14:50:58 2005 UTC revision 1.20, Sun Sep 11 17:02:33 2005 UTC
# Line 783  Line 783 
783      return sort keys %{$entityList};      return sort keys %{$entityList};
784  }  }
785    
786    =head3 IsEntity
787    
788    C<< my $flag = $erdb->IsEntity($entityName); >>
789    
790    Return TRUE if the parameter is an entity name, else FALSE.
791    
792    =over 4
793    
794    =item entityName
795    
796    Object name to be tested.
797    
798    =item RETURN
799    
800    Returns TRUE if the specified string is an entity name, else FALSE.
801    
802    =back
803    
804    =cut
805    
806    sub IsEntity {
807        # Get the parameters.
808        my ($self, $entityName) = @_;
809        # Test to see if it's an entity.
810        return exists $self->{_metaData}->{Entities}->{$entityName};
811    }
812    
813  =head3 Get  =head3 Get
814    
815  C<< my $query = $erdb->Get(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >>  C<< my $query = $erdb->Get(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >>
# Line 1324  Line 1351 
1351              }              }
1352          }          }
1353      }      }
     # Determine whether or not this is a primary relation. Primary relations have an extra  
     # field indicating whether or not a given object is new or was loaded from the flat files.  
     my $primary = $self->_IsPrimary($relationName);  
     # Get the number of fields in this relation.  
     my @fieldList = @{$relation->{Fields}};  
     my $fieldCount = @fieldList;  
     # Start a database transaction.  
     $dbh->begin_tran;  
     # Open the relation file. We need to create a cleaned-up copy before loading.  
     open TABLEIN, '<', $fileName;  
     my $tempName = "$fileName.tbl";  
     open TABLEOUT, '>', $tempName;  
     my $inputCount = 0;  
     # Loop through the file.  
     while (<TABLEIN>) {  
         $inputCount++;  
         # Chop off the new-line character.  
         my $record = Tracer::Strip($_);  
         # Only proceed if the record is non-blank.  
         if ($record) {  
             # Escape all the backslashes found in the line.  
             $record =~ s/\\/\\\\/g;  
             # Insure the number of fields is correct.  
             my @fields = split /\t/, $record;  
             while (@fields > $fieldCount) {  
                 my $extraField = $fields[$#fields];  
                 delete $fields[$#fields];  
                 if ($extraField) {  
                     Trace("Nonblank extra field value \"$extraField\" deleted from record $inputCount of $fileName.") if T(1);  
                 }  
             }  
             while (@fields < $fieldCount) {  
                 push @fields, "";  
             }  
             # If this is a primary relation, add a 0 for the new-record flag (indicating that  
             # this record is not new, but part of the original load).  
             if ($primary) {  
                 push @fields, "0";  
             }  
             # Write the record.  
             $record = join "\t", @fields;  
             print TABLEOUT "$record\n";  
             # Count the record written.  
             my $count = $retVal->Add('records');  
             my $len = length $record;  
             Trace("Record $count written with $len characters.") if T(4);  
         } else {  
             # Here we have a blank record.  
             $retVal->Add('skipped');  
         }  
     }  
     # Close the files.  
     close TABLEIN;  
     close TABLEOUT;  
     Trace("Temporary file $tempName created.") if T(2);  
1354      # Load the table.      # Load the table.
1355      my $rv;      my $rv;
1356      eval {      eval {
1357          $rv = $dbh->load_table(file => $tempName, tbl => $relationName);          $rv = $dbh->load_table(file => $fileName, tbl => $relationName);
1358      };      };
1359      if (!defined $rv) {      if (!defined $rv) {
1360          $retVal->AddMessage($@) if ($@);          $retVal->AddMessage($@) if ($@);
1361          $retVal->AddMessage("Table load failed for $relationName using $tempName.");          $retVal->AddMessage("Table load failed for $relationName using $fileName.");
1362          Trace("Table load failed for $relationName.") if T(1);          Trace("Table load failed for $relationName.") if T(1);
1363      } else {      } else {
1364          # Here we successfully loaded the table. Trace the number of records loaded.          # Here we successfully loaded the table. Trace the number of records loaded.
# Line 1400  Line 1372 
1372                  $retVal->AddMessage($@);                  $retVal->AddMessage($@);
1373              }              }
1374          }          }
         # Analyze the table to help optimize tables.  
1375      }      }
1376      # Commit the database changes.      # Commit the database changes.
1377      $dbh->commit_tran;      $dbh->commit_tran;
1378        # Analyze the table to improve performance.
1379      $dbh->vacuum_it($relationName);      $dbh->vacuum_it($relationName);
     # Delete the temporary file.  
     unlink $tempName;  
1380      # Return the statistics.      # Return the statistics.
1381      return $retVal;      return $retVal;
1382  }  }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3