[ome-devel] findObject problem

Ilya Goldberg igg at nih.gov
Tue Dec 5 19:07:30 GMT 2006


Hi August
Wrapping in an eval isn't really over-kill (brace eval, not string) -  
its the recommended way to catch exceptions.
You could also check first by finding the OME::SemanticType you're  
looking for:
$factory->findObject('OME::SemanticType', 'name' => 'Myattribute' );
These factory calls work for any class that inherits from  
OME::DBObject, which is every class that persists in the DB,  
including "system classes".


I would argue against returning undef because you've asked for an  
object of undefined type.  It seems more like an exception to me, and  
is useful as such for trapping bugs in code.  Otherwise it would  
return undef for two very different conditions:  Object type not  
defined, and Object type defined, but no instances matching criteria.

-Ilya


On Dec 4, 2006, at 3:22 PM, august wrote:

>
> Hi All,
>
> I don't know why I haven't really noticed this problem before, but  
> when
> you do a findObject query in the database for some type def that  
> doesn't
> exist, it causes problems.
>
> so, to check if something exists in the DB, I first have to wrap the
> findObjects in an eval statement.  This seems like overkill to me.  Is
> there no way to have findObject return null or something like that so
> that these sorts of queries can be handled gracefully?
> Or, is there another way to check if the type is defined or not?
>
>
> example:
>
> I do:  $factory->findObject('@Myattribute', 'image_id' => $image_id );
>
> if the @Myattribute  definition  is not already set in the DB, I get
> perl runtime errors.
>
> thanks -august.
>
> _______________________________________________
> 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