Author Topic: method.Parameters.AddNew("...", "...") fails consistently  (Read 5405 times)

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
method.Parameters.AddNew("...", "...") fails consistently
« on: March 24, 2017, 12:43:02 am »
Hi all,
(Edit: EA 12.1)
For some reason adding method parameters into new classes & methods fails consistently during (import from text file). When I look at the db tables (t_operationparams) I noticed that the parameters end up in the table, but no OperationID is ever assigned (or, the params  are not actually attached to the method it seems). Classes and Methods are successfully created though (at least they show up in the model treeview).

This code (with valid string data, see log text below)

Code: [Select]
Private Sub CreateSignature(ByRef aMethod, aSignatureString)
Dim ParamObj As EA.Parameter
''' blah blah
For i = 0 to UBound(arr)
''' Blah, blah
sType = EnsuredTypeName(sType)
Set ParamObj = aMethod.Parameters.AddNew(sName, sType)
''' Blah, blah
LogForced "----------------------------"
LogForced "Parameter Name: " + sName
LogForced "Parameter Type: " + sType
if ParamObj.Update() = False then _
LogForced "#### Error creating Parameter: " + ParamObj.Name
Next
aMethod.Parameters.Refresh
aMethod.Update()
End Sub

... results in consistent errors, like so:


Code: [Select]
[410218891]      14:18:18: ----------------------------
[410218892]      14:18:18: Parameter Name: val
[410218892]      14:18:18: Parameter Type: System.Drawing.Font
[410218900]      14:18:18: #### Error creating Parameter: val
[410218922]      14:18:18: ----------------------------
[410218922]      14:18:18: Parameter Name: key
[410218923]      14:18:18: Parameter Type: String
[410218931]      14:18:18: #### Error creating Parameter: key
[410218936]      14:18:18: ----------------------------

Tables looking like this:


Not one single parameter (out of several hundred) is successfully added to any method. Any ideas about where to look for the problem?

Scratching head.

// Rolf
« Last Edit: March 24, 2017, 12:48:18 am by RIL »
-- There's always a solution --

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #1 on: March 24, 2017, 01:06:07 am »
Solved.

Apparently the method must be "updated" before adding parameters. I added "MethodObj.Update()" before creating the parameters, and now it works.

Code: [Select]
Set MethodObj = aClass.Methods.AddNew(aMethodName, aResultType)
--> if not MethodObj.Update() then _
--> Forcelog "Method '" + aMethodName + "' failed during create."
CreateSignature MethodObj, aSignature
-- There's always a solution --

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11819
  • Karma: +458/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #2 on: March 24, 2017, 03:05:18 am »
You beat me to it.
Yes, the operation needs to exist in the DB before you can add parameters.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7718
  • Karma: +101/-18
    • View Profile
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #3 on: March 24, 2017, 08:18:49 am »
It looks like you'll benefit from running a data integrity check. At least I hope that will find all the operation parameters without a valid operation.
Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #4 on: March 24, 2017, 08:56:40 pm »
Thank you all for your replies.

It looks like you'll benefit from running a data integrity check... will find all the operation parameters without a valid operation.
I'm working on a new import script, so I regenerate the whole thing from start, no problem. While testing my code I manually emptied the operation & operation parameter table

It works fine now, except for lookups of Classes being very slow (checking if class exist, since I must import in different runs from different sources files). I've got some 400 classes and 14.000 class members to import, so it takes tiiiime....

Is there a good way to speed up lookups?

// Rolf

-- There's always a solution --

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11819
  • Karma: +458/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #5 on: March 24, 2017, 11:14:00 pm »
Use SQL to do quick lookups.

Geert

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #6 on: March 26, 2017, 05:58:08 am »
Use SQL to do quick lookups.

Thanks, got the Repository.SQLQuery working (fetched an Element "Object_ID" from t_object)

Besides the XML result from SQLQuery, I also tried assigning the result  to a collection, like so:

Code: [Select]
Dim coll
Set coll = GetElementSet(sql, 1)

... but I don't know how I can make use of this result since the resulting single collection item seems to be an object reference(?). I'm obviously not getting how to use VBScript collections since id =  Coll(0) doesn't return the ID. :-[ ... 

// Rolf
-- There's always a solution --

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11819
  • Karma: +458/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #7 on: March 26, 2017, 05:56:16 pm »
You either use GetElementSet or SQLQuery, no need to use both.

In case of GetEelementset use "2" for the second parameter if you are  going to pass an SQL string.
And you'll have to pass the guid AS CLASSGUID for it to work.

Geert

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #8 on: March 26, 2017, 06:36:24 pm »
You either use GetElementSet or SQLQuery, no need to use both.

Yes, I was just curious to try the other alternative as suggested by Simon (extracting the value from xml doesn't seem optimal).

Have a nice weekend.

// Rolf
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7718
  • Karma: +101/-18
    • View Profile
Re: method.Parameters.AddNew("...", "...") fails consistently
« Reply #9 on: March 27, 2017, 11:48:36 am »
... but I don't know how I can make use of this result since the resulting single collection item seems to be an object reference(?). I'm obviously not getting how to use VBScript collections since id =  Coll(0) doesn't return the ID. :-[ ... 
It's an EA.Collection.

Use it the same way you would use Package.Elements, but it has preloaded all the elements in advance.
Eve

support@sparxsystems.com