[Bio] / Sprout / ERDBObject.pm Repository:
ViewVC logotype

Diff of /Sprout/ERDBObject.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Tue Apr 10 05:54:58 2007 UTC revision 1.5, Tue Feb 5 04:54:38 2008 UTC
# Line 25  Line 25 
25    
26  =head3 new  =head3 new
27    
28  C<< my $dbObject = ERDBObject::new($name1 => \@list1, $name2 => \@list2, ... $nameN => \@listN); >>      my $dbObject = ERDBObject::new($name1 => \@list1, $name2 => \@list2, ... $nameN => \@listN);
29    
30  Create a new transient object. A transient object maps fields to values, but is not  Create a new transient object. A transient object maps fields to values, but is not
31  associated with a database. The parameter list should be an entity name followed by  associated with a database. The parameter list should be an entity name followed by
32  a set of key-value pairs. Each key should be in the standard I<objectName>C<(>I<attributeName>C<)>  a set of key-value pairs. Each key should be in the standard I<objectName>C<(>I<attributeName>C<)>
33  format used by all of the ERDB methods. All values must be list references. For example,  format used by all of the ERDB methods. All values must be list references. For example,
34  the following code fragment creates an pseudo-Feature named C<peg.1> with two aliases.  the following code fragment creates an pseudo-Feature named C<peg.1> with two hyperlinks.
35    
36  C<< my $feature = ERDBObject::new('Feature(id)' => ['peg.1'], >>      my $feature = ERDBObject::new('Feature(id)' => ['peg.1'],
37  C<<                             'Feature(alias)' => ['NC1004', 'PC1006']); >>                                    'Feature(link)' => ['http://www.undhoople.edu/NC1004.html',
38                                                          'http://www.miskatonic.edu/PC1006.html']);
39    
40  =cut  =cut
41    
# Line 58  Line 59 
59    
60  =head3 SetDB  =head3 SetDB
61    
62  C<< my  = $dbObject->SetDB($db, $target); >>      my  = $dbObject->SetDB($db, $target);
63    
64  Attach a database to this object. This method is useful if you have to create an  Attach a database to this object. This method is useful if you have to create an
65  object manually (using L</new>) but want to be able to use the database methods  object manually (using L</new>) but want to be able to use the database methods
# Line 92  Line 93 
93    
94  =head3 Attributes  =head3 Attributes
95    
96  C<< my @attrNames = $dbObject->Attributes(); >>      my @attrNames = $dbObject->Attributes();
97    
98  This method will return a sorted list of the attributes present in this object.  This method will return a sorted list of the attributes present in this object.
99  The list can be used in the L</Values> method to get all the values stored.  The list can be used in the L</Values> method to get all the values stored.
# Line 116  Line 117 
117    
118  =head3 HasField  =head3 HasField
119    
120  C<< my $flag = $dbObject->HasField($fieldSpec); >>      my $flag = $dbObject->HasField($fieldSpec);
121    
122  Return TRUE if this object has the specified field available, else FALSE.  Return TRUE if this object has the specified field available, else FALSE.
123  This method can be used to determine if a value is available without  This method can be used to determine if a value is available without
# Line 148  Line 149 
149    
150  =head3 AddValues  =head3 AddValues
151    
152  C<< $dbObject->AddValues($name, @values); >>      $dbObject->AddValues($name, @values);
153    
154  Add one or more values to a specified field.  Add one or more values to a specified field.
155    
# Line 173  Line 174 
174      # Get the field hash.      # Get the field hash.
175      my $fields = $self->{_values};      my $fields = $self->{_values};
176      # Add the new values.      # Add the new values.
177      Tracer::AddToListMap($fields, $name, @values);      push @{$fields->{$name}}, @values;
178    }
179    
180    =head3 PrimaryValue
181    
182        my $value = $dbObject->PrimaryValue($name);
183    
184    Return the primary value of a field. This will be its first value in a standard value list.
185    
186    This method is a more convenient version of L</Value>. Basically, the call
187    
188        my ($value) = $dbObject->Value($name);
189    
190    is equivalent to
191    
192        my $value = $dbObject->PrimaryValue($name);
193    
194    but the latter is syntactically more convenient.
195    
196    =over 4
197    
198    =item name
199    
200    Name of the field whose value is desired, in the standard form.
201    
202    =item RETURN
203    
204    Returns the value of the specified field, or C<undef> if the field has no value.
205    
206    =back
207    
208    =cut
209    
210    sub PrimaryValue {
211        # Get the parameters.
212        my ($self, $name) = @_;
213        # Get the value.
214        my ($retVal) = $self->Value($name);
215        # Return it.
216        return $retVal;
217  }  }
218    
219  =head3 Value  =head3 Value
220    
221  C<< my @values = $dbObject->Value($attributeName); >>      my @values = $dbObject->Value($attributeName);
222    
223  Return a list of the values for the specified attribute.  Return a list of the values for the specified attribute.
224    
# Line 248  Line 288 
288    
289  =head3 Values  =head3 Values
290    
291  C<< my @values = $dbObject->Values(\@attributeNames); >>      my @values = $dbObject->Values(\@attributeNames);
292    
293  This method returns a list of all the values for a list of field specifiers. Essentially, it calls  This method returns a list of all the values for a list of field specifiers. Essentially, it calls
294  the L</Value> method for each element in the parameter list and returns a flattened list of all  the L</Value> method for each element in the parameter list and returns a flattened list of all
295  the results.  the results.
296    
297  For example, let us say that C<$feature> contains a feature with two aliases and a translation.  For example, let us say that C<$feature> contains a feature with two links and a translation.
298  The following call will put the aliases in C<$alias1> and C<$alias2> and the translation in  The following call will put the feature links in C<$link1> and C<$link2> and the translation in
299  C<$translation>.  C<$translation>.
300    
301  C<< my ($alias1, $alias2, $translation) = $feature->Values(['Feature(alias)', 'Feature(translation)']); >>      my ($link1, $link2, $translation) = $feature->Values(['Feature(link)', 'Feature(translation)']);
302    
303  =over 4  =over 4
304    
# Line 289  Line 329 
329    
330  =head3 Cross  =head3 Cross
331    
332  C<< my $query = $dbObject->Cross($relationshipName, $filterClause, $param1, $param2, ... $paramN); >>      my $query = $dbObject->Cross($relationshipName, $filterClause, $param1, $param2, ... $paramN);
333    
334  Return a query object for instances related to this one via a specified relationship.  Return a query object for instances related to this one via a specified relationship.
335    
# Line 340  Line 380 
380          $targetEntity = $relationship->{from};          $targetEntity = $relationship->{from};
381      }      }
382      # Get the ID of the starting instance.      # Get the ID of the starting instance.
383      my ($id) = $self->Value("$startingEntity(id)");      my $id = $self->PrimaryValue("$startingEntity(id)");
384      # Create the WHERE clause.      # Create the WHERE clause.
385      my $superFilter = "$startLinkName = ?";      my $superFilter = "$startLinkName = ?";
386      # Analyze the filter clause. We need to pull out any strings and put them in parameters.      # Analyze the filter clause. We need to pull out any strings and put them in parameters.
# Line 382  Line 422 
422    
423  =head3 IsNew  =head3 IsNew
424    
425  C<< my $boolean = $dbObject->IsNew(); >>      my $boolean = $dbObject->IsNew();
426    
427  Return TRUE if this is a new object inserted into the database, or FALSE if it was loaded from  Return TRUE if this is a new object inserted into the database, or FALSE if it was loaded from
428  the input data files.  the input data files.

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3