[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.90, Fri Apr 27 22:19:49 2007 UTC revision 1.94, Thu Dec 6 14:58:03 2007 UTC
# Line 372  Line 372 
372                   'medium-string' =>                   'medium-string' =>
373                               { sqlType => 'VARCHAR(160)',       maxLen => 160,          avgLen =>  40, sort => "",                               { sqlType => 'VARCHAR(160)',       maxLen => 160,          avgLen =>  40, sort => "",
374                                 indexMod =>   0, notes => "character string, 0 to 160 characters"},                                 indexMod =>   0, notes => "character string, 0 to 160 characters"},
375                     'long-string' =>
376                                 { sqlType => 'VARCHAR(500)',       maxLen => 500,          avglen => 255, sort => "",
377                                   indexMod =>   0, notes => "character string, 0 to 500 characters"},
378                  );                  );
379    
380  # Table translating arities into natural language.  # Table translating arities into natural language.
# Line 410  Line 413 
413    
414  =head3 new  =head3 new
415    
416  C<< my $database = ERDB->new($dbh, $metaFileName); >>      my $database = ERDB->new($dbh, $metaFileName);
417    
418  Create a new ERDB object.  Create a new ERDB object.
419    
# Line 444  Line 447 
447    
448  =head3 ShowMetaData  =head3 ShowMetaData
449    
450  C<< $erdb->ShowMetaData($fileName); >>      $erdb->ShowMetaData($fileName);
451    
452  This method outputs a description of the database. This description can be used to help users create  This method outputs a description of the database. This description can be used to help users create
453  the data to be loaded into the relations.  the data to be loaded into the relations.
# Line 485  Line 488 
488    
489  =head3 DisplayMetaData  =head3 DisplayMetaData
490    
491  C<< my $html = $erdb->DisplayMetaData(); >>      my $html = $erdb->DisplayMetaData();
492    
493  Return an HTML description of the database. This description can be used to help users create  Return an HTML description of the database. This description can be used to help users create
494  the data to be loaded into the relations and form queries. The output is raw includable HTML  the data to be loaded into the relations and form queries. The output is raw includable HTML
# Line 641  Line 644 
644    
645  =head3 DumpMetaData  =head3 DumpMetaData
646    
647  C<< $erdb->DumpMetaData(); >>      $erdb->DumpMetaData();
648    
649  Return a dump of the metadata structure.  Return a dump of the metadata structure.
650    
# Line 656  Line 659 
659    
660  =head3 CreatePPO  =head3 CreatePPO
661    
662  C<< ERDB::CreatePPO($erdbXMLFile, $ppoXMLFile); >>      ERDB::CreatePPO($erdbXMLFile, $ppoXMLFile);
663    
664  Create a PPO XML file from an ERDB data definition XML file. At the  Create a PPO XML file from an ERDB data definition XML file. At the
665  current time, the PPO XML file can be used to create a database with  current time, the PPO XML file can be used to create a database with
# Line 807  Line 810 
810    
811  =head3 FindIndexForEntity  =head3 FindIndexForEntity
812    
813  C<< my $indexFound = ERDB::FindIndexForEntity($xml, $entityName, $attributeName); >>      my $indexFound = ERDB::FindIndexForEntity($xml, $entityName, $attributeName);
814    
815  This method locates the entry in an entity's index list that begins with the  This method locates the entry in an entity's index list that begins with the
816  specified attribute name. If the entity has no index list, one will be  specified attribute name. If the entity has no index list, one will be
# Line 877  Line 880 
880    
881  =head3 CreateTables  =head3 CreateTables
882    
883  C<< $erdb->CreateTables(); >>      $erdb->CreateTables();
884    
885  This method creates the tables for the database from the metadata structure loaded by the  This method creates the tables for the database from the metadata structure loaded by the
886  constructor. It is expected this function will only be used on rare occasions, when the  constructor. It is expected this function will only be used on rare occasions, when the
# Line 901  Line 904 
904    
905  =head3 CreateTable  =head3 CreateTable
906    
907  C<< $erdb->CreateTable($tableName, $indexFlag, $estimatedRows); >>      $erdb->CreateTable($tableName, $indexFlag, $estimatedRows);
908    
909  Create the table for a relation and optionally create its indexes.  Create the table for a relation and optionally create its indexes.
910    
# Line 957  Line 960 
960      my $estimation = undef;      my $estimation = undef;
961      if ($estimatedRows) {      if ($estimatedRows) {
962          $estimation = [$self->EstimateRowSize($relationName), $estimatedRows];          $estimation = [$self->EstimateRowSize($relationName), $estimatedRows];
963            Trace("$estimation->[1] rows of $estimation->[0] bytes each.") if T(3);
964      }      }
965      # Create the table.      # Create the table.
966      Trace("Creating table $relationName: $fieldThing") if T(2);      Trace("Creating table $relationName: $fieldThing") if T(2);
# Line 971  Line 975 
975    
976  =head3 VerifyFields  =head3 VerifyFields
977    
978  C<< my $count = $erdb->VerifyFields($relName, \@fieldList); >>      my $count = $erdb->VerifyFields($relName, \@fieldList);
979    
980  Run through the list of proposed field values, insuring that all the character fields are  Run through the list of proposed field values, insuring that all the character fields are
981  below the maximum length. If any fields are too long, they will be truncated in place.  below the maximum length. If any fields are too long, they will be truncated in place.
# Line 1014  Line 1018 
1018              my $oldString = $fieldList->[$i];              my $oldString = $fieldList->[$i];
1019              if (length($oldString) > $maxLen) {              if (length($oldString) > $maxLen) {
1020                  # Here it's too big, so we truncate it.                  # Here it's too big, so we truncate it.
1021                  Trace("Truncating field $i in relation $relName to $maxLen characters from \"$oldString\".") if T(1);                  Trace("Truncating field $i ($fieldTypes->[$i]->{name}) in relation $relName to $maxLen characters from \"$oldString\".") if T(1);
1022                  $fieldList->[$i] = substr $oldString, 0, $maxLen;                  $fieldList->[$i] = substr $oldString, 0, $maxLen;
1023                  $retVal++;                  $retVal++;
1024              }              }
# Line 1026  Line 1030 
1030    
1031  =head3 DigestFields  =head3 DigestFields
1032    
1033  C<< $erdb->DigestFields($relName, $fieldList); >>      $erdb->DigestFields($relName, $fieldList);
1034    
1035  Digest the strings in the field list that correspond to data type C<hash-string> in the  Digest the strings in the field list that correspond to data type C<hash-string> in the
1036  specified relation.  specified relation.
# Line 1066  Line 1070 
1070    
1071  =head3 DigestKey  =head3 DigestKey
1072    
1073  C<< my $digested = $erdb->DigestKey($keyValue); >>      my $digested = $erdb->DigestKey($keyValue);
1074    
1075  Return the digested value of a symbolic key. The digested value can then be plugged into a  Return the digested value of a symbolic key. The digested value can then be plugged into a
1076  key-based search into a table with key-type hash-string.  key-based search into a table with key-type hash-string.
# Line 1099  Line 1103 
1103    
1104  =head3 CreateIndex  =head3 CreateIndex
1105    
1106  C<< $erdb->CreateIndex($relationName); >>      $erdb->CreateIndex($relationName);
1107    
1108  Create the indexes for a relation. If a table is being loaded from a large source file (as  Create the indexes for a relation. If a table is being loaded from a large source file (as
1109  is the case in L</LoadTable>), it is sometimes best to create the indexes after the load.  is the case in L</LoadTable>), it is sometimes best to create the indexes after the load.
# Line 1155  Line 1159 
1159    
1160  =head3 GetSecondaryFields  =head3 GetSecondaryFields
1161    
1162  C<< my %fieldTuples = $erdb->GetSecondaryFields($entityName); >>      my %fieldTuples = $erdb->GetSecondaryFields($entityName);
1163    
1164  This method will return a list of the name and type of each of the secondary  This method will return a list of the name and type of each of the secondary
1165  fields for a specified entity. Secondary fields are stored in two-column tables  fields for a specified entity. Secondary fields are stored in two-column tables
# Line 1196  Line 1200 
1200    
1201  =head3 GetFieldRelationName  =head3 GetFieldRelationName
1202    
1203  C<< my $name = $erdb->GetFieldRelationName($objectName, $fieldName); >>      my $name = $erdb->GetFieldRelationName($objectName, $fieldName);
1204    
1205  Return the name of the relation containing a specified field.  Return the name of the relation containing a specified field.
1206    
# Line 1237  Line 1241 
1241    
1242  =head3 DeleteValue  =head3 DeleteValue
1243    
1244  C<< my $numDeleted = $erdb->DeleteValue($entityName, $id, $fieldName, $fieldValue); >>      my $numDeleted = $erdb->DeleteValue($entityName, $id, $fieldName, $fieldValue);
1245    
1246  Delete secondary field values from the database. This method can be used to delete all  Delete secondary field values from the database. This method can be used to delete all
1247  values of a specified field for a particular entity instance, or only a single value.  values of a specified field for a particular entity instance, or only a single value.
# Line 1320  Line 1324 
1324    
1325  =head3 LoadTables  =head3 LoadTables
1326    
1327  C<< my $stats = $erdb->LoadTables($directoryName, $rebuild); >>      my $stats = $erdb->LoadTables($directoryName, $rebuild);
1328    
1329  This method will load the database tables from a directory. The tables must already have been created  This method will load the database tables from a directory. The tables must already have been created
1330  in the database. (This can be done by calling L</CreateTables>.) The caller passes in a directory name;  in the database. (This can be done by calling L</CreateTables>.) The caller passes in a directory name;
# Line 1380  Line 1384 
1384    
1385  =head3 GetTableNames  =head3 GetTableNames
1386    
1387  C<< my @names = $erdb->GetTableNames; >>      my @names = $erdb->GetTableNames;
1388    
1389  Return a list of the relations required to implement this database.  Return a list of the relations required to implement this database.
1390    
# Line 1397  Line 1401 
1401    
1402  =head3 GetEntityTypes  =head3 GetEntityTypes
1403    
1404  C<< my @names = $erdb->GetEntityTypes; >>      my @names = $erdb->GetEntityTypes;
1405    
1406  Return a list of the entity type names.  Return a list of the entity type names.
1407    
# Line 1414  Line 1418 
1418    
1419  =head3 GetDataTypes  =head3 GetDataTypes
1420    
1421  C<< my %types = ERDB::GetDataTypes(); >>      my %types = ERDB::GetDataTypes();
1422    
1423  Return a table of ERDB data types. The table returned is a hash of hashes.  Return a table of ERDB data types. The table returned is a hash of hashes.
1424  The keys of the big hash are the datatypes. Each smaller hash has several  The keys of the big hash are the datatypes. Each smaller hash has several
# Line 1433  Line 1437 
1437    
1438  =head3 IsEntity  =head3 IsEntity
1439    
1440  C<< my $flag = $erdb->IsEntity($entityName); >>      my $flag = $erdb->IsEntity($entityName);
1441    
1442  Return TRUE if the parameter is an entity name, else FALSE.  Return TRUE if the parameter is an entity name, else FALSE.
1443    
# Line 1460  Line 1464 
1464    
1465  =head3 Get  =head3 Get
1466    
1467  C<< my $query = $erdb->Get(\@objectNames, $filterClause, \@params); >>      my $query = $erdb->Get(\@objectNames, $filterClause, \@params);
1468    
1469  This method returns a query object for entities of a specified type using a specified filter.  This method returns a query object for entities of a specified type using a specified filter.
1470  The filter is a standard WHERE/ORDER BY clause with question marks as parameter markers and each  The filter is a standard WHERE/ORDER BY clause with question marks as parameter markers and each
# Line 1468  Line 1472 
1472  following call requests all B<Genome> objects for the genus specified in the variable  following call requests all B<Genome> objects for the genus specified in the variable
1473  $genus.  $genus.
1474    
1475  C<< $query = $erdb->Get(['Genome'], "Genome(genus) = ?", [$genus]); >>      $query = $erdb->Get(['Genome'], "Genome(genus) = ?", [$genus]);
1476    
1477  The WHERE clause contains a single question mark, so there is a single additional  The WHERE clause contains a single question mark, so there is a single additional
1478  parameter representing the parameter value. It would also be possible to code  parameter representing the parameter value. It would also be possible to code
1479    
1480  C<< $query = $erdb->Get(['Genome'], "Genome(genus) = \'$genus\'"); >>      $query = $erdb->Get(['Genome'], "Genome(genus) = \'$genus\'");
1481    
1482  however, this version of the call would generate a syntax error if there were any quote  however, this version of the call would generate a syntax error if there were any quote
1483  characters inside the variable C<$genus>.  characters inside the variable C<$genus>.
# Line 1485  Line 1489 
1489  It is possible to specify multiple entity and relationship names in order to retrieve more than  It is possible to specify multiple entity and relationship names in order to retrieve more than
1490  one object's data at the same time, which allows highly complex joined queries. For example,  one object's data at the same time, which allows highly complex joined queries. For example,
1491    
1492  C<< $query = $erdb->Get(['Genome', 'ComesFrom', 'Source'], "Genome(genus) = ?", [$genus]); >>      $query = $erdb->Get(['Genome', 'ComesFrom', 'Source'], "Genome(genus) = ?", [$genus]);
1493    
1494  If multiple names are specified, then the query processor will automatically determine a  If multiple names are specified, then the query processor will automatically determine a
1495  join path between the entities and relationships. The algorithm used is very simplistic.  join path between the entities and relationships. The algorithm used is very simplistic.
# Line 1521  Line 1525 
1525  with an ORDER BY clause. For example, the following filter string gets all genomes for a  with an ORDER BY clause. For example, the following filter string gets all genomes for a
1526  particular genus and sorts them by species name.  particular genus and sorts them by species name.
1527    
1528  C<< "Genome(genus) = ? ORDER BY Genome(species)" >>      "Genome(genus) = ? ORDER BY Genome(species)"
1529    
1530  Note that the case is important. Only an uppercase "ORDER BY" with a single space will  Note that the case is important. Only an uppercase "ORDER BY" with a single space will
1531  be processed. The idea is to make it less likely to find the verb by accident.  be processed. The idea is to make it less likely to find the verb by accident.
# Line 1534  Line 1538 
1538  be the last thing in the filter clause, and it contains only the word "LIMIT" followed by  be the last thing in the filter clause, and it contains only the word "LIMIT" followed by
1539  a positive number. So, for example  a positive number. So, for example
1540    
1541  C<< "Genome(genus) = ? ORDER BY Genome(species) LIMIT 10" >>      "Genome(genus) = ? ORDER BY Genome(species) LIMIT 10"
1542    
1543  will only return the first ten genomes for the specified genus. The ORDER BY clause is not  will only return the first ten genomes for the specified genus. The ORDER BY clause is not
1544  required. For example, to just get the first 10 genomes in the B<Genome> table, you could  required. For example, to just get the first 10 genomes in the B<Genome> table, you could
1545  use  use
1546    
1547  C<< "LIMIT 10" >>      "LIMIT 10"
1548    
1549  =item params  =item params
1550    
# Line 1561  Line 1565 
1565      my ($suffix, $mappedNameListRef, $mappedNameHashRef) =      my ($suffix, $mappedNameListRef, $mappedNameHashRef) =
1566          $self->_SetupSQL($objectNames, $filterClause);          $self->_SetupSQL($objectNames, $filterClause);
1567      # Create the query.      # Create the query.
1568      my $command = "SELECT DISTINCT " . join(".*, ", @{$mappedNameListRef}) .      my $command = "SELECT " . join(".*, ", @{$mappedNameListRef}) .
1569          ".* $suffix";          ".* $suffix";
1570      my $sth = $self->_GetStatementHandle($command, $params);      my $sth = $self->_GetStatementHandle($command, $params);
1571      # Now we create the relation map, which enables DBQuery to determine the order, name      # Now we create the relation map, which enables DBQuery to determine the order, name
# Line 1579  Line 1583 
1583    
1584  =head3 Search  =head3 Search
1585    
1586  C<< my $query = $erdb->Search($searchExpression, $idx, \@objectNames, $filterClause, \@params); >>      my $query = $erdb->Search($searchExpression, $idx, \@objectNames, $filterClause, \@params);
1587    
1588  Perform a full text search with filtering. The search will be against a specified object  Perform a full text search with filtering. The search will be against a specified object
1589  in the object name list. That object will get an extra field containing the search  in the object name list. That object will get an extra field containing the search
# Line 1662  Line 1666 
1666              $self->_SetupSQL($objectNames, $filterClause, $matchClause);              $self->_SetupSQL($objectNames, $filterClause, $matchClause);
1667          # Create the query. Note that the match clause is inserted at the front of          # Create the query. Note that the match clause is inserted at the front of
1668          # the select fields.          # the select fields.
1669          my $command = "SELECT DISTINCT $matchClause, " . join(".*, ", @{$mappedNameListRef}) .          my $command = "SELECT $matchClause, " . join(".*, ", @{$mappedNameListRef}) .
1670              ".* $suffix";              ".* $suffix";
1671          my $sth = $self->_GetStatementHandle($command, \@myParams);          my $sth = $self->_GetStatementHandle($command, \@myParams);
1672          # Now we create the relation map, which enables DBQuery to determine the order, name          # Now we create the relation map, which enables DBQuery to determine the order, name
# Line 1676  Line 1680 
1680    
1681  =head3 GetFlat  =head3 GetFlat
1682    
1683  C<< my @list = $erdb->GetFlat(\@objectNames, $filterClause, \@parameterList, $field); >>      my @list = $erdb->GetFlat(\@objectNames, $filterClause, \@parameterList, $field);
1684    
1685  This is a variation of L</GetAll> that asks for only a single field per record and  This is a variation of L</GetAll> that asks for only a single field per record and
1686  returns a single flattened list.  returns a single flattened list.
# Line 1729  Line 1733 
1733    
1734  =head3 SpecialFields  =head3 SpecialFields
1735    
1736  C<< my %specials = $erdb->SpecialFields($entityName); >>      my %specials = $erdb->SpecialFields($entityName);
1737    
1738  Return a hash mapping special fields in the specified entity to the value of their  Return a hash mapping special fields in the specified entity to the value of their
1739  C<special> attribute. This enables the subclass to get access to the special field  C<special> attribute. This enables the subclass to get access to the special field
# Line 1771  Line 1775 
1775    
1776  =head3 Delete  =head3 Delete
1777    
1778  C<< my $stats = $erdb->Delete($entityName, $objectID, %options); >>      my $stats = $erdb->Delete($entityName, $objectID, %options);
1779    
1780  Delete an entity instance from the database. The instance is deleted along with all entity and  Delete an entity instance from the database. The instance is deleted along with all entity and
1781  relationship instances dependent on it. The definition of I<dependence> is recursive.  relationship instances dependent on it. The definition of I<dependence> is recursive.
# Line 1956  Line 1960 
1960    
1961  =head3 Disconnect  =head3 Disconnect
1962    
1963  C<< $erdb->Disconnect($relationshipName, $originEntityName, $originEntityID); >>      $erdb->Disconnect($relationshipName, $originEntityName, $originEntityID);
1964    
1965  Disconnect an entity instance from all the objects to which it is related. This  Disconnect an entity instance from all the objects to which it is related. This
1966  will delete each relationship instance that connects to the specified entity.  will delete each relationship instance that connects to the specified entity.
# Line 2010  Line 2014 
2014    
2015  =head3 DeleteRow  =head3 DeleteRow
2016    
2017  C<< $erdb->DeleteRow($relationshipName, $fromLink, $toLink, \%values); >>      $erdb->DeleteRow($relationshipName, $fromLink, $toLink, \%values);
2018    
2019  Delete a row from a relationship. In most cases, only the from-link and to-link are  Delete a row from a relationship. In most cases, only the from-link and to-link are
2020  needed; however, for relationships with intersection data values can be specified  needed; however, for relationships with intersection data values can be specified
# Line 2063  Line 2067 
2067      $dbh->SQL($command, undef, @parms);      $dbh->SQL($command, undef, @parms);
2068  }  }
2069    
2070    =head3 DeleteLike
2071    
2072        my $deleteCount = $erdb->DeleteLike($relName, $filter, \@parms);
2073    
2074    Delete all the relationship rows that satisfy a particular filter condition. Unlike a normal
2075    filter, only fields from the relationship itself can be used.
2076    
2077    =over 4
2078    
2079    =item relName
2080    
2081    Name of the relationship whose records are to be deleted.
2082    
2083    =item filter
2084    
2085    A filter clause (L</Get>-style) for the delete query.
2086    
2087    =item parms
2088    
2089    Reference to a list of parameters for the filter clause.
2090    
2091    =item RETURN
2092    
2093    Returns a count of the number of rows deleted.
2094    
2095    =back
2096    
2097    =cut
2098    
2099    sub DeleteLike {
2100        # Get the parameters.
2101        my ($self, $objectName, $filter, $parms) = @_;
2102        # Declare the return variable.
2103        my $retVal;
2104        # Insure the parms argument is an array reference if the caller left it off.
2105        if (! defined($parms)) {
2106            $parms = [];
2107        }
2108        # Insure we have a relationship. The main reason for this is if we delete an entity
2109        # instance we have to yank out a bunch of other stuff with it.
2110        if ($self->IsEntity($objectName)) {
2111            Confess("Cannot use DeleteLike on $objectName, because it is not a relationship.");
2112        } else {
2113            # Create the SQL command suffix to get the desierd records.
2114            my ($suffix) = $self->_SetupSQL([$objectName], $filter);
2115            # Convert it to a DELETE command.
2116            my $command = "DELETE $suffix";
2117            # Execute the command.
2118            my $dbh = $self->{_dbh};
2119            my $result = $dbh->SQL($command, 0, @{$parms});
2120            # Check the results. Note we convert the "0D0" result to a real zero.
2121            # A failure causes an abnormal termination, so the caller isn't going to
2122            # worry about it.
2123            if (! defined $result) {
2124                Confess("Error deleting from $objectName: " . $dbh->errstr());
2125            } elsif ($result == 0) {
2126                $retVal = 0;
2127            } else {
2128                $retVal = $result;
2129            }
2130        }
2131        # Return the result count.
2132        return $retVal;
2133    }
2134    
2135  =head3 SortNeeded  =head3 SortNeeded
2136    
2137  C<< my $parms = $erdb->SortNeeded($relationName); >>      my $parms = $erdb->SortNeeded($relationName);
2138    
2139  Return the pipe command for the sort that should be applied to the specified  Return the pipe command for the sort that should be applied to the specified
2140  relation when creating the load file.  relation when creating the load file.
# Line 2163  Line 2232 
2232    
2233  =head3 GetList  =head3 GetList
2234    
2235  C<< my @dbObjects = $erdb->GetList(\@objectNames, $filterClause, \@params); >>      my @dbObjects = $erdb->GetList(\@objectNames, $filterClause, \@params);
2236    
2237  Return a list of object descriptors for the specified objects as determined by the  Return a list of object descriptors for the specified objects as determined by the
2238  specified filter clause.  specified filter clause.
# Line 2191  Line 2260 
2260  with an ORDER BY clause. For example, the following filter string gets all genomes for a  with an ORDER BY clause. For example, the following filter string gets all genomes for a
2261  particular genus and sorts them by species name.  particular genus and sorts them by species name.
2262    
2263  C<< "Genome(genus) = ? ORDER BY Genome(species)" >>      "Genome(genus) = ? ORDER BY Genome(species)"
2264    
2265  The rules for field references in a sort order are the same as those for field references in the  The rules for field references in a sort order are the same as those for field references in the
2266  filter clause in general; however, odd things may happen if a sort field is from a secondary  filter clause in general; however, odd things may happen if a sort field is from a secondary
# Line 2226  Line 2295 
2295    
2296  =head3 GetCount  =head3 GetCount
2297    
2298  C<< my $count = $erdb->GetCount(\@objectNames, $filter, \@params); >>      my $count = $erdb->GetCount(\@objectNames, $filter, \@params);
2299    
2300  Return the number of rows found by a specified query. This method would  Return the number of rows found by a specified query. This method would
2301  normally be used to count the records in a single table. For example, in a  normally be used to count the records in a single table. For example, in a
# Line 2319  Line 2388 
2388    
2389  =head3 ComputeObjectSentence  =head3 ComputeObjectSentence
2390    
2391  C<< my $sentence = $erdb->ComputeObjectSentence($objectName); >>      my $sentence = $erdb->ComputeObjectSentence($objectName);
2392    
2393  Check an object name, and if it is a relationship convert it to a relationship sentence.  Check an object name, and if it is a relationship convert it to a relationship sentence.
2394    
# Line 2354  Line 2423 
2423    
2424  =head3 DumpRelations  =head3 DumpRelations
2425    
2426  C<< $erdb->DumpRelations($outputDirectory); >>      $erdb->DumpRelations($outputDirectory);
2427    
2428  Write the contents of all the relations to tab-delimited files in the specified directory.  Write the contents of all the relations to tab-delimited files in the specified directory.
2429  Each file will have the same name as the relation dumped, with an extension of DTX.  Each file will have the same name as the relation dumped, with an extension of DTX.
# Line 2396  Line 2465 
2465    
2466  =head3 InsertValue  =head3 InsertValue
2467    
2468  C<< $erdb->InsertValue($entityID, $fieldName, $value); >>      $erdb->InsertValue($entityID, $fieldName, $value);
2469    
2470  This method will insert a new value into the database. The value must be one  This method will insert a new value into the database. The value must be one
2471  associated with a secondary relation, since primary values cannot be inserted:  associated with a secondary relation, since primary values cannot be inserted:
# Line 2459  Line 2528 
2528    
2529  =head3 InsertObject  =head3 InsertObject
2530    
2531  C<< $erdb->InsertObject($objectType, \%fieldHash); >>      $erdb->InsertObject($objectType, \%fieldHash);
2532    
2533  Insert an object into the database. The object is defined by a type name and then a hash  Insert an object into the database. The object is defined by a type name and then a hash
2534  of field names to values. Field values in the primary relation are represented by scalars.  of field names to values. Field values in the primary relation are represented by scalars.
# Line 2468  Line 2537 
2537  example, the following line inserts an inactive PEG feature named C<fig|188.1.peg.1> with aliases  example, the following line inserts an inactive PEG feature named C<fig|188.1.peg.1> with aliases
2538  C<ZP_00210270.1> and C<gi|46206278>.  C<ZP_00210270.1> and C<gi|46206278>.
2539    
2540  C<< $erdb->InsertObject('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >>      $erdb->InsertObject('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']});
2541    
2542  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and
2543  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.
2544    
2545  C<< $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>      $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'});
2546    
2547  =over 4  =over 4
2548    
# Line 2596  Line 2665 
2665    
2666  =head3 UpdateEntity  =head3 UpdateEntity
2667    
2668  C<< $erdb->UpdateEntity($entityName, $id, \%fields); >>      $erdb->UpdateEntity($entityName, $id, \%fields);
2669    
2670  Update the values of an entity. This is an unprotected update, so it should only be  Update the values of an entity. This is an unprotected update, so it should only be
2671  done if the database resides on a database server.  done if the database resides on a database server.
# Line 2654  Line 2723 
2723    
2724  =head3 LoadTable  =head3 LoadTable
2725    
2726  C<< my $results = $erdb->LoadTable($fileName, $relationName, $truncateFlag); >>      my $results = $erdb->LoadTable($fileName, $relationName, $truncateFlag);
2727    
2728  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
2729  first.  first.
# Line 2697  Line 2766 
2766      if ($truncateFlag) {      if ($truncateFlag) {
2767          Trace("Creating table $relationName") if T(2);          Trace("Creating table $relationName") if T(2);
2768          # 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,
2769          # divide it by the estimated row size, and then multiply by 1.5 to          # divide it by the estimated row size, and then multiply by 2 to
2770          # leave extra room. We postulate a minimum row count of 1000 to          # leave extra room. We postulate a minimum row count of 1000 to
2771          # prevent problems with incoming empty load files.          # prevent problems with incoming empty load files.
2772          my $rowSize = $self->EstimateRowSize($relationName);          my $rowSize = $self->EstimateRowSize($relationName);
2773          my $estimate = $fileSize * 1.5 / $rowSize;          my $estimate = $fileSize * 8 / $rowSize;
2774          if ($estimate < 1000) {          if ($estimate < 1000) {
2775              $estimate = 1000;              $estimate = 1000;
2776          }          }
# Line 2762  Line 2831 
2831    
2832  =head3 CreateSearchIndex  =head3 CreateSearchIndex
2833    
2834  C<< $erdb->CreateSearchIndex($objectName); >>      $erdb->CreateSearchIndex($objectName);
2835    
2836  Check for a full-text search index on the specified entity or relationship object, and  Check for a full-text search index on the specified entity or relationship object, and
2837  if one is required, rebuild it.  if one is required, rebuild it.
# Line 2799  Line 2868 
2868    
2869  =head3 DropRelation  =head3 DropRelation
2870    
2871  C<< $erdb->DropRelation($relationName); >>      $erdb->DropRelation($relationName);
2872    
2873  Physically drop a relation from the database.  Physically drop a relation from the database.
2874    
# Line 2827  Line 2896 
2896    
2897  =head3 MatchSqlPattern  =head3 MatchSqlPattern
2898    
2899  C<< my $matched = ERDB::MatchSqlPattern($value, $pattern); >>      my $matched = ERDB::MatchSqlPattern($value, $pattern);
2900    
2901  Determine whether or not a specified value matches an SQL pattern. An SQL  Determine whether or not a specified value matches an SQL pattern. An SQL
2902  pattern has two wild card characters: C<%> that matches multiple characters,  pattern has two wild card characters: C<%> that matches multiple characters,
# Line 2910  Line 2979 
2979    
2980  =head3 GetEntity  =head3 GetEntity
2981    
2982  C<< my $entityObject = $erdb->GetEntity($entityType, $ID); >>      my $entityObject = $erdb->GetEntity($entityType, $ID);
2983    
2984  Return an object describing the entity instance with a specified ID.  Return an object describing the entity instance with a specified ID.
2985    
# Line 2946  Line 3015 
3015    
3016  =head3 GetChoices  =head3 GetChoices
3017    
3018  C<< my @values = $erdb->GetChoices($entityName, $fieldName); >>      my @values = $erdb->GetChoices($entityName, $fieldName);
3019    
3020  Return a list of all the values for the specified field that are represented in the  Return a list of all the values for the specified field that are represented in the
3021  specified entity.  specified entity.
# Line 3001  Line 3070 
3070    
3071  =head3 GetEntityValues  =head3 GetEntityValues
3072    
3073  C<< my @values = $erdb->GetEntityValues($entityType, $ID, \@fields); >>      my @values = $erdb->GetEntityValues($entityType, $ID, \@fields);
3074    
3075  Return a list of values from a specified entity instance. If the entity instance  Return a list of values from a specified entity instance. If the entity instance
3076  does not exist, an empty list is returned.  does not exist, an empty list is returned.
# Line 3045  Line 3114 
3114    
3115  =head3 GetAll  =head3 GetAll
3116    
3117  C<< my @list = $erdb->GetAll(\@objectNames, $filterClause, \@parameters, \@fields, $count); >>      my @list = $erdb->GetAll(\@objectNames, $filterClause, \@parameters, \@fields, $count);
3118    
3119  Return a list of values taken from the objects returned by a query. The first three  Return a list of values taken from the objects returned by a query. The first three
3120  parameters correspond to the parameters of the L</Get> method. The final parameter is  parameters correspond to the parameters of the L</Get> method. The final parameter is
# Line 3059  Line 3128 
3128  fields specified returns multiple values, they are flattened in with the rest. For  fields specified returns multiple values, they are flattened in with the rest. For
3129  example, the following call will return a list of the features in a particular  example, the following call will return a list of the features in a particular
3130  spreadsheet cell, and each feature will be represented by a list containing the  spreadsheet cell, and each feature will be represented by a list containing the
3131  feature ID followed by all of its aliases.  feature ID followed by all of its essentiality determinations.
3132    
3133  C<< @query = $erdb->Get(['ContainsFeature', 'Feature'], "ContainsFeature(from-link) = ?", [$ssCellID], ['Feature(id)', 'Feature(alias)']); >>      @query = $erdb->Get(['ContainsFeature', 'Feature'], "ContainsFeature(from-link) = ?", [$ssCellID], ['Feature(id)', 'Feature(essential)']);
3134    
3135  =over 4  =over 4
3136    
# Line 3139  Line 3208 
3208    
3209  =head3 Exists  =head3 Exists
3210    
3211  C<< my $found = $sprout->Exists($entityName, $entityID); >>      my $found = $sprout->Exists($entityName, $entityID);
3212    
3213  Return TRUE if an entity exists, else FALSE.  Return TRUE if an entity exists, else FALSE.
3214    
# Line 3174  Line 3243 
3243    
3244  =head3 EstimateRowSize  =head3 EstimateRowSize
3245    
3246  C<< my $rowSize = $erdb->EstimateRowSize($relName); >>      my $rowSize = $erdb->EstimateRowSize($relName);
3247    
3248  Estimate the row size of the specified relation. The estimated row size is computed by adding  Estimate the row size of the specified relation. The estimated row size is computed by adding
3249  up the average length for each data type.  up the average length for each data type.
# Line 3212  Line 3281 
3281    
3282  =head3 GetFieldTable  =head3 GetFieldTable
3283    
3284  C<< my $fieldHash = $self->GetFieldTable($objectnName); >>      my $fieldHash = $self->GetFieldTable($objectnName);
3285    
3286  Get the field structure for a specified entity or relationship.  Get the field structure for a specified entity or relationship.
3287    
# Line 3241  Line 3310 
3310    
3311  =head3 SplitKeywords  =head3 SplitKeywords
3312    
3313  C<< my @keywords = ERDB::SplitKeywords($keywordString); >>      my @keywords = ERDB::SplitKeywords($keywordString);
3314    
3315  This method returns a list of the positive keywords in the specified  This method returns a list of the positive keywords in the specified
3316  keyword string. All of the operators will have been stripped off,  keyword string. All of the operators will have been stripped off,
# Line 3290  Line 3359 
3359    
3360  =head3 ValidateFieldName  =head3 ValidateFieldName
3361    
3362  C<< my $okFlag = ERDB::ValidateFieldName($fieldName); >>      my $okFlag = ERDB::ValidateFieldName($fieldName);
3363    
3364  Return TRUE if the specified field name is valid, else FALSE. Valid field names must  Return TRUE if the specified field name is valid, else FALSE. Valid field names must
3365  be hyphenated words subject to certain restrictions.  be hyphenated words subject to certain restrictions.
# Line 3345  Line 3414 
3414    
3415  =head3 ReadMetaXML  =head3 ReadMetaXML
3416    
3417  C<< my $rawMetaData = ERDB::ReadDBD($fileName); >>      my $rawMetaData = ERDB::ReadDBD($fileName);
3418    
3419  This method reads a raw database definition XML file and returns it.  This method reads a raw database definition XML file and returns it.
3420  Normally, the metadata used by the ERDB system has been processed and  Normally, the metadata used by the ERDB system has been processed and
# Line 3378  Line 3447 
3447    
3448  =head3 GetEntityFieldHash  =head3 GetEntityFieldHash
3449    
3450  C<< my $fieldHashRef = ERDB::GetEntityFieldHash($structure, $entityName); >>      my $fieldHashRef = ERDB::GetEntityFieldHash($structure, $entityName);
3451    
3452  Get the field hash of the named entity in the specified raw XML structure.  Get the field hash of the named entity in the specified raw XML structure.
3453  The field hash may not exist, in which case we need to create it.  The field hash may not exist, in which case we need to create it.
# Line 3420  Line 3489 
3489    
3490  =head3 WriteMetaXML  =head3 WriteMetaXML
3491    
3492  C<< ERDB::WriteMetaXML($structure, $fileName); >>      ERDB::WriteMetaXML($structure, $fileName);
3493    
3494  Write the metadata XML to a file. This method is the reverse of L</ReadMetaXML>, and is  Write the metadata XML to a file. This method is the reverse of L</ReadMetaXML>, and is
3495  used to update the database definition. It must be used with care, however, since it  used to update the database definition. It must be used with care, however, since it
# Line 3459  Line 3528 
3528  Except for C<[p]>, all the codes are closed by slash-codes. So, for  Except for C<[p]>, all the codes are closed by slash-codes. So, for
3529  example, C<[b]Feature[/b]> displays the string C<Feature> in boldface.  example, C<[b]Feature[/b]> displays the string C<Feature> in boldface.
3530    
3531  C<< my $realHtml = ERDB::HTMLNote($dataString); >>      my $realHtml = ERDB::HTMLNote($dataString);
3532    
3533  =over 4  =over 4
3534    
# Line 3491  Line 3560 
3560    
3561  =head3 BeginTran  =head3 BeginTran
3562    
3563  C<< $erdb->BeginTran(); >>      $erdb->BeginTran();
3564    
3565  Start a database transaction.  Start a database transaction.
3566    
# Line 3505  Line 3574 
3574    
3575  =head3 CommitTran  =head3 CommitTran
3576    
3577  C<< $erdb->CommitTran(); >>      $erdb->CommitTran();
3578    
3579  Commit an active database transaction.  Commit an active database transaction.
3580    
# Line 3518  Line 3587 
3587    
3588  =head3 RollbackTran  =head3 RollbackTran
3589    
3590  C<< $erdb->RollbackTran(); >>      $erdb->RollbackTran();
3591    
3592  Roll back an active database transaction.  Roll back an active database transaction.
3593    
# Line 3531  Line 3600 
3600    
3601  =head3 UpdateField  =head3 UpdateField
3602    
3603  C<< my $count = $erdb->UpdateField($objectNames, $fieldName, $oldValue, $newValue, $filter, $parms); >>      my $count = $erdb->UpdateField($objectNames, $fieldName, $oldValue, $newValue, $filter, $parms);
3604    
3605  Update all occurrences of a specific field value to a new value. The number of rows changed will be  Update all occurrences of a specific field value to a new value. The number of rows changed will be
3606  returned.  returned.
# Line 3611  Line 3680 
3680    
3681  =head3 GetUsefulCrossValues  =head3 GetUsefulCrossValues
3682    
3683  C<< my @attrNames = $sprout->GetUsefulCrossValues($sourceEntity, $relationship); >>      my @attrNames = $sprout->GetUsefulCrossValues($sourceEntity, $relationship);
3684    
3685  Return a list of the useful attributes that would be returned by a B<Cross> call  Return a list of the useful attributes that would be returned by a B<Cross> call
3686  from an entity of the source entity type through the specified relationship. This  from an entity of the source entity type through the specified relationship. This
# Line 3672  Line 3741 
3741    
3742  =head3 FindColumn  =head3 FindColumn
3743    
3744  C<< my $colIndex = ERDB::FindColumn($headerLine, $columnIdentifier); >>      my $colIndex = ERDB::FindColumn($headerLine, $columnIdentifier);
3745    
3746  Return the location a desired column in a data mining header line. The data  Return the location a desired column in a data mining header line. The data
3747  mining header line is a tab-separated list of column names. The column  mining header line is a tab-separated list of column names. The column
# Line 3730  Line 3799 
3799    
3800  =head3 ParseColumns  =head3 ParseColumns
3801    
3802  C<< my @columns = ERDB::ParseColumns($line); >>      my @columns = ERDB::ParseColumns($line);
3803    
3804  Convert the specified data line to a list of columns.  Convert the specified data line to a list of columns.
3805    
# Line 3764  Line 3833 
3833    
3834  =head3 _CreatePPOIndex  =head3 _CreatePPOIndex
3835    
3836  C<< my $index = ERDB::_CreatePPOIndex($indexObject); >>      my $index = ERDB::_CreatePPOIndex($indexObject);
3837    
3838  Convert the XML for an ERDB index to the XML structure for a PPO  Convert the XML for an ERDB index to the XML structure for a PPO
3839  index.  index.
# Line 3795  Line 3864 
3864    
3865  =head3 _CreatePPOField  =head3 _CreatePPOField
3866    
3867  C<< my $fieldXML = ERDB::_CreatePPOField($fieldName, $fieldObject); >>      my $fieldXML = ERDB::_CreatePPOField($fieldName, $fieldObject);
3868    
3869  Convert the ERDB XML structure for a field to a PPO scalar XML structure.  Convert the ERDB XML structure for a field to a PPO scalar XML structure.
3870    
# Line 3832  Line 3901 
3901    
3902  =head3 CleanKeywords  =head3 CleanKeywords
3903    
3904  C<< my $cleanedString = $erdb->CleanKeywords($searchExpression); >>      my $cleanedString = $erdb->CleanKeywords($searchExpression);
3905    
3906  Clean up a search expression or keyword list. This is a virtual method that may  Clean up a search expression or keyword list. This is a virtual method that may
3907  be overridden by the subclass. The base-class method removes extra spaces  be overridden by the subclass. The base-class method removes extra spaces
# Line 3869  Line 3938 
3938    
3939  =head3 GetSourceObject  =head3 GetSourceObject
3940    
3941  C<< my $source = $erdb->GetSourceObject($entityName); >>      my $source = $erdb->GetSourceObject($entityName);
3942    
3943  Return the object to be used in loading special attributes of the specified entity. The  Return the object to be used in loading special attributes of the specified entity. The
3944  algorithm for loading special attributes is stored in the C<DataGen> elements of the  algorithm for loading special attributes is stored in the C<DataGen> elements of the
# Line 3879  Line 3948 
3948    
3949  =head3 _RelationMap  =head3 _RelationMap
3950    
3951  C<< my @relationMap = _RelationMap($mappedNameHashRef, $mappedNameListRef); >>      my @relationMap = _RelationMap($mappedNameHashRef, $mappedNameListRef);
3952    
3953  Create the relation map for an SQL query. The relation map is used by B<ERDBObject>  Create the relation map for an SQL query. The relation map is used by B<ERDBObject>
3954  to determine how to interpret the results of the query.  to determine how to interpret the results of the query.
# Line 4192  Line 4261 
4261  sub _GetStatementHandle {  sub _GetStatementHandle {
4262      # Get the parameters.      # Get the parameters.
4263      my ($self, $command, $params) = @_;      my ($self, $command, $params) = @_;
4264        Confess("Invalid parameter list.") if (! defined($params) || ref($params) ne 'ARRAY');
4265      # Trace the query.      # Trace the query.
4266      Trace("SQL query: $command") if T(SQL => 3);      Trace("SQL query: $command") if T(SQL => 3);
4267      Trace("PARMS: '" . (join "', '", @{$params}) . "'") if (T(SQL => 4) && (@{$params} > 0));      Trace("PARMS: '" . (join "', '", @{$params}) . "'") if (T(SQL => 4) && (@{$params} > 0));
# Line 4441  Line 4511 
4511    
4512  =head3 _LoadMetaData  =head3 _LoadMetaData
4513    
4514  C<< my $metadata = ERDB::_LoadMetaData($filename); >>      my $metadata = ERDB::_LoadMetaData($filename);
4515    
4516  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.
4517  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
# Line 4799  Line 4869 
4869    
4870  =head3 _ProcessIndexes  =head3 _ProcessIndexes
4871    
4872  C<< ERDB::_ProcessIndexes($indexList, $relation); >>      ERDB::_ProcessIndexes($indexList, $relation);
4873    
4874  Build the data structures for the specified indexes in the specified relation.  Build the data structures for the specified indexes in the specified relation.
4875    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3