We're Hiring!

Multiple-elements unique keys in ome.xml models

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.

Multiple-elements unique keys in ome.xml models

Postby luca.lianas » Tue Aug 31, 2010 1:12 pm

Hi everyone,
I'm writing some new ome.xml files to extend omero data model and I wanted to know if I can write a multi-elements unique key inside the XML code.
I try to explain using an example.

I want to create a new item with some fields

Code: Select all
<type id="ome.model.DummyItem">
  <properties>
    <required name="label" type="string"/>
    <required name="myDate" type="timestamp"/>
    <required name="myOtherUniqueField" type="string"/>
  </properties>
</type>


My problem is that each DummyItem object must have a unique key for the myDate AND the myOtherUniqueField fields, two items with the same values in both these fields have to be considered two duplicated items and one of them must raise an exception during the save operation.
I wanted to know if there is a syntax that I can use to create this kind of key or if I have to use a "combined" field with the unique constraint like this

Code: Select all
<type id="ome.model.DummyItem">
  <properties>
    <required name="label" type="string"/>
    <required name="myDate" type="timestamp"/>
    <required name="myOtherUniqueField" type="string"/>
    <required name="uniqueKeyValues" type="string" unique="true"/>
  </properties>
</type>


where uniqueKeyValues can be (for example) a string field obtained using the two fields (myDate and myOtherUniqueField).
luca.lianas
 
Posts: 2
Joined: Wed Jul 14, 2010 3:21 pm

Re: Multiple-elements unique keys in ome.xml models

Postby jmoore » Sun Sep 05, 2010 7:01 pm

Hi Luca,

the functionality you describe has not been implemented. The intended syntax was that any value other than "true"/"false" would become the name of a unique constraint on all the values with that string. E.g.
Code: Select all
<type id="ome.model.DummyItem">
  <properties>
    <required name="label" type="string"/>
    <required name="myDate" type="timestamp" unique="DummyItemTwoFieldUniqueCheck"/>
    <required name="myOtherUniqueField" type="string" unique="DummyItemTwoFieldUniqueCheck"/>
  </properties>
</type>


You can take a look at line 555 in ome.dsl.Property.Property(SemanticType, Properties) under components/dsl/src:
Code: Select all
setUnique(Boolean.valueOf(attrs.getProperty("unique", "false"))); // TODO
. Rather than setting unique to true, a map needs to be kept and injected into ome.dsl.SemanticType.getUniqueConstraints(). I've created ticket 2817. Let us know if you'd like to try your hand at it.

Cheers,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany


Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests