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

Diff of /Sprout/ERDBLoadGroup.pm

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

revision 1.1, Tue Sep 30 15:23:55 2008 UTC revision 1.3, Thu Oct 2 16:32:42 2008 UTC
# Line 119  Line 119 
119    
120  =item source  =item source
121    
122  The object to be used by the subclass to access the source data.  The object to be used by the subclass to access the source data. If this parameter
123    is undefined, the source object will be retrieved from the database object as soon
124    as the client calls the L</source> method.
125    
126  =item db  =item db
127    
128  The [[ErdbPm]] object for the database being loaded.  The [[ErdbPm]] object for the database being loaded.
129    
 =item directory  
   
 Name of the directory to contain the load files.  
   
130  =item options  =item options
131    
132  Reference to a hash of options. At the current time, no options are needed  Reference to a hash of options. At the current time, no options are needed
# Line 140  Line 138 
138    
139  =back  =back
140    
 This constructor is deliberately kept lightweight in order to insure that  
 L</GetGroupHash> is high-performance. For this reason, the [[ERDBGeneratePm]]  
 objects in the loaders hash are not created until L</ProcessSection>.  
   
141  =cut  =cut
142    
143  sub new {  sub new {
144      # Get the parameters.      # Get the parameters.
145      my ($class, $source, $db, $directory, $options, @tables) = @_;      my ($class, $source, $db, $options, @tables) = @_;
146      # Create a statistics object      # Create a statistics object
147      my $stats = Stats->new();      my $stats = Stats->new();
148      # Compute the group name from the class name. It is the first word in      # Compute the group name from the class name. It is the first word in
149      # a name that is presumably capital case.      # a name that is presumably capital case.
150      my $group = ($class =~ /^([A-Z][a-z]+)/ ? $1 : $class);      my $group = ($class =~ /^([A-Z][a-z]+)/ ? $1 : $class);
151      # Validate the directory.      # Get the directory.
152        my $directory = $db->LoadDirectory();
153      Confess("Load directory \"$directory\" not found or invalid.") if ! -d $directory;      Confess("Load directory \"$directory\" not found or invalid.") if ! -d $directory;
154      # Create the ERDBLoadGroup object. Note that so far we don't have any loaders      # Create the ERDBLoadGroup object. Note that so far we don't have any loaders
155      # defined and the section has not yet been assigned. The "ProcessSection"      # defined and the section has not yet been assigned. The "ProcessSection"
# Line 324  Line 319 
319  sub source {  sub source {
320      # Get the parameters.      # Get the parameters.
321      my ($self) = @_;      my ($self) = @_;
322        # If we do not have a source object, retrieve it.
323        if (! defined $self->{source}) {
324            $self->{source} = $self->{db}->GetSourceObject();
325        }
326      # Return the result.      # Return the result.
327      return $self->{source};      return $self->{source};
328  }  }
# Line 468  Line 467 
467      my $retVal = {};      my $retVal = {};
468      # Loop through the list of load groups.      # Loop through the list of load groups.
469      for my $group ($erdb->LoadGroupList()) {      for my $group ($erdb->LoadGroupList()) {
         # Get a loader for this group.  
         my $loader = $erdb->Loader($group, {});  
470          # Stash the loader's tables in the output hash.          # Stash the loader's tables in the output hash.
471          $retVal->{$group} = $loader->{tables};          $retVal->{$group} = GetTables($erdb, $group);
472      }      }
473      # Return the result.      # Return the result.
474      return $retVal;      return $retVal;
475  }  }
476    
477  =head3 ComputeGroups  =head3 GetTables
478    
479      my @groupList = ERDBLoadGroup::ComputeGroups($erdb, $options, \@groups);      my @tables = ERDBLoadGroup::GetTables($group);
480    
481  Compute the actual list of groups determined by the incoming options and  Return the list of tables belonging to the specified load group.
 group list. If the list is an asterisk (C<*>), this method returns a list  
 of all the groups. If the options include C<resume>, this method returns  
 the first specified group and all the groups after it in the standard  
 ordering.  
482    
483  =over 4  =over 4
484    
485  =item erdb  =item erdb
486    
487  [[ErdbPm]] object for the database being loaded.  Return the list of tables for the specified load group.
488    
489  =item options  =item group
490    
491    Name of relevant group.
492    
493    =item RETURN
494    
495    Returns a list of a tables loaded by the specified group.
496    
497    =back
498    
499    =cut
500    
501    sub GetTables {
502        # Get the parameters.
503        my ($erdb, $group) = @_;
504        # Create a loader for the specified group.
505        my $loader = $erdb->Loader($group, undef, {});
506        # Extract the list of tables.
507        my @retVal = @{$loader->{tables}};
508        # Return the result.
509        return @retVal;
510    }
511    
512    
513    =head3 ComputeGroups
514    
515        my @groupList = ERDBLoadGroup::ComputeGroups($erdb, \@groups);
516    
517  Reference to a hash of command-line options for the command that started  Compute the actual list of groups determined by the incoming group list.
518  this load operation.  
519    =over 4
520    
521    =item erdb
522    
523    [[ErdbPm]] object for the database being loaded.
524    
525  =item groups  =item groups
526    
527  Reference to a list of group names specified on the command line.  Reference to a list of group names specified on the command line. A plus sign
528    (C<+>) has special meaning.
529    
530  =item RETURN  =item RETURN
531    
# Line 513  Line 538 
538    
539  sub ComputeGroups {  sub ComputeGroups {
540      # Get the parameters.      # Get the parameters.
541      my ($erdb, $options, $groups) = @_;      my ($erdb, $groups) = @_;
542      # Declare the return variable.      # Get the complete group list in standard order.
543        my @allGroups = $erdb->LoadGroupList();
544        # Create a hash for validation purposes. This will map each valid group
545        # name to its position in the standard order.
546        my %allGroupHash;
547        for (my $i = 0; $i <= $#allGroups; $i++) {
548            $allGroupHash{$allGroups[$i]} = $i;
549        }
550        # This variable will be the index of the last-processed group in
551        # the standard order. We start it before the first group in the list.
552        my $lastI = -1;
553        # The listed groups will be put in here.
554      my @retVal;      my @retVal;
555      # Check the group list.      # Process the group list.
556      if ($groups->[0] eq '*') {      for my $group (@$groups) {
557          # Load all groups.          # Process this group.
558          @retVal = $erdb->LoadGroupList();          if ($group eq '+') {
559      } elsif ($options->{resume}) {              # Here we have a plus sign. Push in everything after the previous
560          # Load all groups after and including the specified one.              # group processed. Note that we'll be ending at the last position.
561          my $starter = $groups->[0];              # A second "+" after this one will generate no entries in the result
         @retVal = $erdb->LoadGroupList();  
         shift @retVal until (! @retVal) || $retVal[0] eq $starter;  
         # If we didn't find the specified group, it's an error.  
         Confess("Invalid group name \"$starter\" in parameter list.") if (! @retVal);  
     } else {  
         # Here the groups are all on the command line. Stuff them in the return  
562          # list.          # list.
563          @retVal = @{$groups};              my $firstI = $lastI + 1;
564          # Verify that they're all valid.              $lastI = $#allGroups;
565          my %checker = map { $_ => 1 } $erdb->LoadGroupList();              push @retVal, @allGroups[$firstI..$lastI];
566          for my $group (@retVal) {          } elsif (exists $allGroupHash{$group}) {
567              Confess("Invalid group name \"$group\" in parameter list.")              # Here we have a valid group name. Push it into the list.
568                  if ! $checker{$group};              push @retVal, $group;
569                # Remember its location in case there's a plus sign.
570                $lastI = $allGroupHash{$group};
571            } else {
572                # This is an error.
573                Confess("Invalid load group name $group.");
574          }          }
575      }      }
576      # Normalize the group names and return them.      # Normalize the group names and return them.
577      return map { ucfirst $_ } @retVal;      return map { ucfirst $_ } @retVal;
578  }  }
579    
580    =head3 KillFileName
581    
582        my $fileName = ERDBLoadGroup::KillFileName($erdb, $directory);
583    
584    Compute the kill file name for the specified database in the specified
585    directory. When the [[ERDBGeneratorPl]] script sees the kill file, it will
586    terminate itself at the end of the current section.
587    
588    =over 4
589    
590    =item erdb
591    
592    Database
593    
594    =item directory (optional)
595    
596    Load directory for the database.
597    
598    =item RETURN
599    
600    Returns the specified database's kill file name. If a directory is specified,
601    it is prefixed to the name with an intervening slash.
602    
603    
604    =back
605    
606    =cut
607    
608    sub KillFileName {
609        # Get the parameters.
610        my ($erdb, $directory) = @_;
611        # Compute the kill file name. We start with the database name in
612        # lower case, then prefix it with "kill_";
613        my $dbName = lc ref $erdb;
614        my $retVal = ERDBGenerate::CreateFileName("kill_$dbName", undef, 'control', $directory);
615        # Return the result.
616        return $retVal;
617    }
618    
619    
620  =head2 Virtual Methods  =head2 Virtual Methods
621    
622  =head3 Generate  =head3 Generate

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3