[ome-devel] update fields
Josiah Johnston
siah at nih.gov
Thu Feb 23 17:52:54 GMT 2006
Attributes weren't designed to be updated. There are no mechanisms to
leave an audit trail when doing updates. Audit trails of who, when, and
how are only made when attributes are created. So the recommended
procedure is to make new objects.
You can delete the old one if you wish with deleteObject(), but it may
not be necessary. Your example assumes one object per image. If you use
the annotation manager to make new attributes, then you can load the
most recent one to get what you want:
my $obj = $factory->findObject( '@MyType', image => $image, __order =>
'!module_execution.timestamp' );
Deletion can be complicated because any objects that refer to the
object being deleted will need to be either deleted or updated.
That said, the usage of OME in a development environment can be much
different than a production environment. In a development environment,
updates are sometimes useful, even if they lack an audit trail. Because
there is no updateObject() method, an update would go like so:
my $updatefields = { 'F1' => 1, 'F2' => 2 };
# The next line assumes that each image has exactly one object
my $obj = $factory->findObject('@MyType', { image_id = $image });
foreach my $field ( keys %$updatefields ) {
$obj->$field( $updatefields->{ $field } );
}
$obj->storeObject ();
...
$session->commitTransaction();
On Feb 21, 2006, at 6:07 PM, kris wrote:
>
> I would like to update an object with a data hash similarly to the
> way we can create object i.e.
>
> my $updatefields = { 'F1' : 1, 'F2' : 2 };
> my $obj = findObject('@MyType', { $image_id = $image });
> $obj->updateObject ($updatefields) ;
> $obj->storeObject ();
>
>
> Or is the proper way to delete and recreate?
>
>
> PS.
>
> I could write some sort of eval loop based on
> the keys in the hash and interpreting them as accessor methods,
> but I wondered if this was necessary.
>
>
> --
> Kristian Kvilekval
> kris at cs.ucsb.edu http://www.cs.ucsb.edu/~kris w:805-893-2526
> h:504-9756
>
> _______________________________________________
> ome-devel mailing list
> ome-devel at lists.openmicroscopy.org.uk
> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel
>
More information about the ome-devel
mailing list