Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 284701 - [DB] Implement tableName and columnName annotation
Summary: [DB] Implement tableName and columnName annotation
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: M1   Edit
Assignee: Eike Stepper CLA
QA Contact:
URL:
Whiteboard: Power to the People
Keywords:
Depends on: 282976
Blocks:
  Show dependency tree
 
Reported: 2009-07-27 04:41 EDT by Kai Schlamp CLA
Modified: 2010-06-29 04:40 EDT (History)
3 users (show)

See Also:
stepper: documentation+
stepper: helios+


Attachments
Implementation + Test (7.07 KB, patch)
2009-07-27 04:45 EDT, Kai Schlamp CLA
no flags Details | Diff
Reworked Implementation + Test (10.34 KB, patch)
2009-07-27 10:43 EDT, Kai Schlamp CLA
no flags Details | Diff
Implementation + Test (8.83 KB, patch)
2009-08-03 11:40 EDT, Kai Schlamp CLA
stepper: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Schlamp CLA 2009-07-27 04:41:56 EDT
Implement tableName and columnName annotation:
See Bug 256635 and Bug 282976
Comment 1 Kai Schlamp CLA 2009-07-27 04:45:43 EDT
Created attachment 142625 [details]
Implementation + Test
Comment 2 Kai Schlamp CLA 2009-07-27 08:59:04 EDT
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? 
Comment 3 Kai Schlamp CLA 2009-07-27 10:43:22 EDT
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.
Comment 4 Stefan Winkler CLA 2009-08-03 10:40:34 EDT
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.
Comment 5 Ed Merks CLA 2009-08-03 10:45:14 EDT
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.
Comment 6 Kai Schlamp CLA 2009-08-03 10:47:14 EDT
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 
Comment 7 Kai Schlamp CLA 2009-08-03 10:50:15 EDT
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).
Comment 8 Kai Schlamp CLA 2009-08-03 10:50:44 EDT
> 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.
Comment 9 Kai Schlamp CLA 2009-08-03 11:40:16 EDT
Created attachment 143286 [details]
Implementation + Test

Another reworked patch. Works with EcoreUtil, DBAnnotation remains untouched, just a slight change in the test.
Comment 10 Eike Stepper CLA 2009-08-14 01:06:13 EDT
Committed to HEAD
Comment 11 Eike Stepper CLA 2010-05-08 05:45:09 EDT
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>
Comment 12 Eike Stepper CLA 2010-06-29 04:40:50 EDT
Available in 3.0 GA:
http://download.eclipse.org/modeling/emf/cdo/updates/3.0-releases/