Community
Participate
Working Groups
Implement tableName and columnName annotation: See Bug 256635 and Bug 282976
Created attachment 142625 [details] Implementation + Test
Adding two or more annotations to an ENamedElement fails, or better to say only the first is used, the others are ignored. Thats cause of a problem with ECoreUtil.getAnnotation(). I wrote the below to the newsgroup. We could easily fetch the annotation ourselves without the help of ECoreUtil, or wait for what the EMF guys say. In CDO a structural feature can have multiple annotation with the same source, like: <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"> <eAnnotations source="http://www.eclipse.org/CDO/DBStore"> <details key="columnName" value="HOLY"/> </eAnnotations> <eAnnotations source="http://www.eclipse.org/CDO/DBStore"> <details key="columnType" value="CLOB"/> </eAnnotations> </eStructuralFeatures> The problem with EcoreUtil.getAnnotation() now is that it always only checks the first annotation. Shouldn't it check all annotations with that source if the key exists?
Created attachment 142662 [details] Reworked Implementation + Test This patch provides a solution for the problem with ECoreUtil.getAnnnotation. DBAnnotation now fetches the annotation itself. The test now also contains a test case where a feature structure has two annotations. Everything seems to work fine now.
Kai, did you ask Ed about annotations and EcoreUtil? Because, why not use <eAnnotations source="http://www.eclipse.org/CDO/DBStore"> <details key="columnName" value="HOLY"/> <details key="columnType" value="CLOB"/> </eAnnotations> instead of two distinct eAnnotation elements? Because, if EcoreUtil works the way it does then either it is unwanted to have EAnnotations of the same source split up in two, or it's a bug in EcoreUtil and should be fixed there and not worked around.
EAnnotations can be structured however one likes, but the convenience methods in EcoreUtil will only look at the first annotation with the given source, i.e., it's generally expected that there will only be one EAnnotation with a given source; this is also the most concise and space efficient way to specify it.
Yes, I asked him ... below is the answer. So your provided example would indeed be the better way to do it. Kai, While it's certainly possible to have more than one annotations with the same source, it's not a good idea and the helper methods for accessing annotations don't provide help for that pattern of usage. Obviously it would be possible to have duplicate or conflicting mappings with such an approach. Kai Schlamp wrote: > Hi. > > In CDO a structural feature can have multiple annotation with the same source, like: > > <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"> > <eAnnotations source="http://www.eclipse.org/CDO/DBStore"> > <details key="columnName" value="HOLY"/> > </eAnnotations> > <eAnnotations source="http://www.eclipse.org/CDO/DBStore"> > <details key="columnType" value="CLOB"/> > </eAnnotations> > </eStructuralFeatures> > > The problem with EcoreUtil.getAnnotation() now is that it always only checks the first annotation. > Shouldn't it check all annotations with that source if the key exists? > > Regards, > Kai
Thanks again Ed. @Stefan ... ok, then let's change the way those annotations are parsed. Will you change it? Otherwise I will look into it in the upcoming days (tests also have to changed).
> 1) The number of lines that you changed (after copying from HSQLDB) is smaller > than 250. Confirmed. > > 2) You are the only author of these changed lines. Confirmed. > > 3) You apply the EPL to these changed lines. Confirmed.
Created attachment 143286 [details] Implementation + Test Another reworked patch. Works with EcoreUtil, DBAnnotation remains untouched, just a slight change in the test.
Committed to HEAD
The following new annotations are now recognized by the DBStore: public enum DBAnnotation { TABLE_MAPPING("tableMapping"), TABLE_NAME("tableName"), COLUMN_NAME("columnName"), COLUMN_TYPE("columnType"), COLUMN_LENGTH("columnLength"); public final static String SOURCE_URI = "http://www.eclipse.org/CDO/DBStore"; } In CDO a structural feature can have multiple annotation with the same source, like: <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"> <eAnnotations source="http://www.eclipse.org/CDO/DBStore"> <details key="columnName" value="HOLY"/> </eAnnotations> <eAnnotations source="http://www.eclipse.org/CDO/DBStore"> <details key="columnType" value="CLOB"/> </eAnnotations> </eStructuralFeatures>
Available in 3.0 GA: http://download.eclipse.org/modeling/emf/cdo/updates/3.0-releases/