[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.94, Thu Dec 6 14:58:03 2007 UTC revision 1.100, Tue Aug 12 06:07:06 2008 UTC
# Line 11  Line 11 
11      use Time::HiRes qw(gettimeofday);      use Time::HiRes qw(gettimeofday);
12      use Digest::MD5 qw(md5_base64);      use Digest::MD5 qw(md5_base64);
13      use CGI;      use CGI;
14        use WikiTools;
15    
16  =head1 Entity-Relationship Database Package  =head1 Entity-Relationship Database Package
17    
# Line 389  Line 390 
390                                    Entities => 'Entity',                                    Entities => 'Entity',
391                                    Fields => 'Field',                                    Fields => 'Field',
392                                    Indexes => 'Index',                                    Indexes => 'Index',
393                                    IndexFields => 'IndexField'                                    IndexFields => 'IndexField',
394                                      Issues => 'Issue',
395                                      Shapes => 'Shape'
396                                  },                                  },
397                    KeyAttr =>    { Relationship => 'name',                    KeyAttr =>    { Relationship => 'name',
398                                    Entity => 'name',                                    Entity => 'name',
399                                    Field => 'name'                                    Field => 'name',
400                                      Shape => 'name'
401                                  },                                  },
402                    SuppressEmpty => 1,                    SuppressEmpty => 1,
403                   );                   );
404    
405  my %XmlInOpts  = (  my %XmlInOpts  = (
406                    ForceArray => ['Field', 'Index', 'IndexField', 'Relationship', 'Entity'],                    ForceArray => [qw(Field Index IndexField Relationship Entity Shape)],
407                    ForceContent => 1,                    ForceContent => 1,
408                    NormalizeSpace => 2,                    NormalizeSpace => 2,
409                   );                   );
# Line 408  Line 412 
412                    XMLDecl => 1,                    XMLDecl => 1,
413                   );                   );
414    
   
415  =head2 Public Methods  =head2 Public Methods
416    
417  =head3 new  =head3 new
# Line 433  Line 436 
436    
437  sub new {  sub new {
438      # Get the parameters.      # Get the parameters.
439      my ($class, $dbh, $metaFileName, $options) = @_;      my ($class, $dbh, $metaFileName, %options) = @_;
440      # Load the meta-data.      # Load the meta-data.
441      my $metaData = _LoadMetaData($metaFileName);      my $metaData = _LoadMetaData($metaFileName);
442      # Create the object.      # Create the object.
# Line 657  Line 660 
660      return Data::Dumper::Dumper($self->{_metaData});      return Data::Dumper::Dumper($self->{_metaData});
661  }  }
662    
663    =head3 GenerateWikiData
664    
665        my @wikiLines = $erdb->GenerateWikiData();
666    
667    Build a description of the database for the wiki. The database will be
668    organized into a single page, with sections for each entity and relationship.
669    The return value is a list of text lines.
670    
671    =cut
672    
673    sub GenerateWikiData {
674        # Get the parameters.
675        my ($self) = @_;
676        # We'll build the wiki text in here.
677        my @retVal = ();
678        # Get the metadata object.
679        my $metadata = $self->{_metaData};
680        # Get the title string. This will become the page name.
681        my $title = $metadata->{Title}->{content};
682        # Get the entity and relationship lists.
683        my $entityList = $metadata->{Entities};
684        my $relationshipList = $metadata->{Relationships};
685        my $shapeList = $metadata->{Shapes};
686        # Start with the introductory text.
687        push @retVal, WikiTools::Heading(2, "Introduction");
688        if (my $notes = $metadata->{Notes}) {
689            push @retVal, WikiNote($notes->{content});
690        }
691        # Generate issue list.
692        if (my $issues = $metadata->{Issues}) {
693            push @retVal, WikiTools::Heading(3, 'Issues');
694            push @retVal, WikiTools::List(map { $_->{content} } @{$issues});
695        }
696        # Start the entity section.
697        push @retVal, WikiTools::Heading(2, "Entities");
698        # Loop through the entities. Note that unlike the situation with HTML, we
699        # don't need to generate the table of contents manually, just the data
700        # itself.
701        for my $key (sort keys %$entityList) {
702            # Create a header for this entity.
703            push @retVal, "", WikiTools::Heading(3, $key);
704            # Get the entity data.
705            my $entityData = $entityList->{$key};
706            # Plant the notes here, if there are any.
707            push @retVal, _ObjectNotes($entityData);
708            # Now we list the entity's relationships (if any). First, we build a list
709            # of the relationships relevant to this entity.
710            my @rels = ();
711            for my $rel (sort keys %$relationshipList) {
712                my $relStructure = $relationshipList->{$rel};
713                if ($relStructure->{from} eq $key || $relStructure->{to} eq $key) {
714                    # Get the relationship sentence.
715                    my $relSentence = _ComputeRelationshipSentence($rel, $relStructure);
716                    # Linkify it.
717                    my $linkedRel = WikiTools::LinkMarkup("#$rel", $rel);
718                    $relSentence =~ s/$rel/$linkedRel/;
719                    push @rels, $relSentence;
720                }
721            }
722            # Add the relationships as a Wiki list.
723            push @retVal, WikiTools::List(@rels);
724            # Get the entity's relations.
725            my $relationList = $entityData->{Relations};
726            # Loop through the relations, displaying them.
727            for my $relation (sort keys %{$relationList}) {
728                my $wikiString = _WikiRelationTable($relation, $relationList->{$relation});
729                push @retVal, $wikiString;
730            }
731        }
732        # Now the entities are documented. Next we do the relationships.
733        push @retVal, WikiTools::Heading(2, "Relationships");
734        for my $key (sort keys %$relationshipList) {
735            my $relationshipData = $relationshipList->{$key};
736            # Create the relationship heading.
737            push @retVal, WikiTools::Heading(3, $key);
738            # Describe the relationship arity. Note there's a bit of trickiness involving recursive
739            # many-to-many relationships. In a normal many-to-many we use two sentences to describe
740            # the arity (one for each direction). This is a bad idea for a recursive relationship,
741            # since both sentences will say the same thing.
742            my $arity = $relationshipData->{arity};
743            my $fromEntity = $relationshipData->{from};
744            my $toEntity = $relationshipData->{to};
745            my @listElements = ();
746            my $boldCode = WikiTools::BoldCode();
747            if ($arity eq "11") {
748                push @listElements, "Each $boldCode$fromEntity$boldCode relates to at most one $boldCode$toEntity$boldCode.";
749            } else {
750                push @listElements, "Each $boldCode$fromEntity$boldCode relates to multiple $boldCode${toEntity}s$boldCode.";
751                if ($arity eq "MM" && $fromEntity ne $toEntity) {
752                    push @listElements, "Each $boldCode$toEntity$boldCode relates to multiple $boldCode${fromEntity}s$boldCode.";
753                }
754            }
755            push @retVal, WikiTools::List(@listElements);
756            # Plant the notes here, if there are any.
757            push @retVal, _ObjectNotes($relationshipData);
758            # Finally, the relationship table.
759            my $wikiString = _WikiRelationTable($key, $relationshipData->{Relations}->{$key});
760            push @retVal, $wikiString;
761        }
762        # Now loop through the miscellaneous shapes.
763        if ($shapeList) {
764            push @retVal, WikiTools::Heading(2, "Miscellaneous");
765            for my $shape (sort keys %$shapeList) {
766                push @retVal, WikiTools::Heading(3, $shape);
767                my $shapeData = $shapeList->{$shape};
768                push @retVal, _ObjectNotes($shapeData);
769            }
770        }
771        # All done. Return the lines.
772        return @retVal;
773    }
774    
775    
776  =head3 CreatePPO  =head3 CreatePPO
777    
778      ERDB::CreatePPO($erdbXMLFile, $ppoXMLFile);      ERDB::CreatePPO($erdbXMLFile, $ppoXMLFile);
# Line 946  Line 1062 
1062          # Push the result into the field list.          # Push the result into the field list.
1063          push @fieldList, $fieldString;          push @fieldList, $fieldString;
1064      }      }
     # If this is a root table, add the "new_record" flag. It defaults to 0, so  
     if ($rootFlag) {  
         push @fieldList, "new_record $TypeTable{boolean}->{sqlType} NOT NULL DEFAULT 0";  
     }  
1065      # Convert the field list into a comma-delimited string.      # Convert the field list into a comma-delimited string.
1066      my $fieldThing = join(', ', @fieldList);      my $fieldThing = join(', ', @fieldList);
1067      # Insure the table is not already there.      # Insure the table is not already there.
# Line 1416  Line 1528 
1528      return sort keys %{$entityList};      return sort keys %{$entityList};
1529  }  }
1530    
1531    =head3 GetConnectingRelationships
1532    
1533        my @list = $erdb->GetConnectingRelationships($entityName);
1534    
1535    Return a list of the relationships connected to the specified entity.
1536    
1537    =over 4
1538    
1539    =item entityName
1540    
1541    Entity whose connected relationships are desired.
1542    
1543    =item RETURN
1544    
1545    Returns a list of the relationships that originate from the entity.
1546    If the entity is on the from end, it will return the relationship
1547    name. If the entity is on the to end it will return the converse of
1548    the relationship name.
1549    
1550    =back
1551    
1552    =cut
1553    
1554    sub GetConnectingRelationships {
1555        # Get the parameters.
1556        my ($self, $entityName) = @_;
1557        # Declare the return variable.
1558        my @retVal;
1559        # Get the relationship list.
1560        my $relationships = $self->{_metaData}->{Relationships};
1561        # Find the entity.
1562        my $entity = $self->{_metaData}->{Entities}->{$entityName};
1563        # Only proceed if the entity exists.
1564        if (! defined $entity) {
1565            Trace("Entity $entityName not found.") if T(3);
1566        } else {
1567            # Loop through the relationships.
1568            my @rels = keys %$relationships;
1569            Trace(scalar(@rels) . " relationships found in connection search.") if T(3);
1570            for my $relationshipName (@rels) {
1571                my $relationship = $relationships->{$relationshipName};
1572                if ($relationship->{from} eq $entityName) {
1573                    # Here we have a forward relationship.
1574                    push @retVal, $relationshipName;
1575                } elsif ($relationship->{to} eq $entityName) {
1576                    # Here we have a backward relationship. In this case, the
1577                    # converse relationship name is preferred if it exists.
1578                    my $converse = $relationship->{converse} || $relationshipName;
1579                    push @retVal, $converse;
1580                }
1581            }
1582        }
1583        # Return the result.
1584        return @retVal;
1585    }
1586    
1587    
1588    
1589    
1590  =head3 GetDataTypes  =head3 GetDataTypes
1591    
1592      my %types = ERDB::GetDataTypes();      my %types = ERDB::GetDataTypes();
# Line 1999  Line 2170 
2170          # Loop through the ends of the relationship.          # Loop through the ends of the relationship.
2171          for my $dir ('from', 'to') {          for my $dir ('from', 'to') {
2172              if ($structure->{$dir} eq $originEntityName) {              if ($structure->{$dir} eq $originEntityName) {
                 # Delete all relationship instances on this side of the entity instance.  
                 Trace("Disconnecting in $dir direction with ID \"$originEntityID\".");  
                 $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ?", 0, $originEntityID);  
2173                  $found = 1;                  $found = 1;
2174                    # Here we want to delete all relationship instances on this side of the
2175                    # entity instance.
2176                    Trace("Disconnecting in $dir direction with ID \"$originEntityID\".");
2177                    # We do this delete in batches to keep it from dragging down the
2178                    # server.
2179                    my $limitClause = ($FIG_Config::delete_limit ? "LIMIT $FIG_Config::delete_limit" : "");
2180                    my $done = 0;
2181                    while (! $done) {
2182                        # Do the delete.
2183                        my $rows = $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ? $limitClause", 0, $originEntityID);
2184                        # See if we're done. We're done if no rows were found or the delete is unlimited.
2185                        $done = ($rows == 0 || ! $limitClause);
2186                    }
2187              }              }
2188          }          }
2189          # Insure we found the entity on at least one end.          # Insure we found the entity on at least one end.
# Line 2190  Line 2371 
2371      }      }
2372      # Now we parse the key names into sort parameters. First, we prime the return      # Now we parse the key names into sort parameters. First, we prime the return
2373      # string.      # string.
2374      my $retVal = "sort -t\"\t\" ";      my $retVal = "sort -T\"$FIG_Config::temp\" -t\"\t\" ";
2375      # Get the relation's field list.      # Get the relation's field list.
2376      my @fields = @{$relationData->{Fields}};      my @fields = @{$relationData->{Fields}};
2377      # Loop through the keys.      # Loop through the keys.
# Line 2220  Line 2401 
2401                  # will stop the inner loop. Note that the field number is                  # will stop the inner loop. Note that the field number is
2402                  # 1-based in the sort command, so we have to increment the                  # 1-based in the sort command, so we have to increment the
2403                  # index.                  # index.
2404                  $fieldSpec = ($i + 1) . $modifier;                  my $realI = $i + 1;
2405                    $fieldSpec = "$realI,$realI$modifier";
2406              }              }
2407          }          }
2408          # Add this field to the sort command.          # Add this field to the sort command.
# Line 2611  Line 2793 
2793                  push @missing, $fieldName;                  push @missing, $fieldName;
2794              }              }
2795          }          }
         # If we are the primary relation, add the new-record flag.  
         if ($relationName eq $newObjectType) {  
             push @valueList, 1;  
             push @fieldNameList, "new_record";  
         }  
2796          # Only proceed if there are no missing fields.          # Only proceed if there are no missing fields.
2797          if (@missing > 0) {          if (@missing > 0) {
2798              Trace("Relation $relationName for $newObjectType skipped due to missing fields: " .              Trace("Relation $relationName for $newObjectType skipped due to missing fields: " .
# Line 2723  Line 2900 
2900    
2901  =head3 LoadTable  =head3 LoadTable
2902    
2903      my $results = $erdb->LoadTable($fileName, $relationName, $truncateFlag);      my $results = $erdb->LoadTable($fileName, $relationName, %options);
2904    
2905  Load data from a tab-delimited file into a specified table, optionally re-creating the table  Load data from a tab-delimited file into a specified table, optionally re-creating the table
2906  first.  first.
# Line 2738  Line 2915 
2915    
2916  Name of the relation to be loaded. This is the same as the table name.  Name of the relation to be loaded. This is the same as the table name.
2917    
2918  =item truncateFlag  =item options
2919    
2920  TRUE if the table should be dropped and re-created, else FALSE  A hash of load options.
2921    
2922  =item RETURN  =item RETURN
2923    
# Line 2748  Line 2925 
2925    
2926  =back  =back
2927    
2928    The permissible options are as follows.
2929    
2930    =over 4
2931    
2932    =item truncate
2933    
2934    If TRUE, then the table will be erased before loading.
2935    
2936    =item mode
2937    
2938    Mode in which the load should operate, either C<low_priority> or C<concurrent>.
2939    This option is only applicable to a MySQL database.
2940    
2941    =item partial
2942    
2943    If TRUE, then it is assumed that this is a partial load, and the table will not
2944    be analyzed and compacted at the end.
2945    
2946    =back
2947    
2948  =cut  =cut
2949  sub LoadTable {  sub LoadTable {
2950      # Get the parameters.      # Get the parameters.
2951      my ($self, $fileName, $relationName, $truncateFlag) = @_;      my ($self, $fileName, $relationName, %options) = @_;
2952      # Create the statistical return object.      # Create the statistical return object.
2953      my $retVal = _GetLoadStats();      my $retVal = _GetLoadStats();
2954      # Trace the fact of the load.      # Trace the fact of the load.
# Line 2763  Line 2960 
2960      # Get the relation data.      # Get the relation data.
2961      my $relation = $self->_FindRelation($relationName);      my $relation = $self->_FindRelation($relationName);
2962      # Check the truncation flag.      # Check the truncation flag.
2963      if ($truncateFlag) {      if ($options{truncate}) {
2964          Trace("Creating table $relationName") if T(2);          Trace("Creating table $relationName") if T(2);
2965          # Compute the row count estimate. We take the size of the load file,          # Compute the row count estimate. We take the size of the load file,
2966          # divide it by the estimated row size, and then multiply by 2 to          # divide it by the estimated row size, and then multiply by 2 to
# Line 2789  Line 2986 
2986      # Load the table.      # Load the table.
2987      my $rv;      my $rv;
2988      eval {      eval {
2989          $rv = $dbh->load_table(file => $fileName, tbl => $relationName);          $rv = $dbh->load_table(file => $fileName, tbl => $relationName, style => $options{mode});
2990      };      };
2991      if (!defined $rv) {      if (!defined $rv) {
2992          $retVal->AddMessage($@) if ($@);          $retVal->AddMessage($@) if ($@);
# Line 2800  Line 2997 
2997          $retVal->Add("tables");          $retVal->Add("tables");
2998          my $size = -s $fileName;          my $size = -s $fileName;
2999          Trace("$size bytes loaded into $relationName.") if T(2);          Trace("$size bytes loaded into $relationName.") if T(2);
3000            $retVal->Add("bytes", $size);
3001          # If we're rebuilding, we need to create the table indexes.          # If we're rebuilding, we need to create the table indexes.
3002          if ($truncateFlag) {          if ($options{truncate}) {
3003              # Indexes are created here for PostGres. For PostGres, indexes are              # Indexes are created here for PostGres. For PostGres, indexes are
3004              # best built at the end. For MySQL, the reverse is true.              # best built at the end. For MySQL, the reverse is true.
3005              if (! $dbh->{_preIndex}) {              if (! $dbh->{_preIndex}) {
# Line 2822  Line 3020 
3020          }          }
3021      }      }
3022      # Analyze the table to improve performance.      # Analyze the table to improve performance.
3023        if (! $options{partial}) {
3024      Trace("Analyzing and compacting $relationName.") if T(3);      Trace("Analyzing and compacting $relationName.") if T(3);
3025      $dbh->vacuum_it($relationName);          $self->Analyze($relationName);
3026        }
3027      Trace("$relationName load completed.") if T(3);      Trace("$relationName load completed.") if T(3);
3028      # Return the statistics.      # Return the statistics.
3029      return $retVal;      return $retVal;
3030  }  }
3031    
3032    =head3 Analyze
3033    
3034        $erdb->Analyze($tableName);
3035    
3036    Analyze and compact a table in the database. This is useful after a load
3037    to improve the performance of the indexes.
3038    
3039    =over 4
3040    
3041    =item tableName
3042    
3043    Name of the table to be analyzed and compacted.
3044    
3045    =back
3046    
3047    =cut
3048    
3049    sub Analyze {
3050        # Get the parameters.
3051        my ($self, $tableName) = @_;
3052        # Analyze the table.
3053        $self->{_dbh}->vacuum_it($tableName);
3054    }
3055    
3056    =head3 TruncateTable
3057    
3058        $erdb->TruncateTable($table);
3059    
3060    Delete all rows from a table quickly. This uses the built-in SQL
3061    C<TRUNCATE> statement, which effectively drops and re-creates a table
3062    with all its settings intact.
3063    
3064    =over 4
3065    
3066    =item table
3067    
3068    Name of the table to be cleared.
3069    
3070    =back
3071    
3072    =cut
3073    
3074    sub TruncateTable {
3075        # Get the parameters.
3076        my ($self, $table) = @_;
3077        # Get the database handle.
3078        my $dbh = $self->{_dbh};
3079        # Execute a truncation comment.
3080        $dbh->SQL("TRUNCATE TABLE $table");
3081    }
3082    
3083    
3084  =head3 CreateSearchIndex  =head3 CreateSearchIndex
3085    
3086      $erdb->CreateSearchIndex($objectName);      $erdb->CreateSearchIndex($objectName);
# Line 3558  Line 3810 
3810      return $retVal;      return $retVal;
3811  }  }
3812    
3813    =head3 WikiNote
3814    
3815    Convert a note or comment to Wiki text by replacing some bulletin-board codes with HTML. The codes
3816    supported are C<[b]> for B<bold>, C<[i]> for I<italics>, and C<[p]> for a new paragraph.
3817    Except for C<[p]>, all the codes are closed by slash-codes. So, for
3818    example, C<[b]Feature[/b]> displays the string C<Feature> in boldface.
3819    
3820        my $wikiText = ERDB::WikiNote($dataString);
3821    
3822    =over 4
3823    
3824    =item dataString
3825    
3826    String to convert to Wiki text.
3827    
3828    =item RETURN
3829    
3830    An Wiki text string derived from the input string.
3831    
3832    =back
3833    
3834    =cut
3835    
3836    sub WikiNote {
3837        # Get the parameter.
3838        my ($dataString) = @_;
3839        # HTML-escape the text.
3840        my $retVal = CGI::escapeHTML($dataString);
3841        # Substitute the bulletin board codes.
3842        my $italic = WikiTools::ItalicCode();
3843        $retVal =~ s/\[\/?i\]/$italic/g;
3844        my $bold = WikiTools::BoldCode();
3845        $retVal =~ s/\[\/?b\]/$bold/g;
3846        # Paragraph breaks are the same no matter which Wiki you're using.
3847        $retVal =~ s!\[p\]!\n\n!g;
3848        # Now we do the links, which are complicated by the need to know two
3849        # things: the target URL and the text.
3850        while ($retVal =~ /\[link\s+([^\]]+)\]([^\[]+)\[\/link\]/g) {
3851            # Replace the matched string with the Wiki markup for links. Note that
3852            # $-[0] is the starting position of the match for the entire expression,
3853            # and $+[0] is past the ending position.
3854            substr $retVal, $-[0], $+[0] - $-[0], WikiTools::LinkMarkup($1, $2);
3855        }
3856        # Return the result.
3857        return $retVal;
3858    }
3859    
3860  =head3 BeginTran  =head3 BeginTran
3861    
3862      $erdb->BeginTran();      $erdb->BeginTran();
# Line 3840  Line 4139 
4139    
4140  =over 4  =over 4
4141    
4142    =item indexObject
4143    
4144  ERDB XML structure for an index.  ERDB XML structure for an index.
4145    
4146  =item RETURN  =item RETURN
# Line 4499  Line 4800 
4800      # be a null string.      # be a null string.
4801      if ($fileName ne "") {      if ($fileName ne "") {
4802          # Load the relation from the file.          # Load the relation from the file.
4803          $retVal = $self->LoadTable($fileName, $relationName, $rebuild);          $retVal = $self->LoadTable($fileName, $relationName, truncate => $rebuild);
4804      } elsif ($rebuild) {      } elsif ($rebuild) {
4805          # Here we are rebuilding, but no file exists, so we just re-create the table.          # Here we are rebuilding, but no file exists, so we just re-create the table.
4806          $self->CreateTable($relationName, 1);          $self->CreateTable($relationName, 1);
# Line 5246  Line 5547 
5547      return $retVal;      return $retVal;
5548  }  }
5549    
5550  =head2 HTML Documentation Utility Methods  =head2 Documentation Utility Methods
5551    
5552  =head3 _ComputeRelationshipSentence  =head3 _ComputeRelationshipSentence
5553    
# Line 5278  Line 5579 
5579      # Get the parameters.      # Get the parameters.
5580      my ($relationshipName, $relationshipStructure) = @_;      my ($relationshipName, $relationshipStructure) = @_;
5581      # Format the relationship sentence.      # Format the relationship sentence.
5582      my $result = "$relationshipStructure->{from} <b>$relationshipName</b> $relationshipStructure->{to}";      my $result = "$relationshipStructure->{from} $relationshipName $relationshipStructure->{to}";
5583      # Compute the arity.      # Compute the arity.
5584      my $arityCode = $relationshipStructure->{arity};      my $arityCode = $relationshipStructure->{arity};
5585      my $arity = $ArityTable{$arityCode};      my $arity = $ArityTable{$arityCode};
# Line 5323  Line 5624 
5624      return $result;      return $result;
5625  }  }
5626    
5627    =head3 _WikiRelationTable
5628    
5629    Generate the Wiki text for a particular relation. The relation's data will be formatted as a
5630    table with three columns-- the field name, the field type, and the field description.
5631    
5632    This is a static method.
5633    
5634    =over 4
5635    
5636    =item relationName
5637    
5638    Name of the relation being formatted.
5639    
5640    =item relationData
5641    
5642    Hash containing the relation's fields and indexes.
5643    
5644    =item RETURN
5645    
5646    Returns a Wiki string that can be used to display the relation name and all of its fields.
5647    
5648    =back
5649    
5650    =cut
5651    
5652    sub _WikiRelationTable {
5653        # Get the parameters.
5654        my ($relationName, $relationData) = @_;
5655        # We'll create a list of lists in here, then call WikiTools::Table to
5656        # convert it into a table.
5657        my @rows = ();
5658        # Push in the header row.
5659        push @rows, [qw(Field Type Description)];
5660        # Loop through the fields.
5661        for my $field (@{$relationData->{Fields}}) {
5662            # Create this field's row. We always have a name and type.
5663            my @row = ($field->{name}, $field->{type});
5664            # If we have a description, add it as the third column.
5665            if (exists $field->{Notes}) {
5666                push @row, WikiNote($field->{Notes}->{content});
5667            }
5668            # Push this row onto the table list.
5669            push @rows, \@row;
5670        }
5671        # Store the rows as a Wiki table with a level-4 heading.
5672        my $retVal = join("\n\n", WikiTools::Heading(4, "$relationName Table"),
5673                          WikiTools::Table(@rows));
5674        # Now we show the relation's indexes. These are formatted as another
5675        # table.
5676        @rows = ();
5677        # Push in the header row.
5678        push @rows, [qw(Index Unique Fields Notes)];
5679        # Get the index hash.
5680        my $indexTable = $relationData->{Indexes};
5681        # Loop through the indexes. For an entity, there is always at least one index.
5682        # For a relationship, there are at least two. The upshot is we don't need to
5683        # worry about accidentally generating a frivolous table here.
5684        for my $indexName (sort keys %$indexTable) {
5685            my $indexData = $indexTable->{$indexName};
5686            # Determine whether or not the index is unique.
5687            my $unique = ((exists $indexData->{Unique} && $indexData->{Unique} eq "true") ?
5688                          "yes" : "");
5689            # Get the field list.
5690            my $fields = join(', ', @{$indexData->{IndexFields}});
5691            # Get the note text.
5692            my $description = "";
5693            if (my $note = $indexData->{Notes}) {
5694                $description = WikiNote($note->{content});
5695            }
5696            # Format this row.
5697            my @row = ($indexName, $unique, $fields, $description);
5698            push @rows, \@row;
5699        }
5700        # Add the index list to the result.
5701        $retVal .= "\n\n" . WikiTools::Table(@rows);
5702    }
5703    
5704  =head3 _ShowRelationTable  =head3 _ShowRelationTable
5705    
5706  Generate the HTML string for a particular relation. The relation's data will be formatted as an HTML  Generate the HTML string for a particular relation. The relation's data will be formatted as an HTML
# Line 5496  Line 5874 
5874      return $htmlString;      return $htmlString;
5875  }  }
5876    
5877    =head3 _ObjectNotes
5878    
5879        my @noteParagraphs = _ObjectNotes($objectData);
5880    
5881    Return a list of the notes and asides for an entity or relationship in
5882    Wiki format.
5883    
5884    =over 4
5885    
5886    =item objectData
5887    
5888    The metadata for the desired entity or relationship.
5889    
5890    =item RETURN
5891    
5892    Returns a list of text paragraphs in Wiki markup form.
5893    
5894    =back
5895    
5896    =cut
5897    
5898    sub _ObjectNotes {
5899        # Get the parameters.
5900        my ($objectData) = @_;
5901        # Declare the return variable.
5902        my @retVal;
5903        # Loop through the types of notes.
5904        for my $noteType (qw(Notes Asides)) {
5905            my $text = $objectData->{$noteType};
5906            if ($text) {
5907                push @retVal, "", WikiNote($text->{content});
5908            }
5909        }
5910        # Return the result.
5911        return @retVal;
5912    }
5913    
5914  1;  1;

Legend:
Removed from v.1.94  
changed lines
  Added in v.1.100

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3