Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » autoincremented id
autoincremented id [message #415199] Wed, 05 December 2007 07:44 Go to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hello,

For my GMF editor I want to add a autoincremented id for my Step object.

The step object has a name, which was basically used as ID. Since this
name may contain spaces it is no suitable anymore. My idea is now to have
an additional EAttribute ID for the Step EClass. This id may not be set by
the user but is set automatically.

So in the ecore model I would set the properties, unique ture and
unsettable true. But how can I set the id programmatically? Where do I
have to do this? In the StepItemProvider?

Thanks.

Marsha
Re: autoincremented id [message #415202 is a reply to message #415199] Wed, 05 December 2007 12:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marsha,

It's quite easy to define an EDataType that wraps java.lang.String and
encodes non-NCName characters in some fashion, i.e., you might encode
space as _. and _ as __. Then you can use that as the type of your ID
attribute. This seems better if you know those things are unique within
the resource.

The unique property only has significance for a multi-valued property in
which case is specifies that the same value can't appear more than
once. Unsettable likely doesn't mean what you assume either. It
doesn't mean you can't set it but rather than there is a meaningful
difference between the feature's value being in the default state verses
having been explicitly set to a value that's the same as the default
value, i.e., it adds one additional state to the set of states a feature
can take on. And you don't want to make it unchangeable, since you need
to read it in from a serialization. You don't want to just let the
resource assign an ID for you? If you specialize
XMLResourceImpl.useUUIDs to return true, unique IDs will be generated
for you...


Marsha wrote:
> Hello,
>
> For my GMF editor I want to add a autoincremented id for my Step object.
>
> The step object has a name, which was basically used as ID. Since this
> name may contain spaces it is no suitable anymore. My idea is now to
> have an additional EAttribute ID for the Step EClass. This id may not
> be set by the user but is set automatically.
>
> So in the ecore model I would set the properties, unique ture and
> unsettable true. But how can I set the id programmatically? Where do I
> have to do this? In the StepItemProvider?
>
> Thanks.
>
> Marsha
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: autoincremented id [message #415205 is a reply to message #415202] Wed, 05 December 2007 12:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Ed,

Thank you for your promt answer. I haven't thought of wrapping the
java.lang.String Class yet, but this is a good idea.

I can't find that XMLResourceImpl.useUUIDs in my classes that were
generated with GMF. Do I have to add it? Or is this a configuration of the
genmodel? How do I have to configure my ID EAttribute in that case? The
IDs that get generated are these of the form \\@object.0 etc.?

Thank you.

Marsha


Ed Merks wrote:

> Marsha,

> It's quite easy to define an EDataType that wraps java.lang.String and
> encodes non-NCName characters in some fashion, i.e., you might encode
> space as _. and _ as __. Then you can use that as the type of your ID
> attribute. This seems better if you know those things are unique within
> the resource.

> The unique property only has significance for a multi-valued property in
> which case is specifies that the same value can't appear more than
> once. Unsettable likely doesn't mean what you assume either. It
> doesn't mean you can't set it but rather than there is a meaningful
> difference between the feature's value being in the default state verses
> having been explicitly set to a value that's the same as the default
> value, i.e., it adds one additional state to the set of states a feature
> can take on. And you don't want to make it unchangeable, since you need
> to read it in from a serialization. You don't want to just let the
> resource assign an ID for you? If you specialize
> XMLResourceImpl.useUUIDs to return true, unique IDs will be generated
> for you...


> Marsha wrote:
>> Hello,
>>
>> For my GMF editor I want to add a autoincremented id for my Step object.
>>
>> The step object has a name, which was basically used as ID. Since this
>> name may contain spaces it is no suitable anymore. My idea is now to
>> have an additional EAttribute ID for the Step EClass. This id may not
>> be set by the user but is set automatically.
>>
>> So in the ecore model I would set the properties, unique ture and
>> unsettable true. But how can I set the id programmatically? Where do I
>> have to do this? In the StepItemProvider?
>>
>> Thanks.
>>
>> Marsha
>>
Re: autoincremented id [message #415206 is a reply to message #415205] Wed, 05 December 2007 12:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050302020903080100090008
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Marsha,

It looks like this:

protected boolean useUUIDs()
{
return false;
}

With this approach, you don't need to have IDs in your model. The
resource will maintain them for you.


Marsha wrote:
> Hi Ed,
>
> Thank you for your promt answer. I haven't thought of wrapping the
> java.lang.String Class yet, but this is a good idea.
>
> I can't find that XMLResourceImpl.useUUIDs in my classes that were
> generated with GMF. Do I have to add it? Or is this a configuration of
> the genmodel? How do I have to configure my ID EAttribute in that
> case? The IDs that get generated are these of the form \\@object.0 etc.?
> Thank you.
>
> Marsha
>
>
> Ed Merks wrote:
>
>> Marsha,
>
>> It's quite easy to define an EDataType that wraps java.lang.String
>> and encodes non-NCName characters in some fashion, i.e., you might
>> encode space as _. and _ as __. Then you can use that as the type of
>> your ID attribute. This seems better if you know those things are
>> unique within the resource.
>
>> The unique property only has significance for a multi-valued property
>> in which case is specifies that the same value can't appear more than
>> once. Unsettable likely doesn't mean what you assume either. It
>> doesn't mean you can't set it but rather than there is a meaningful
>> difference between the feature's value being in the default state
>> verses having been explicitly set to a value that's the same as the
>> default value, i.e., it adds one additional state to the set of
>> states a feature can take on. And you don't want to make it
>> unchangeable, since you need to read it in from a serialization. You
>> don't want to just let the resource assign an ID for you? If you
>> specialize XMLResourceImpl.useUUIDs to return true, unique IDs will
>> be generated for you...
>
>
>> Marsha wrote:
>>> Hello,
>>>
>>> For my GMF editor I want to add a autoincremented id for my Step
>>> object.
>>>
>>> The step object has a name, which was basically used as ID. Since
>>> this name may contain spaces it is no suitable anymore. My idea is
>>> now to have an additional EAttribute ID for the Step EClass. This id
>>> may not be set by the user but is set automatically.
>>>
>>> So in the ecore model I would set the properties, unique ture and
>>> unsettable true. But how can I set the id programmatically? Where do
>>> I have to do this? In the StepItemProvider?
>>>
>>> Thanks.
>>>
>>> Marsha
>>>
>
>


--------------050302020903080100090008
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">
Marsha,<br>
<br>
It looks like this:<br>
<blockquote><small>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: autoincremented id [message #415219 is a reply to message #415206] Wed, 05 December 2007 16:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Ed,

I don't have this method in my code, where to I have to add it?

Thanks

Marsha

Ed Merks wrote:

> Marsha,

> It looks like this:

> protected boolean useUUIDs()
> {
> return false;
> }

> With this approach, you don't need to have IDs in your model. The
> resource will maintain them for you.


> Marsha wrote:
>> Hi Ed,
>>
>> Thank you for your promt answer. I haven't thought of wrapping the
>> java.lang.String Class yet, but this is a good idea.
>>
>> I can't find that XMLResourceImpl.useUUIDs in my classes that were
>> generated with GMF. Do I have to add it? Or is this a configuration of
>> the genmodel? How do I have to configure my ID EAttribute in that
>> case? The IDs that get generated are these of the form \@object.0 etc.?
>> Thank you.
>>
>> Marsha
>>
>>
>> Ed Merks wrote:
>>
>>> Marsha,
>>
>>> It's quite easy to define an EDataType that wraps java.lang.String
>>> and encodes non-NCName characters in some fashion, i.e., you might
>>> encode space as _. and _ as __. Then you can use that as the type of
>>> your ID attribute. This seems better if you know those things are
>>> unique within the resource.
>>
>>> The unique property only has significance for a multi-valued property
>>> in which case is specifies that the same value can't appear more than
>>> once. Unsettable likely doesn't mean what you assume either. It
>>> doesn't mean you can't set it but rather than there is a meaningful
>>> difference between the feature's value being in the default state
>>> verses having been explicitly set to a value that's the same as the
>>> default value, i.e., it adds one additional state to the set of
>>> states a feature can take on. And you don't want to make it
>>> unchangeable, since you need to read it in from a serialization. You
>>> don't want to just let the resource assign an ID for you? If you
>>> specialize XMLResourceImpl.useUUIDs to return true, unique IDs will
>>> be generated for you...
>>
>>
>>> Marsha wrote:
>>>> Hello,
>>>>
>>>> For my GMF editor I want to add a autoincremented id for my Step
>>>> object.
>>>>
>>>> The step object has a name, which was basically used as ID. Since
>>>> this name may contain spaces it is no suitable anymore. My idea is
>>>> now to have an additional EAttribute ID for the Step EClass. This id
>>>> may not be set by the user but is set automatically.
>>>>
>>>> So in the ecore model I would set the properties, unique ture and
>>>> unsettable true. But how can I set the id programmatically? Where do
>>>> I have to do this? In the StepItemProvider?
>>>>
>>>> Thanks.
>>>>
>>>> Marsha
>>>>
>>
>>
Re: autoincremented id [message #415220 is a reply to message #415219] Wed, 05 December 2007 16:16 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marsha,

This method must exist in org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl
and you'd override it in your own derived class to return true. You'd
then need to register your own factory to create your specialized
resource. If you change the GenPackage's Resource Type property to XMI,
the scaffolding would be generated for you. Note that the plugin.xml
registration wouldn't appear unless you delete your MANIFEST.MF and
plugin.xml and regenerate them.


Marsha wrote:
> Hi Ed,
>
> I don't have this method in my code, where to I have to add it?
>
> Thanks
>
> Marsha
>
> Ed Merks wrote:
>
>> Marsha,
>
>> It looks like this:
>
>> protected boolean useUUIDs()
>> {
>> return false;
>> }
>
>> With this approach, you don't need to have IDs in your model. The
>> resource will maintain them for you.
>
>
>> Marsha wrote:
>>> Hi Ed,
>>>
>>> Thank you for your promt answer. I haven't thought of wrapping the
>>> java.lang.String Class yet, but this is a good idea.
>>>
>>> I can't find that XMLResourceImpl.useUUIDs in my classes that were
>>> generated with GMF. Do I have to add it? Or is this a configuration
>>> of the genmodel? How do I have to configure my ID EAttribute in that
>>> case? The IDs that get generated are these of the form \@object.0 etc.?
>>> Thank you.
>>>
>>> Marsha
>>>
>>>
>>> Ed Merks wrote:
>>>
>>>> Marsha,
>>>
>>>> It's quite easy to define an EDataType that wraps java.lang.String
>>>> and encodes non-NCName characters in some fashion, i.e., you might
>>>> encode space as _. and _ as __. Then you can use that as the type
>>>> of your ID attribute. This seems better if you know those things
>>>> are unique within the resource.
>>>
>>>> The unique property only has significance for a multi-valued
>>>> property in which case is specifies that the same value can't
>>>> appear more than once. Unsettable likely doesn't mean what you
>>>> assume either. It doesn't mean you can't set it but rather than
>>>> there is a meaningful difference between the feature's value being
>>>> in the default state verses having been explicitly set to a value
>>>> that's the same as the default value, i.e., it adds one additional
>>>> state to the set of states a feature can take on. And you don't
>>>> want to make it unchangeable, since you need to read it in from a
>>>> serialization. You don't want to just let the resource assign an
>>>> ID for you? If you specialize XMLResourceImpl.useUUIDs to return
>>>> true, unique IDs will be generated for you...
>>>
>>>
>>>> Marsha wrote:
>>>>> Hello,
>>>>>
>>>>> For my GMF editor I want to add a autoincremented id for my Step
>>>>> object.
>>>>>
>>>>> The step object has a name, which was basically used as ID. Since
>>>>> this name may contain spaces it is no suitable anymore. My idea is
>>>>> now to have an additional EAttribute ID for the Step EClass. This
>>>>> id may not be set by the user but is set automatically.
>>>>>
>>>>> So in the ecore model I would set the properties, unique ture and
>>>>> unsettable true. But how can I set the id programmatically? Where
>>>>> do I have to do this? In the StepItemProvider?
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Marsha
>>>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:SDO Java - EDataGraph - serialize-transmit (RMI/IIOP)-deserialize then access via *static* SDO API?
Next Topic:Fully qualified package name
Goto Forum:
  


Current Time: Tue Apr 23 17:14:55 GMT 2024

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

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

Back to the top