0
我有两个版本的基于同一个ecore模型的EMF实例。我需要准备的东西,从V1改变以以下格式与EMF的EMF模型比较
到v2对于模型中的 对象名称的每个对象的列表: 修改的属性: 添加的属性: 删除属性:
每这些emf实例文件实际上是DB数据的表示。用户不直接更改数据库,但他们更改emf实例文件。该工具需要识别这些更改,然后需要生成必要的DML语句。欣赏是否可以介绍如何实现这个伪代码,或者是否有更好的选择。下面是代码我现在有
public Comparison compare()
{
// Load the two input models
ResourceSet resourceSet1 = new ResourceSetImpl();
ResourceSet resourceSet2 = new ResourceSetImpl();
String xmi1 = "src/test/java/com/equifax/ic/provisioning/service/v1.xmi";
String xmi2 = "src/test/java/com/equifax/ic/provisioning/service/v2.xmi";
load(xmi1, resourceSet1);
load(xmi2, resourceSet2);
// Configure EMF Compare
EMFCompare comparator = EMFCompare.builder().build();
// Compare the two models
IComparisonScope scope = EMFCompare.createDefaultScope(resourceSet1, resourceSet2);
return comparator.compare(scope);
}
@Test
public void testCompare()
{
Comparison comparison = compare();
List<Diff> differences = comparison.getDifferences();
for(Diff d: differences)
{
System.err.println("d.getKind(): "+d.getKind());
System.err.println("d.getMatch(): " + d.getMatch());
System.err.println("State: " + d.getState());
}
assertSame(Integer.valueOf(12), Integer.valueOf(differences.size()));
}
输出
d.getKind(): ADD
d.getMatch(): MatchSpec{[email protected] Application Processed, [email protected] Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
d.getKind(): DELETE
d.getMatch(): MatchSpec{[email protected] Application Processed, [email protected] Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
您能否准确地告诉我们您期待的输出结果?你在这里展示的是比较你的XMI文件的预期结果吗? – Kellindil 2013-04-09 08:04:38
@Kellindil我期望每个模型对象的所有更改的列表,以便我可以根据差异生成SQL插入,更新和删除。 – 2013-04-09 13:44:16