[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.9, Thu Jun 16 19:08:59 2005 UTC revision 1.16, Tue Jun 28 23:51:06 2005 UTC
# Line 2  Line 2 
2    
3          use strict;          use strict;
4          use Tracer;          use Tracer;
5          use DBKernel;      use DBrtns;
6          use Data::Dumper;          use Data::Dumper;
7          use XML::Simple;          use XML::Simple;
8          use DBQuery;          use DBQuery;
# Line 637  Line 637 
637  C<< $database->CreateIndex($relationName); >>  C<< $database->CreateIndex($relationName); >>
638    
639  Create the indexes for a relation. If a table is being loaded from a large source file (as  Create the indexes for a relation. If a table is being loaded from a large source file (as
640  is the case in L</LoadTable>), it is best to create the indexes after the load. If that is  is the case in L</LoadTable>), it is sometimes best to create the indexes after the load.
641  the case, then L</CreateTable> should be called with the index flag set to FALSE, and this  If that is the case, then L</CreateTable> should be called with the index flag set to
642  method used after the load to create the indexes for the table.  FALSE, and this method used after the load to create the indexes for the table.
643    
644  =cut  =cut
645    
# Line 1283  Line 1283 
1283          # Create the statistical return object.          # Create the statistical return object.
1284          my $retVal = _GetLoadStats();          my $retVal = _GetLoadStats();
1285          # Trace the fact of the load.          # Trace the fact of the load.
1286          Trace("Loading table $relationName from $fileName") if T(1);      Trace("Loading table $relationName from $fileName") if T(2);
1287          # Get the database handle.          # Get the database handle.
1288          my $dbh = $self->{_dbh};          my $dbh = $self->{_dbh};
1289          # Get the relation data.          # Get the relation data.
1290          my $relation = $self->_FindRelation($relationName);          my $relation = $self->_FindRelation($relationName);
1291          # Check the truncation flag.          # Check the truncation flag.
1292          if ($truncateFlag) {          if ($truncateFlag) {
1293                  Trace("Creating table $relationName") if T(1);          Trace("Creating table $relationName") if T(2);
1294                  # Re-create the table without its index.                  # Re-create the table without its index.
1295                  $self->CreateTable($relationName, 0);                  $self->CreateTable($relationName, 0);
1296            # If this is a pre-index DBMS, create the index here.
1297            if ($dbh->{_preIndex}) {
1298                eval {
1299                    $self->CreateIndex($relationName);
1300                };
1301                if ($@) {
1302                    $retVal->AddMessage($@);
1303                }
1304            }
1305          }          }
1306          # Determine whether or not this is a primary relation. Primary relations have an extra          # Determine whether or not this is a primary relation. Primary relations have an extra
1307          # field indicating whether or not a given object is new or was loaded from the flat files.          # field indicating whether or not a given object is new or was loaded from the flat files.
# Line 1348  Line 1357 
1357          # Close the files.          # Close the files.
1358          close TABLEIN;          close TABLEIN;
1359          close TABLEOUT;          close TABLEOUT;
1360      Trace("Temporary file $tempName created.") if T(4);      Trace("Temporary file $tempName created.") if T(2);
1361      # Load the table.      # Load the table.
1362          my $rv;          my $rv;
1363          eval {          eval {
# Line 1360  Line 1369 
1369                  Trace("Table load failed for $relationName.") if T(1);                  Trace("Table load failed for $relationName.") if T(1);
1370          } else {          } else {
1371                  # Here we successfully loaded the table. Trace the number of records loaded.                  # Here we successfully loaded the table. Trace the number of records loaded.
1372                  Trace("$retVal->{records} records read for $relationName.") if T(1);          Trace("$retVal->{records} records read for $relationName.") if T(2);
1373                  # If we're rebuilding, we need to create the table indexes.                  # If we're rebuilding, we need to create the table indexes.
1374                  if ($truncateFlag) {          if ($truncateFlag && ! $dbh->{_preIndex}) {
1375                          eval {                          eval {
1376                                  $self->CreateIndex($relationName);                                  $self->CreateIndex($relationName);
1377                          };                          };
# Line 1370  Line 1379 
1379                                  $retVal->AddMessage($@);                                  $retVal->AddMessage($@);
1380                          }                          }
1381                  }                  }
1382            # Analyze the table to help optimize tables.
1383          }          }
1384          # Commit the database changes.          # Commit the database changes.
1385          $dbh->commit_tran;          $dbh->commit_tran;
1386        $dbh->vacuum_it($relationName);
1387          # Delete the temporary file.          # Delete the temporary file.
1388          unlink $tempName;          unlink $tempName;
1389          # Return the statistics.          # Return the statistics.
# Line 1978  Line 1989 
1989  sub _LoadMetaData {  sub _LoadMetaData {
1990          # Get the parameters.          # Get the parameters.
1991          my ($filename) = @_;          my ($filename) = @_;
1992        Trace("Reading Sprout DBD from $filename.") if T(2);
1993          # Slurp the XML file into a variable. Extensive use of options is used to insure we          # Slurp the XML file into a variable. Extensive use of options is used to insure we
1994          # get the exact structure we want.          # get the exact structure we want.
1995          my $metadata = XML::Simple::XMLin($filename,          my $metadata = XML::Simple::XMLin($filename,
# Line 2005  Line 2017 
2017          for my $entityName (keys %{$entityList}) {          for my $entityName (keys %{$entityList}) {
2018                  my $entityStructure = $entityList->{$entityName};                  my $entityStructure = $entityList->{$entityName};
2019                  #                  #
2020                  # The first step is to run creating all the entity's default values. For C<Field> elements,          # The first step is to create all the entity's default values. For C<Field> elements,
2021                  # the relation name must be added where it is not specified. For relationships,                  # the relation name must be added where it is not specified. For relationships,
2022                  # the B<from-link> and B<to-link> fields must be inserted, and for entities an B<id>                  # the B<from-link> and B<to-link> fields must be inserted, and for entities an B<id>
2023                  # field must be added to each relation. Finally, each field will have a C<PrettySort> attribute                  # field must be added to each relation. Finally, each field will have a C<PrettySort> attribute
# Line 2316  Line 2328 
2328          # index descriptor does not exist, it will be created automatically so we can add          # index descriptor does not exist, it will be created automatically so we can add
2329          # the field to it.          # the field to it.
2330          unshift @{$newIndex->{IndexFields}}, $firstField;          unshift @{$newIndex->{IndexFields}}, $firstField;
2331        # If this is a one-to-many relationship, the "To" index is unique.
2332        if ($relationshipStructure->{arity} eq "1M" && $indexKey eq "To") {
2333            $newIndex->{Unique} = 'true';
2334        }
2335          # Add the index to the relation.          # Add the index to the relation.
2336          _AddIndex("idx$relationshipName$indexKey", $relationStructure, $newIndex);          _AddIndex("idx$relationshipName$indexKey", $relationStructure, $newIndex);
2337  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.16

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3