Book a Demo

Author Topic: Java: Creating associations does not work any more  (Read 3741 times)

paphko

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Java: Creating associations does not work any more
« on: March 06, 2008, 02:52:47 am »
Hi!

I use the following code to create a new connector using Java and the automation interface. This works in Versions 6 and 6.5 but failes in version 7. Any idea? Did they change something in the new version?

Code: [Select]
...
Collection collection = eaElement.GetConnectors();
Connector newEaConnector = (Connector)collection.AddNew("conn", "Association");
newEaConnector.SetName("conn");
newEaConnector.SetNotes("generated");
newEaConnector.Update(); // <--- here an Exception occurs in v7
collection.Refresh();
...

Bye!
Patrick

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Java: Creating associations does not work any
« Reply #1 on: March 06, 2008, 03:16:26 am »
Patrick,

This might not be a bug. In fact it might be evidence that a bug has been repaired.

You seem to be creating a single-ended connector. For quite some time - since before EA 5.0 - the COM API has required you to designate both ends of a connector (at least the ones I've tried) before you do the initial Update. If you do not do so EA throws an exception.

It sounds like the Java API is working like the COM API, which is the way things are supposed to be.

David
No, you can't have it!

paphko

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Java: Creating associations does not work any
« Reply #2 on: March 06, 2008, 07:15:13 pm »
Yes, thank you!
Setting both connector ends before calling Update() did the trick.  :)

But I have to implement both ways to make my tool compatible to all versions  ;)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Java: Creating associations does not work any
« Reply #3 on: March 06, 2008, 11:14:48 pm »
Perhaps you need to handle both ways, but think twice before you go too far.

The requirement for both ends has been around for some time. Why you were able to handle it the other way I don't know. What I suspect is that this was a hole, perhaps only in the Java interface. If you later had an exception (or something) that prevented the other connector end from being 'attached' you would likely end up with an orphan record in the EA schema. Generally this is not a big issue, and it should be corrected by running a Project Integrity Check. But in the meantime I have seen some nasty surprises when orphaned connectors are encountered. This usually happens in automation projects - it is quite difficult for a user to encounter one, since they don't show up on diagrams or the Project Browser - where it can be quite difficult to diagnose.

So my guess is that if you have older code that works the other way, think about correcting that version. Keep the new version simple. If you cannot do that, make sure you wrap your 'alternate' method in an outer transaction. That way you can roll back the connector (the first 'end' thereof) if you have an exception before you've got the second 'end' attached.

David
No, you can't have it!

paphko

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Java: Creating associations does not work any
« Reply #4 on: March 07, 2008, 01:54:55 am »
Hi David,

thanks for the warning. IMO you should always set both ends of a connector explicitly if you create one. This is what I do, only later. And I needed to call Update() in previous versions because the ConnectorEnd objects were only available after that call. As I have seen, this also changed in version 7 - they are available right away now  :)