[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.85, Fri Feb 9 22:59:53 2007 UTC revision 1.87, Sun Feb 18 21:28:19 2007 UTC
# Line 228  Line 228 
228    
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 in an
232  all be from the same relation. The alternate indexes assist in ordering results  index must all be from the same relation. The alternate indexes assist in searching
233  from a query. A relationship can have up to two indexes-- a I<to-index> and a  on fields other than the entity ID. A relationship has at least two indexes-- a I<to-index> and a
234  I<from-index>. These order the results when crossing the relationship. For  I<from-index> that 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
236  from-index would order the contigs of a ganome, and the to-index would order  from-index would order the contigs of a ganome, and the to-index would order
237  the genomes of a contig. A relationship's index must specify only fields in  the genomes of a contig. In addition, it can have zero or more alternate
238    indexes. A relationship's index must specify only fields in
239  the relationship.  the relationship.
240    
241  The indexes for an entity must be listed inside the B<Indexes> tag. The from-index  The alternate indexes for an entity or relationship must be listed inside the B<Indexes> tag.
242  of a relationship is specified using the B<FromIndex> tag; the to-index is specified  The from-index of a relationship is specified using the B<FromIndex> tag; the to-index is
243  using the B<ToIndex> tag.  specified using the B<ToIndex> tag.
244    
245  Each index can contain a B<Notes> tag. In addition, it will have an B<IndexFields>  Each index can contain a B<Notes> tag. In addition, it will have an B<IndexFields>
246  tag containing the B<IndexField> tags. These specify, in order, the fields used in  tag containing the B<IndexField> tags. These specify, in order, the fields used in
# Line 303  Line 304 
304    
305  A relationship is described by the C<Relationship> tag. Within a relationship,  A relationship is described by the C<Relationship> tag. Within a relationship,
306  there can be a C<Notes> tag, a C<Fields> tag containing the intersection data  there can be a C<Notes> tag, a C<Fields> tag containing the intersection data
307  fields, a C<FromIndex> tag containing the from-index, and a C<ToIndex> tag containing  fields, a C<FromIndex> tag containing the from-index, a C<ToIndex> tag containing
308  the to-index.  the to-index, and an C<Indexes> tag containing the alternate indexes.
309    
310  The C<Relationship> tag has the following attributes.  The C<Relationship> tag has the following attributes.
311    
# Line 743  Line 744 
744      # Loop through the relations.      # Loop through the relations.
745      for my $relationName (@relNames) {      for my $relationName (@relNames) {
746          # Create a table for this relation.          # Create a table for this relation.
747          $self->CreateTable($relationName);          $self->CreateTable($relationName, 1);
748          Trace("Relation $relationName created.") if T(2);          Trace("Relation $relationName created.") if T(2);
749      }      }
750  }  }
# Line 3335  Line 3336 
3336      return $retVal;      return $retVal;
3337  }  }
3338    
3339    =head3 BeginTran
3340    
3341    C<< $erdb->BeginTran(); >>
3342    
3343    Start a database transaction.
3344    
3345    =cut
3346    
3347    sub BeginTran {
3348        my ($self) = @_;
3349        $self->{_dbh}->begin_tran();
3350    
3351    }
3352    
3353    =head3 CommitTran
3354    
3355    C<< $erdb->CommitTran(); >>
3356    
3357    Commit an active database transaction.
3358    
3359    =cut
3360    
3361    sub CommitTran {
3362        my ($self) = @_;
3363        $self->{_dbh}->commit_tran();
3364    }
3365    
3366    =head3 RollbackTran
3367    
3368    C<< $erdb->RollbackTran(); >>
3369    
3370    Roll back an active database transaction.
3371    
3372    =cut
3373    
3374    sub RollbackTran {
3375        my ($self) = @_;
3376        $self->{_dbh}->roll_tran();
3377    }
3378    
3379    
3380  =head2 Data Mining Methods  =head2 Data Mining Methods
3381    
# Line 4102  Line 4143 
4143    
4144  =head3 _LoadMetaData  =head3 _LoadMetaData
4145    
4146    C<< my $metadata = ERDB::_LoadMetaData($filename); >>
4147    
4148  This method loads the data describing this database from an XML file into a metadata structure.  This method loads the data describing this database from an XML file into a metadata structure.
4149  The resulting structure is a set of nested hash tables containing all the information needed to  The resulting structure is a set of nested hash tables containing all the information needed to
4150  load or use the database. The schema for the XML file is F<ERDatabase.xml>.  load or use the database. The schema for the XML file is F<ERDatabase.xml>.
# Line 4251  Line 4294 
4294              if ($found == 0) {              if ($found == 0) {
4295                  push @{$indexList}, { IndexFields => [ {name => 'id', order => 'ascending'} ] };                  push @{$indexList}, { IndexFields => [ {name => 'id', order => 'ascending'} ] };
4296              }              }
4297              # Now we need to convert the relation's index list to an index table. We begin by creating              # Attach all the indexes to the relation.
4298              # an empty table in the relation structure.              _ProcessIndexes($indexList, $relation);
             $relation->{Indexes} = { };  
             # Loop through the indexes.  
             my $count = 0;  
             for my $index (@{$indexList}) {  
                 # Add this index to the index table.  
                 _AddIndex("idx$count", $relation, $index);  
                 # Increment the counter so that the next index has a different name.  
                 $count++;  
             }  
4299          }          }
4300          # Finally, we add the relation structure to the entity.          # Finally, we add the relation structure to the entity.
4301          $entityStructure->{Relations} = $relationTable;          $entityStructure->{Relations} = $relationTable;
# Line 4297  Line 4331 
4331          my $thisRelation = { Fields => _ReOrderRelationTable($relationshipStructure->{Fields}),          my $thisRelation = { Fields => _ReOrderRelationTable($relationshipStructure->{Fields}),
4332                               Indexes => { } };                               Indexes => { } };
4333          $relationshipStructure->{Relations} = { $relationshipName => $thisRelation };          $relationshipStructure->{Relations} = { $relationshipName => $thisRelation };
4334    
4335            # Add the alternate indexes (if any). This MUST be done before the FROM and
4336            # TO indexes, because it erases the relation's index list.
4337            if (exists $relationshipStructure->{Indexes}) {
4338                _ProcessIndexes($relationshipStructure->{Indexes}, $thisRelation);
4339            }
4340            # Add the relation to the master table.
4341          # Create the FROM and TO indexes.          # Create the FROM and TO indexes.
4342          _CreateRelationshipIndex("From", $relationshipName, $relationshipStructure);          _CreateRelationshipIndex("From", $relationshipName, $relationshipStructure);
4343          _CreateRelationshipIndex("To", $relationshipName, $relationshipStructure);          _CreateRelationshipIndex("To", $relationshipName, $relationshipStructure);
         # Add the relation to the master table.  
4344          $masterRelationTable{$relationshipName} = $thisRelation;          $masterRelationTable{$relationshipName} = $thisRelation;
4345      }      }
4346      # Now store the master relation table in the metadata structure.      # Now store the master relation table in the metadata structure.
# Line 4459  Line 4499 
4499      _AddIndex("idx$indexKey", $relationStructure, $newIndex);      _AddIndex("idx$indexKey", $relationStructure, $newIndex);
4500  }  }
4501    
4502    =head3 _ProcessIndexes
4503    
4504    C<< ERDB::_ProcessIndexes($indexList, $relation); >>
4505    
4506    Build the data structures for the specified indexes in the specified relation.
4507    
4508    =over 4
4509    
4510    =item indexList
4511    
4512    Reference to a list of indexes. Each index is a hash reference containing an optional
4513    C<Notes> value that describes the index and an C<IndexFields> value that is a reference
4514    to a list of index field structures. An index field structure, in turn, is a reference
4515    to a hash that contains a C<name> attribute for the field name and an C<order>
4516    attribute that specifies either C<ascending> or C<descending>. In this sense the
4517    index list encapsulates the XML C<Indexes> structure in the database definition.
4518    
4519    =item relation
4520    
4521    The structure that describes the current relation. The new index descriptors will
4522    be stored in the structure's C<Indexes> member. Any previous data in the structure
4523    will be lost.
4524    
4525    =back
4526    
4527    =cut
4528    
4529    sub _ProcessIndexes {
4530        # Get the parameters.
4531        my ($indexList, $relation) = @_;
4532        # Now we need to convert the relation's index list to an index table. We begin by creating
4533        # an empty table in the relation structure.
4534        $relation->{Indexes} = { };
4535        # Loop through the indexes.
4536        my $count = 0;
4537        for my $index (@{$indexList}) {
4538            # Add this index to the index table.
4539            _AddIndex("idx$count", $relation, $index);
4540            # Increment the counter so that the next index has a different name.
4541            $count++;
4542        }
4543    }
4544    
4545  =head3 _AddIndex  =head3 _AddIndex
4546    
4547  Add an index to a relation structure.  Add an index to a relation structure.

Legend:
Removed from v.1.85  
changed lines
  Added in v.1.87

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3