Book a Demo

Author Topic: Create connector-note  (Read 4790 times)

ch

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Create connector-note
« on: July 04, 2008, 12:30:36 am »
Hey,
I want to create a note to a connector from java.

Element s = elements.GetByName("myClass");      
Collection<Connector> conn = s.GetConnectors();
Connector c = conn.AddNew("myConn", "Composition");
c.SetSupplierID(idSupp);
c.Update();

How can I create a note to this connector?
Can somebody help?
Thanks
« Last Edit: July 04, 2008, 12:30:52 am by leene »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create connector-note
« Reply #1 on: July 04, 2008, 04:08:03 am »
I'm not really sure, since I used to do this by directly tweaking the database.

[If anyone knows of a way to set this up directly through the API please chime in.]

Try creating a Note element, and setting its Subtype to 1 (note this is a Long value). Then you need to get the PDATA4 field to include the string "idref=<cid>;" (without quotes, but with the trailing semicolon. The <cid> string should be the connector ID of the connector you need to attach to. To attach the note to multiple connectors, repeat the entire sequence for each connector ID.

You can read, but not write this field with the MiscData(3) property of your note element. I do not know if you can set the field contents directly through the EA API. Perhaps a 'special' property would link to this field (as well as the CustomProperties or Properties collections), but I don't think so.

If you've got a Java ODBC or OLEDB driver, you can use the Repository.ConnectionString property to retrieve the connection string for the currently open project. [In the case of an EAP file this might return only the file name.] You could then tweak the PDATA4 field yourself.

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

ch

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Create connector-note
« Reply #2 on: July 04, 2008, 04:30:46 pm »
Hmm,
thats bad :-(
I need a solution with the API. Is there a chance to create constraints?
I tried:

Collection<ConnectorConstraint> con = c.GetConstraints();
ConnectorConstraint cc = con.AddNew("constraintName", "");
cc.SetNotes("constraintNotes");
cc.Update();

But nothing happens - neither in diagram nor in connector->properties->constraints.

Thanks!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create connector-note
« Reply #3 on: July 04, 2008, 09:29:24 pm »
First thing, and this is important...

Please note that I first fooled around with this aspect of the API since EA 4.1, and much has changed. At that time I needed to do some (really) fancy footwork because EA used to open EAP files for exclusive access (it no longer does). I wrote a second thread to open and close the database as well as insert the necessary text fields (as above).

Once EA started opening EAP files for shared access - around version 5.0 - I cleaned up my code a bit and left it at that.

The bottom line is that there may be another way of going about this, without stepping outside of the 'basic' API. For all I know it might have been there all the time.

Perhaps someone will let us know, so mark this thread to alert you on new posts.

Meanwhile... [See next]

David

[edit]While you are waiting, take the time to search the forum. This general subject area has been discussed, but not often and not recently. Still, there might have been a solution since I stopped looking for one.[/edit]
« Last Edit: July 04, 2008, 09:44:20 pm by Midnight »
No, you can't have it!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create connector-note
« Reply #4 on: July 04, 2008, 09:42:55 pm »
Until we learn of an easy way out...

Constraint on multiple connectors work just like notes do. That is, EA does not treat them as "connector constraints" in the sense of a constraint on a single connector. It treats them as (almost) the same kind of 'special' case as it does notes on links.

What EA does internally is almost the same as with notes. It creates a new element with a Type attribute of "Constraint" and adds this to the t_object table. The Subtype attribute is left as 0 (the default).

NOTE: This is not the same as adding a constraint to an element or a connector. In either of these cases an entry is made in a different table (t_elementconstraint or t_connectorconstraint) and the constraint shows up in the Constraints collection of the entity concerned. [I don't know if 'shared' constraints of the type you are thinking of will show up in these collections; my guess is that they do not.] While we're on the subject, you can also add constraints to roles and attributes and such. If you tweak the database be aware that you for attributes (I think this is the only case) the table name is plural: t_attributeconstraints). This can wreck havoc with 'smart' coding of table names.

Meanwhile, back to our core problem. The rest of the new 'shared' constraint is simple. The 'sort' of constraint (to avoid using the word "Type" since it is an attribute of the Element class) is identified by setting the Stereotype attribute of the new constraint. [So we'd have a Constraint element with a stereotype of "Invariant" (note the leading capital letter), for example.

As for connecting the new constraint to links, that's done just as before, using the same syntax in the PDATA4 field.

Sigh...

So we continue to wait for a solution.

David
No, you can't have it!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create connector-note
« Reply #5 on: July 04, 2008, 09:58:51 pm »
And here's a long shot, but it just might work. [And you won't be any worse off if it doesn't.]

You can define custom search queries in EA. It used to be that if you inserted some of your own SQL - paying attention to how EA set up the search - you could (with some limits) write an Update query into your search. I think these worked with EAP files, but you'll have to check. [Hint: Check out the SQL Editor in EA help.]

This was the subject of a few forum threads a long time ago, so you need to search all posts. I have no idea if it is still possible, but I don't remember this being explicitly 'plugged' by Sparx. I think it was treated as a convenient side effect, but there was no sense of it being either a bug or a feature.

If you can still do this you might be in luck. You can run a search query from EA, via the Repository.RunModelSearch method. Maybe that would work.

You can also directly execute SQL query from the API. Be careful when doing this, since the consequences of errors are dire.

Take a look at the Repository.SQLQuery method. The documentation says it works with "select statements" but I do not know if it enforces this. It is probably worth a shot. [It might enforce this, since it probably parses the statement to assemble a field list to set up the return values.]

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Create connector-note
« Reply #6 on: July 07, 2008, 08:15:46 am »
Quote
Please note that I first fooled around with this aspect of the API since EA 4.1, and much has changed. At that time I needed to do some (really) fancy footwork because EA used to open EAP files for exclusive access (it no longer does). I wrote a second thread to open and close the database as well as insert the necessary text fields (as above).

Once EA started opening EAP files for shared access - around version 5.0 - I cleaned up my code a bit and left it at that.
Since at least 4.0 (and probably before then) the Desktop edition has opened eap files for exclusive access while the professional and corporate editions have allowed for shared models.  This hasn't changed to my knowledge, and is documented as part of the limitation for the desktop edition.  (http://www.sparxsystems.com.au/products/ea/editions.html)