[InterMine Dev] How to instantiate an Item from its identifier?

Justin Clark-Casey jc955 at cam.ac.uk
Thu Feb 25 16:17:28 GMT 2016


Hi Sam.  I might have the wrong end of the stick here.  If I do, a bit more context for this code would be great.  However, when you add an Item to a collection 
(e.g. via Item.addToCollection(String name, Item item) then it is only the reference ID that is stored, not the Item object.

If the Item has already been written to the objectstore then it should be available via ObjectStore.getObjectById(Integer id).  Otherwise, I believe you have to 
keep your own map of the Items as you've been doing.

--
Justin Clark-Casey, Synbiomine/InterMine Developer
http://synbiomine.org
http://twitter.com/justincc

On 23/02/16 22:13, Sam Hokin wrote:
> Hi, devs. This has to be something folks do all the time, but I'm stumped on the class/method for doing it. I've got a Collection of Items stored in an Item,
> and I'd like to instantiate them. In other words, with an Item bigItem already existing with a Collection called smallItems:
>
> ReferenceList smallItemRefList = bigItem.getCollection("smallItems");
> if (smallItemRefList!=null) {
>      List<String> smallItemRefIdList = smallItemRefList.getRefIds();
>      for (String smallItemRefId : smallItemRefIdList) {
>              // how can I instantiate this SmallItem given its smallItemRefId????
>          }
> }
>
> So far I've been creating lots of maps to store Items separately, but it sure would be nice if I could use the InterMine API to instantiate Items that already
> exist in a Collection!
>
> Thanks!
> Sam
>
> _______________________________________________
> dev mailing list
> dev at intermine.org
> http://mail.intermine.org/cgi-bin/mailman/listinfo/dev



More information about the dev mailing list