[ome-devel] OMERO API Import

josh.moore at gmx.de josh.moore at gmx.de
Wed Feb 6 10:12:11 GMT 2008


Matthias Dunda writes:
 > Hi there,

Hi Matthias.

 > I'm using this sample code (which is mainly an aggregation of
 > ImportFixture and which we created during our session with Josh -
 > thanks for this...) to import pictures via the java API:
 > 
 > public static void main(String[] args) throws Exception {
 >     ServiceFactory sf = new ServiceFactory(...);
 > 
 >     Project p = new Project();
 >     p.setName("aaaaaaaaaaaaaaa");
 >     p = sf.getUpdateService().saveAndReturnObject(p);
 > 
 >     // StartPlate
 >     Dataset d = new Dataset();
 >     d.setName("bbbbbbbbbbbbbbb");
 >     p.linkDataset(d);
 >     d = sf.getUpdateService().saveAndReturnObject(d);
 > 
 >     File file = new File(
 >             "u:\\mdu\\BPAE_cells_DAPI_MitoTrackerRed_Phallacidin_3.tif");
 >     ImportContainer container = new ImportContainer(file, d, "unbenutzt",
 >             true);
 > 
 >     OMEROMetadataStore store = new OMEROMetadataStore(sf);
 >     OMEROWrapper reader = new ODIPImportReader();
 >     ImportLibrary library = new ImportLibrary(store, reader,
 >             new ImportContainer[] { container });
 > 
 >     // WriteImageFile
 >     String fileName = file.getAbsolutePath();
 >     library.setDataset(d);
 >     library.open(fileName);
 >     library.calculateImageCount(fileName, 0);
 > 
 >     List<Pixels> pixId = library.importMetadata(file.getAbsolutePath());
 >     library.importData(pixId.get(0).getId(), fileName, 0,
 >             new ImportLibrary.Step() {
 >             @Override
 >             public void step(int arg0, int arg1) {
 >             System.out.println(arg0 + "," + arg1);
 >             }
 >             });
 > 
 >     // Get Pixels (unnecessary) & in Beta3 no more defaultPixels
 >     d = sf.getQueryService()
 >         .findByQuery("select d from Dataset d join fetch d.imageLinks dil " +
 >                 "join fetch dil.child image join fetch image.defaultPixels where d.id = :id",
 >                 new Parameters().addId(d.getId()));
 > 
 >     Image i = (Image) d.linkedImageList().get(0);
 >     i.setName("asdfsdafgfgsdfgd");
 >     Pixels px = i.getDefaultPixels(); // getPrimaryPixels
 > 
 >     // WriteWellData (auch anderes in Beta3)
 >     DatasetAnnotation da = new DatasetAnnotation();
 >     da.setDataset(d);
 >     da.setContent("cccccccccccccccc");
 >     sf.getUpdateService().saveObject(da);
 > }
 > 
 > My question is: where does the actual saving in the database take
 > place? After running this code I (think I) see new models for Image
 > and Pixels although I never do an explicit saveObject.
 > 
 > Does this all happen recursively due to saving the
 > DatasetAnnotation in the last line?

No. Hibernate does find all changes (both INSERTs and UPDATEs)
transivitely ("persistence by reachability") and takes the proper
actions. (Sometimes this can be surprising if, for example, you've
received a filtered collection back from the server and then try to
save the same instance. Caveat hacker.)

But in this case, `library.importMetadata` has created a Dataset,
Image, and Pixels instance for you via OMEROMetadataStore.saveToDB()

 > What happenes in this step:
 >     List<Pixels> pixId = library.importMetadata(file.getAbsolutePath());
 >     library.importData(pixId.get(0).getId(), fileName, 0,
 >             new ImportLibrary.Step() {
 >             @Override
 >             public void step(int arg0, int arg1) {
 >             System.out.println(arg0 + "," + arg1);
 >             }
 >             });

import*Data*() takes care of uploading the actually binary data to the
server, whereas importMetadata saves things to the database.

~J.

 > --
 > Matthias Dunda, Dipl.-Inform.
 > c.a.r.u.s. HMS GmbH
 > Bornbarch 9, D-22848 Norderstedt
 > Fon: +49.(0)40.5 14 35-0
 > Fax: +49.(0)40.5 14 35-11 11
 > 
 > Amtsgericht/Register Court: Kiel, HRB 4587 NO
 > Sitz/Registered Office: Norderstedt
 > Geschäftsführer/Managing Directors: Karl-Heinz Witt, Dr. Matthias Rath


More information about the ome-devel mailing list