Book a Demo

Author Topic: max length of OCL constraint or precondition?  (Read 7585 times)

PY

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • I love Python
    • View Profile
max length of OCL constraint or precondition?
« on: January 08, 2008, 12:38:26 am »
Hello,
using automation I am filling very long expressions in OCL constraint/precondition fields for some methods and attributes (not of my choice, we are doing reverse engineering)

It works fine by short expressions (e.g. 30 characters) but not at longer ones (100 or more characters)... is there any know limitation?

thanks for any help in advance,

Pablo
« Last Edit: January 08, 2008, 12:47:34 am by PY »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #1 on: January 08, 2008, 04:15:05 am »
Hi Pablo,

I don't know if I can help; your explanation of the problem is a bit vague.

What specifically is happening? And what are you doing at the time?

David
No, you can't have it!

PY

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • I love Python
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #2 on: January 08, 2008, 04:32:26 am »
Hi  David,

ok. I will try to be clearer.

lets say I have two OCL expressions:
(by now the content and syntax is not important, just the length)

myOCL1 = 'aaaaa'

myOCL2 = 'bbbbbbbbbbbbbbbbbbbbbbbcdsfsfbbbbbbbsdfsdbbbbbbbbbbbsfbbb'

# make it even longer...

then I call the following in my program using both variables like here:

....
theOCL = aNode.Constraints.AddNew(myOCL1 ,'OCL')
if not theOCL.Update:
   ... raise error
     
aNode.Constraints.Refresh
....

where aNode is a variable (Attribute in EA-API jargon)

after calling this using myOCL1 and doing all that refreshing stuff, I check under Attribute Properties -> Constraints and I can find there as expected the whole myOCL1.

But by using myOCL2 there is nothing there.

hope this is clearer now, otherwise let me know.

EA version: 7.0.818

thanks for any help!

Pablo





« Last Edit: January 08, 2008, 05:10:27 am by PY »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #3 on: January 08, 2008, 05:01:22 am »
OK Pablo,

I think I see it now.

The AddNew function is used throughout EA, and sometimes gets a bit 'bent' to do the appropriate thing. In general, the first parameter is the type of the thing you're adding, and the second is the name. Of course the collection itself helps specify the type so sometimes that parameter is relaxed a bit. As well, the name parameter may be ignored or treated differently by different collections.

But...

You are always attempting to add a constraint called OCL to the collection, with a type that's dictated by the content of your variables (myOCLx). That's probably not being accepted by the collection, though for whatever reason the AddNew function (and Update) are not throwing an error.

Try just adding the constraint, providing a name and a type of 'Constraint' (case sensitive). Now try adding the rest of the data to the various properties of the resulting Constraint object. [Remember that AddNew returns an Object, which you'll have to cast appropriately.] Then do the Update.

BTW, constraint elements are stored in the EA schema in the t_objectconstraint table. [Attribute constraints have their own table, but it is similar.] Take a look at the structure of these tables - you can use one of the SQL files provided by Sparx or open an EAP file with Access - and you'll see that the Type field is 30 characters long. That's the one you are currently attempting to load your longer string into when you are calling AddNew.

HTH, David
No, you can't have it!

PY

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • I love Python
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #4 on: January 09, 2008, 01:28:59 am »
Hi David,
thanks for the hints, but in Help File -> the EA Object Model -> Code Samples -> Element Extras is just the opposite: first the Name of the constraint, then the Type?? by Attributes (Work with Attributes) and Methods it seems to be the same.... ???

it seems anyway it was a bug somewhere else in my program, now seems to be working, regardless of length of the expression. Was already thinking on moving all to notes...

regards,

Pablo








«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #5 on: January 09, 2008, 04:04:54 am »
Sorry Pablo, I did get the order wrong.

Regardless, you've got a 30 character limit on the field you're populating, which is causing the occasional problem with Update.

I think the actual text of the constraint - in whatever language - needs to go into the Notes field. Otherwise how would you handle a constraint with > 255 characters? Of course, who'd ever write an OCL block that long?   ;)

David
No, you can't have it!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #6 on: January 09, 2008, 04:08:08 am »
While we're on the subject...

Are you trying to access your constraint element right away? If you are trying to retrieve the element from its collection, you need to call a Refresh on the collection first. This is particularly important when you retrieve by iterating through the collection. The collection won't 'see' the elements until it is refreshed.

David
No, you can't have it!

PY

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • I love Python
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #7 on: January 09, 2008, 04:17:47 am »
Hi David,

well as said before we get that weird expressions doing some weird reverse engineering of some weird code.. :(

I also think it is safer to use Notes for that. maybe in the EA help the limit of the fields should be mentioned clearly for someone having same use cases like me (same applies f.e. to Tagged Values, where some colleagues are reporting some issues)

I check the Constraint Fields later on, and now is working :)

thanks for the promptly answers and have a good day,

Pablo



«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #8 on: January 09, 2008, 04:39:48 am »
Quote
...
I also think it is safer to use Notes for that. maybe in the EA help the limit of the fields should be mentioned clearly for someone having same use cases like me (same applies f.e. to Tagged Values, where some colleagues are reporting some issues)
...

Hi Pablo,

First, regarding tagged values. These are a bit of a special case. While the value portion can always be represented as a string, we often have a more specific use in mind. A common example is when the value should be a 2 or 3 state logical value. Many times we expect a short string with no real restrictions on content. However, sometimes the value should be taken from a list - in a management dashboard or traffic control application, a state might be "red," "yellow" or "green" but is unlikely to be "sponge" - or have some other constraints. Finally, the value could well be a BLOB of some kind.

EA allows you to define a 'type' for a tagged value. You can also define domains (lists) from which legal values may be taken. The definition and the field contents are somewhat interdependent. Look at the EA documentation for some help here. [I think there's a minor bug in the docs, so experiment a bit. Once you get the general idea you will be fine.]

Overall I am happy to hear that you seem to be getting results. But I am concerned that a solution that is 'magically' working now might just as magically revert back. When I encounter these I tend to put any time 'saved' back into finding out what's really happening and making sure I have the real solution.

David
No, you can't have it!

PY

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • I love Python
    • View Profile
Re: max length of OCL constraint or precondition?
« Reply #9 on: January 09, 2008, 04:58:03 am »
Hi David,

well, I found a bug  in my program as said before :( , so thats the real reason and by moving into Notes the whole stuff will be stable and robust.

regarding tagged values, we put there chunks of not yet fully classified information - apart from plain comments, OCL and etc, etc - that otherwise would get lost. That strings may be much longer than state labels, so some colleagues came across to similar length-issues.

However, the hint about domains is good, I guess we can make use of it. Thanks again. :)

Pablo