We're Hiring!

create a dataset for 4.3.x

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

create a dataset for 4.3.x

Postby bhcho » Wed Feb 22, 2012 3:47 am

Code: Select all
    dataset = conn.getUpdateService().saveAndReturnObject(dataset)
    dataset_id = dataset.id.val

should do it.

Cheers,
~Josh
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: create a dataset for 4.3.x

Postby bhcho » Wed Feb 22, 2012 4:27 am

self reply.

I just decided to use old code (which is not deprecated yet)

Code: Select all
session = conn.c.sf

gateway = session.createGateway()
dataset = omero.model.DatasetI()
dataset.name = omero.rtypes.rstring( name )
try:
   dataset2 = gateway.saveAndReturnObject( dataset )
   gateway.close()
except:
   gateway.close()

ID=dataset2.getId().getValue()
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: create a dataset for 4.3.x

Postby wmoore » Wed Feb 22, 2012 8:41 am

Hi BK,

This is deprecated.
Code: Select all
session.createGateway()

You're also creating a stateful service, which you don't need for simply saving an object.

Use the update service instead to call saveAndReturnObject(). It does exactly the same thing.
You also don't need to access the session itself.

If you use services created by the Blitz Gateway connection "conn", these are proxies that have additional error and reconnection handling.

You also don't need to use 'dataset2'. Just reassign to 'dataset'

Code: Select all
dataset = omero.model.DatasetI()
dataset.name = omero.rtypes.rstring( name )

dataset = conn.getUpdateService().saveAndReturnObject( dataset )

ID=dataset.getId().getValue()
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests