Author Topic: Change/Set the objectID  (Read 8226 times)

Kaspatoo

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Change/Set the objectID
« on: April 10, 2015, 10:45:26 pm »
Hello,

we have a classmodel and do something with automation on it. We are using the objectIds to do some hard code (its no option to change this way of work).

Sometimes we are going to update the classmodel by an external file (new classes/ attributes, some will go, most times any datatype or column changes). To be clean we are deleting the old class and create a completely new one. Due to new creation the objectID of that class changes. Its assigned by EA.

I am looking for a way to keep the old objectID for that class, so that our hard code will function in future.

The alternative ist to update the existing class. Thats a kind of dirty. We need then to make a full check for any difference between the old and the new class. If we would simply just change or add the data from the new class in the old one, then changes like removed data in the new class will be missing (e.g. a method has been deleted, the new class would still contain the method).

Thanks for any help.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change/Set the objectID
« Reply #1 on: April 11, 2015, 01:08:09 am »
Without understanding the whys and hows of your question: save the object_id, delete the class via API. Create the new via API. Replace the object_id with a SQL to be the old saved one. (And do the same for the guid since that is more important.)

q.

VKN

  • EA User
  • **
  • Posts: 187
  • Karma: +9/-1
    • View Profile
Re: Change/Set the objectID
« Reply #2 on: April 13, 2015, 10:41:39 am »
Quote
Replace the object_id with a SQL to be the old saved one. (And do the same for the guid since that is more important.)
q.
Can you replace the IDs with SQL? AutoNumber type?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change/Set the objectID
« Reply #3 on: April 13, 2015, 05:33:19 pm »
Good point. Any RDBMS can do that. Auto-counter are meant to set a value when the row is created and can be changed afterwards. Not so Mickeysoft's Access. Or maybe it's some restriction EA's Repository.Execute has. I tested with an EAP and yes, it's not possible to change Object_id :( I currently have no RDBMS setup for testing.

q.
« Last Edit: April 13, 2015, 05:34:11 pm by qwerty »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Change/Set the objectID
« Reply #4 on: April 14, 2015, 12:28:47 am »
Hello,


It's highly doubtful whether you'd be able to modify the numeric Element.ElementID (t_object.Object_ID).
It's read-only in the API, and attempting to modify it using raw SQL through Repository.Execute() gives an error message saying "3113 field not updatable", which indicates that it is indeed an AutoNumber field.

By contrast, you can change the GUID (t_object.ea_guid) using Execute() even though it too is read-only in the API (Element.ElementGUID).

So if you are able to modify your automation scripts to be hard-coded on the GUID as opposed to the numeric ID, you can then delete the old class, create a new one and set its GUID to the old one.

HTH.


/Uffe
« Last Edit: April 14, 2015, 12:39:48 am by Uffe »
My theories are always correct, just apply them to the right reality.

Kaspatoo

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Change/Set the objectID
« Reply #5 on: April 15, 2015, 08:42:03 pm »
so did I understand it right, that the object ID is not editable since it relates to an autonumber field in acess database and witihin microsoft access editing cells of an autonumbercolumns is not possible at no chance?

two thoughts then:
1) what if I transform my EAP to a repository, commonly mysql is used then, there it may would work, and then re-transform my EAP back to a local EAP. would this work?

2) could it be possible to edit the start value of that autonumber field before inserting a new class?

eg. I want to recreate a class with old object_id 12345.
I delete the old class, set the start-value of the autonumber field to 12345 and insert the new class.

I redo this for every class to recreate. Next time I may then set auto number start value to a lower value than 12345, later to a higher one.
At the very end I set the auto value to the old last maximum + 1.

Would this function or dont I have enought privileges to do that?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Change/Set the objectID
« Reply #6 on: April 15, 2015, 08:55:36 pm »
You have started on the wrong premises.
You cannot and should not use elementID that way. ElementID may change when exported/imported, or even using one of the maintance functions.
To uniquely identify an element you should use the GUID. That is guaranteed to never change, even when exporting to xmi and importing into another model.

I'm sorry, there is just no sane way to implement your requirements using element ID's.

Geert

Kaspatoo

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Change/Set the objectID
« Reply #7 on: April 15, 2015, 09:23:33 pm »
3) create new class wih new object ID
do an insert into by selecting the last inserted row BUT (and thats my problem I dont have a solution for) edit the object_id before inserting

doing insert with a self-defined value for tha autonumber column is possible, its just not updatable but creatable.


edit:
tried the following sucessfully, so that currently my preferred way:
- create all classes as "usual"
- identify the classes and run for every the following sqls:
  - INSERT INTO t_object SELECT '123456' as object_id, field1, field2, ..., '{AAAA-1111-2222-...} as ea_guid, fieldn FROM t_object WHERE object_id = 234567;
 - delete from t_object where object_id = 234567;

What I do not know is, whether there are some triggers which will notice that and will do something in other tables.
« Last Edit: April 15, 2015, 09:41:36 pm by Kaspatoo »

Kaspatoo

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Change/Set the objectID
« Reply #8 on: April 15, 2015, 09:26:42 pm »
Quote
...

thanks for answer, and I understand, but I did not invented our code I am just the one who has to maintain it.
Thats why I now am looking for an "un-sane" way.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change/Set the objectID
« Reply #9 on: April 15, 2015, 10:06:37 pm »
I'm feeling with you  :-X

EA does not use any triggers. You are free to add them on your own but of course then the DB backend needs special treatment in case of migration, backup, etc.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Change/Set the objectID
« Reply #10 on: April 15, 2015, 11:06:42 pm »
Quote
Quote
...

thanks for answer, and I understand, but I did not invented our code I am just the one who has to maintain it.
Thats why I now am looking for an "un-sane" way.
If I were in your shoes I would tell your boss that the only option is to rewrite part of the code because of these wrong premises.
It will save you and your boss a lot of headaches and money in the long run. (and probably in the short run too)

Quick and Dirty -> Almost always dirty, almost never quick  :-X

Geert