Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » Teneo : persistence of objects URI
Teneo : persistence of objects URI [message #58396] |
Fri, 20 October 2006 05:38  |
Eclipse User |
|
|
|
Originally posted by: mat.loo.gmail.com
Hi
Are we ensured that the URI of an object will remain the same during all
its life cycle ?
I mean, when I create a Marker on an EMF Object (that I identify with its
URI, as EMF does in general), am I sure this URI will remain the same the
next time I launch Eclipse ? When Teneo/Jpox builds EObjects while reading
database, will all URIs be unique for each object and the same as the last
time Teneo/Jpox read the database ?
Thx
|
|
|
Re: Teneo : persistence of objects URI [message #58435 is a reply to message #58396] |
Fri, 20 October 2006 06:23   |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Mat,
URIs are how EMF references other objects in general so this is a more
general question. The URI consists of the <base>#<fragment> where the
base identifies the resource containing the object and the fragment
identifies the object within that resource. If you actually moved the
object to a new resource, then clearly the base could change. The
fragment might well be a fragment path, so if the object moved within
the tree structure of the resource, then that path could change. If the
fragment is just an ID/UUID, then it won't change no matter how the
object is moved around within its resource. The URI should generally
not change arbitrarily unless you move or change the object. I assume
this is the case for how Teneo uses URIs as well...
Mat Lo wrote:
> Hi
>
> Are we ensured that the URI of an object will remain the same during
> all its life cycle ? I mean, when I create a Marker on an EMF Object
> (that I identify with its URI, as EMF does in general), am I sure this
> URI will remain the same the next time I launch Eclipse ? When
> Teneo/Jpox builds EObjects while reading database, will all URIs be
> unique for each object and the same as the last time Teneo/Jpox read
> the database ?
>
> Thx
>
|
|
|
Re: Teneo : persistence of objects URI [message #58449 is a reply to message #58435] |
Fri, 20 October 2006 06:50   |
Eclipse User |
|
|
|
Mat,
The relational database does not have a notion of resources. The way you read the objects in the
resource determines there ordering and therefore the uri, if the uri is based on position.
So it is a safer approach to use the concept of an EMF id. You can try to map the emf id notion to
the same efeature as the database id. However, afaik (please correct me Ed if I am wrong) an EMF id
is always a string while the database id can be something else (auto-increment long or something).
This can be workarounded pretty easily by having a separate EMF id and database id efeature and
keeping the EMF id in sync with the database id.
gr. Martin
Ed Merks wrote:
> Mat,
>
> URIs are how EMF references other objects in general so this is a more
> general question. The URI consists of the <base>#<fragment> where the
> base identifies the resource containing the object and the fragment
> identifies the object within that resource. If you actually moved the
> object to a new resource, then clearly the base could change. The
> fragment might well be a fragment path, so if the object moved within
> the tree structure of the resource, then that path could change. If the
> fragment is just an ID/UUID, then it won't change no matter how the
> object is moved around within its resource. The URI should generally
> not change arbitrarily unless you move or change the object. I assume
> this is the case for how Teneo uses URIs as well...
>
>
> Mat Lo wrote:
>> Hi
>>
>> Are we ensured that the URI of an object will remain the same during
>> all its life cycle ? I mean, when I create a Marker on an EMF Object
>> (that I identify with its URI, as EMF does in general), am I sure this
>> URI will remain the same the next time I launch Eclipse ? When
>> Teneo/Jpox builds EObjects while reading database, will all URIs be
>> unique for each object and the same as the last time Teneo/Jpox read
>> the database ?
>>
>> Thx
>>
--
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 : persistence of objects URI [message #58460 is a reply to message #58449] |
Fri, 20 October 2006 07:07   |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
This is a multi-part message in MIME format.
--------------000800040507010000000902
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Martin,
EMF doesn't force the ID to be a string. As you can see in these
EcoreUtil methods, it will convert to and from a string representation
as necessary.
/**
* Returns the value of the object's ID attribute as a String.
* If the object has no ID attribute or the ID attribute is not
set, it returns <code>null</code>.
* @param eObject the object in question.
* @return the value of the object's ID attribute as a String.
* @see org.eclipse.emf.ecore.EAttribute#isID
* @see org.eclipse.emf.ecore.EClass#getEIDAttribute
* @see #setID(EObject, String)
*/
public static String getID(EObject eObject)
{
EClass eClass = eObject.eClass();
EAttribute eIDAttribute = eClass.getEIDAttribute();
return eIDAttribute == null || !eObject.eIsSet(eIDAttribute) ?
null : convertToString(
eIDAttribute.getEAttributeType(),
eObject.eGet(eIDAttribute));
}
/**
* Sets the value of the object's ID attribute according to the
value represented by the String.
* A <code>null</code> ID will unset the attribute rather than
setting it to <code>null</code>.
* @param eObject the object in question.
* @param id the String value of the new ID.
* @return the value of the object's ID attribute as a String.
* @throws IllegalArgumentException if the object has no ID attribute.
* @see #getID(EObject)
* @see org.eclipse.emf.ecore.EAttribute#isID
* @see org.eclipse.emf.ecore.EClass#getEIDAttribute
*/
public static void setID(EObject eObject, String id)
{
EClass eClass = eObject.eClass();
EAttribute eIDAttribute = eClass.getEIDAttribute();
if (eIDAttribute == null)
{
throw new IllegalArgumentException("The object doesn't have an
ID feature.");
}
else if (id == null)
{
eObject.eUnset(eIDAttribute);
}
else
{
eObject.eSet(eIDAttribute,
createFromString(eIDAttribute.getEAttributeType(), id));
}
}
Martin Taal wrote:
> Mat,
> The relational database does not have a notion of resources. The way
> you read the objects in the resource determines there ordering and
> therefore the uri, if the uri is based on position.
> So it is a safer approach to use the concept of an EMF id. You can try
> to map the emf id notion to the same efeature as the database id.
> However, afaik (please correct me Ed if I am wrong) an EMF id is
> always a string while the database id can be something else
> (auto-increment long or something). This can be workarounded pretty
> easily by having a separate EMF id and database id efeature and
> keeping the EMF id in sync with the database id.
>
> gr. Martin
>
> Ed Merks wrote:
>> Mat,
>>
>> URIs are how EMF references other objects in general so this is a
>> more general question. The URI consists of the <base>#<fragment>
>> where the base identifies the resource containing the object and the
>> fragment identifies the object within that resource. If you actually
>> moved the object to a new resource, then clearly the base could
>> change. The fragment might well be a fragment path, so if the object
>> moved within the tree structure of the resource, then that path could
>> change. If the fragment is just an ID/UUID, then it won't change no
>> matter how the object is moved around within its resource. The URI
>> should generally not change arbitrarily unless you move or change the
>> object. I assume this is the case for how Teneo uses URIs as well...
>>
>>
>> Mat Lo wrote:
>>> Hi
>>>
>>> Are we ensured that the URI of an object will remain the same during
>>> all its life cycle ? I mean, when I create a Marker on an EMF Object
>>> (that I identify with its URI, as EMF does in general), am I sure
>>> this URI will remain the same the next time I launch Eclipse ? When
>>> Teneo/Jpox builds EObjects while reading database, will all URIs be
>>> unique for each object and the same as the last time Teneo/Jpox read
>>> the database ?
>>>
>>> Thx
>>>
>
>
--------------000800040507010000000902
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Martin,<br>
<br>
EMF doesn't force the ID to be a string.
|
|
| | | | |
Re: Teneo : persistence of objects URI [message #60030 is a reply to message #60006] |
Fri, 03 November 2006 03:38  |
Eclipse User |
|
|
|
Mat,
You can do JDOHelper.getObjectId(Object obj).
gr. Martin
Mat Lo wrote:
> thx again but I work on JPox, so the Hibernate solution is not useful.
> Is there a way with JPox to access the synthetic ID ?
>
--
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 : persistence of objects URI [message #594447 is a reply to message #58396] |
Fri, 20 October 2006 06:23  |
Eclipse User |
|
|
|
Mat,
URIs are how EMF references other objects in general so this is a more
general question. The URI consists of the <base>#<fragment> where the
base identifies the resource containing the object and the fragment
identifies the object within that resource. If you actually moved the
object to a new resource, then clearly the base could change. The
fragment might well be a fragment path, so if the object moved within
the tree structure of the resource, then that path could change. If the
fragment is just an ID/UUID, then it won't change no matter how the
object is moved around within its resource. The URI should generally
not change arbitrarily unless you move or change the object. I assume
this is the case for how Teneo uses URIs as well...
Mat Lo wrote:
> Hi
>
> Are we ensured that the URI of an object will remain the same during
> all its life cycle ? I mean, when I create a Marker on an EMF Object
> (that I identify with its URI, as EMF does in general), am I sure this
> URI will remain the same the next time I launch Eclipse ? When
> Teneo/Jpox builds EObjects while reading database, will all URIs be
> unique for each object and the same as the last time Teneo/Jpox read
> the database ?
>
> Thx
>
|
|
|
Re: Teneo : persistence of objects URI [message #594456 is a reply to message #58435] |
Fri, 20 October 2006 06:50  |
Eclipse User |
|
|
|
Mat,
The relational database does not have a notion of resources. The way you read the objects in the
resource determines there ordering and therefore the uri, if the uri is based on position.
So it is a safer approach to use the concept of an EMF id. You can try to map the emf id notion to
the same efeature as the database id. However, afaik (please correct me Ed if I am wrong) an EMF id
is always a string while the database id can be something else (auto-increment long or something).
This can be workarounded pretty easily by having a separate EMF id and database id efeature and
keeping the EMF id in sync with the database id.
gr. Martin
Ed Merks wrote:
> Mat,
>
> URIs are how EMF references other objects in general so this is a more
> general question. The URI consists of the <base>#<fragment> where the
> base identifies the resource containing the object and the fragment
> identifies the object within that resource. If you actually moved the
> object to a new resource, then clearly the base could change. The
> fragment might well be a fragment path, so if the object moved within
> the tree structure of the resource, then that path could change. If the
> fragment is just an ID/UUID, then it won't change no matter how the
> object is moved around within its resource. The URI should generally
> not change arbitrarily unless you move or change the object. I assume
> this is the case for how Teneo uses URIs as well...
>
>
> Mat Lo wrote:
>> Hi
>>
>> Are we ensured that the URI of an object will remain the same during
>> all its life cycle ? I mean, when I create a Marker on an EMF Object
>> (that I identify with its URI, as EMF does in general), am I sure this
>> URI will remain the same the next time I launch Eclipse ? When
>> Teneo/Jpox builds EObjects while reading database, will all URIs be
>> unique for each object and the same as the last time Teneo/Jpox read
>> the database ?
>>
>> Thx
>>
--
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 : persistence of objects URI [message #594467 is a reply to message #58449] |
Fri, 20 October 2006 07:07  |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------000800040507010000000902
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Martin,
EMF doesn't force the ID to be a string. As you can see in these
EcoreUtil methods, it will convert to and from a string representation
as necessary.
/**
* Returns the value of the object's ID attribute as a String.
* If the object has no ID attribute or the ID attribute is not
set, it returns <code>null</code>.
* @param eObject the object in question.
* @return the value of the object's ID attribute as a String.
* @see org.eclipse.emf.ecore.EAttribute#isID
* @see org.eclipse.emf.ecore.EClass#getEIDAttribute
* @see #setID(EObject, String)
*/
public static String getID(EObject eObject)
{
EClass eClass = eObject.eClass();
EAttribute eIDAttribute = eClass.getEIDAttribute();
return eIDAttribute == null || !eObject.eIsSet(eIDAttribute) ?
null : convertToString(
eIDAttribute.getEAttributeType(),
eObject.eGet(eIDAttribute));
}
/**
* Sets the value of the object's ID attribute according to the
value represented by the String.
* A <code>null</code> ID will unset the attribute rather than
setting it to <code>null</code>.
* @param eObject the object in question.
* @param id the String value of the new ID.
* @return the value of the object's ID attribute as a String.
* @throws IllegalArgumentException if the object has no ID attribute.
* @see #getID(EObject)
* @see org.eclipse.emf.ecore.EAttribute#isID
* @see org.eclipse.emf.ecore.EClass#getEIDAttribute
*/
public static void setID(EObject eObject, String id)
{
EClass eClass = eObject.eClass();
EAttribute eIDAttribute = eClass.getEIDAttribute();
if (eIDAttribute == null)
{
throw new IllegalArgumentException("The object doesn't have an
ID feature.");
}
else if (id == null)
{
eObject.eUnset(eIDAttribute);
}
else
{
eObject.eSet(eIDAttribute,
createFromString(eIDAttribute.getEAttributeType(), id));
}
}
Martin Taal wrote:
> Mat,
> The relational database does not have a notion of resources. The way
> you read the objects in the resource determines there ordering and
> therefore the uri, if the uri is based on position.
> So it is a safer approach to use the concept of an EMF id. You can try
> to map the emf id notion to the same efeature as the database id.
> However, afaik (please correct me Ed if I am wrong) an EMF id is
> always a string while the database id can be something else
> (auto-increment long or something). This can be workarounded pretty
> easily by having a separate EMF id and database id efeature and
> keeping the EMF id in sync with the database id.
>
> gr. Martin
>
> Ed Merks wrote:
>> Mat,
>>
>> URIs are how EMF references other objects in general so this is a
>> more general question. The URI consists of the <base>#<fragment>
>> where the base identifies the resource containing the object and the
>> fragment identifies the object within that resource. If you actually
>> moved the object to a new resource, then clearly the base could
>> change. The fragment might well be a fragment path, so if the object
>> moved within the tree structure of the resource, then that path could
>> change. If the fragment is just an ID/UUID, then it won't change no
>> matter how the object is moved around within its resource. The URI
>> should generally not change arbitrarily unless you move or change the
>> object. I assume this is the case for how Teneo uses URIs as well...
>>
>>
>> Mat Lo wrote:
>>> Hi
>>>
>>> Are we ensured that the URI of an object will remain the same during
>>> all its life cycle ? I mean, when I create a Marker on an EMF Object
>>> (that I identify with its URI, as EMF does in general), am I sure
>>> this URI will remain the same the next time I launch Eclipse ? When
>>> Teneo/Jpox builds EObjects while reading database, will all URIs be
>>> unique for each object and the same as the last time Teneo/Jpox read
>>> the database ?
>>>
>>> Thx
>>>
>
>
--------------000800040507010000000902
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Martin,<br>
<br>
EMF doesn't force the ID to be a string.
|
|
|
Re: Teneo : persistence of objects URI [message #595087 is a reply to message #58460] |
Thu, 02 November 2006 12:02  |
Eclipse User |
|
|
|
Originally posted by: mat.loo.gmail.com
Thanks for your answers.
I want to use Id automatically generated by Teneo (I don't want to add an
attribute to my eObjects and set it to "id").
Is there a way to access the id managed by Teneo (I saw it generates them
when no id is set in ECore model)
Thx again.
|
|
|
Re: Teneo : persistence of objects URI [message #595103 is a reply to message #59888] |
Thu, 02 November 2006 12:09  |
Eclipse User |
|
|
|
Mat,
I assume that eObject.eResource().getURIFragment(eObject) will return
the ID managed by the resource that contains the eObject.
Mat Lo wrote:
> Thanks for your answers.
>
> I want to use Id automatically generated by Teneo (I don't want to add
> an attribute to my eObjects and set it to "id").
> Is there a way to access the id managed by Teneo (I saw it generates
> them when no id is set in ECore model)
>
> Thx again.
>
|
|
|
Re: Teneo : persistence of objects URI [message #595109 is a reply to message #59888] |
Thu, 02 November 2006 13:46  |
Eclipse User |
|
|
|
Mat,
You can get to the synthetic id for an object through static methods of this class:
org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rCacheHandler
Note that these synthetic id's work with object equality (meaning a == b) so it won't work if your
objects are traveling over the net. In that case you need a real id feature.
gr. Martin
Mat Lo wrote:
> Thanks for your answers.
>
> I want to use Id automatically generated by Teneo (I don't want to add
> an attribute to my eObjects and set it to "id").
> Is there a way to access the id managed by Teneo (I saw it generates
> them when no id is set in ECore model)
>
> Thx again.
>
--
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 : persistence of objects URI [message #595130 is a reply to message #60006] |
Fri, 03 November 2006 03:38  |
Eclipse User |
|
|
|
Mat,
You can do JDOHelper.getObjectId(Object obj).
gr. Martin
Mat Lo wrote:
> thx again but I work on JPox, so the Hibernate solution is not useful.
> Is there a way with JPox to access the synthetic ID ?
>
--
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
|
|
|
Goto Forum:
Current Time: Sat May 03 14:13:56 EDT 2025
Powered by FUDForum. Page generated in 0.05607 seconds
|