[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.48, Wed Jun 21 03:12:20 2006 UTC revision 1.58, Wed Jun 28 22:22:42 2006 UTC
# Line 1544  Line 1544 
1544      }      }
1545  }  }
1546    
1547    =head3 InsertValue
1548    
1549    C<< $erdb->InsertValue($entityID, $fieldName, $value); >>
1550    
1551    This method will insert a new value into the database. The value must be one
1552    associated with a secondary relation, since primary values cannot be inserted:
1553    they occur exactly once. Secondary values, on the other hand, can be missing
1554    or multiply-occurring.
1555    
1556    =over 4
1557    
1558    =item entityID
1559    
1560    ID of the object that is to receive the new value.
1561    
1562    =item fieldName
1563    
1564    Field name for the new value-- this includes the entity name, since
1565    field names are of the format I<objectName>C<(>I<fieldName>C<)>.
1566    
1567    =item value
1568    
1569    New value to be put in the field.
1570    
1571    =back
1572    
1573    =cut
1574    
1575    sub InsertValue {
1576        # Get the parameters.
1577        my ($self, $entityID, $fieldName, $value) = @_;
1578        # Parse the entity name and the real field name.
1579        if ($fieldName =~ /^([^(]+)\(([^)]+)\)/) {
1580            my $entityName = $1;
1581            my $fieldTitle = $2;
1582            # Get its descriptor.
1583            if (!$self->IsEntity($entityName)) {
1584                Confess("$entityName is not a valid entity.");
1585            } else {
1586                my $entityData = $self->{_metaData}->{Entities}->{$entityName};
1587                # Find the relation containing this field.
1588                my $fieldHash = $entityData->{Fields};
1589                if (! exists $fieldHash->{$fieldTitle}) {
1590                    Confess("$fieldTitle not found in $entityName.");
1591                } else {
1592                    my $relation = $fieldHash->{$fieldTitle}->{relation};
1593                    if ($relation eq $entityName) {
1594                        Confess("Cannot do InsertValue on primary field $fieldTitle of $entityName.");
1595                    } else {
1596                        # Now we can create an INSERT statement.
1597                        my $dbh = $self->{_dbh};
1598                        my $fixedName = _FixName($fieldTitle);
1599                        my $statement = "INSERT INTO $relation (id, $fixedName) VALUES(?, ?)";
1600                        # Execute the command.
1601                        $dbh->SQL($statement, 0, $entityID, $value);
1602                    }
1603                }
1604            }
1605        } else {
1606            Confess("$fieldName is not a valid field name.");
1607        }
1608    }
1609    
1610  =head3 InsertObject  =head3 InsertObject
1611    
1612  C<< my $ok = $erdb->InsertObject($objectType, \%fieldHash); >>  C<< my $ok = $erdb->InsertObject($objectType, \%fieldHash); >>
# Line 1560  Line 1623 
1623  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
1624  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>.
1625    
1626  C<< $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>  C<< $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>
1627    
1628  =over 4  =over 4
1629    
# Line 1771  Line 1834 
1834      }      }
1835      # Analyze the table to improve performance.      # Analyze the table to improve performance.
1836      $dbh->vacuum_it($relationName);      $dbh->vacuum_it($relationName);
1837        # Flush the database cache.
1838        $dbh->flush_tables();
1839      # Return the statistics.      # Return the statistics.
1840      return $retVal;      return $retVal;
1841  }  }
# Line 2001  Line 2066 
2066          push @retVal, \@rowData;          push @retVal, \@rowData;
2067          $fetched++;          $fetched++;
2068      }      }
2069        Trace("$fetched rows returned in GetAll.") if T(SQL => 4);
2070      # Return the resulting list.      # Return the resulting list.
2071      return @retVal;      return @retVal;
2072  }  }
2073    
2074    =head3 Exists
2075    
2076    C<< my $found = $sprout->Exists($entityName, $entityID); >>
2077    
2078    Return TRUE if an entity exists, else FALSE.
2079    
2080    =over 4
2081    
2082    =item entityName
2083    
2084    Name of the entity type (e.g. C<Feature>) relevant to the existence check.
2085    
2086    =item entityID
2087    
2088    ID of the entity instance whose existence is to be checked.
2089    
2090    =item RETURN
2091    
2092    Returns TRUE if the entity instance exists, else FALSE.
2093    
2094    =back
2095    
2096    =cut
2097    #: Return Type $;
2098    sub Exists {
2099        # Get the parameters.
2100        my ($self, $entityName, $entityID) = @_;
2101        # Check for the entity instance.
2102        Trace("Checking existence of $entityName with ID=$entityID.") if T(4);
2103        my $testInstance = $self->GetEntity($entityName, $entityID);
2104        # Return an existence indicator.
2105        my $retVal = ($testInstance ? 1 : 0);
2106        return $retVal;
2107    }
2108    
2109  =head3 EstimateRowSize  =head3 EstimateRowSize
2110    
2111  C<< my $rowSize = $erdb->EstimateRowSize($relName); >>  C<< my $rowSize = $erdb->EstimateRowSize($relName); >>
# Line 2195  Line 2296 
2296    
2297  =head3 ParseColumns  =head3 ParseColumns
2298    
2299  C<< my @columns = ERDB->ParseColumns($line); >>  C<< my @columns = ERDB::ParseColumns($line); >>
2300    
2301  Convert the specified data line to a list of columns.  Convert the specified data line to a list of columns.
2302    
# Line 2216  Line 2317 
2317    
2318  sub ParseColumns {  sub ParseColumns {
2319      # Get the parameters.      # Get the parameters.
2320      my ($self, $line) = @_;      my ($line) = @_;
2321      # Chop off the line-end.      # Chop off the line-end.
2322      chomp $line;      chomp $line;
2323      # Split it into a list.      # Split it into a list.

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.58

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3