[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.35, Sat Jan 28 09:57:43 2006 UTC revision 1.38, Fri Mar 17 22:02:03 2006 UTC
# Line 962  Line 962 
962              # whole.              # whole.
963              my $nameLength = 2 + length $objectName;              my $nameLength = 2 + length $objectName;
964              # Get the object's field list.              # Get the object's field list.
965              my $fieldList = $self->_GetFieldTable($objectName);              my $fieldList = $self->GetFieldTable($objectName);
966              # Find the field references for this object.              # Find the field references for this object.
967              while ($filterString =~ m/$objectName\(([^)]*)\)/g) {              while ($filterString =~ m/$objectName\(([^)]*)\)/g) {
968                  # At this point, $1 contains the field name, and the current position                  # At this point, $1 contains the field name, and the current position
# Line 1178  Line 1178 
1178          while (my $path = pop @pathList) {          while (my $path = pop @pathList) {
1179              # Get the table whose rows are to be deleted.              # Get the table whose rows are to be deleted.
1180              my @pathTables = @{$path};              my @pathTables = @{$path};
1181              # Start the DELETE statement.              # Start the DELETE statement. We need to call DBKernel because the
1182                # syntax of a DELETE-USING varies among DBMSs.
1183              my $target = $pathTables[$#pathTables];              my $target = $pathTables[$#pathTables];
1184              my $stmt = "DELETE FROM $target";              my $stmt = $db->SetUsing(@pathTables);
             # If there's more than just the one table, we need a USING clause.  
             if (@pathTables > 1) {  
                 $stmt .= " USING " . join(", ", @pathTables[0 .. ($#pathTables - 1)]);  
             }  
1185              # Now start the WHERE. The first thing is the ID field from the starting table. That              # Now start the WHERE. The first thing is the ID field from the starting table. That
1186              # starting table will either be the entity relation or one of the entity's              # starting table will either be the entity relation or one of the entity's
1187              # sub-relations.              # sub-relations.
# Line 1209  Line 1206 
1206              } else {              } else {
1207                  # Here we can delete. Note that the SQL method dies with a confessing                  # Here we can delete. Note that the SQL method dies with a confessing
1208                  # if an error occurs, so we just go ahead and do it.                  # if an error occurs, so we just go ahead and do it.
1209                  Trace("Executing delete: $stmt") if T(3);                  Trace("Executing delete from $target using '$objectID'.") if T(3);
1210                  my $rv = $db->SQL($stmt, 0, [$objectID]);                  my $rv = $db->SQL($stmt, 0, $objectID);
1211                  # Accumulate the statistics for this delete. The only rows deleted                  # Accumulate the statistics for this delete. The only rows deleted
1212                  # are from the target table, so we use its name to record the                  # are from the target table, so we use its name to record the
1213                  # statistic.                  # statistic.
# Line 1859  Line 1856 
1856      return $retVal;      return $retVal;
1857  }  }
1858    
1859    =head3 GetFieldTable
1860    
1861    C<< my $fieldHash = $self->GetFieldTable($objectnName); >>
1862    
1863    Get the field structure for a specified entity or relationship.
1864    
1865    =over 4
1866    
1867    =item objectName
1868    
1869    Name of the desired entity or relationship.
1870    
1871    =item RETURN
1872    
1873    The table containing the field descriptors for the specified object.
1874    
1875    =back
1876    
1877    =cut
1878    
1879    sub GetFieldTable {
1880        # Get the parameters.
1881        my ($self, $objectName) = @_;
1882        # Get the descriptor from the metadata.
1883        my $objectData = $self->_GetStructure($objectName);
1884        # Return the object's field table.
1885        return $objectData->{Fields};
1886    }
1887    
1888    =head3 GetUsefulCrossValues
1889    
1890    C<< my @attrNames = $sprout->GetUsefulCrossValues($sourceEntity, $relationship); >>
1891    
1892    Return a list of the useful attributes that would be returned by a B<Cross> call
1893    from an entity of the source entity type through the specified relationship. This
1894    means it will return the fields of the target entity type and the intersection data
1895    fields in the relationship. Only primary table fields are returned. In other words,
1896    the field names returned will be for fields where there is always one and only one
1897    value.
1898    
1899    =over 4
1900    
1901    =item sourceEntity
1902    
1903    Name of the entity from which the relationship crossing will start.
1904    
1905    =item relationship
1906    
1907    Name of the relationship being crossed.
1908    
1909    =item RETURN
1910    
1911    Returns a list of field names in Sprout field format (I<objectName>C<(>I<fieldName>C<)>.
1912    
1913    =back
1914    
1915    =cut
1916    #: Return Type @;
1917    sub GetUsefulCrossValues {
1918        # Get the parameters.
1919        my ($self, $sourceEntity, $relationship) = @_;
1920        # Declare the return variable.
1921        my @retVal = ();
1922        # Determine the target entity for the relationship. This is whichever entity is not
1923        # the source entity. So, if the source entity is the FROM, we'll get the name of
1924        # the TO, and vice versa.
1925        my $relStructure = $self->_GetStructure($relationship);
1926        my $targetEntityType = ($relStructure->{from} eq $sourceEntity ? "to" : "from");
1927        my $targetEntity = $relStructure->{$targetEntityType};
1928        # Get the field table for the entity.
1929        my $entityFields = $self->GetFieldTable($targetEntity);
1930        # The field table is a hash. The hash key is the field name. The hash value is a structure.
1931        # For the entity fields, the key aspect of the target structure is that the {relation} value
1932        # must match the entity name.
1933        my @fieldList = map { "$targetEntity($_)" } grep { $entityFields->{$_}->{relation} eq $targetEntity }
1934                            keys %{$entityFields};
1935        # Push the fields found onto the return variable.
1936        push @retVal, sort @fieldList;
1937        # Get the field table for the relationship.
1938        my $relationshipFields = $self->GetFieldTable($relationship);
1939        # Here we have a different rule. We want all the fields other than "from-link" and "to-link".
1940        # This may end up being an empty set.
1941        my @fieldList2 = map { "$relationship($_)" } grep { $_ ne "from-link" && $_ ne "to-link" }
1942                            keys %{$relationshipFields};
1943        # Push these onto the return list.
1944        push @retVal, sort @fieldList2;
1945        # Return the result.
1946        return @retVal;
1947    }
1948    
1949  =head2 Internal Utility Methods  =head2 Internal Utility Methods
1950    
1951  =head3 GetLoadStats  =head3 GetLoadStats
# Line 2065  Line 2152 
2152      return $objectData->{Relations};      return $objectData->{Relations};
2153  }  }
2154    
 =head3 GetFieldTable  
   
 Get the field structure for a specified entity or relationship.  
   
 This is an instance method.  
   
 =over 4  
   
 =item objectName  
   
 Name of the desired entity or relationship.  
   
 =item RETURN  
   
 The table containing the field descriptors for the specified object.  
   
 =back  
   
 =cut  
   
 sub _GetFieldTable {  
     # Get the parameters.  
     my ($self, $objectName) = @_;  
     # Get the descriptor from the metadata.  
     my $objectData = $self->_GetStructure($objectName);  
     # Return the object's field table.  
     return $objectData->{Fields};  
 }  
   
2155  =head3 ValidateFieldNames  =head3 ValidateFieldNames
2156    
2157  Determine whether or not the field names are valid. A description of the problems with the names  Determine whether or not the field names are valid. A description of the problems with the names

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.38

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3