From: Lars H. <he...@se...> - 2009-11-03 13:47:50
|
Hi Christian, > i tried to merge two topic maps and received an IdentityConstraintException > because the same identifier was added to two different topics which in my > opinion is correct behaviour according to the TMDM. > So I wrote the following test program where I added the same subject > identifier to two different topics which should be merged by the engine. The > result was the same exception. Am I missing something? Thanks for your e-mail. tinyTiM does not merge topics automatically. That means, the IdentityConstraintException is correct. You can always catch is and merge topics manually: Topic topic1 = testMap.createTopicBySubjectIdentifier(testMap.createLocator(test_locator)); topic1.createName("Test1"); Topic topic2 = testMap.createTopic(); topic2.createName("Test2"); try { topic2.addSubjectIdentifier(testMap.createLocator(test_locator)); catch (IdentityConstraintException ex) { Topic existing = (Topic) ex.getExisting(); topic2.mergeIn(existing); } An alternative, and much better approach would be: Topic topic1 = testMap.createTopicBySubjectIdentifier( testMap.createLocator(test_locator)); topic1.createName("Test1"); Topic topic2 = testMap.createTopicBySubjectIdentifier(test_locator); topic2.createName("Test2"); Here, topic2 would be equals to topic1 since the engine ensures that it either returns an existing topic with the provided subject identifier or creates a topic with that subject identifier in the "TopicMap.createTopicBySubjectIdentifier" method. TMAPI 2.0 supports also "createTopicByItemIdentifier" and "createTopicBySubjectLocator" with the same semantics. Best regards, Lars -- Semagia <http://www.semagia.com> |