[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.2, Tue Jan 25 01:00:20 2005 UTC revision 1.5, Tue Apr 5 05:17:01 2005 UTC
# Line 67  Line 67 
67  was inserted by the L</InsertObject> method.  was inserted by the L</InsertObject> method.
68    
69  To facilitate testing, the ERDB module supports automatic generation of test data. This process  To facilitate testing, the ERDB module supports automatic generation of test data. This process
70  is described in the L</GenerateEntity> and L</GenerateConnection> methods.  is described in the L</GenerateEntity> and L</GenerateConnection> methods, though it is not yet
71    fully implemented.
72    
73  =cut  =cut
74    
# Line 111  Line 112 
112    
113  =head3 new  =head3 new
114    
115  C<< my $database = ERDB::new($dbh, $metaFileName); >>  C<< my $database = ERDB->new($dbh, $metaFileName); >>
116    
117  Create a new ERDB object.  Create a new ERDB object.
118    
# Line 136  Line 137 
137          my $metaData = _LoadMetaData($metaFileName);          my $metaData = _LoadMetaData($metaFileName);
138          # Create the object.          # Create the object.
139          my $self = { _dbh => $dbh,          my $self = { _dbh => $dbh,
140                                   _metaData => $metaData,                                   _metaData => $metaData
                                  _options => $options,  
141                             };                             };
142          # Bless and return it.          # Bless and return it.
143          bless $self;          bless $self;
# Line 163  Line 163 
163    
164  sub ShowMetaData {  sub ShowMetaData {
165          # Get the parameters.          # Get the parameters.
166          my $self = shift @_;          my ($self, $filename) = @_;
         my ($filename) = @_;  
167          # Get the metadata and the title string.          # Get the metadata and the title string.
168          my $metadata = $self->{_metaData};          my $metadata = $self->{_metaData};
169          # Get the title string.          # Get the title string.
# Line 174  Line 173 
173          my $relationshipList = $metadata->{Relationships};          my $relationshipList = $metadata->{Relationships};
174          # Open the output file.          # Open the output file.
175          open(HTMLOUT, ">$filename") || Confess("Could not open MetaData display file $filename: $!");          open(HTMLOUT, ">$filename") || Confess("Could not open MetaData display file $filename: $!");
176            Trace("Building MetaData table of contents.") if T(4);
177          # Write the HTML heading stuff.          # Write the HTML heading stuff.
178          print HTMLOUT "<html>\n<head>\n<title>$title</title>\n";          print HTMLOUT "<html>\n<head>\n<title>$title</title>\n";
179          print HTMLOUT "</head>\n<body>\n";          print HTMLOUT "</head>\n<body>\n";
# Line 201  Line 201 
201          print HTMLOUT "<a name=\"EntitiesSection\"></a><h2>Entities</h2>\n";          print HTMLOUT "<a name=\"EntitiesSection\"></a><h2>Entities</h2>\n";
202          # Loop through the entities.          # Loop through the entities.
203          for my $key (sort keys %{$entityList}) {          for my $key (sort keys %{$entityList}) {
204                    Trace("Building MetaData entry for $key entity.") if T(4);
205                  # Create the entity header. It contains a bookmark and the entity name.                  # Create the entity header. It contains a bookmark and the entity name.
206                  print HTMLOUT "<a name=\"$key\"></a><h3>$key</h3>\n";                  print HTMLOUT "<a name=\"$key\"></a><h3>$key</h3>\n";
207                  # Get the entity data.                  # Get the entity data.
# Line 239  Line 240 
240          print HTMLOUT "<a name=\"RelationshipsSection\"></a><h2>Relationships</h2>\n";          print HTMLOUT "<a name=\"RelationshipsSection\"></a><h2>Relationships</h2>\n";
241          # Loop through the relationships.          # Loop through the relationships.
242          for my $key (sort keys %{$relationshipList}) {          for my $key (sort keys %{$relationshipList}) {
243                    Trace("Building MetaData entry for $key relationship.") if T(4);
244                  # Get the relationship's structure.                  # Get the relationship's structure.
245                  my $relationshipStructure = $relationshipList->{$key};                  my $relationshipStructure = $relationshipList->{$key};
246                  # Create the relationship header.                  # Create the relationship header.
# Line 269  Line 271 
271                  my $htmlString = _ShowRelationTable($key, $relationshipStructure->{Relations}->{$key});                  my $htmlString = _ShowRelationTable($key, $relationshipStructure->{Relations}->{$key});
272                  print HTMLOUT $htmlString;                  print HTMLOUT $htmlString;
273          }          }
274            Trace("Building MetaData join table.") if T(4);
275          # Denote we're starting the join table.          # Denote we're starting the join table.
276          print HTMLOUT "<a name=\"JoinTable\"></a><h3>Join Table</h3>\n";          print HTMLOUT "<a name=\"JoinTable\"></a><h3>Join Table</h3>\n";
277          # Create a table header.          # Create a table header.
# Line 290  Line 293 
293          print HTMLOUT "</body>\n</html>\n";          print HTMLOUT "</body>\n</html>\n";
294          # Close the file.          # Close the file.
295          close HTMLOUT;          close HTMLOUT;
296            Trace("Built MetaData web page.") if T(3);
297  }  }
298    
299  =head3 DumpMetaData  =head3 DumpMetaData
# Line 302  Line 306 
306    
307  sub DumpMetaData {  sub DumpMetaData {
308          # Get the parameters.          # Get the parameters.
309          my $self = shift @_;          my ($self) = @_;
310          # Dump the meta-data.          # Dump the meta-data.
311          return Data::Dumper::Dumper($self->{_metaData});          return Data::Dumper::Dumper($self->{_metaData});
312  }  }
# Line 320  Line 324 
324    
325  sub CreateTables {  sub CreateTables {
326          # Get the parameters.          # Get the parameters.
327          my $self = shift @_;          my ($self) = @_;
328          my $metadata = $self->{_metaData};          my $metadata = $self->{_metaData};
329          my $dbh = $self->{_dbh};          my $dbh = $self->{_dbh};
330          # Loop through the entities.          # Loop through the entities.
# Line 366  Line 370 
370    
371  sub CreateTable {  sub CreateTable {
372          # Get the parameters.          # Get the parameters.
373          my $self = shift @_;          my ($self, $relationName, $indexFlag) = @_;
         my ($relationName, $indexFlag) = @_;  
374          # Get the database handle.          # Get the database handle.
375          my $dbh = $self->{_dbh};          my $dbh = $self->{_dbh};
376          # Get the relation data and determine whether or not the relation is primary.          # Get the relation data and determine whether or not the relation is primary.
# Line 414  Line 417 
417    
418  sub CreateIndex {  sub CreateIndex {
419          # Get the parameters.          # Get the parameters.
420          my $self = shift @_;          my ($self, $relationName) = @_;
         my ($relationName) = @_;  
421          # Get the relation's descriptor.          # Get the relation's descriptor.
422          my $relationData = $self->_FindRelation($relationName);          my $relationData = $self->_FindRelation($relationName);
423          # Get the database handle.          # Get the database handle.
# Line 471  Line 473 
473    
474  sub LoadTables {  sub LoadTables {
475          # Get the parameters.          # Get the parameters.
476          my $self = shift @_;          my ($self, $directoryName, $rebuild) = @_;
         my ($directoryName, $rebuild) = @_;  
477          # Start the timer.          # Start the timer.
478          my $startTime = gettimeofday;          my $startTime = gettimeofday;
479          # Clean any trailing slash from the directory name.          # Clean any trailing slash from the directory name.
# Line 514  Line 515 
515    
516  sub GetTableNames {  sub GetTableNames {
517          # Get the parameters.          # Get the parameters.
518          my $self = shift @_;          my ($self) = @_;
519          # Get the relation list from the metadata.          # Get the relation list from the metadata.
520          my $relationTable = $self->{_metaData}->{RelationTable};          my $relationTable = $self->{_metaData}->{RelationTable};
521          # Return the relation names.          # Return the relation names.
# Line 531  Line 532 
532    
533  sub GetEntityTypes {  sub GetEntityTypes {
534          # Get the database object.          # Get the database object.
535          my $self = shift @_;          my ($self) = @_;
536          # Get the entity list from the metadata object.          # Get the entity list from the metadata object.
537          my $entityList = $self->{_metaData}->{Entities};          my $entityList = $self->{_metaData}->{Entities};
538          # Return the list of entity names in alphabetical order.          # Return the list of entity names in alphabetical order.
# Line 616  Line 617 
617    
618  sub Get {  sub Get {
619          # Get the parameters.          # Get the parameters.
620          my $self = shift @_;          my ($self, $objectNames, $filterClause, @params) = @_;
         my ($objectNames, $filterClause, @params) = @_;  
621          # Construct the SELECT statement. The general pattern is          # Construct the SELECT statement. The general pattern is
622          #          #
623          # SELECT name1.*, name2.*, ... nameN.* FROM name1, name2, ... nameN          # SELECT name1.*, name2.*, ... nameN.* FROM name1, name2, ... nameN
# Line 761  Line 761 
761    
762  sub ComputeObjectSentence {  sub ComputeObjectSentence {
763          # Get the parameters.          # Get the parameters.
764          my $self = shift @_;          my ($self, $objectName) = @_;
         my ($objectName) = @_;  
765          # Set the default return value.          # Set the default return value.
766          my $retVal = $objectName;          my $retVal = $objectName;
767          # Look for the object as a relationship.          # Look for the object as a relationship.
# Line 794  Line 793 
793    
794  sub DumpRelations {  sub DumpRelations {
795          # Get the parameters.          # Get the parameters.
796          my $self = shift @_;          my ($self, $outputDirectory) = @_;
         my ($outputDirectory) = @_;  
797          # Now we need to run through all the relations. First, we loop through the entities.          # Now we need to run through all the relations. First, we loop through the entities.
798          my $metaData = $self->{_metaData};          my $metaData = $self->{_metaData};
799          my $entities = $metaData->{Entities};          my $entities = $metaData->{Entities};
# Line 853  Line 851 
851    
852  sub InsertObject {  sub InsertObject {
853          # Get the parameters.          # Get the parameters.
854          my $self = shift @_;          my ($self, $newObjectType, $fieldHash) = @_;
         my ($newObjectType, $fieldHash) = @_;  
855          # Denote that so far we appear successful.          # Denote that so far we appear successful.
856          my $retVal = 1;          my $retVal = 1;
857          # Get the database handle.          # Get the database handle.
# Line 981  Line 978 
978  =cut  =cut
979  sub LoadTable {  sub LoadTable {
980          # Get the parameters.          # Get the parameters.
981          my $self = shift @_;          my ($self, $fileName, $relationName, $truncateFlag) = @_;
         my ($fileName, $relationName, $truncateFlag) = @_;  
982          # Create the statistical return object.          # Create the statistical return object.
983          my $retVal = _GetLoadStats();          my $retVal = _GetLoadStats();
984          # Trace the fact of the load.          # Trace the fact of the load.
# Line 1031  Line 1027 
1027              print TABLEOUT "$record\n";              print TABLEOUT "$record\n";
1028              # Count the record read.              # Count the record read.
1029              my $count = $retVal->Add('records');              my $count = $retVal->Add('records');
1030                my $len = length $record;
1031                Trace("Record $count written with $len characters.") if T(4);
1032          }          }
1033          }          }
1034          # Close the files.          # Close the files.
1035          close TABLEIN;          close TABLEIN;
1036          close TABLEOUT;          close TABLEOUT;
1037        Trace("Temporary file $tempName created.") if T(4);
1038          # Load the table.          # Load the table.
1039          my $rv;          my $rv;
1040          eval {          eval {
1041                  $rv = $dbh->load_table(file => $tempName, tbl => $relationName);                  $rv = $dbh->load_table(file => $tempName, tbl => $relationName);
1042          };          };
1043          if (!defined $rv) {          if (!defined $rv) {
1044                  $retVal->AddMessage("Table load failed for $relationName.");          $retVal->AddMessage($@) if ($@);
1045            $retVal->AddMessage("Table load failed for $relationName using $tempName.");
1046                  Trace("Table load failed for $relationName.") if T(1);                  Trace("Table load failed for $relationName.") if T(1);
1047          } else {          } else {
1048                  # Here we successfully loaded the table. Trace the number of records loaded.                  # Here we successfully loaded the table. Trace the number of records loaded.
# Line 1105  Line 1105 
1105    
1106  sub GenerateEntity {  sub GenerateEntity {
1107          # Get the parameters.          # Get the parameters.
1108          my $self = shift @_;          my ($self, $id, $type, $values) = @_;
         my ($id, $type, $values) = @_;  
1109          # Create the return hash.          # Create the return hash.
1110          my $this = { id => $id };          my $this = { id => $id };
1111          # Get the metadata structure.          # Get the metadata structure.
# Line 1239  Line 1238 
1238    
1239  sub _DumpRelation {  sub _DumpRelation {
1240          # Get the parameters.          # Get the parameters.
1241          my $self = shift @_;          my ($self, $outputDirectory, $relationName, $relation) = @_;
         my ($outputDirectory, $relationName, $relation) = @_;  
1242          # Open the output file.          # Open the output file.
1243          my $fileName = "$outputDirectory/$relationName.dtx";          my $fileName = "$outputDirectory/$relationName.dtx";
1244          open(DTXOUT, ">$fileName") || Confess("Could not open dump file $fileName: $!");          open(DTXOUT, ">$fileName") || Confess("Could not open dump file $fileName: $!");
# Line 1286  Line 1284 
1284    
1285  sub _GetStructure {  sub _GetStructure {
1286          # Get the parameters.          # Get the parameters.
1287          my $self = shift @_;          my ($self, $objectName) = @_;
         my ($objectName) = @_;  
1288          # Get the metadata structure.          # Get the metadata structure.
1289          my $metadata = $self->{_metaData};          my $metadata = $self->{_metaData};
1290          # Declare the variable to receive the descriptor.          # Declare the variable to receive the descriptor.
# Line 1326  Line 1323 
1323    
1324  sub _GetRelationTable {  sub _GetRelationTable {
1325          # Get the parameters.          # Get the parameters.
1326          my $self = shift @_;          my ($self, $objectName) = @_;
         my ($objectName) = @_;  
1327          # Get the descriptor from the metadata.          # Get the descriptor from the metadata.
1328          my $objectData = $self->_GetStructure($objectName);          my $objectData = $self->_GetStructure($objectName);
1329          # Return the object's relation list.          # Return the object's relation list.
# Line 1356  Line 1352 
1352    
1353  sub _GetFieldTable {  sub _GetFieldTable {
1354          # Get the parameters.          # Get the parameters.
1355          my $self = shift @_;          my ($self, $objectName) = @_;
         my ($objectName) = @_;  
1356          # Get the descriptor from the metadata.          # Get the descriptor from the metadata.
1357          my $objectData = $self->_GetStructure($objectName);          my $objectData = $self->_GetStructure($objectName);
1358          # Return the object's field table.          # Return the object's field table.
# Line 1454  Line 1449 
1449    
1450  sub _LoadRelation {  sub _LoadRelation {
1451          # Get the parameters.          # Get the parameters.
1452          my $self = shift @_;          my ($self, $directoryName, $relationName, $rebuild) = @_;
         my ($directoryName, $relationName, $rebuild) = @_;  
1453          # Create the file name.          # Create the file name.
1454          my $fileName = "$directoryName/$relationName";          my $fileName = "$directoryName/$relationName";
1455          # If the file doesn't exist, try adding the .dtx suffix.          # If the file doesn't exist, try adding the .dtx suffix.
# Line 2109  Line 2103 
2103    
2104  sub _IsPrimary {  sub _IsPrimary {
2105          # Get the parameters.          # Get the parameters.
2106          my $self = shift @_;          my ($self, $relationName) = @_;
         my ($relationName) = @_;  
2107          # Check for the relation in the entity table.          # Check for the relation in the entity table.
2108          my $entityTable = $self->{_metaData}->{Entities};          my $entityTable = $self->{_metaData}->{Entities};
2109          my $retVal = exists $entityTable->{$relationName};          my $retVal = exists $entityTable->{$relationName};
# Line 2144  Line 2137 
2137  =cut  =cut
2138  sub _FindRelation {  sub _FindRelation {
2139          # Get the parameters.          # Get the parameters.
2140          my $self = shift @_;          my ($self, $relationName) = @_;
         my ($relationName) = @_;  
2141          # Get the relation's structure from the master relation table in the metadata structure.          # Get the relation's structure from the master relation table in the metadata structure.
2142          my $metaData = $self->{_metaData};          my $metaData = $self->{_metaData};
2143          my $retVal = $metaData->{RelationTable}->{$relationName};          my $retVal = $metaData->{RelationTable}->{$relationName};
# Line 2273  Line 2265 
2265                  my $indexData = $indexTable->{$indexName};                  my $indexData = $indexTable->{$indexName};
2266                  # Determine whether or not the index is unique.                  # Determine whether or not the index is unique.
2267                  my $fullName = $indexName;                  my $fullName = $indexName;
2268                  if ($indexData->{Unique} eq "true") {                  if (exists $indexData->{Unique} && $indexData->{Unique} eq "true") {
2269                          $fullName .= " (unique)";                          $fullName .= " (unique)";
2270                  }                  }
2271                  # Start an HTML list item for this index.                  # Start an HTML list item for this index.

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3