我有两个版本的 EMF 实例,它们基于相同的 ecore 模型。我需要按照以下格式准备从 v1 更改为 v2 的内容列表
对于模型中的每个对象对象名称:修改属性:添加属性:删除属性:
这些 emf 实例文件中的每一个实际上都是数据库数据的表示。用户不直接更改数据库,但他们更改了 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{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
d.getKind(): DELETE
d.getMatch(): MatchSpec{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED