[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.73, Fri Nov 3 00:33:26 2006 UTC revision 1.74, Fri Nov 3 16:49:44 2006 UTC
# Line 229  Line 229 
229  =head3 Indexes  =head3 Indexes
230    
231  An entity can have multiple alternate indexes associated with it. The fields must  An entity can have multiple alternate indexes associated with it. The fields must
232  be from the primary relation. The alternate indexes assist in ordering results  all be from the same relation. The alternate indexes assist in ordering results
233  from a query. A relationship can have up to two indexes-- a I<to-index> and a  from a query. A relationship can have up to two indexes-- a I<to-index> and a
234  I<from-index>. These order the results when crossing the relationship. For  I<from-index>. These order the results when crossing the relationship. For
235  example, in the relationship C<HasContig> from C<Genome> to C<Contig>, the  example, in the relationship C<HasContig> from C<Genome> to C<Contig>, the
# Line 646  Line 646 
646      return Data::Dumper::Dumper($self->{_metaData});      return Data::Dumper::Dumper($self->{_metaData});
647  }  }
648    
649    =head3 FindIndexForEntity
650    
651    C<< my $indexFound = ERDB::FindIndexForEntity($xml, $entityName, $attributeName); >>
652    
653    This method locates the entry in an entity's index list that begins with the
654    specified attribute name. If the entity has no index list, one will be
655    created. This method works on raw XML, not a live ERDB object.
656    
657    =over 4
658    
659    =item xml
660    
661    The raw XML structure defining the database.
662    
663    =item entityName
664    
665    The name of the relevant entity.
666    
667    =item attributeName
668    
669    The name of the attribute relevant to the search.
670    
671    =item RETURN
672    
673    The numerical index in the index list of the index entry for the specified entity and
674    attribute, or C<undef> if no such index exists.
675    
676    =back
677    
678    =cut
679    
680    sub FindIndexForEntity {
681        # Get the parameters.
682        my ($xml, $entityName, $attributeName) = @_;
683        # Declare the return variable.
684        my $retVal;
685        # Get the named entity.
686        my $entityData = $xml->{Entities}->{$entityName};
687        if (! $entityData) {
688            Confess("Entity $entityName not found in DBD structure.");
689        } else {
690            # Insure it has an index list.
691            if (! exists $entityData->{Indexes}) {
692                $entityData->{Indexes} = [];
693            } else {
694                # Search for the desired index.
695                my $indexList = $entityData->{Indexes};
696                my $n = scalar @{$indexList};
697                Trace("Searching $n indexes in index list for $entityName.") if T(2);
698                # We use an indexed FOR here because we're returning an
699                # index number instead of an object. We do THAT so we can
700                # delete the index from the list if needed.
701                for (my $i = 0; $i < $n && !defined($retVal); $i++) {
702                    my $index = $indexList->[$i];
703                    my $fields = $index->{IndexFields};
704                    # Technically this IF should be safe (that is, we are guaranteed
705                    # the existence of a "$fields->[0]"), because when we load the XML
706                    # we have SuppressEmpty specified.
707                    if ($fields->[0]->{name} eq $attributeName) {
708                        $retVal = $i;
709                    }
710                }
711            }
712        }
713        Trace("Index for $attributeName of $entityName found at position $retVal.") if defined($retVal) && T(3);
714        Trace("Index for $attributeName not found in $entityName.") if !defined($retVal) && T(3);
715        # Return the result.
716        return $retVal;
717    }
718    
719  =head3 CreateTables  =head3 CreateTables
720    
721  C<< $erdb->CreateTables(); >>  C<< $erdb->CreateTables(); >>
# Line 2189  Line 2259 
2259      my $dbh = $self->{_dbh};      my $dbh = $self->{_dbh};
2260      # Drop the relation. The method used here has no effect if the relation      # Drop the relation. The method used here has no effect if the relation
2261      # does not exist.      # does not exist.
2262      $dbh->drop_table($relationName);      Trace("Invoking DB Kernel to drop $relationName.") if T(3);
2263        $dbh->drop_table(tbl => $relationName);
2264  }  }
2265    
2266  =head3 GetEntity  =head3 GetEntity

Legend:
Removed from v.1.73  
changed lines
  Added in v.1.74

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3