Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Storing EStructuralFeatures from their containing generated packages
[Teneo] Storing EStructuralFeatures from their containing generated packages [message #75708] Thu, 15 March 2007 01:55 Go to next message
Didier Villevalois is currently offline Didier VillevaloisFriend
Messages: 86
Registered: July 2009
Member
Hello again Martin,

I have EStructuralFeatures as part of the model I'd like to store in
Teneo. However, I'd like Teneo to use the static instances of these
features from their corresponding generated packages.

Let me explain my use case, if you don't mind:

1) Web is dug for data, data are put in model objects, and stored. As
part of this import process, reports are made for the
uncertainty/reliability of those created model objects. Those reports
are also stored.

2) Changes of those model objects are tracked (hand-edit, merge with
imports from other data sources...) and those changes are also stored.

Both reports and changes (for the later i used Ecore Change package)
references EStructuralFeatures.

However, those reports and change descriptions are contributed by third
party code. And i wish that they do not have to query the database to
retrieve the feature instances but instead use the static ones from the
generated packages.

I look a bit in the Teneo code, tried to debug a bit. But all this seems
confusing to me.

Should I specialize the mapping of features to indicate Teneo that an
EPackage is unique based on its nsURI and that a ENamedElement is unique
in a package based on its name. But how would Teneo recognize the static
instances of the generated packages as its instances ?

Could you give some hints as how to do this ? Or maybe is there already
support for this ?
Thanks for your help. Didier.
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #75741 is a reply to message #75708] Thu, 15 March 2007 12:06 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Didier,
Sorry but I do not understand what you mean.
Do you mean that there are references to the model itself from the instance data? So is your
question how to persist references to estructuralfeatures without requiring it to persist the
complete ecore package?
What do you mean 'do not have to query the database', you mean that you prefer them not to use sql?
When you query the database through hibernate then hibernate/Teneo will return the generated java
objects.

gr. Martin

Ptitjes wrote:
> Hello again Martin,
>
> I have EStructuralFeatures as part of the model I'd like to store in
> Teneo. However, I'd like Teneo to use the static instances of these
> features from their corresponding generated packages.
>
> Let me explain my use case, if you don't mind:
>
> 1) Web is dug for data, data are put in model objects, and stored. As
> part of this import process, reports are made for the
> uncertainty/reliability of those created model objects. Those reports
> are also stored.
>
> 2) Changes of those model objects are tracked (hand-edit, merge with
> imports from other data sources...) and those changes are also stored.
>
> Both reports and changes (for the later i used Ecore Change package)
> references EStructuralFeatures.
>
> However, those reports and change descriptions are contributed by third
> party code. And i wish that they do not have to query the database to
> retrieve the feature instances but instead use the static ones from the
> generated packages.
>
> I look a bit in the Teneo code, tried to debug a bit. But all this seems
> confusing to me.
>
> Should I specialize the mapping of features to indicate Teneo that an
> EPackage is unique based on its nsURI and that a ENamedElement is unique
> in a package based on its name. But how would Teneo recognize the static
> instances of the generated packages as its instances ?
>
> Could you give some hints as how to do this ? Or maybe is there already
> support for this ?
> Thanks for your help. Didier.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #75758 is a reply to message #75741] Thu, 15 March 2007 13:58 Go to previous messageGo to next message
Didier Villevalois is currently offline Didier VillevaloisFriend
Messages: 86
Registered: July 2009
Member
Martin,

Sorry, for the misunderstanding!

Martin Taal a écrit :
> Hi Didier,
> Sorry but I do not understand what you mean.
> Do you mean that there are references to the model itself from the
> instance data?

Yes! To get an idea, you can look at
http://www.eclipse.org/emf/2003/Change (aka
org.eclipse.emf.ecore.change/model/Change.ecore)

For instance, the eclass FeatureChange has a feature 'feature' of etype
EStructuralFeature, and i need to persist some FeatureChange objects.

> So is your question how to persist references to
> estructuralfeatures without requiring it to persist the complete ecore
> package?

(If i can persist just EStructuralFeatures that is better but...)

What i primarily want to do is that my users may add to the database
FeatureChange objects (for instance) to the database and setting the
'feature' feature of those objects with the static EStructuralFeature
instances of generated EPackages.

For instance, let say i have an epackage People like this :

EClass Person
EAttribute firstname

I want to persist PeoplePackage.Literals.PERSON__FIRSTNAME. However if i
persist this three times, i'll have three times the same feature in the
database. Also, if i query the database none of those three retrieved
instance will be == to PeoplePackage.Literals.PERSON__FIRSTNAME.

> What do you mean 'do not have to query the database', you mean that you
> prefer them not to use sql?
> When you query the database through hibernate then hibernate/Teneo will
> return the generated java objects.

Is there a mean to shortcut the instantiation of the queried objects and
filter them so that if an object is of type EStructuralFeature we return
the one from the corresponding static (generated) EPackage ?

And is there a way that when i store an object that references an
EStructuralFeature, Teneo changes the reference to point to the already
stored same feature ?

I hope i'm a bit more clear...
Thanks for your help!
Didier.
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #75792 is a reply to message #75758] Thu, 15 March 2007 15:00 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080909000903080207000703
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi Didier,
Now I understand better. The best approach is to define a hibernate usertype for the reference to
the estructuralfeature. I would store the reference as a string (varchar) in the db (for example the
concatenation of the package ns uri and the eclassname and efeaturename) and when retrieving it from
the db convert the string to the actual one instance in memory.
You can get to the in-memory E-Package through the EPackage.registry and from the EPackage you can
get the eclass and the estructuralfeature.

This is for example an annotation for a type definition on an EAttribute:
@Type(type=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")

On an EDataType you can do:
@TypeDef(name="nameType" typeClass=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")

The system then expects that there is a class
org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e which implements the hibernate UserType.

I have attached an ecore with a type def annotation on the Name EDataType and the related NameType.

See for the rest the hibernate manual.

gr. Martin

Ptitjes wrote:
> Martin,
>
> Sorry, for the misunderstanding!
>
> Martin Taal a
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #75896 is a reply to message #75792] Sun, 18 March 2007 01:08 Go to previous messageGo to next message
Didier Villevalois is currently offline Didier VillevaloisFriend
Messages: 86
Registered: July 2009
Member
Again...

The type annotation seems to be available for EAttributes only. Looking
at the Javadoc, it seems that org.hibernate.usertype.*UserType classes
are only suitable for properties. In fact, i get an exception:

org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
The eclass: HbAnnotatedEReference does not have an efeature for Type

However, i'm wondering whether i could force the mapping of my reference
to be a property and not a relation. So i generated the mapping of my
core package and modified it to change the many-to-one to a property.

<property name="feature" lazy="false" insert="true" update="true"
not-null="false" unique="false"
type=" org.beuz.casual.datastore.management.data.types.EStructuralF eatureType ">
<column not-null="false" unique="false" name="`feature`"/>
</property>

<!--many-to-one name="feature" entity-name="EStructuralFeature"
cascade="merge,persist,save-update,lock,refresh" lazy="false"
insert="true" update="true" not-null="false"/-->

But now i'm stuck to a new problem. As my ePackages are contributed by
many plugins via an extension point, i cannot generate all the mapping
in one piece.

In addition, if i use the usertype trick, i'll have
- my core package for which i must provide a manual mapping,
- the ecore Change package (that i can't modify) for which i must
provide a manual mapping, and
- plugins-provided packages that are derived from my core package so i
can't generate them (because GenerateHBM seems to not find the loaded
resources in my ecore).

So i'll need to merge mappings anyway.

So I sub-classed HbDataStore, overided mapModel and mapEPackages, added
some more accessors in order to call many times addURL (for generated
mappings) and addXML (for the mapping computed by mapEPackages for the
packages which are not generated).

However, DefaultAnnotator requires that all EClasses are in the
PAnnotatedModel. Do you think it is feasible to merge mappings? in a way
or another? (like generating a genmodel may use some dependent genmodel)

Thanks for your help.
Didier.

Martin Taal a écrit :
> Hi Didier,
> Now I understand better. The best approach is to define a hibernate
> usertype for the reference to the estructuralfeature. I would store the
> reference as a string (varchar) in the db (for example the concatenation
> of the package ns uri and the eclassname and efeaturename) and when
> retrieving it from the db convert the string to the actual one instance
> in memory.
> You can get to the in-memory E-Package through the EPackage.registry and
> from the EPackage you can get the eclass and the estructuralfeature.
>
> This is for example an annotation for a type definition on an EAttribute:
> @Type(type=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")
>
> On an EDataType you can do:
> @TypeDef(name="nameType"
> typeClass=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")
>
> The system then expects that there is a class
> org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e which
> implements the hibernate UserType.
>
> I have attached an ecore with a type def annotation on the Name
> EDataType and the related NameType.
>
> See for the rest the hibernate manual.
>
> gr. Martin
>
> Ptitjes wrote:
>> Martin,
>>
>> Sorry, for the misunderstanding!
>>
>> Martin Taal a écrit :
>>> Hi Didier,
>>> Sorry but I do not understand what you mean.
>>> Do you mean that there are references to the model itself from the
>>> instance data?
>>
>> Yes! To get an idea, you can look at
>> http://www.eclipse.org/emf/2003/Change (aka
>> org.eclipse.emf.ecore.change/model/Change.ecore)
>>
>> For instance, the eclass FeatureChange has a feature 'feature' of etype
>> EStructuralFeature, and i need to persist some FeatureChange objects.
>>
>>> So is your question how to persist references to
>>> estructuralfeatures without requiring it to persist the complete ecore
>>> package?
>>
>> (If i can persist just EStructuralFeatures that is better but...)
>>
>> What i primarily want to do is that my users may add to the database
>> FeatureChange objects (for instance) to the database and setting the
>> 'feature' feature of those objects with the static EStructuralFeature
>> instances of generated EPackages.
>>
>> For instance, let say i have an epackage People like this :
>>
>> EClass Person
>> EAttribute firstname
>>
>> I want to persist PeoplePackage.Literals.PERSON__FIRSTNAME. However if i
>> persist this three times, i'll have three times the same feature in the
>> database. Also, if i query the database none of those three retrieved
>> instance will be == to PeoplePackage.Literals.PERSON__FIRSTNAME.
>>
>>> What do you mean 'do not have to query the database', you mean that you
>>> prefer them not to use sql?
>>> When you query the database through hibernate then hibernate/Teneo will
>>> return the generated java objects.
>>
>> Is there a mean to shortcut the instantiation of the queried objects and
>> filter them so that if an object is of type EStructuralFeature we return
>> the one from the corresponding static (generated) EPackage ?
>>
>> And is there a way that when i store an object that references an
>> EStructuralFeature, Teneo changes the reference to point to the already
>> stored same feature ?
>>
>> I hope i'm a bit more clear...
>> Thanks for your help!
>> Didier.
>
>
>
> ------------------------------------------------------------ ------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="usertype"
> nsURI="http://www.elver.org/samples/emf/hibernate/usertype" nsPrefix="usertype">
> <eClassifiers xsi:type="ecore:EDataType" name="Name" instanceClassName="org.eclipse.emf.teneo.samples.emf.hibernate.usertype.Name ">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value=" &#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&# x9;@TypeDef(name=&quot;nameType&quot; typeClass=&quot;org.eclipse.emf.teneo.samples.emf.hibern ate.usertype.NameType&quot;)&#xA;&#x9;&#x9;& amp;#x9;&#x9;&#x9;&#x9;@Columns({@Column(name=&a mp;quot;first_name&quot;), @Column(name=&quot;last_name&quot;)})&#xA;&# x9;&#x9;&#x9;&#x9;&#x9; "/>
> </eAnnotations>
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Name"/>
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Person">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Person"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" lowerBound="1"
> eType="#//Name">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="name"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="numbers" unique="false"
> lowerBound="1" eType="#//IntArray">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="intArray"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="phoneNumbers" upperBound="100"
> eType="#//PhoneNumber"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="emergencyContact" eType="#//PhoneNumber"
> defaultValueLiteral=""/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="addresses" upperBound="-1"
> eType="#//Address" eOpposite="#//Address/person">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value=" @OnDelete(action=OnDeleteAction.CASCADE)&#xA;@OneToMany( indexed=false, unique=true)"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="PhoneNumber" instanceClassName=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.UsaPhon eNumber "/>
> <eClassifiers xsi:type="ecore:EDataType" name="IntArray" instanceClassName="int[]">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="IntArray"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value=" &#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&# x9;@TypeDef(name=&quot;intArrayType&quot; typeClass=&quot;org.eclipse.emf.teneo.hibernate.mapping. DefaultToStringUserType&quot;, parameters={@Parameter(name=&quot;epackage&quot; value=&quot; http://www.elver.org/samples/emf/hibernate/usertype&quot;), @Parameter(name=&quot;edatatype&quot;, value=&quot;IntArray&quot;)})&#xA;&#x9;& #x9;&#x9;&#x9;&#x9; "/>
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Address">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Person"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="addressInfo" unique="false"
> lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="name"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="person" eType="#//Person"
> eOpposite="#//Person/addresses"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> ------------------------------------------------------------ ------------
>
> package org.eclipse.emf.teneo.samples.emf.hibernate.usertype;
>
> import java.io.Serializable;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Types;
>
> import org.hibernate.Hibernate;
> import org.hibernate.HibernateException;
> import org.hibernate.usertype.UserType;
>
> /**
> * Trivial example implementation of a UserType.
> */
> public class NameType implements UserType {
>
> private static final int[] SQL_TYPES = new int[] { Types.VARCHAR, Types.VARCHAR };
>
> public Object assemble(Serializable cached, Object owner) throws HibernateException {
> return deepCopy(cached);
> }
>
> public Object deepCopy(Object value) throws HibernateException {
> Name name = (Name) value;
> return new Name(name.getFirst(), name.getLast());
> }
>
> public Serializable disassemble(Object value) throws HibernateException {
> return (Serializable) deepCopy(value);
> }
>
> public boolean equals(Object x, Object y) throws HibernateException {
> if (x == y) {
> return true;
> } else if (x == null || y == null) {
> return false;
> }
> return x.equals(y);
> }
>
> public int hashCode(Object x) throws HibernateException {
> return x.hashCode();
> }
>
> public boolean isMutable() {
> return true;
> }
>
> public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
> String first = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
> String last = (String) Hibernate.STRING.nullSafeGet(rs, names[1]);
> return new Name(first, last);
> }
>
> public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
> Name name = (Name) value;
> Hibernate.STRING.nullSafeSet(st, name.getFirst(), index);
> Hibernate.STRING.nullSafeSet(st, name.getLast(), index + 1);
> }
>
> public Object replace(Object original, Object target, Object owner) throws HibernateException {
> return original;
> }
>
> public Class returnedClass() {
> return Name.class;
> }
>
> public int[] sqlTypes() {
> return SQL_TYPES;
> }
>
> }
[Resolved] Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #75945 is a reply to message #75792] Sun, 18 March 2007 21:02 Go to previous messageGo to next message
Didier Villevalois is currently offline Didier VillevaloisFriend
Messages: 86
Registered: July 2009
Member
Hi Martin,

I resolved my problems by doing the following:

1) Created a fake Ecore package with same nsURI but
- with only a EStructuralFeatue class defined
- with a little tweaking of the generated EcorePackage class so that it
is not published in the registry

2) Subclassed HbDataStore and
- overrided setEPackages() to filter the Ecore package and replacing it
with my fake Ecore package
- overrided mapEPackages() doing the same as the original but filtering
the generated mapping and replacing manyToOnes to EStructuralFeatures by
properties to my usertype.

This seems to work like a charm. I'm still testing however to verify
there are no side effects...

I would find a good point for teneo if there was an integrated feature
to manage this (like a persistance option). Because it would enable
people to store metadata along with their data.

It is in fact very common to reference EStructuralFeatures in metadata.
An example of such use is the Ecore Change package
(http://www.eclipse.org/emf/2003/Change) that i use by the way. When
using the Change package you can't customize the mapping generated by
teneo as you don't have hand over the .ecore file.

I filter the generated mapping when it is in the simpledom form (i made
it quick and dirty, and i did not want to change teneo's own code).
However maybe the filtering could be done before in the DefaultAnnotator.

Tell me if you would like i share my code.

Thanks for all. I very enjoy using that great tool!
Didier.
Re: [Resolved] Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #75964 is a reply to message #75945] Sun, 18 March 2007 21:12 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Didier,
Good that it works. I completely agree that it is very common to reference the model itself from
runtime data (having the model available at runtime is a great feature of emf).
Can you enter a feature request in bugzilla for this (support references to an ecore model,
estructuralfeatures/eclass, etc. in an efficient fashion)?
If you can attach your code (as a patch) then that would be nice, thanks.

gr. Martin

Ptitjes wrote:
> Hi Martin,
>
> I resolved my problems by doing the following:
>
> 1) Created a fake Ecore package with same nsURI but
> - with only a EStructuralFeatue class defined
> - with a little tweaking of the generated EcorePackage class so that it
> is not published in the registry
>
> 2) Subclassed HbDataStore and
> - overrided setEPackages() to filter the Ecore package and replacing it
> with my fake Ecore package
> - overrided mapEPackages() doing the same as the original but filtering
> the generated mapping and replacing manyToOnes to EStructuralFeatures by
> properties to my usertype.
>
> This seems to work like a charm. I'm still testing however to verify
> there are no side effects...
>
> I would find a good point for teneo if there was an integrated feature
> to manage this (like a persistance option). Because it would enable
> people to store metadata along with their data.
>
> It is in fact very common to reference EStructuralFeatures in metadata.
> An example of such use is the Ecore Change package
> (http://www.eclipse.org/emf/2003/Change) that i use by the way. When
> using the Change package you can't customize the mapping generated by
> teneo as you don't have hand over the .ecore file.
>
> I filter the generated mapping when it is in the simpledom form (i made
> it quick and dirty, and i did not want to change teneo's own code).
> However maybe the filtering could be done before in the DefaultAnnotator.
>
> Tell me if you would like i share my code.
>
> Thanks for all. I very enjoy using that great tool!
> Didier.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #603676 is a reply to message #75708] Thu, 15 March 2007 12:06 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Didier,
Sorry but I do not understand what you mean.
Do you mean that there are references to the model itself from the instance data? So is your
question how to persist references to estructuralfeatures without requiring it to persist the
complete ecore package?
What do you mean 'do not have to query the database', you mean that you prefer them not to use sql?
When you query the database through hibernate then hibernate/Teneo will return the generated java
objects.

gr. Martin

Ptitjes wrote:
> Hello again Martin,
>
> I have EStructuralFeatures as part of the model I'd like to store in
> Teneo. However, I'd like Teneo to use the static instances of these
> features from their corresponding generated packages.
>
> Let me explain my use case, if you don't mind:
>
> 1) Web is dug for data, data are put in model objects, and stored. As
> part of this import process, reports are made for the
> uncertainty/reliability of those created model objects. Those reports
> are also stored.
>
> 2) Changes of those model objects are tracked (hand-edit, merge with
> imports from other data sources...) and those changes are also stored.
>
> Both reports and changes (for the later i used Ecore Change package)
> references EStructuralFeatures.
>
> However, those reports and change descriptions are contributed by third
> party code. And i wish that they do not have to query the database to
> retrieve the feature instances but instead use the static ones from the
> generated packages.
>
> I look a bit in the Teneo code, tried to debug a bit. But all this seems
> confusing to me.
>
> Should I specialize the mapping of features to indicate Teneo that an
> EPackage is unique based on its nsURI and that a ENamedElement is unique
> in a package based on its name. But how would Teneo recognize the static
> instances of the generated packages as its instances ?
>
> Could you give some hints as how to do this ? Or maybe is there already
> support for this ?
> Thanks for your help. Didier.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #603679 is a reply to message #75741] Thu, 15 March 2007 13:58 Go to previous message
Didier Villevalois is currently offline Didier VillevaloisFriend
Messages: 86
Registered: July 2009
Member
Martin,

Sorry, for the misunderstanding!

Martin Taal a écrit :
> Hi Didier,
> Sorry but I do not understand what you mean.
> Do you mean that there are references to the model itself from the
> instance data?

Yes! To get an idea, you can look at
http://www.eclipse.org/emf/2003/Change (aka
org.eclipse.emf.ecore.change/model/Change.ecore)

For instance, the eclass FeatureChange has a feature 'feature' of etype
EStructuralFeature, and i need to persist some FeatureChange objects.

> So is your question how to persist references to
> estructuralfeatures without requiring it to persist the complete ecore
> package?

(If i can persist just EStructuralFeatures that is better but...)

What i primarily want to do is that my users may add to the database
FeatureChange objects (for instance) to the database and setting the
'feature' feature of those objects with the static EStructuralFeature
instances of generated EPackages.

For instance, let say i have an epackage People like this :

EClass Person
EAttribute firstname

I want to persist PeoplePackage.Literals.PERSON__FIRSTNAME. However if i
persist this three times, i'll have three times the same feature in the
database. Also, if i query the database none of those three retrieved
instance will be == to PeoplePackage.Literals.PERSON__FIRSTNAME.

> What do you mean 'do not have to query the database', you mean that you
> prefer them not to use sql?
> When you query the database through hibernate then hibernate/Teneo will
> return the generated java objects.

Is there a mean to shortcut the instantiation of the queried objects and
filter them so that if an object is of type EStructuralFeature we return
the one from the corresponding static (generated) EPackage ?

And is there a way that when i store an object that references an
EStructuralFeature, Teneo changes the reference to point to the already
stored same feature ?

I hope i'm a bit more clear...
Thanks for your help!
Didier.
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #603685 is a reply to message #75758] Thu, 15 March 2007 15:00 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080909000903080207000703
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi Didier,
Now I understand better. The best approach is to define a hibernate usertype for the reference to
the estructuralfeature. I would store the reference as a string (varchar) in the db (for example the
concatenation of the package ns uri and the eclassname and efeaturename) and when retrieving it from
the db convert the string to the actual one instance in memory.
You can get to the in-memory E-Package through the EPackage.registry and from the EPackage you can
get the eclass and the estructuralfeature.

This is for example an annotation for a type definition on an EAttribute:
@Type(type=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")

On an EDataType you can do:
@TypeDef(name="nameType" typeClass=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")

The system then expects that there is a class
org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e which implements the hibernate UserType.

I have attached an ecore with a type def annotation on the Name EDataType and the related NameType.

See for the rest the hibernate manual.

gr. Martin

Ptitjes wrote:
> Martin,
>
> Sorry, for the misunderstanding!
>
> Martin Taal a
Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #603705 is a reply to message #75792] Sun, 18 March 2007 01:08 Go to previous message
Didier Villevalois is currently offline Didier VillevaloisFriend
Messages: 86
Registered: July 2009
Member
Again...

The type annotation seems to be available for EAttributes only. Looking
at the Javadoc, it seems that org.hibernate.usertype.*UserType classes
are only suitable for properties. In fact, i get an exception:

org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
The eclass: HbAnnotatedEReference does not have an efeature for Type

However, i'm wondering whether i could force the mapping of my reference
to be a property and not a relation. So i generated the mapping of my
core package and modified it to change the many-to-one to a property.

<property name="feature" lazy="false" insert="true" update="true"
not-null="false" unique="false"
type=" org.beuz.casual.datastore.management.data.types.EStructuralF eatureType ">
<column not-null="false" unique="false" name="`feature`"/>
</property>

<!--many-to-one name="feature" entity-name="EStructuralFeature"
cascade="merge,persist,save-update,lock,refresh" lazy="false"
insert="true" update="true" not-null="false"/-->

But now i'm stuck to a new problem. As my ePackages are contributed by
many plugins via an extension point, i cannot generate all the mapping
in one piece.

In addition, if i use the usertype trick, i'll have
- my core package for which i must provide a manual mapping,
- the ecore Change package (that i can't modify) for which i must
provide a manual mapping, and
- plugins-provided packages that are derived from my core package so i
can't generate them (because GenerateHBM seems to not find the loaded
resources in my ecore).

So i'll need to merge mappings anyway.

So I sub-classed HbDataStore, overided mapModel and mapEPackages, added
some more accessors in order to call many times addURL (for generated
mappings) and addXML (for the mapping computed by mapEPackages for the
packages which are not generated).

However, DefaultAnnotator requires that all EClasses are in the
PAnnotatedModel. Do you think it is feasible to merge mappings? in a way
or another? (like generating a genmodel may use some dependent genmodel)

Thanks for your help.
Didier.

Martin Taal a écrit :
> Hi Didier,
> Now I understand better. The best approach is to define a hibernate
> usertype for the reference to the estructuralfeature. I would store the
> reference as a string (varchar) in the db (for example the concatenation
> of the package ns uri and the eclassname and efeaturename) and when
> retrieving it from the db convert the string to the actual one instance
> in memory.
> You can get to the in-memory E-Package through the EPackage.registry and
> from the EPackage you can get the eclass and the estructuralfeature.
>
> This is for example an annotation for a type definition on an EAttribute:
> @Type(type=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")
>
> On an EDataType you can do:
> @TypeDef(name="nameType"
> typeClass=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e ")
>
> The system then expects that there is a class
> org.eclipse.emf.teneo.samples.emf.hibernate.usertype.NameTyp e which
> implements the hibernate UserType.
>
> I have attached an ecore with a type def annotation on the Name
> EDataType and the related NameType.
>
> See for the rest the hibernate manual.
>
> gr. Martin
>
> Ptitjes wrote:
>> Martin,
>>
>> Sorry, for the misunderstanding!
>>
>> Martin Taal a écrit :
>>> Hi Didier,
>>> Sorry but I do not understand what you mean.
>>> Do you mean that there are references to the model itself from the
>>> instance data?
>>
>> Yes! To get an idea, you can look at
>> http://www.eclipse.org/emf/2003/Change (aka
>> org.eclipse.emf.ecore.change/model/Change.ecore)
>>
>> For instance, the eclass FeatureChange has a feature 'feature' of etype
>> EStructuralFeature, and i need to persist some FeatureChange objects.
>>
>>> So is your question how to persist references to
>>> estructuralfeatures without requiring it to persist the complete ecore
>>> package?
>>
>> (If i can persist just EStructuralFeatures that is better but...)
>>
>> What i primarily want to do is that my users may add to the database
>> FeatureChange objects (for instance) to the database and setting the
>> 'feature' feature of those objects with the static EStructuralFeature
>> instances of generated EPackages.
>>
>> For instance, let say i have an epackage People like this :
>>
>> EClass Person
>> EAttribute firstname
>>
>> I want to persist PeoplePackage.Literals.PERSON__FIRSTNAME. However if i
>> persist this three times, i'll have three times the same feature in the
>> database. Also, if i query the database none of those three retrieved
>> instance will be == to PeoplePackage.Literals.PERSON__FIRSTNAME.
>>
>>> What do you mean 'do not have to query the database', you mean that you
>>> prefer them not to use sql?
>>> When you query the database through hibernate then hibernate/Teneo will
>>> return the generated java objects.
>>
>> Is there a mean to shortcut the instantiation of the queried objects and
>> filter them so that if an object is of type EStructuralFeature we return
>> the one from the corresponding static (generated) EPackage ?
>>
>> And is there a way that when i store an object that references an
>> EStructuralFeature, Teneo changes the reference to point to the already
>> stored same feature ?
>>
>> I hope i'm a bit more clear...
>> Thanks for your help!
>> Didier.
>
>
>
> ------------------------------------------------------------ ------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="usertype"
> nsURI="http://www.elver.org/samples/emf/hibernate/usertype" nsPrefix="usertype">
> <eClassifiers xsi:type="ecore:EDataType" name="Name" instanceClassName="org.eclipse.emf.teneo.samples.emf.hibernate.usertype.Name ">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value=" &#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&# x9;@TypeDef(name=&quot;nameType&quot; typeClass=&quot;org.eclipse.emf.teneo.samples.emf.hibern ate.usertype.NameType&quot;)&#xA;&#x9;&#x9;& amp;#x9;&#x9;&#x9;&#x9;@Columns({@Column(name=&a mp;quot;first_name&quot;), @Column(name=&quot;last_name&quot;)})&#xA;&# x9;&#x9;&#x9;&#x9;&#x9; "/>
> </eAnnotations>
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Name"/>
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Person">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Person"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" lowerBound="1"
> eType="#//Name">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="name"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="numbers" unique="false"
> lowerBound="1" eType="#//IntArray">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="intArray"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="phoneNumbers" upperBound="100"
> eType="#//PhoneNumber"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="emergencyContact" eType="#//PhoneNumber"
> defaultValueLiteral=""/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="addresses" upperBound="-1"
> eType="#//Address" eOpposite="#//Address/person">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value=" @OnDelete(action=OnDeleteAction.CASCADE)&#xA;@OneToMany( indexed=false, unique=true)"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="PhoneNumber" instanceClassName=" org.eclipse.emf.teneo.samples.emf.hibernate.usertype.UsaPhon eNumber "/>
> <eClassifiers xsi:type="ecore:EDataType" name="IntArray" instanceClassName="int[]">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="IntArray"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value=" &#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&# x9;@TypeDef(name=&quot;intArrayType&quot; typeClass=&quot;org.eclipse.emf.teneo.hibernate.mapping. DefaultToStringUserType&quot;, parameters={@Parameter(name=&quot;epackage&quot; value=&quot; http://www.elver.org/samples/emf/hibernate/usertype&quot;), @Parameter(name=&quot;edatatype&quot;, value=&quot;IntArray&quot;)})&#xA;&#x9;& #x9;&#x9;&#x9;&#x9; "/>
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Address">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Person"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="addressInfo" unique="false"
> lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="name"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="person" eType="#//Person"
> eOpposite="#//Person/addresses"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> ------------------------------------------------------------ ------------
>
> package org.eclipse.emf.teneo.samples.emf.hibernate.usertype;
>
> import java.io.Serializable;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Types;
>
> import org.hibernate.Hibernate;
> import org.hibernate.HibernateException;
> import org.hibernate.usertype.UserType;
>
> /**
> * Trivial example implementation of a UserType.
> */
> public class NameType implements UserType {
>
> private static final int[] SQL_TYPES = new int[] { Types.VARCHAR, Types.VARCHAR };
>
> public Object assemble(Serializable cached, Object owner) throws HibernateException {
> return deepCopy(cached);
> }
>
> public Object deepCopy(Object value) throws HibernateException {
> Name name = (Name) value;
> return new Name(name.getFirst(), name.getLast());
> }
>
> public Serializable disassemble(Object value) throws HibernateException {
> return (Serializable) deepCopy(value);
> }
>
> public boolean equals(Object x, Object y) throws HibernateException {
> if (x == y) {
> return true;
> } else if (x == null || y == null) {
> return false;
> }
> return x.equals(y);
> }
>
> public int hashCode(Object x) throws HibernateException {
> return x.hashCode();
> }
>
> public boolean isMutable() {
> return true;
> }
>
> public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
> String first = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
> String last = (String) Hibernate.STRING.nullSafeGet(rs, names[1]);
> return new Name(first, last);
> }
>
> public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
> Name name = (Name) value;
> Hibernate.STRING.nullSafeSet(st, name.getFirst(), index);
> Hibernate.STRING.nullSafeSet(st, name.getLast(), index + 1);
> }
>
> public Object replace(Object original, Object target, Object owner) throws HibernateException {
> return original;
> }
>
> public Class returnedClass() {
> return Name.class;
> }
>
> public int[] sqlTypes() {
> return SQL_TYPES;
> }
>
> }
[Resolved] Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #603712 is a reply to message #75792] Sun, 18 March 2007 21:02 Go to previous message
Didier Villevalois is currently offline Didier VillevaloisFriend
Messages: 86
Registered: July 2009
Member
Hi Martin,

I resolved my problems by doing the following:

1) Created a fake Ecore package with same nsURI but
- with only a EStructuralFeatue class defined
- with a little tweaking of the generated EcorePackage class so that it
is not published in the registry

2) Subclassed HbDataStore and
- overrided setEPackages() to filter the Ecore package and replacing it
with my fake Ecore package
- overrided mapEPackages() doing the same as the original but filtering
the generated mapping and replacing manyToOnes to EStructuralFeatures by
properties to my usertype.

This seems to work like a charm. I'm still testing however to verify
there are no side effects...

I would find a good point for teneo if there was an integrated feature
to manage this (like a persistance option). Because it would enable
people to store metadata along with their data.

It is in fact very common to reference EStructuralFeatures in metadata.
An example of such use is the Ecore Change package
(http://www.eclipse.org/emf/2003/Change) that i use by the way. When
using the Change package you can't customize the mapping generated by
teneo as you don't have hand over the .ecore file.

I filter the generated mapping when it is in the simpledom form (i made
it quick and dirty, and i did not want to change teneo's own code).
However maybe the filtering could be done before in the DefaultAnnotator.

Tell me if you would like i share my code.

Thanks for all. I very enjoy using that great tool!
Didier.
Re: [Resolved] Re: [Teneo] Storing EStructuralFeatures from their containing generated packages [message #603716 is a reply to message #75945] Sun, 18 March 2007 21:12 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Didier,
Good that it works. I completely agree that it is very common to reference the model itself from
runtime data (having the model available at runtime is a great feature of emf).
Can you enter a feature request in bugzilla for this (support references to an ecore model,
estructuralfeatures/eclass, etc. in an efficient fashion)?
If you can attach your code (as a patch) then that would be nice, thanks.

gr. Martin

Ptitjes wrote:
> Hi Martin,
>
> I resolved my problems by doing the following:
>
> 1) Created a fake Ecore package with same nsURI but
> - with only a EStructuralFeatue class defined
> - with a little tweaking of the generated EcorePackage class so that it
> is not published in the registry
>
> 2) Subclassed HbDataStore and
> - overrided setEPackages() to filter the Ecore package and replacing it
> with my fake Ecore package
> - overrided mapEPackages() doing the same as the original but filtering
> the generated mapping and replacing manyToOnes to EStructuralFeatures by
> properties to my usertype.
>
> This seems to work like a charm. I'm still testing however to verify
> there are no side effects...
>
> I would find a good point for teneo if there was an integrated feature
> to manage this (like a persistance option). Because it would enable
> people to store metadata along with their data.
>
> It is in fact very common to reference EStructuralFeatures in metadata.
> An example of such use is the Ecore Change package
> (http://www.eclipse.org/emf/2003/Change) that i use by the way. When
> using the Change package you can't customize the mapping generated by
> teneo as you don't have hand over the .ecore file.
>
> I filter the generated mapping when it is in the simpledom form (i made
> it quick and dirty, and i did not want to change teneo's own code).
> However maybe the filtering could be done before in the DefaultAnnotator.
>
> Tell me if you would like i share my code.
>
> Thanks for all. I very enjoy using that great tool!
> Didier.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:[Teneo] org.eclipse.emf.teneo.hibernate.mapper/model not included in sources builds
Next Topic:JET Null Pointer Exception & XPath Axes
Goto Forum:
  


Current Time: Fri Nov 27 12:47:14 GMT 2020

Powered by FUDForum. Page generated in 0.02816 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top